OpenShot Audio Library | OpenShotAudio 0.3.2
Loading...
Searching...
No Matches
juce_MPEInstrument.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
23namespace juce
24{
25
26//==============================================================================
55class JUCE_API MPEInstrument
56{
57public:
65 MPEInstrument() noexcept;
66
68 virtual ~MPEInstrument();
69
70 //==============================================================================
77 MPEZoneLayout getZoneLayout() const noexcept;
78
85 void setZoneLayout (MPEZoneLayout newLayout);
86
93 bool isMemberChannel (int midiChannel) const noexcept;
94
100 bool isMasterChannel (int midiChannel) const noexcept;
101
108 bool isUsingChannel (int midiChannel) const noexcept;
109
110 //==============================================================================
125
127 void setPressureTrackingMode (TrackingMode modeToUse);
128
130 void setPitchbendTrackingMode (TrackingMode modeToUse);
131
133 void setTimbreTrackingMode (TrackingMode modeToUse);
134
135 //==============================================================================
142 virtual void processNextMidiEvent (const MidiMessage& message);
143
144 //==============================================================================
151 virtual void noteOn (int midiChannel, int midiNoteNumber, MPEValue midiNoteOnVelocity);
152
159 virtual void noteOff (int midiChannel, int midiNoteNumber, MPEValue midiNoteOffVelocity);
160
169 virtual void pitchbend (int midiChannel, MPEValue pitchbend);
170
177 virtual void pressure (int midiChannel, MPEValue value);
178
186 virtual void timbre (int midiChannel, MPEValue value);
187
193 virtual void polyAftertouch (int midiChannel, int midiNoteNumber, MPEValue value);
194
200 virtual void sustainPedal (int midiChannel, bool isDown);
201
207 virtual void sostenutoPedal (int midiChannel, bool isDown);
208
213 void releaseAllNotes();
214
215 //==============================================================================
217 int getNumPlayingNotes() const noexcept;
218
224 MPENote getNote (int index) const noexcept;
225
230 MPENote getNote (int midiChannel, int midiNoteNumber) const noexcept;
231
237 MPENote getMostRecentNote (int midiChannel) const noexcept;
238
244 MPENote getMostRecentNoteOtherThan (MPENote otherThanThisNote) const noexcept;
245
246 //==============================================================================
256 {
257 public:
259 virtual ~Listener() = default;
260
264 virtual void noteAdded (MPENote newNote) { ignoreUnused (newNote); }
265
269 virtual void notePressureChanged (MPENote changedNote) { ignoreUnused (changedNote); }
270
278 virtual void notePitchbendChanged (MPENote changedNote) { ignoreUnused (changedNote); }
279
283 virtual void noteTimbreChanged (MPENote changedNote) { ignoreUnused (changedNote); }
284
292 virtual void noteKeyStateChanged (MPENote changedNote) { ignoreUnused (changedNote); }
293
299 virtual void noteReleased (MPENote finishedNote) { ignoreUnused (finishedNote); }
300 };
301
302 //==============================================================================
304 void addListener (Listener* listenerToAdd);
305
307 void removeListener (Listener* listenerToRemove);
308
309 //==============================================================================
329 void enableLegacyMode (int pitchbendRange = 2,
330 Range<int> channelRange = Range<int> (1, 17));
331
333 bool isLegacyModeEnabled() const noexcept;
334
336 Range<int> getLegacyModeChannelRange() const noexcept;
337
339 void setLegacyModeChannelRange (Range<int> channelRange);
340
342 int getLegacyModePitchbendRange() const noexcept;
343
345 void setLegacyModePitchbendRange (int pitchbendRange);
346
348 //==============================================================================
349 CriticalSection lock;
350
351private:
352 //==============================================================================
353 Array<MPENote> notes;
354 MPEZoneLayout zoneLayout;
355 ListenerList<Listener> listeners;
356
357 uint8 lastPressureLowerBitReceivedOnChannel[16];
358 uint8 lastTimbreLowerBitReceivedOnChannel[16];
359 bool isMemberChannelSustained[16];
360
361 struct LegacyMode
362 {
363 bool isEnabled;
364 Range<int> channelRange;
365 int pitchbendRange;
366 };
367
368 struct MPEDimension
369 {
370 TrackingMode trackingMode = lastNotePlayedOnChannel;
371 MPEValue lastValueReceivedOnChannel[16];
372 MPEValue MPENote::* value;
373 MPEValue& getValue (MPENote& note) noexcept { return note.*(value); }
374 };
375
376 LegacyMode legacyMode;
377 MPEDimension pitchbendDimension, pressureDimension, timbreDimension;
378
379 void updateDimension (int midiChannel, MPEDimension&, MPEValue);
380 void updateDimensionMaster (bool, MPEDimension&, MPEValue);
381 void updateDimensionForNote (MPENote&, MPEDimension&, MPEValue);
382 void callListenersDimensionChanged (const MPENote&, const MPEDimension&);
383 MPEValue getInitialValueForNewNote (int midiChannel, MPEDimension&) const;
384
385 void processMidiNoteOnMessage (const MidiMessage&);
386 void processMidiNoteOffMessage (const MidiMessage&);
387 void processMidiPitchWheelMessage (const MidiMessage&);
388 void processMidiChannelPressureMessage (const MidiMessage&);
389 void processMidiControllerMessage (const MidiMessage&);
390 void processMidiResetAllControllersMessage (const MidiMessage&);
391 void processMidiAfterTouchMessage (const MidiMessage&);
392 void handlePressureMSB (int midiChannel, int value) noexcept;
393 void handlePressureLSB (int midiChannel, int value) noexcept;
394 void handleTimbreMSB (int midiChannel, int value) noexcept;
395 void handleTimbreLSB (int midiChannel, int value) noexcept;
396 void handleSustainOrSostenuto (int midiChannel, bool isDown, bool isSostenuto);
397
398 const MPENote* getNotePtr (int midiChannel, int midiNoteNumber) const noexcept;
399 MPENote* getNotePtr (int midiChannel, int midiNoteNumber) noexcept;
400 const MPENote* getNotePtr (int midiChannel, TrackingMode) const noexcept;
401 MPENote* getNotePtr (int midiChannel, TrackingMode) noexcept;
402 const MPENote* getLastNotePlayedPtr (int midiChannel) const noexcept;
403 MPENote* getLastNotePlayedPtr (int midiChannel) noexcept;
404 const MPENote* getHighestNotePtr (int midiChannel) const noexcept;
405 MPENote* getHighestNotePtr (int midiChannel) noexcept;
406 const MPENote* getLowestNotePtr (int midiChannel) const noexcept;
407 MPENote* getLowestNotePtr (int midiChannel) noexcept;
408 void updateNoteTotalPitchbend (MPENote&);
409
410 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPEInstrument)
411};
412
413} // namespace juce
virtual void notePitchbendChanged(MPENote changedNote)
virtual void noteAdded(MPENote newNote)
virtual void notePressureChanged(MPENote changedNote)
virtual void noteTimbreChanged(MPENote changedNote)
virtual void noteReleased(MPENote finishedNote)
virtual ~Listener()=default
virtual void noteKeyStateChanged(MPENote changedNote)