64 int startSample,
int numSamples)
68 startSample, numSamples);
103 return voices.add (newVoice);
121 return sounds.add (newSound);
151 for (
auto* voice :
voices)
152 voice->setCurrentPlaybackSampleRate (newRate);
156template <
typename floatType>
168 bool firstEvent =
true;
172 for (; numSamples > 0; ++midiIterator)
174 if (midiIterator == midiData.
cend())
176 if (targetChannels > 0)
182 const auto metadata = *midiIterator;
183 const int samplesToNextMidiMessage = metadata.samplePosition - startSample;
185 if (samplesToNextMidiMessage >= numSamples)
187 if (targetChannels > 0)
194 if (samplesToNextMidiMessage < ((firstEvent && ! subBlockSubdivisionIsStrict) ? 1 : minimumSubBlockSize))
196 handleMidiEvent (metadata.getMessage());
202 if (targetChannels > 0)
203 renderVoices (outputAudio, startSample, samplesToNextMidiMessage);
205 handleMidiEvent (metadata.getMessage());
206 startSample += samplesToNextMidiMessage;
207 numSamples -= samplesToNextMidiMessage;
210 std::for_each (midiIterator,
212 [&] (
const MidiMessageMetadata& meta) { handleMidiEvent (meta.getMessage()); });
216template void Synthesiser::processNextBlock<float> (AudioBuffer<float>&,
const MidiBuffer&,
int,
int);
217template void Synthesiser::processNextBlock<double> (AudioBuffer<double>&,
const MidiBuffer&,
int,
int);
220 int startSample,
int numSamples)
226 int startSample,
int numSamples)
233 for (
auto* voice :
voices)
234 voice->renderNextBlock (buffer, startSample, numSamples);
239 for (
auto* voice :
voices)
240 voice->renderNextBlock (buffer, startSample, numSamples);
245 const int channel =
m.getChannel();
249 noteOn (channel,
m.getNoteNumber(),
m.getFloatVelocity());
251 else if (
m.isNoteOff())
253 noteOff (channel,
m.getNoteNumber(),
m.getFloatVelocity(),
true);
255 else if (
m.isAllNotesOff() ||
m.isAllSoundOff())
259 else if (
m.isPitchWheel())
261 const int wheelPos =
m.getPitchWheelValue();
265 else if (
m.isAftertouch())
269 else if (
m.isChannelPressure())
273 else if (
m.isController())
277 else if (
m.isProgramChange())
285 const int midiNoteNumber,
286 const float velocity)
290 for (
auto* sound :
sounds)
292 if (sound->appliesToNote (midiNoteNumber) && sound->appliesToChannel (midiChannel))
296 for (
auto* voice :
voices)
297 if (voice->getCurrentlyPlayingNote() == midiNoteNumber && voice->isPlayingChannel (midiChannel))
301 sound, midiChannel, midiNoteNumber, velocity);
308 const int midiChannel,
309 const int midiNoteNumber,
310 const float velocity)
312 if (voice !=
nullptr && sound !=
nullptr)
325 voice->
startNote (midiNoteNumber, velocity, sound,
334 voice->
stopNote (velocity, allowTailOff);
341 const int midiNoteNumber,
342 const float velocity,
343 const bool allowTailOff)
347 for (
auto* voice :
voices)
349 if (voice->getCurrentlyPlayingNote() == midiNoteNumber
350 && voice->isPlayingChannel (midiChannel))
352 if (
auto sound = voice->getCurrentlyPlayingSound())
354 if (sound->appliesToNote (midiNoteNumber)
355 && sound->appliesToChannel (midiChannel))
359 voice->setKeyDown (
false);
361 if (! (voice->isSustainPedalDown() || voice->isSostenutoPedalDown()))
362 stopVoice (voice, velocity, allowTailOff);
373 for (
auto* voice :
voices)
374 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
375 voice->stopNote (1.0f, allowTailOff);
384 for (
auto* voice :
voices)
385 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
386 voice->pitchWheelMoved (wheelValue);
390 const int controllerNumber,
391 const int controllerValue)
393 switch (controllerNumber)
397 case 0x43:
handleSoftPedal (midiChannel, controllerValue >= 64);
break;
403 for (
auto* voice :
voices)
404 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
405 voice->controllerMoved (controllerNumber, controllerValue);
412 for (
auto* voice :
voices)
413 if (voice->getCurrentlyPlayingNote() == midiNoteNumber
414 && (midiChannel <= 0 || voice->isPlayingChannel (midiChannel)))
415 voice->aftertouchChanged (aftertouchValue);
422 for (
auto* voice :
voices)
423 if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
424 voice->channelPressureChanged (channelPressureValue);
429 jassert (midiChannel > 0 && midiChannel <= 16);
436 for (
auto* voice :
voices)
437 if (voice->isPlayingChannel (midiChannel) && voice->isKeyDown())
438 voice->setSustainPedalDown (
true);
442 for (
auto* voice :
voices)
444 if (voice->isPlayingChannel (midiChannel))
446 voice->setSustainPedalDown (
false);
448 if (! (voice->isKeyDown() || voice->isSostenutoPedalDown()))
459 jassert (midiChannel > 0 && midiChannel <= 16);
462 for (
auto* voice :
voices)
464 if (voice->isPlayingChannel (midiChannel))
467 voice->setSostenutoPedalDown (
true);
468 else if (voice->isSostenutoPedalDown())
477 jassert (midiChannel > 0 && midiChannel <= 16);
483 jassert (midiChannel > 0 && midiChannel <= 16);
488 int midiChannel,
int midiNoteNumber,
489 const bool stealIfNoneAvailable)
const
493 for (
auto* voice :
voices)
494 if ((! voice->isVoiceActive()) && voice->canPlaySound (soundToPlay))
497 if (stealIfNoneAvailable)
504 int ,
int midiNoteNumber)
const
521 for (
auto* voice :
voices)
523 if (voice->canPlaySound (soundToPlay))
525 jassert (voice->isVoiceActive());
527 usableVoices.
add (voice);
536 std::sort (usableVoices.
begin(), usableVoices.
end(), Sorter());
538 if (! voice->isPlayingButReleased())
540 auto note = voice->getCurrentlyPlayingNote();
542 if (low ==
nullptr || note < low->getCurrentlyPlayingNote())
556 for (
auto* voice : usableVoices)
557 if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
561 for (
auto* voice : usableVoices)
566 for (
auto* voice : usableVoices)
567 if (voice != low && voice != top && ! voice->
isKeyDown())
571 for (
auto* voice : usableVoices)
572 if (voice != low && voice != top)
uint8_t a
Definition Spc_Cpu.h:141
Definition juce_Array.h:56
void ensureStorageAllocated(int minNumElements)
Definition juce_Array.h:1065
ElementType * begin() noexcept
Definition juce_Array.h:328
ElementType * end() noexcept
Definition juce_Array.h:344
void add(const ElementType &newElement)
Definition juce_Array.h:418
Definition juce_AudioSampleBuffer.h:34
void makeCopyOf(const AudioBuffer< OtherType > &other, bool avoidReallocating=false)
Definition juce_AudioSampleBuffer.h:525
int getNumChannels() const noexcept
Definition juce_AudioSampleBuffer.h:236
Type ** getArrayOfWritePointers() noexcept
Definition juce_AudioSampleBuffer.h:342
Definition juce_MidiBuffer.h:145
MidiBufferIterator findNextSamplePosition(int samplePosition) const noexcept
Definition juce_MidiBuffer.cpp:203
MidiBufferIterator cend() const noexcept
Definition juce_MidiBuffer.h:268
Definition juce_MidiMessage.h:35
Synthesiser()
Definition juce_Synthesiser.cpp:76
virtual ~Synthesiser()
Definition juce_Synthesiser.cpp:82
virtual SynthesiserVoice * findFreeVoice(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber, bool stealIfNoneAvailable) const
Definition juce_Synthesiser.cpp:487
virtual void handleProgramChange(int midiChannel, int programNumber)
Definition juce_Synthesiser.cpp:480
BigInteger sustainPedalsDown
Definition juce_Synthesiser.h:629
void removeVoice(int index)
Definition juce_Synthesiser.cpp:106
void processNextBlock(AudioBuffer< floatType > &, const MidiBuffer &, int startSample, int numSamples)
Definition juce_Synthesiser.cpp:157
double sampleRate
Definition juce_Synthesiser.h:624
int minimumSubBlockSize
Definition juce_Synthesiser.h:626
void startVoice(SynthesiserVoice *voice, SynthesiserSound *sound, int midiChannel, int midiNoteNumber, float velocity)
Definition juce_Synthesiser.cpp:306
virtual void handleAftertouch(int midiChannel, int midiNoteNumber, int aftertouchValue)
Definition juce_Synthesiser.cpp:408
void renderNextBlock(AudioBuffer< float > &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
Definition juce_Synthesiser.cpp:219
virtual void handleController(int midiChannel, int controllerNumber, int controllerValue)
Definition juce_Synthesiser.cpp:389
void clearSounds()
Definition juce_Synthesiser.cpp:112
virtual SynthesiserVoice * findVoiceToSteal(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber) const
Definition juce_Synthesiser.cpp:503
virtual void handleSoftPedal(int midiChannel, bool isDown)
Definition juce_Synthesiser.cpp:474
void removeSound(int index)
Definition juce_Synthesiser.cpp:124
virtual void allNotesOff(int midiChannel, bool allowTailOff)
Definition juce_Synthesiser.cpp:369
SynthesiserVoice * addVoice(SynthesiserVoice *newVoice)
Definition juce_Synthesiser.cpp:99
void stopVoice(SynthesiserVoice *, float velocity, bool allowTailOff)
Definition juce_Synthesiser.cpp:330
bool shouldStealNotes
Definition juce_Synthesiser.h:628
SynthesiserSound * addSound(const SynthesiserSound::Ptr &newSound)
Definition juce_Synthesiser.cpp:118
virtual void renderVoices(AudioBuffer< float > &outputAudio, int startSample, int numSamples)
Definition juce_Synthesiser.cpp:231
virtual void handleMidiEvent(const MidiMessage &)
Definition juce_Synthesiser.cpp:243
OwnedArray< SynthesiserVoice > voices
Definition juce_Synthesiser.h:565
uint32 lastNoteOnCounter
Definition juce_Synthesiser.h:625
void setNoteStealingEnabled(bool shouldStealNotes)
Definition juce_Synthesiser.cpp:130
virtual void handlePitchWheel(int midiChannel, int wheelValue)
Definition juce_Synthesiser.cpp:380
CriticalSection lock
Definition juce_Synthesiser.h:563
int lastPitchWheelValues[16]
Definition juce_Synthesiser.h:569
virtual void noteOn(int midiChannel, int midiNoteNumber, float velocity)
Definition juce_Synthesiser.cpp:284
SynthesiserVoice * getVoice(int index) const
Definition juce_Synthesiser.cpp:87
ReferenceCountedArray< SynthesiserSound > sounds
Definition juce_Synthesiser.h:566
virtual void noteOff(int midiChannel, int midiNoteNumber, float velocity, bool allowTailOff)
Definition juce_Synthesiser.cpp:340
virtual void handleChannelPressure(int midiChannel, int channelPressureValue)
Definition juce_Synthesiser.cpp:418
void clearVoices()
Definition juce_Synthesiser.cpp:93
virtual void setCurrentPlaybackSampleRate(double sampleRate)
Definition juce_Synthesiser.cpp:143
void setMinimumRenderingSubdivisionSize(int numSamples, bool shouldBeStrict=false) noexcept
Definition juce_Synthesiser.cpp:135
bool subBlockSubdivisionIsStrict
Definition juce_Synthesiser.h:627
virtual void handleSustainPedal(int midiChannel, bool isDown)
Definition juce_Synthesiser.cpp:427
virtual void handleSostenutoPedal(int midiChannel, bool isDown)
Definition juce_Synthesiser.cpp:457
Definition juce_Synthesiser.h:42
~SynthesiserSound() override
Definition juce_Synthesiser.cpp:27
SynthesiserSound()
Definition juce_Synthesiser.cpp:26
ReferenceCountedObjectPtr< SynthesiserSound > Ptr
Definition juce_Synthesiser.h:67
Definition juce_Synthesiser.h:88
virtual void stopNote(float velocity, bool allowTailOff)=0
AudioBuffer< float > tempBuffer
Definition juce_Synthesiser.h:275
void setSustainPedalDown(bool isNowDown) noexcept
Definition juce_Synthesiser.h:232
int currentlyPlayingNote
Definition juce_Synthesiser.h:270
uint32 noteOnTime
Definition juce_Synthesiser.h:271
SynthesiserVoice()
Definition juce_Synthesiser.cpp:30
virtual void channelPressureChanged(int newChannelPressureValue)
Definition juce_Synthesiser.cpp:56
void setSostenutoPedalDown(bool isNowDown) noexcept
Definition juce_Synthesiser.h:238
virtual void renderNextBlock(AudioBuffer< float > &outputBuffer, int startSample, int numSamples)=0
virtual bool isPlayingChannel(int midiChannel) const
Definition juce_Synthesiser.cpp:33
double currentSampleRate
Definition juce_Synthesiser.h:269
SynthesiserSound::Ptr currentlyPlayingSound
Definition juce_Synthesiser.h:272
bool isKeyDown() const noexcept
Definition juce_Synthesiser.h:221
void setKeyDown(bool isNowDown) noexcept
Definition juce_Synthesiser.h:226
virtual void setCurrentPlaybackSampleRate(double newRate)
Definition juce_Synthesiser.cpp:38
virtual void aftertouchChanged(int newAftertouchValue)
Definition juce_Synthesiser.cpp:55
int getCurrentlyPlayingNote() const noexcept
Definition juce_Synthesiser.h:101
virtual void startNote(int midiNoteNumber, float velocity, SynthesiserSound *sound, int currentPitchWheelPosition)=0
void clearCurrentNote()
Definition juce_Synthesiser.cpp:48
bool wasStartedBefore(const SynthesiserVoice &other) const noexcept
Definition juce_Synthesiser.cpp:58
int currentPlayingMidiChannel
Definition juce_Synthesiser.h:270
virtual ~SynthesiserVoice()
Definition juce_Synthesiser.cpp:31
bool isPlayingButReleased() const noexcept
Definition juce_Synthesiser.h:241
SynthesiserSound::Ptr getCurrentlyPlayingSound() const noexcept
Definition juce_Synthesiser.h:106
virtual bool isVoiceActive() const
Definition juce_Synthesiser.cpp:43
unsigned * m
Definition inflate.c:1559
register unsigned i
Definition inflate.c:1575
Definition carla_juce.cpp:31
CriticalSection::ScopedLockType ScopedLock
Definition juce_CriticalSection.h:186
void ignoreUnused(Types &&...) noexcept
Definition juce_MathsFunctions.h:333
constexpr int numElementsInArray(Type(&)[N]) noexcept
Definition juce_MathsFunctions.h:344