117 return voices.add (newVoice);
132 return sounds.add (newSound);
161 for (
int i =
voices.size(); --
i >= 0;)
162 voices.getUnchecked (
i)->setCurrentPlaybackSampleRate (newRate);
178 bool firstEvent =
true;
183 while (numSamples > 0)
187 if (targetChannels > 0)
193 const int samplesToNextMidiMessage = midiEventPos - startSample;
195 if (samplesToNextMidiMessage >= numSamples)
197 if (targetChannels > 0)
212 if (targetChannels > 0)
213 renderVoices (outputAudio, startSample, samplesToNextMidiMessage);
216 startSample += samplesToNextMidiMessage;
217 numSamples -= samplesToNextMidiMessage;
226 for (
int i =
voices.size(); --
i >= 0;)
227 voices.getUnchecked (
i)->renderNextBlock (buffer, startSample, numSamples);
232 const int channel =
m.getChannel();
236 noteOn (channel,
m.getNoteNumber(),
m.getFloatVelocity());
238 else if (
m.isNoteOff())
240 noteOff (channel,
m.getNoteNumber(),
m.getFloatVelocity(),
true);
242 else if (
m.isAllNotesOff() ||
m.isAllSoundOff())
246 else if (
m.isPitchWheel())
248 const int wheelPos =
m.getPitchWheelValue();
252 else if (
m.isAftertouch())
256 else if (
m.isChannelPressure())
260 else if (
m.isController())
264 else if (
m.isProgramChange())
272 const int midiNoteNumber,
273 const float velocity)
276 for (
int i =
sounds.size(); --
i >= 0;)
285 for (
int j =
voices.size(); --
j >= 0;)
295 sound, midiChannel, midiNoteNumber, velocity);
302 const int midiChannel,
303 const int midiNoteNumber,
304 const float velocity)
306 if (voice !=
nullptr && sound !=
nullptr)
321 voice->
startNote (midiNoteNumber, velocity, sound,
330 voice->
stopNote (velocity, allowTailOff);
337 const int midiNoteNumber,
338 const float velocity,
339 const bool allowTailOff)
343 for (
int i =
voices.size(); --
i >= 0;)
352 if (sound->appliesToNote (midiNoteNumber)
353 && sound->appliesToChannel (midiChannel))
360 stopVoice (voice, velocity, allowTailOff);
369 for (
int i =
voices.size(); --
i >= 0;)
373 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
374 voice->
stopNote (1.0f, allowTailOff);
382 for (
int i =
voices.size(); --
i >= 0;)
386 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
392 const int controllerNumber,
393 const int controllerValue)
395 switch (controllerNumber)
399 case 0x43:
handleSoftPedal (midiChannel, controllerValue >= 64);
break;
404 for (
int i =
voices.size(); --
i >= 0;)
408 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
416 for (
int i =
voices.size(); --
i >= 0;)
421 && (midiChannel <= 0 || voice->isPlayingChannel (midiChannel)))
429 for (
int i =
voices.size(); --
i >= 0;)
433 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
446 for (
int i =
voices.size(); --
i >= 0;)
456 for (
int i =
voices.size(); --
i >= 0;)
475 wassert (midiChannel > 0 && midiChannel <= 16);
477 for (
int i =
voices.size(); --
i >= 0;)
494 wassert (midiChannel > 0 && midiChannel <= 16);
500 wassert (midiChannel > 0 && midiChannel <= 16);
505 int midiChannel,
int midiNoteNumber,
506 const bool stealIfNoneAvailable)
const
509 for (
size_t i = 0;
i <
voices.size(); ++
i)
517 if (stealIfNoneAvailable)
527 return v1->wasStartedBefore (*
v2) ? -1 : (
v2->wasStartedBefore (*v1) ? 1 : 0);
532 int ,
int midiNoteNumber)
const
549 for (
size_t i = 0;
i <
voices.size(); ++
i)
564 if (low ==
nullptr || note < low->getCurrentlyPlayingNote())
577 const int numUsableVoices = usableVoices.
size();
580 for (
int i = 0;
i < numUsableVoices; ++
i)
589 for (
int i = 0;
i < numUsableVoices; ++
i)
598 for (
int i = 0;
i < numUsableVoices; ++
i)
602 if (voice != low && voice != top && ! voice->
isKeyDown())
607 for (
int i = 0;
i < numUsableVoices; ++
i)
611 if (voice != low && voice != top)
#define CARLA_SAFE_ASSERT_RETURN(cond, ret)
Definition CarlaDefines.h:190
bool ensureStorageAllocated(const int minNumElements) noexcept
Definition Array.h:1004
int size() const noexcept
Definition Array.h:187
ElementType getUnchecked(const int index) const
Definition Array.h:228
int addSorted(ElementComparator &comparator, ParameterType newElement)
Definition Array.h:655
Definition AudioSampleBuffer.h:42
uint32_t getNumChannels() const noexcept
Definition AudioSampleBuffer.h:212
Definition MidiBuffer.h:176
void setNextSamplePosition(int samplePosition) noexcept
Definition MidiBuffer.cpp:203
bool getNextEvent(MidiMessage &result, int &samplePosition) noexcept
Definition MidiBuffer.cpp:226
Definition MidiBuffer.h:48
Definition MidiMessage.h:40
double sampleRate
Definition Synthesiser.h:610
bool sustainPedalsDown[17]
Definition Synthesiser.h:615
virtual void handleSoftPedal(int midiChannel, bool isDown)
Definition Synthesiser.cpp:491
virtual void handleSostenutoPedal(int midiChannel, bool isDown)
Definition Synthesiser.cpp:473
int lastPitchWheelValues[16]
Definition Synthesiser.h:562
virtual void renderVoices(AudioSampleBuffer &outputAudio, int startSample, int numSamples)
Definition Synthesiser.cpp:224
virtual void allNotesOff(int midiChannel, bool allowTailOff)
Definition Synthesiser.cpp:367
virtual ~Synthesiser()
Definition Synthesiser.cpp:99
virtual SynthesiserVoice * findVoiceToSteal(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber) const
Definition Synthesiser.cpp:531
void removeSound(int index)
Definition Synthesiser.cpp:135
virtual void handleSustainPedal(int midiChannel, bool isDown)
Definition Synthesiser.cpp:438
int minimumSubBlockSize
Definition Synthesiser.h:612
void setMinimumRenderingSubdivisionSize(int numSamples, bool shouldBeStrict=false) noexcept
Definition Synthesiser.cpp:145
Synthesiser()
Definition Synthesiser.cpp:86
void removeVoice(int index)
Definition Synthesiser.cpp:120
void clearVoices()
Definition Synthesiser.cpp:109
virtual void handleChannelPressure(int midiChannel, int channelPressureValue)
Definition Synthesiser.cpp:426
virtual void handlePitchWheel(int midiChannel, int wheelValue)
Definition Synthesiser.cpp:380
void stopVoice(SynthesiserVoice *, float velocity, bool allowTailOff)
Definition Synthesiser.cpp:326
void processNextBlock(AudioSampleBuffer &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
Definition Synthesiser.cpp:166
void setNoteStealingEnabled(bool shouldStealNotes)
Definition Synthesiser.cpp:140
uint32 lastNoteOnCounter
Definition Synthesiser.h:611
virtual void setCurrentPlaybackSampleRate(double sampleRate)
Definition Synthesiser.cpp:153
virtual void handleMidiEvent(const MidiMessage &)
Definition Synthesiser.cpp:230
bool shouldStealNotes
Definition Synthesiser.h:614
SynthesiserVoice * getVoice(int index) const
Definition Synthesiser.cpp:104
bool subBlockSubdivisionIsStrict
Definition Synthesiser.h:613
virtual void handleController(int midiChannel, int controllerNumber, int controllerValue)
Definition Synthesiser.cpp:391
virtual SynthesiserVoice * findFreeVoice(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber, bool stealIfNoneAvailable) const
Definition Synthesiser.cpp:504
virtual void noteOn(int midiChannel, int midiNoteNumber, float velocity)
Definition Synthesiser.cpp:271
void startVoice(SynthesiserVoice *voice, SynthesiserSound *sound, int midiChannel, int midiNoteNumber, float velocity)
Definition Synthesiser.cpp:300
virtual void handleProgramChange(int midiChannel, int programNumber)
Definition Synthesiser.cpp:497
void clearSounds()
Definition Synthesiser.cpp:125
SynthesiserSound * addSound(const SynthesiserSound::Ptr &newSound)
Definition Synthesiser.cpp:130
virtual void noteOff(int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff)
Definition Synthesiser.cpp:336
OwnedArray< SynthesiserVoice > voices
Definition Synthesiser.h:558
SynthesiserVoice * addVoice(SynthesiserVoice *newVoice)
Definition Synthesiser.cpp:114
ReferenceCountedArray< SynthesiserSound > sounds
Definition Synthesiser.h:559
virtual void handleAftertouch(int midiChannel, int midiNoteNumber, int aftertouchValue)
Definition Synthesiser.cpp:413
Definition Synthesiser.h:52
virtual ~SynthesiserSound()
Definition Synthesiser.cpp:36
virtual bool appliesToChannel(int midiChannel)=0
virtual bool appliesToNote(int midiNoteNumber)=0
SynthesiserSound()
Definition Synthesiser.cpp:35
ReferenceCountedObjectPtr< SynthesiserSound > Ptr
Definition Synthesiser.h:77
Definition Synthesiser.h:96
bool keyIsDown
Definition Synthesiser.h:265
SynthesiserSound::Ptr currentlyPlayingSound
Definition Synthesiser.h:264
bool isKeyDown() const noexcept
Definition Synthesiser.h:224
virtual void aftertouchChanged(int newAftertouchValue)
Definition Synthesiser.cpp:76
bool sustainPedalDown
Definition Synthesiser.h:265
int currentlyPlayingNote
Definition Synthesiser.h:262
int currentPlayingMidiChannel
Definition Synthesiser.h:262
virtual ~SynthesiserVoice()
Definition Synthesiser.cpp:50
virtual void channelPressureChanged(int newChannelPressureValue)
Definition Synthesiser.cpp:77
void clearCurrentNote()
Definition Synthesiser.cpp:69
virtual void stopNote(float velocity, bool allowTailOff)=0
SynthesiserSound::Ptr getCurrentlyPlayingSound() const noexcept
Definition Synthesiser.h:114
virtual void controllerMoved(int controllerNumber, int newControllerValue)=0
bool isPlayingButReleased() const noexcept
Definition Synthesiser.h:233
double currentSampleRate
Definition Synthesiser.h:261
int getCurrentlyPlayingNote() const noexcept
Definition Synthesiser.h:109
virtual void setCurrentPlaybackSampleRate(double newRate)
Definition Synthesiser.cpp:59
bool wasStartedBefore(const SynthesiserVoice &other) const noexcept
Definition Synthesiser.cpp:79
SynthesiserVoice()
Definition Synthesiser.cpp:39
virtual bool isPlayingChannel(int midiChannel) const
Definition Synthesiser.cpp:54
virtual void startNote(int midiNoteNumber, float velocity, SynthesiserSound *sound, int currentPitchWheelPosition)=0
virtual void pitchWheelMoved(int newPitchWheelValue)=0
virtual bool canPlaySound(SynthesiserSound *)=0
uint32 noteOnTime
Definition Synthesiser.h:263
bool sostenutoPedalDown
Definition Synthesiser.h:265
virtual bool isVoiceActive() const
Definition Synthesiser.cpp:64
unsigned * m
Definition inflate.c:1559
register unsigned j
Definition inflate.c:1576
register unsigned i
Definition inflate.c:1575
static void v2(register WDL_FFT_REAL *a)
Definition fft.c:1099
#define wassert(expression)
Definition AudioSampleBuffer.h:33
void ignoreUnused(const Type1 &) noexcept
Definition MathsFunctions.h:237
void zerostruct(Type &structure) noexcept
Definition Memory.h:41
size_t numElementsInArray(Type(&array)[N])
Definition MathsFunctions.h:257
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
Definition Synthesiser.cpp:524
static int compareElements(SynthesiserVoice *v1, SynthesiserVoice *v2) noexcept
Definition Synthesiser.cpp:525