OpenShot Audio Library | OpenShotAudio: juce_MPEInstrument.h Source File

OpenShot Audio Library | OpenShotAudio 0.4.0

Loading...
Searching...
No Matches
juce_MPEInstrument.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
23namespace juce
24{
25
26//==============================================================================
53 class JUCE_API MPEInstrument
54{
55public:
63 MPEInstrument() noexcept;
64
66 MPEInstrument (MPEZoneLayout layout);
67
69 virtual ~MPEInstrument();
70
71 //==============================================================================
78 MPEZoneLayout getZoneLayout() const noexcept;
79
86 void setZoneLayout (MPEZoneLayout newLayout);
87
94 bool isMemberChannel (int midiChannel) const noexcept;
95
101 bool isMasterChannel (int midiChannel) const noexcept;
102
109 bool isUsingChannel (int midiChannel) const noexcept;
110
111 //==============================================================================
119 enum TrackingMode
120 {
121 lastNotePlayedOnChannel,
122 lowestNoteOnChannel,
123 highestNoteOnChannel,
124 allNotesOnChannel
125 };
126
128 void setPressureTrackingMode (TrackingMode modeToUse);
129
131 void setPitchbendTrackingMode (TrackingMode modeToUse);
132
134 void setTimbreTrackingMode (TrackingMode modeToUse);
135
136 //==============================================================================
143 virtual void processNextMidiEvent (const MidiMessage& message);
144
145 //==============================================================================
152 virtual void noteOn (int midiChannel, int midiNoteNumber, MPEValue midiNoteOnVelocity);
153
160 virtual void noteOff (int midiChannel, int midiNoteNumber, MPEValue midiNoteOffVelocity);
161
170 virtual void pitchbend (int midiChannel, MPEValue pitchbend);
171
178 virtual void pressure (int midiChannel, MPEValue value);
179
187 virtual void timbre (int midiChannel, MPEValue value);
188
194 virtual void polyAftertouch (int midiChannel, int midiNoteNumber, MPEValue value);
195
201 virtual void sustainPedal (int midiChannel, bool isDown);
202
208 virtual void sostenutoPedal (int midiChannel, bool isDown);
209
214 void releaseAllNotes();
215
216 //==============================================================================
218 int getNumPlayingNotes() const noexcept;
219
225 MPENote getNote (int index) const noexcept;
226
231 MPENote getNote (int midiChannel, int midiNoteNumber) const noexcept;
232
234 MPENote getNoteWithID (uint16 noteID) const noexcept;
235
241 MPENote getMostRecentNote (int midiChannel) const noexcept;
242
248 MPENote getMostRecentNoteOtherThan (MPENote otherThanThisNote) const noexcept;
249
250 //==============================================================================
259 class JUCE_API Listener
260 {
261 public:
263 virtual ~Listener() = default;
264
268 virtual void noteAdded (MPENote newNote);
269
273 virtual void notePressureChanged (MPENote changedNote);
274
282 virtual void notePitchbendChanged (MPENote changedNote);
283
287 virtual void noteTimbreChanged (MPENote changedNote);
288
296 virtual void noteKeyStateChanged (MPENote changedNote);
297
303 virtual void noteReleased (MPENote finishedNote);
304
308 virtual void zoneLayoutChanged();
309 };
310
311 //==============================================================================
313 void addListener (Listener* listenerToAdd);
314
316 void removeListener (Listener* listenerToRemove);
317
318 //==============================================================================
340 void enableLegacyMode (int pitchbendRange = 2,
341 Range<int> channelRange = Range<int> (1, 17));
342
344 bool isLegacyModeEnabled() const noexcept;
345
347 Range<int> getLegacyModeChannelRange() const noexcept;
348
350 void setLegacyModeChannelRange (Range<int> channelRange);
351
353 int getLegacyModePitchbendRange() const noexcept;
354
356 void setLegacyModePitchbendRange (int pitchbendRange);
357
358protected:
359 //==============================================================================
360 CriticalSection lock;
361
362private:
363 //==============================================================================
364 Array<MPENote> notes;
365 MPEZoneLayout zoneLayout;
366 ListenerList<Listener> listeners;
367
368 uint8 lastPressureLowerBitReceivedOnChannel[16];
369 uint8 lastTimbreLowerBitReceivedOnChannel[16];
370 bool isMemberChannelSustained[16];
371
372 struct LegacyMode
373 {
374 bool isEnabled = false;
375 Range<int> channelRange;
376 int pitchbendRange = 2;
377 };
378
379 struct MPEDimension
380 {
381 TrackingMode trackingMode = lastNotePlayedOnChannel;
382 MPEValue lastValueReceivedOnChannel[16];
383 MPEValue MPENote::* value;
384 MPEValue& getValue (MPENote& note) noexcept { return note.*(value); }
385 };
386
387 LegacyMode legacyMode;
388 MPEDimension pitchbendDimension, pressureDimension, timbreDimension;
389
390 void resetLastReceivedValues();
391
392 void updateDimension (int midiChannel, MPEDimension&, MPEValue);
393 void updateDimensionMaster (bool, MPEDimension&, MPEValue);
394 void updateDimensionForNote (MPENote&, MPEDimension&, MPEValue);
395 void callListenersDimensionChanged (const MPENote&, const MPEDimension&);
396 MPEValue getInitialValueForNewNote (int midiChannel, MPEDimension&) const;
397
398 void processMidiNoteOnMessage (const MidiMessage&);
399 void processMidiNoteOffMessage (const MidiMessage&);
400 void processMidiPitchWheelMessage (const MidiMessage&);
401 void processMidiChannelPressureMessage (const MidiMessage&);
402 void processMidiControllerMessage (const MidiMessage&);
403 void processMidiResetAllControllersMessage (const MidiMessage&);
404 void processMidiAfterTouchMessage (const MidiMessage&);
405 void handlePressureMSB (int midiChannel, int value) noexcept;
406 void handlePressureLSB (int midiChannel, int value) noexcept;
407 void handleTimbreMSB (int midiChannel, int value) noexcept;
408 void handleTimbreLSB (int midiChannel, int value) noexcept;
409 void handleSustainOrSostenuto (int midiChannel, bool isDown, bool isSostenuto);
410
411 const MPENote* getNotePtr (int midiChannel, int midiNoteNumber) const noexcept;
412 MPENote* getNotePtr (int midiChannel, int midiNoteNumber) noexcept;
413 const MPENote* getNotePtr (int midiChannel, TrackingMode) const noexcept;
414 MPENote* getNotePtr (int midiChannel, TrackingMode) noexcept;
415 const MPENote* getLastNotePlayedPtr (int midiChannel) const noexcept;
416 MPENote* getLastNotePlayedPtr (int midiChannel) noexcept;
417 const MPENote* getHighestNotePtr (int midiChannel) const noexcept;
418 MPENote* getHighestNotePtr (int midiChannel) noexcept;
419 const MPENote* getLowestNotePtr (int midiChannel) const noexcept;
420 MPENote* getLowestNotePtr (int midiChannel) noexcept;
421 void updateNoteTotalPitchbend (MPENote&);
422
423 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPEInstrument)
424};
425
426} // namespace juce
juce::Array
Definition juce_Array.h:56
juce::CriticalSection
Definition juce_CriticalSection.h:43
juce::ListenerList
Definition juce_ListenerList.h:81
juce::MPEInstrument::Listener
Definition juce_MPEInstrument.h:260
juce::MPEInstrument::Listener::~Listener
virtual ~Listener()=default
juce::MPEInstrument
Definition juce_MPEInstrument.h:54
juce::MPEInstrument::~MPEInstrument
virtual ~MPEInstrument()
juce::MPEInstrument::TrackingMode
TrackingMode
Definition juce_MPEInstrument.h:120
juce::MPEInstrument::highestNoteOnChannel
@ highestNoteOnChannel
Definition juce_MPEInstrument.h:123
juce::MPEInstrument::lowestNoteOnChannel
@ lowestNoteOnChannel
Definition juce_MPEInstrument.h:122
juce::MPEInstrument::lastNotePlayedOnChannel
@ lastNotePlayedOnChannel
Definition juce_MPEInstrument.h:121
juce::MPEValue
Definition juce_MPEValue.h:37
juce::MPEZoneLayout
Definition juce_MPEZoneLayout.h:123
juce::MidiMessage
Definition juce_MidiMessage.h:35
juce::Range
Definition juce_Range.h:40
juce::MPENote
Definition juce_MPENote.h:40