OpenShot Audio Library | OpenShotAudio  0.3.0
juce_MPESynthesiser.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2017 - ROLI Ltd.
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 
23 namespace juce
24 {
25 
26 //==============================================================================
54 class JUCE_API MPESynthesiser : public MPESynthesiserBase
55 {
56 public:
57  //==============================================================================
64 
72  MPESynthesiser (MPEInstrument* instrumentToUse);
73 
75  ~MPESynthesiser() override;
76 
77  //==============================================================================
79  void clearVoices();
80 
82  int getNumVoices() const noexcept { return voices.size(); }
83 
85  MPESynthesiserVoice* getVoice (int index) const;
86 
95  void addVoice (MPESynthesiserVoice* newVoice);
96 
98  void removeVoice (int index);
99 
106  void reduceNumVoices (int newNumVoices);
107 
116  virtual void turnOffAllVoices (bool allowTailOff);
117 
118  //==============================================================================
125  void setVoiceStealingEnabled (bool shouldSteal) noexcept { shouldStealVoices = shouldSteal; }
126 
128  bool isVoiceStealingEnabled() const noexcept { return shouldStealVoices; }
129 
130  //==============================================================================
137  void setCurrentPlaybackSampleRate (double newRate) override;
138 
139  //==============================================================================
154  void handleMidiEvent (const MidiMessage&) override;
155 
163  virtual void handleController (int /*midiChannel*/,
164  int /*controllerNumber*/,
165  int /*controllerValue*/) {}
166 
174  virtual void handleProgramChange (int /*midiChannel*/,
175  int /*programNumber*/) {}
176 
177 protected:
178  //==============================================================================
191  void noteAdded (MPENote newNote) override;
192 
206  void noteReleased (MPENote finishedNote) override;
207 
214  void notePressureChanged (MPENote changedNote) override;
215 
222  void notePitchbendChanged (MPENote changedNote) override;
223 
230  void noteTimbreChanged (MPENote changedNote) override;
231 
238  void noteKeyStateChanged (MPENote changedNote) override;
239 
240  //==============================================================================
245  void renderNextSubBlock (AudioBuffer<float>& outputAudio,
246  int startSample,
247  int numSamples) override;
248 
253  void renderNextSubBlock (AudioBuffer<double>& outputAudio,
254  int startSample,
255  int numSamples) override;
256 
257  //==============================================================================
268  virtual MPESynthesiserVoice* findFreeVoice (MPENote noteToFindVoiceFor,
269  bool stealIfNoneAvailable) const;
270 
283  virtual MPESynthesiserVoice* findVoiceToSteal (MPENote noteToStealVoiceFor = MPENote()) const;
284 
290  void startVoice (MPESynthesiserVoice* voice, MPENote noteToStart);
291 
298  void stopVoice (MPESynthesiserVoice* voice, MPENote noteToStop, bool allowTailOff);
299 
300  //==============================================================================
302  CriticalSection voicesLock;
303 
304 private:
305  //==============================================================================
306  bool shouldStealVoices = false;
307  uint32 lastNoteOnCounter = 0;
308 
309  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiser)
310 };
311 
312 } // namespace juce
bool isVoiceStealingEnabled() const noexcept
int getNumVoices() const noexcept
void setVoiceStealingEnabled(bool shouldSteal) noexcept
virtual void handleProgramChange(int, int)
virtual void handleController(int, int, int)