OpenShot Audio Library | OpenShotAudio  0.6.0
juce_MPESynthesiser.h
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 
23 namespace juce
24 {
25 
26 //==============================================================================
54 class JUCE_API MPESynthesiser : public MPESynthesiserBase
55 {
56 public:
57  //==============================================================================
64 
71  MPESynthesiser (MPEInstrument& instrumentToUse);
72 
74  ~MPESynthesiser() override;
75 
76  //==============================================================================
78  void clearVoices();
79 
81  int getNumVoices() const noexcept { return voices.size(); }
82 
84  MPESynthesiserVoice* getVoice (int index) const;
85 
94  void addVoice (MPESynthesiserVoice* newVoice);
95 
97  void removeVoice (int index);
98 
105  void reduceNumVoices (int newNumVoices);
106 
115  virtual void turnOffAllVoices (bool allowTailOff);
116 
117  //==============================================================================
124  void setVoiceStealingEnabled (bool shouldSteal) noexcept { shouldStealVoices = shouldSteal; }
125 
127  bool isVoiceStealingEnabled() const noexcept { return shouldStealVoices; }
128 
129  //==============================================================================
136  void setCurrentPlaybackSampleRate (double newRate) override;
137 
138  //==============================================================================
153  void handleMidiEvent (const MidiMessage&) override;
154 
162  virtual void handleController (int /*midiChannel*/,
163  int /*controllerNumber*/,
164  int /*controllerValue*/) {}
165 
173  virtual void handleProgramChange (int /*midiChannel*/,
174  int /*programNumber*/) {}
175 
176 protected:
177  //==============================================================================
190  void noteAdded (MPENote newNote) override;
191 
205  void noteReleased (MPENote finishedNote) override;
206 
213  void notePressureChanged (MPENote changedNote) override;
214 
221  void notePitchbendChanged (MPENote changedNote) override;
222 
229  void noteTimbreChanged (MPENote changedNote) override;
230 
237  void noteKeyStateChanged (MPENote changedNote) override;
238 
239  //==============================================================================
244  void renderNextSubBlock (AudioBuffer<float>& outputAudio,
245  int startSample,
246  int numSamples) override;
247 
252  void renderNextSubBlock (AudioBuffer<double>& outputAudio,
253  int startSample,
254  int numSamples) override;
255 
256  //==============================================================================
267  virtual MPESynthesiserVoice* findFreeVoice (MPENote noteToFindVoiceFor,
268  bool stealIfNoneAvailable) const;
269 
282  virtual MPESynthesiserVoice* findVoiceToSteal (MPENote noteToStealVoiceFor = MPENote()) const;
283 
289  void startVoice (MPESynthesiserVoice* voice, MPENote noteToStart);
290 
297  void stopVoice (MPESynthesiserVoice* voice, MPENote noteToStop, bool allowTailOff);
298 
299  //==============================================================================
301  CriticalSection voicesLock;
302 
303 private:
304  //==============================================================================
305  std::atomic<bool> shouldStealVoices { false };
306  uint32 lastNoteOnCounter = 0;
307  mutable CriticalSection stealLock;
308  mutable Array<MPESynthesiserVoice*> usableVoicesToStealArray;
309 
310  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPESynthesiser)
311 };
312 
313 } // 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)