45 voice->noteOnTime = lastNoteOnCounter++;
70 for (
auto*
voice : voices)
75 voice->notePressureChanged();
84 for (
auto*
voice : voices)
89 voice->notePitchbendChanged();
98 for (
auto*
voice : voices)
103 voice->noteTimbreChanged();
112 for (
auto*
voice : voices)
117 voice->noteKeyStateChanged();
126 for (
auto i = voices.size(); --i >= 0;)
128 auto*
voice = voices.getUnchecked (i);
143 for (
auto i = voices.size(); --i >= 0;)
144 voices.getUnchecked (i)->setCurrentSampleRate (
newRate);
161 for (
auto*
voice : voices)
163 if (!
voice->isActive())
193 usableVoicesToStealArray.clear();
195 for (
auto*
voice : voices)
199 usableVoicesToStealArray.add (
voice);
208 std::sort (usableVoicesToStealArray.begin(), usableVoicesToStealArray.end(),
Sorter());
210 if (!
voice->isPlayingButReleased())
229 for (
auto*
voice : usableVoicesToStealArray)
234 for (
auto*
voice : usableVoicesToStealArray)
239 for (
auto*
voice : usableVoicesToStealArray)
246 for (
auto*
voice : usableVoicesToStealArray)
271 usableVoicesToStealArray.ensureStorageAllocated (voices.size() + 1);
284 return voices [index];
290 voices.remove (index);
303 voices.removeObject (
voice);
316 for (
auto*
voice : voices)
334 for (
auto*
voice : voices)
336 if (
voice->isActive())
337 voice->renderNextBlock (buffer, startSample, numSamples);
345 for (
auto*
voice : voices)
347 if (
voice->isActive())
348 voice->renderNextBlock (buffer, startSample, numSamples);
A multi-channel buffer containing floating point audio samples.
Automatically locks and unlocks a mutex object.
This class represents an instrument handling MPE.
void releaseAllNotes()
Discard all currently playing notes.
Represents an MPE voice that an MPESynthesiser can use to play a sound.
MPENote getCurrentlyPlayingNote() const noexcept
Returns the MPENote that this voice is currently playing.
uint32 noteOnTime
This will be set to an incrementing counter value in MPESynthesiser::startVoice() and can be used to ...
bool isPlayingButReleased() const noexcept
Returns true if a voice is sounding in its release phase.
void removeVoice(int index)
Deletes one of the voices.
void reduceNumVoices(int newNumVoices)
Reduces the number of voices to newNumVoices.
virtual MPESynthesiserVoice * findFreeVoice(MPENote noteToFindVoiceFor, bool stealIfNoneAvailable) const
Searches through the voices to find one that's not currently playing, and which can play the given MP...
MPESynthesiser()
Constructor.
void stopVoice(MPESynthesiserVoice *voice, MPENote noteToStop, bool allowTailOff)
Stops a given voice and tells it to stop playing a particular MPENote (which should be the same note ...
void setCurrentPlaybackSampleRate(double newRate) override
Tells the synthesiser what the sample rate is for the audio it's being used to render.
void startVoice(MPESynthesiserVoice *voice, MPENote noteToStart)
Starts a specified voice and tells it to play a particular MPENote.
void notePressureChanged(MPENote changedNote) override
Will find any voice that is currently playing changedNote, update its currently playing note,...
void noteReleased(MPENote finishedNote) override
Stops playing a note.
void clearVoices()
Deletes all voices.
void addVoice(MPESynthesiserVoice *newVoice)
Adds a new voice to the synth.
~MPESynthesiser() override
Destructor.
virtual MPESynthesiserVoice * findVoiceToSteal(MPENote noteToStealVoiceFor=MPENote()) const
Chooses a voice that is most suitable for being re-used to play a new note, or for being deleted by r...
void noteTimbreChanged(MPENote changedNote) override
Will find any voice that is currently playing changedNote, update its currently playing note,...
void noteAdded(MPENote newNote) override
Attempts to start playing a new note.
MPESynthesiserVoice * getVoice(int index) const
Returns one of the voices that have been added.
void noteKeyStateChanged(MPENote changedNote) override
Will find any voice that is currently playing changedNote, update its currently playing note,...
virtual void turnOffAllVoices(bool allowTailOff)
Release all MPE notes and turn off all voices.
virtual void handleProgramChange(int, int)
Callback for MIDI program change messages.
void renderNextSubBlock(AudioBuffer< float > &outputAudio, int startSample, int numSamples) override
This will simply call renderNextBlock for each currently active voice and fill the buffer with the su...
void notePitchbendChanged(MPENote changedNote) override
Will find any voice that is currently playing changedNote, update its currently playing note,...
void handleMidiEvent(const MidiMessage &) override
Handle incoming MIDI events.
virtual void handleController(int, int, int)
Callback for MIDI controller messages.
static MPEValue from7BitInt(int value) noexcept
Constructs an MPEValue from an integer between 0 and 127 (using 7-bit precision).
Encapsulates a MIDI message.
int getChannel() const noexcept
Returns the midi channel associated with the message.
bool isProgramChange() const noexcept
Returns true if the message is a program (patch) change message.
bool isController() const noexcept
Returns true if this is a midi controller message.
int getControllerNumber() const noexcept
Returns the controller number of a controller message.
int getProgramChangeNumber() const noexcept
Returns the new program number of a program change message.
int getControllerValue() const noexcept
Returns the controller value from a controller message.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
This struct represents a playing MPE note.
@ keyDown
The note key is currently down (pressed).
@ off
The key is up (off).
@ keyDownAndSustained
The note key is down and sustained (by a sustain or sostenuto pedal).
uint8 initialNote
The MIDI note number that was sent when the note was triggered.
KeyState keyState
Current key state.
Derive from this class to create a basic audio generator capable of MPE.
virtual void handleMidiEvent(const MidiMessage &)
Handle incoming MIDI events (called from renderNextBlock).
virtual void setCurrentPlaybackSampleRate(double sampleRate)
Tells the synthesiser what the sample rate is for the audio it's being used to render.
double getSampleRate() const noexcept
Returns the current target sample rate at which rendering is being done.