LMMS
Loading...
Searching...
No Matches
Synthesiser.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the Water library.
5 Copyright (c) 2016 ROLI Ltd.
6 Copyright (C) 2018 Filipe Coelho <falktx@falktx.com>
7
8 Permission is granted to use this software under the terms of the ISC license
9 http://www.isc.org/downloads/software-support-policy/isc-license/
10
11 Permission to use, copy, modify, and/or distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies.
14
15 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
16 TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
18 OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
19 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
21 OF THIS SOFTWARE.
22
23 ==============================================================================
24*/
25
26#ifndef WATER_SYNTHESISER_H_INCLUDED
27#define WATER_SYNTHESISER_H_INCLUDED
28
32
33#include "CarlaJuceUtils.hpp"
34#include "CarlaMutex.hpp"
35
36namespace water {
37
38//==============================================================================
52{
53protected:
54 //==============================================================================
56
57public:
59 virtual ~SynthesiserSound();
60
61 //==============================================================================
67 virtual bool appliesToNote (int midiNoteNumber) = 0;
68
74 virtual bool appliesToChannel (int midiChannel) = 0;
75
78
79
80private:
81 //==============================================================================
82 CARLA_LEAK_DETECTOR (SynthesiserSound)
83};
84
85
86//==============================================================================
96{
97public:
98 //==============================================================================
101
103 virtual ~SynthesiserVoice();
104
105 //==============================================================================
110
115
125 virtual bool canPlaySound (SynthesiserSound*) = 0;
126
130 virtual void startNote (int midiNoteNumber,
131 float velocity,
132 SynthesiserSound* sound,
133 int currentPitchWheelPosition) = 0;
134
150 virtual void stopNote (float velocity, bool allowTailOff) = 0;
151
156 virtual bool isVoiceActive() const;
157
161 virtual void pitchWheelMoved (int newPitchWheelValue) = 0;
162
166 virtual void controllerMoved (int controllerNumber, int newControllerValue) = 0;
167
171 virtual void aftertouchChanged (int newAftertouchValue);
172
176 virtual void channelPressureChanged (int newChannelPressureValue);
177
178 //==============================================================================
194 virtual void renderNextBlock (AudioSampleBuffer& outputBuffer,
195 int startSample,
196 int numSamples) = 0;
197
206 virtual void setCurrentPlaybackSampleRate (double newRate);
207
213 virtual bool isPlayingChannel (int midiChannel) const;
214
219
225
228
231
237
239 bool wasStartedBefore (const SynthesiserVoice& other) const noexcept;
240
241protected:
254 void clearCurrentNote();
255
256
257private:
258 //==============================================================================
259 friend class Synthesiser;
260
266
268
269 CARLA_LEAK_DETECTOR (SynthesiserVoice)
270};
271
272
273//==============================================================================
298{
299public:
300 //==============================================================================
304 Synthesiser();
305
307 virtual ~Synthesiser();
308
309 //==============================================================================
311 void clearVoices();
312
314 size_t getNumVoices() const noexcept { return voices.size(); }
315
317 SynthesiserVoice* getVoice (int index) const;
318
328
330 void removeVoice (int index);
331
332 //==============================================================================
334 void clearSounds();
335
337 int getNumSounds() const noexcept { return sounds.size(); }
338
340 SynthesiserSound* getSound (int index) const noexcept { return sounds [index]; }
341
348
350 void removeSound (int index);
351
352 //==============================================================================
360
365
366 //==============================================================================
380 virtual void noteOn (int midiChannel,
381 int midiNoteNumber,
382 float velocity);
383
396 virtual void noteOff (int midiChannel,
397 int midiNoteNumber,
398 float velocity,
399 bool allowTailOff);
400
415 virtual void allNotesOff (int midiChannel,
416 bool allowTailOff);
417
429 virtual void handlePitchWheel (int midiChannel,
430 int wheelValue);
431
444 virtual void handleController (int midiChannel,
445 int controllerNumber,
446 int controllerValue);
447
461 virtual void handleAftertouch (int midiChannel, int midiNoteNumber, int aftertouchValue);
462
475 virtual void handleChannelPressure (int midiChannel, int channelPressureValue);
476
478 virtual void handleSustainPedal (int midiChannel, bool isDown);
479
481 virtual void handleSostenutoPedal (int midiChannel, bool isDown);
482
484 virtual void handleSoftPedal (int midiChannel, bool isDown);
485
490 virtual void handleProgramChange (int midiChannel,
491 int programNumber);
492
493 //==============================================================================
499 virtual void setCurrentPlaybackSampleRate (double sampleRate);
500
513 inline void renderNextBlock (AudioSampleBuffer& outputAudio,
514 const MidiBuffer& inputMidi,
515 int startSample,
516 int numSamples)
517 { processNextBlock (outputAudio, inputMidi, startSample, numSamples); }
518
523
544 void setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict = false) noexcept;
545
550 virtual void renderVoices (AudioSampleBuffer& outputAudio,
551 int startSample, int numSamples);
552
554 virtual void handleMidiEvent (const MidiMessage&);
555
556protected:
557 //==============================================================================
560
563
572 virtual SynthesiserVoice* findFreeVoice (SynthesiserSound* soundToPlay,
573 int midiChannel,
574 int midiNoteNumber,
575 bool stealIfNoneAvailable) const;
576
583 int midiChannel,
584 int midiNoteNumber) const;
585
590 void startVoice (SynthesiserVoice* voice,
591 SynthesiserSound* sound,
592 int midiChannel,
593 int midiNoteNumber,
594 float velocity);
595
601 void stopVoice (SynthesiserVoice*, float velocity, bool allowTailOff);
602
603private:
604 //==============================================================================
605 void processNextBlock (AudioSampleBuffer& outputAudio,
606 const MidiBuffer& inputMidi,
607 int startSample,
608 int numSamples);
609 //==============================================================================
616
617 CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Synthesiser)
618};
619
620}
621
622#endif // WATER_SYNTHESISER_H_INCLUDED
#define noexcept
Definition DistrhoDefines.h:72
Definition AudioSampleBuffer.h:42
Definition MidiBuffer.h:48
Definition MidiMessage.h:40
Definition OwnedArray.h:57
Definition ReferenceCountedArray.h:56
ReferenceCountedObject()
Definition ReferenceCountedObject.h:107
Definition ReferenceCountedObject.h:227
size_t getNumVoices() const noexcept
Definition Synthesiser.h:314
double sampleRate
Definition Synthesiser.h:610
bool isNoteStealingEnabled() const noexcept
Definition Synthesiser.h:364
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
SynthesiserSound * getSound(int index) const noexcept
Definition Synthesiser.h:340
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
int getNumSounds() const noexcept
Definition Synthesiser.h:337
Synthesiser()
Definition Synthesiser.cpp:86
double getSampleRate() const noexcept
Definition Synthesiser.h:522
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 renderNextBlock(AudioSampleBuffer &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
Definition Synthesiser.h:513
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
bool isSostenutoPedalDown() const noexcept
Definition Synthesiser.h:230
virtual void aftertouchChanged(int newAftertouchValue)
Definition Synthesiser.cpp:76
bool sustainPedalDown
Definition Synthesiser.h:265
int currentlyPlayingNote
Definition Synthesiser.h:262
bool isSustainPedalDown() const noexcept
Definition Synthesiser.h:227
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
virtual void renderNextBlock(AudioSampleBuffer &outputBuffer, int startSample, int numSamples)=0
friend class Synthesiser
Definition Synthesiser.h:259
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
AudioSampleBuffer tempBuffer
Definition Synthesiser.h:267
uint32 noteOnTime
Definition Synthesiser.h:263
bool sostenutoPedalDown
Definition Synthesiser.h:265
virtual bool isVoiceActive() const
Definition Synthesiser.cpp:64
double getSampleRate() const noexcept
Definition Synthesiser.h:218
Definition AudioSampleBuffer.h:33
unsigned int uint32
Definition water.h:98
#define const
Definition zconf.h:137