openshot-audio  0.1.5
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) 2015 - ROLI Ltd.
6 
7  Permission is granted to use this software under the terms of either:
8  a) the GPL v2 (or any later version)
9  b) the Affero GPL v3
10 
11  Details of these licenses can be found at: www.gnu.org/licenses
12 
13  JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
14  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15  A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 
17  ------------------------------------------------------------------------------
18 
19  To release a closed-source product which uses JUCE, commercial licenses are
20  available: visit www.juce.com for more information.
21 
22  ==============================================================================
23 */
24 
25 #ifndef JUCE_SYNTHESISER_H_INCLUDED
26 #define JUCE_SYNTHESISER_H_INCLUDED
27 
28 
29 //==============================================================================
43 {
44 protected:
45  //==============================================================================
47 
48 public:
50  virtual ~SynthesiserSound();
51 
52  //==============================================================================
58  virtual bool appliesToNote (int midiNoteNumber) = 0;
59 
65  virtual bool appliesToChannel (int midiChannel) = 0;
66 
69 
70 
71 private:
72  //==============================================================================
74 };
75 
76 
77 //==============================================================================
87 {
88 public:
89  //==============================================================================
92 
94  virtual ~SynthesiserVoice();
95 
96  //==============================================================================
100  int getCurrentlyPlayingNote() const noexcept { return currentlyPlayingNote; }
101 
105  SynthesiserSound::Ptr getCurrentlyPlayingSound() const noexcept { return currentlyPlayingSound; }
106 
116  virtual bool canPlaySound (SynthesiserSound*) = 0;
117 
121  virtual void startNote (int midiNoteNumber,
122  float velocity,
123  SynthesiserSound* sound,
124  int currentPitchWheelPosition) = 0;
125 
141  virtual void stopNote (float velocity, bool allowTailOff) = 0;
142 
147  virtual bool isVoiceActive() const;
148 
152  virtual void pitchWheelMoved (int newPitchWheelValue) = 0;
153 
157  virtual void controllerMoved (int controllerNumber, int newControllerValue) = 0;
158 
162  virtual void aftertouchChanged (int newAftertouchValue);
163 
167  virtual void channelPressureChanged (int newChannelPressureValue);
168 
169  //==============================================================================
185  virtual void renderNextBlock (AudioSampleBuffer& outputBuffer,
186  int startSample,
187  int numSamples) = 0;
188 
197  virtual void setCurrentPlaybackSampleRate (double newRate);
198 
204  virtual bool isPlayingChannel (int midiChannel) const;
205 
209  double getSampleRate() const noexcept { return currentSampleRate; }
210 
215  bool isKeyDown() const noexcept { return keyIsDown; }
216 
218  bool isSustainPedalDown() const noexcept { return sustainPedalDown; }
219 
221  bool isSostenutoPedalDown() const noexcept { return sostenutoPedalDown; }
222 
225  {
226  return isVoiceActive() && ! (isKeyDown() || isSostenutoPedalDown() || isSustainPedalDown());
227  }
228 
230  bool wasStartedBefore (const SynthesiserVoice& other) const noexcept;
231 
232 protected:
245  void clearCurrentNote();
246 
247 
248 private:
249  //==============================================================================
250  friend class Synthesiser;
251 
252  double currentSampleRate;
253  int currentlyPlayingNote, currentPlayingMidiChannel;
254  uint32 noteOnTime;
255  SynthesiserSound::Ptr currentlyPlayingSound;
256  bool keyIsDown, sustainPedalDown, sostenutoPedalDown;
257 
258  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
259  // Note the new parameters for this method.
260  virtual int stopNote (bool) { return 0; }
261  #endif
262 
264 };
265 
266 
267 //==============================================================================
292 {
293 public:
294  //==============================================================================
298  Synthesiser();
299 
301  virtual ~Synthesiser();
302 
303  //==============================================================================
305  void clearVoices();
306 
308  int getNumVoices() const noexcept { return voices.size(); }
309 
311  SynthesiserVoice* getVoice (int index) const;
312 
321  SynthesiserVoice* addVoice (SynthesiserVoice* newVoice);
322 
324  void removeVoice (int index);
325 
326  //==============================================================================
328  void clearSounds();
329 
331  int getNumSounds() const noexcept { return sounds.size(); }
332 
334  SynthesiserSound* getSound (int index) const noexcept { return sounds [index]; }
335 
341  SynthesiserSound* addSound (const SynthesiserSound::Ptr& newSound);
342 
344  void removeSound (int index);
345 
346  //==============================================================================
353  void setNoteStealingEnabled (bool shouldStealNotes);
354 
358  bool isNoteStealingEnabled() const noexcept { return shouldStealNotes; }
359 
360  //==============================================================================
374  virtual void noteOn (int midiChannel,
375  int midiNoteNumber,
376  float velocity);
377 
390  virtual void noteOff (int midiChannel,
391  int midiNoteNumber,
392  float velocity,
393  bool allowTailOff);
394 
409  virtual void allNotesOff (int midiChannel,
410  bool allowTailOff);
411 
423  virtual void handlePitchWheel (int midiChannel,
424  int wheelValue);
425 
438  virtual void handleController (int midiChannel,
439  int controllerNumber,
440  int controllerValue);
441 
455  virtual void handleAftertouch (int midiChannel, int midiNoteNumber, int aftertouchValue);
456 
469  virtual void handleChannelPressure (int midiChannel, int channelPressureValue);
470 
472  virtual void handleSustainPedal (int midiChannel, bool isDown);
473 
475  virtual void handleSostenutoPedal (int midiChannel, bool isDown);
476 
478  virtual void handleSoftPedal (int midiChannel, bool isDown);
479 
484  virtual void handleProgramChange (int midiChannel,
485  int programNumber);
486 
487  //==============================================================================
493  virtual void setCurrentPlaybackSampleRate (double sampleRate);
494 
507  void renderNextBlock (AudioSampleBuffer& outputAudio,
508  const MidiBuffer& inputMidi,
509  int startSample,
510  int numSamples);
511 
515  double getSampleRate() const noexcept { return sampleRate; }
516 
531  void setMinimumRenderingSubdivisionSize (int numSamples) noexcept;
532 
533 protected:
534  //==============================================================================
537 
540 
542  int lastPitchWheelValues [16];
543 
548  virtual void renderVoices (AudioSampleBuffer& outputAudio,
549  int startSample, int numSamples);
550 
559  virtual SynthesiserVoice* findFreeVoice (SynthesiserSound* soundToPlay,
560  int midiChannel,
561  int midiNoteNumber,
562  bool stealIfNoneAvailable) const;
563 
569  virtual SynthesiserVoice* findVoiceToSteal (SynthesiserSound* soundToPlay,
570  int midiChannel,
571  int midiNoteNumber) const;
572 
578  void startVoice (SynthesiserVoice* voice,
579  SynthesiserSound* sound,
580  int midiChannel,
581  int midiNoteNumber,
582  float velocity);
583 
585  virtual void handleMidiEvent (const MidiMessage&);
586 
587 private:
588  //==============================================================================
589  double sampleRate;
590  uint32 lastNoteOnCounter;
591  int minimumSubBlockSize;
592  bool shouldStealNotes;
593  BigInteger sustainPedalsDown;
594 
595  void stopVoice (SynthesiserVoice*, float velocity, bool allowTailOff);
596 
597  #if JUCE_CATCH_DEPRECATED_CODE_MISUSE
598  // Note the new parameters for these methods.
599  virtual int findFreeVoice (const bool) const { return 0; }
600  virtual int noteOff (int, int, int) { return 0; }
601  virtual int findFreeVoice (SynthesiserSound*, const bool) { return 0; }
602  virtual int findVoiceToSteal (SynthesiserSound*) const { return 0; }
603  #endif
604 
606 };
607 
608 
609 #endif // JUCE_SYNTHESISER_H_INCLUDED
Definition: juce_AudioSampleBuffer.h:34
Definition: juce_BigInteger.h:43
double getSampleRate() const noexcept
Definition: juce_Synthesiser.h:209
int getNumSounds() const noexcept
Definition: juce_Synthesiser.h:331
#define noexcept
Definition: juce_CompilerSupport.h:141
double getSampleRate() const noexcept
Definition: juce_Synthesiser.h:515
bool isNoteStealingEnabled() const noexcept
Definition: juce_Synthesiser.h:358
bool isKeyDown() const noexcept
Definition: juce_Synthesiser.h:215
#define JUCE_API
Definition: juce_StandardHeader.h:139
OwnedArray< SynthesiserVoice > voices
Definition: juce_Synthesiser.h:538
SynthesiserSound * getSound(int index) const noexcept
Definition: juce_Synthesiser.h:334
Definition: juce_Synthesiser.h:291
CriticalSection lock
Definition: juce_Synthesiser.h:536
Definition: juce_ReferenceCountedObject.h:65
Definition: juce_CriticalSection.h:47
ReferenceCountedArray< SynthesiserSound > sounds
Definition: juce_Synthesiser.h:539
int getNumVoices() const noexcept
Definition: juce_Synthesiser.h:308
bool isSostenutoPedalDown() const noexcept
Definition: juce_Synthesiser.h:221
unsigned int uint32
Definition: juce_MathsFunctions.h:51
int getCurrentlyPlayingNote() const noexcept
Definition: juce_Synthesiser.h:100
SynthesiserSound::Ptr getCurrentlyPlayingSound() const noexcept
Definition: juce_Synthesiser.h:105
bool isSustainPedalDown() const noexcept
Definition: juce_Synthesiser.h:218
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Definition: juce_PlatformDefs.h:198
Definition: juce_Synthesiser.h:42
Definition: juce_Synthesiser.h:86
#define JUCE_LEAK_DETECTOR(OwnerClass)
Definition: juce_LeakedObjectDetector.h:141
Definition: juce_MidiBuffer.h:43
ReferenceCountedObjectPtr< SynthesiserSound > Ptr
Definition: juce_Synthesiser.h:68
Definition: juce_MidiMessage.h:35
bool isPlayingButReleased() const noexcept
Definition: juce_Synthesiser.h:224