OpenShot Library | libopenshot-audio 0.2.0
juce_MPESynthesiserBase.cpp
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2017 - ROLI Ltd.
6
7 JUCE is an open source library subject to commercial or open-source
8 licensing.
9
10 The code included in this file is provided under the terms of the ISC license
11 http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12 To use, copy, modify, and/or distribute this software for any purpose with or
13 without fee is hereby granted provided that the above copyright notice and
14 this permission notice appear in all copies.
15
16 JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17 EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18 DISCLAIMED.
19
20 ==============================================================================
21*/
22
23namespace juce
24{
25
27 : instrument (new MPEInstrument)
28{
29 instrument->addListener (this);
30}
31
33 : instrument (inst)
34{
35 jassert (instrument != nullptr);
36 instrument->addListener (this);
37}
38
39//==============================================================================
44
49
50//==============================================================================
51void MPESynthesiserBase::enableLegacyMode (int pitchbendRange, Range<int> channelRange)
52{
53 instrument->enableLegacyMode (pitchbendRange, channelRange);
54}
55
57{
58 return instrument->isLegacyModeEnabled();
59}
60
62{
63 return instrument->getLegacyModeChannelRange();
64}
65
67{
68 instrument->setLegacyModeChannelRange (channelRange);
69}
70
72{
73 return instrument->getLegacyModePitchbendRange();
74}
75
77{
78 instrument->setLegacyModePitchbendRange (pitchbendRange);
79}
80
81//==============================================================================
86
91
96
97//==============================================================================
99{
100 instrument->processNextMidiEvent (m);
101}
102
103//==============================================================================
104template <typename floatType>
106 const MidiBuffer& inputMidi,
107 int startSample,
108 int numSamples)
109{
110 // you must set the sample rate before using this!
111 jassert (sampleRate != 0);
112
114 midiIterator.setNextSamplePosition (startSample);
115
116 bool firstEvent = true;
117 int midiEventPos;
119
120 const ScopedLock sl (noteStateLock);
121
122 while (numSamples > 0)
123 {
124 if (! midiIterator.getNextEvent (m, midiEventPos))
125 {
126 renderNextSubBlock (outputAudio, startSample, numSamples);
127 return;
128 }
129
130 auto samplesToNextMidiMessage = midiEventPos - startSample;
131
132 if (samplesToNextMidiMessage >= numSamples)
133 {
134 renderNextSubBlock (outputAudio, startSample, numSamples);
136 break;
137 }
138
139 if (samplesToNextMidiMessage < ((firstEvent && ! subBlockSubdivisionIsStrict) ? 1 : minimumSubBlockSize))
140 {
142 continue;
143 }
144
145 firstEvent = false;
146
149 startSample += samplesToNextMidiMessage;
150 numSamples -= samplesToNextMidiMessage;
151 }
152
153 while (midiIterator.getNextEvent (m, midiEventPos))
155}
156
157// explicit instantiation for supported float types:
158template void MPESynthesiserBase::renderNextBlock<float> (AudioBuffer<float>&, const MidiBuffer&, int, int);
159template void MPESynthesiserBase::renderNextBlock<double> (AudioBuffer<double>&, const MidiBuffer&, int, int);
160
161//==============================================================================
163{
164 if (sampleRate != newRate)
165 {
166 const ScopedLock sl (noteStateLock);
167 instrument->releaseAllNotes();
168 sampleRate = newRate;
169 }
170}
171
172//==============================================================================
174{
175 jassert (numSamples > 0); // it wouldn't make much sense for this to be less than 1
176 minimumSubBlockSize = numSamples;
177 subBlockSubdivisionIsStrict = shouldBeStrict;
178}
179
180} // namespace juce
Holds a resizable array of primitive or copy-by-value objects.
Definition juce_Array.h:60
This class represents an instrument handling MPE.
TrackingMode
The MPE note tracking mode.
This class represents the current MPE zone layout of a device capable of handling MPE.
Used to iterate through the events in a MidiBuffer.
Holds a sequence of time-stamped midi events.
Encapsulates a MIDI message.
void setPitchbendTrackingMode(TrackingMode modeToUse)
Set the MPE tracking mode for the pitchbend dimension.
virtual void handleMidiEvent(const MidiMessage &)
Handle incoming MIDI events (called from renderNextBlock).
bool isLegacyModeEnabled() const noexcept
Returns true if the instrument is in legacy mode, false otherwise.
MPEZoneLayout getZoneLayout() const noexcept
Returns the synthesiser's internal MPE zone layout.
void setZoneLayout(MPEZoneLayout newLayout)
Re-sets the synthesiser's internal MPE zone layout to the one passed in.
int getLegacyModePitchbendRange() const noexcept
Returns the pitchbend range in semitones (0-96) to be used for notes when in legacy mode.
void setLegacyModeChannelRange(Range< int > channelRange)
Re-sets the range of MIDI channels (1-16) to be used for notes when in legacy mode.
void setLegacyModePitchbendRange(int pitchbendRange)
Re-sets the pitchbend range in semitones (0-96) to be used for notes when in legacy mode.
void enableLegacyMode(int pitchbendRange=2, Range< int > channelRange=Range< int >(1, 17))
Puts the synthesiser into legacy mode.
void setTimbreTrackingMode(TrackingMode modeToUse)
Set the MPE tracking mode for the timbre dimension.
std::unique_ptr< MPEInstrument > instrument
void setPressureTrackingMode(TrackingMode modeToUse)
Set the MPE tracking mode for the pressure dimension.
Range< int > getLegacyModeChannelRange() const noexcept
Returns the range of MIDI channels (1-16) to be used for notes when in legacy mode.
virtual void setCurrentPlaybackSampleRate(double sampleRate)
Tells the synthesiser what the sample rate is for the audio it's being used to render.
void renderNextBlock(AudioBuffer< floatType > &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
Creates the next block of audio output.
void setMinimumRenderingSubdivisionSize(int numSamples, bool shouldBeStrict=false) noexcept
Sets a minimum limit on the size to which audio sub-blocks will be divided when rendering.
virtual void renderNextSubBlock(AudioBuffer< float > &outputAudio, int startSample, int numSamples)=0
Implement this method to render your audio inside.