LMMS
Loading...
Searching...
No Matches
juce_Synthesiser.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the JUCE library.
5 Copyright (c) 2022 - Raw Material Software Limited
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
26//==============================================================================
42{
43protected:
44 //==============================================================================
46
47public:
49 ~SynthesiserSound() override;
50
51 //==============================================================================
57 virtual bool appliesToNote (int midiNoteNumber) = 0;
58
64 virtual bool appliesToChannel (int midiChannel) = 0;
65
68
69
70private:
71 //==============================================================================
73};
74
75
76//==============================================================================
88{
89public:
90 //==============================================================================
93
95 virtual ~SynthesiserVoice();
96
97 //==============================================================================
102
107
117 virtual bool canPlaySound (SynthesiserSound*) = 0;
118
122 virtual void startNote (int midiNoteNumber,
123 float velocity,
124 SynthesiserSound* sound,
125 int currentPitchWheelPosition) = 0;
126
142 virtual void stopNote (float velocity, bool allowTailOff) = 0;
143
148 virtual bool isVoiceActive() const;
149
153 virtual void pitchWheelMoved (int newPitchWheelValue) = 0;
154
158 virtual void controllerMoved (int controllerNumber, int newControllerValue) = 0;
159
163 virtual void aftertouchChanged (int newAftertouchValue);
164
168 virtual void channelPressureChanged (int newChannelPressureValue);
169
170 //==============================================================================
186 virtual void renderNextBlock (AudioBuffer<float>& outputBuffer,
187 int startSample,
188 int numSamples) = 0;
189
191 virtual void renderNextBlock (AudioBuffer<double>& outputBuffer,
192 int startSample,
193 int numSamples);
194
203 virtual void setCurrentPlaybackSampleRate (double newRate);
204
210 virtual bool isPlayingChannel (int midiChannel) const;
211
216
222
226 void setKeyDown (bool isNowDown) noexcept { keyIsDown = isNowDown; }
227
230
232 void setSustainPedalDown (bool isNowDown) noexcept { sustainPedalDown = isNowDown; }
233
236
238 void setSostenutoPedalDown (bool isNowDown) noexcept { sostenutoPedalDown = isNowDown; }
239
245
247 bool wasStartedBefore (const SynthesiserVoice& other) const noexcept;
248
249protected:
262 void clearCurrentNote();
263
264
265private:
266 //==============================================================================
267 friend class Synthesiser;
268
269 double currentSampleRate = 44100.0;
273 bool keyIsDown = false, sustainPedalDown = false, sostenutoPedalDown = false;
274
276
278};
279
280
281//==============================================================================
308{
309public:
310 //==============================================================================
314 Synthesiser();
315
317 virtual ~Synthesiser();
318
319 //==============================================================================
321 void clearVoices();
322
324 int getNumVoices() const noexcept { return voices.size(); }
325
327 SynthesiserVoice* getVoice (int index) const;
328
337 SynthesiserVoice* addVoice (SynthesiserVoice* newVoice);
338
340 void removeVoice (int index);
341
342 //==============================================================================
344 void clearSounds();
345
347 int getNumSounds() const noexcept { return sounds.size(); }
348
350 SynthesiserSound::Ptr getSound (int index) const noexcept { return sounds[index]; }
351
357 SynthesiserSound* addSound (const SynthesiserSound::Ptr& newSound);
358
360 void removeSound (int index);
361
362 //==============================================================================
369 void setNoteStealingEnabled (bool shouldStealNotes);
370
375
376 //==============================================================================
390 virtual void noteOn (int midiChannel,
391 int midiNoteNumber,
392 float velocity);
393
406 virtual void noteOff (int midiChannel,
407 int midiNoteNumber,
408 float velocity,
409 bool allowTailOff);
410
425 virtual void allNotesOff (int midiChannel,
426 bool allowTailOff);
427
439 virtual void handlePitchWheel (int midiChannel,
440 int wheelValue);
441
454 virtual void handleController (int midiChannel,
455 int controllerNumber,
456 int controllerValue);
457
471 virtual void handleAftertouch (int midiChannel, int midiNoteNumber, int aftertouchValue);
472
485 virtual void handleChannelPressure (int midiChannel, int channelPressureValue);
486
488 virtual void handleSustainPedal (int midiChannel, bool isDown);
489
491 virtual void handleSostenutoPedal (int midiChannel, bool isDown);
492
494 virtual void handleSoftPedal (int midiChannel, bool isDown);
495
500 virtual void handleProgramChange (int midiChannel,
501 int programNumber);
502
503 //==============================================================================
509 virtual void setCurrentPlaybackSampleRate (double sampleRate);
510
523 void renderNextBlock (AudioBuffer<float>& outputAudio,
524 const MidiBuffer& inputMidi,
525 int startSample,
526 int numSamples);
527
528 void renderNextBlock (AudioBuffer<double>& outputAudio,
529 const MidiBuffer& inputMidi,
530 int startSample,
531 int numSamples);
532
537
558 void setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict = false) noexcept;
559
560protected:
561 //==============================================================================
564
567
570
575 virtual void renderVoices (AudioBuffer<float>& outputAudio,
576 int startSample, int numSamples);
577 virtual void renderVoices (AudioBuffer<double>& outputAudio,
578 int startSample, int numSamples);
579
588 virtual SynthesiserVoice* findFreeVoice (SynthesiserSound* soundToPlay,
589 int midiChannel,
590 int midiNoteNumber,
591 bool stealIfNoneAvailable) const;
592
599 int midiChannel,
600 int midiNoteNumber) const;
601
606 void startVoice (SynthesiserVoice* voice,
607 SynthesiserSound* sound,
608 int midiChannel,
609 int midiNoteNumber,
610 float velocity);
611
617 void stopVoice (SynthesiserVoice*, float velocity, bool allowTailOff);
618
620 virtual void handleMidiEvent (const MidiMessage&);
621
622private:
623 //==============================================================================
624 double sampleRate = 0;
630
631 template <typename floatType>
632 void processNextBlock (AudioBuffer<floatType>&, const MidiBuffer&, int startSample, int numSamples);
633
635};
636
637} // namespace juce
#define noexcept
Definition DistrhoDefines.h:72
Definition juce_AudioSampleBuffer.h:34
Definition juce_BigInteger.h:39
Definition juce_CriticalSection.h:43
Definition juce_MidiBuffer.h:145
Definition juce_MidiMessage.h:35
Definition juce_OwnedArray.h:51
Definition juce_ReferenceCountedArray.h:51
Definition juce_ReferenceCountedObject.h:247
Synthesiser()
Definition juce_Synthesiser.cpp:76
virtual SynthesiserVoice * findFreeVoice(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber, bool stealIfNoneAvailable) const
Definition juce_Synthesiser.cpp:487
BigInteger sustainPedalsDown
Definition juce_Synthesiser.h:629
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 SynthesiserVoice * findVoiceToSteal(SynthesiserSound *soundToPlay, int midiChannel, int midiNoteNumber) const
Definition juce_Synthesiser.cpp:503
void stopVoice(SynthesiserVoice *, float velocity, bool allowTailOff)
Definition juce_Synthesiser.cpp:330
int getNumSounds() const noexcept
Definition juce_Synthesiser.h:347
bool shouldStealNotes
Definition juce_Synthesiser.h:628
double getSampleRate() const noexcept
Definition juce_Synthesiser.h:536
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
int getNumVoices() const noexcept
Definition juce_Synthesiser.h:324
OwnedArray< SynthesiserVoice > voices
Definition juce_Synthesiser.h:565
bool isNoteStealingEnabled() const noexcept
Definition juce_Synthesiser.h:374
uint32 lastNoteOnCounter
Definition juce_Synthesiser.h:625
SynthesiserSound::Ptr getSound(int index) const noexcept
Definition juce_Synthesiser.h:350
CriticalSection lock
Definition juce_Synthesiser.h:563
int lastPitchWheelValues[16]
Definition juce_Synthesiser.h:569
ReferenceCountedArray< SynthesiserSound > sounds
Definition juce_Synthesiser.h:566
void clearVoices()
Definition juce_Synthesiser.cpp:93
bool subBlockSubdivisionIsStrict
Definition juce_Synthesiser.h:627
Definition juce_Synthesiser.h:42
SynthesiserSound()
Definition juce_Synthesiser.cpp:26
ReferenceCountedObjectPtr< SynthesiserSound > Ptr
Definition juce_Synthesiser.h:67
virtual bool appliesToNote(int midiNoteNumber)=0
virtual bool appliesToChannel(int midiChannel)=0
Definition juce_Synthesiser.h:88
bool isSostenutoPedalDown() const noexcept
Definition juce_Synthesiser.h:235
double getSampleRate() const noexcept
Definition juce_Synthesiser.h:215
virtual void stopNote(float velocity, bool allowTailOff)=0
AudioBuffer< float > tempBuffer
Definition juce_Synthesiser.h:275
bool sustainPedalDown
Definition juce_Synthesiser.h:273
bool sostenutoPedalDown
Definition juce_Synthesiser.h:273
bool isSustainPedalDown() const noexcept
Definition juce_Synthesiser.h:229
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
friend class Synthesiser
Definition juce_Synthesiser.h:267
virtual void aftertouchChanged(int newAftertouchValue)
Definition juce_Synthesiser.cpp:55
bool keyIsDown
Definition juce_Synthesiser.h:273
virtual void controllerMoved(int controllerNumber, int newControllerValue)=0
int getCurrentlyPlayingNote() const noexcept
Definition juce_Synthesiser.h:101
virtual void startNote(int midiNoteNumber, float velocity, SynthesiserSound *sound, int currentPitchWheelPosition)=0
int currentPlayingMidiChannel
Definition juce_Synthesiser.h:270
virtual bool canPlaySound(SynthesiserSound *)=0
virtual void pitchWheelMoved(int newPitchWheelValue)=0
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
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition juce_LeakedObjectDetector.h:138
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
#define JUCE_API
Definition juce_StandardHeader.h:152
Definition carla_juce.cpp:31
unsigned int uint32
Definition juce_MathsFunctions.h:45
#define true
Definition ordinals.h:82
#define false
Definition ordinals.h:83
#define const
Definition zconf.h:137