Loading...
Searching...
No Matches
juce_MPEInstrument.h
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2022 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
The code included in this file is provided under the terms of the ISC license
http://www.isc.org/downloads/software-support-policy/isc-license. Permission
To use, copy, modify, and/or distribute this software for any purpose with or
without fee is hereby granted provided that the above copyright notice and
this permission notice appear in all copies.
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
//==============================================================================
class JUCE_API MPEInstrument
{
public:
MPEInstrument() noexcept;
MPEInstrument (MPEZoneLayout layout);
virtual ~MPEInstrument();
//==============================================================================
MPEZoneLayout getZoneLayout() const noexcept;
void setZoneLayout (MPEZoneLayout newLayout);
bool isMemberChannel (int midiChannel) const noexcept;
bool isMasterChannel (int midiChannel) const noexcept;
bool isUsingChannel (int midiChannel) const noexcept;
//==============================================================================
enum TrackingMode
{
lastNotePlayedOnChannel,
lowestNoteOnChannel,
highestNoteOnChannel,
allNotesOnChannel
};
void setPressureTrackingMode (TrackingMode modeToUse);
void setPitchbendTrackingMode (TrackingMode modeToUse);
void setTimbreTrackingMode (TrackingMode modeToUse);
//==============================================================================
virtual void processNextMidiEvent (const MidiMessage& message);
//==============================================================================
virtual void noteOn (int midiChannel, int midiNoteNumber, MPEValue midiNoteOnVelocity);
virtual void noteOff (int midiChannel, int midiNoteNumber, MPEValue midiNoteOffVelocity);
virtual void pitchbend (int midiChannel, MPEValue pitchbend);
virtual void pressure (int midiChannel, MPEValue value);
virtual void timbre (int midiChannel, MPEValue value);
virtual void polyAftertouch (int midiChannel, int midiNoteNumber, MPEValue value);
virtual void sustainPedal (int midiChannel, bool isDown);
virtual void sostenutoPedal (int midiChannel, bool isDown);
void releaseAllNotes();
//==============================================================================
int getNumPlayingNotes() const noexcept;
MPENote getNote (int index) const noexcept;
MPENote getNote (int midiChannel, int midiNoteNumber) const noexcept;
MPENote getNoteWithID (uint16 noteID) const noexcept;
MPENote getMostRecentNote (int midiChannel) const noexcept;
MPENote getMostRecentNoteOtherThan (MPENote otherThanThisNote) const noexcept;
//==============================================================================
class JUCE_API Listener
{
public:
virtual ~Listener() = default;
virtual void noteAdded (MPENote newNote);
virtual void notePressureChanged (MPENote changedNote);
virtual void notePitchbendChanged (MPENote changedNote);
virtual void noteTimbreChanged (MPENote changedNote);
virtual void noteKeyStateChanged (MPENote changedNote);
virtual void noteReleased (MPENote finishedNote);
virtual void zoneLayoutChanged();
};
//==============================================================================
void addListener (Listener* listenerToAdd);
void removeListener (Listener* listenerToRemove);
//==============================================================================
void enableLegacyMode (int pitchbendRange = 2,
Range<int> channelRange = Range<int> (1, 17));
bool isLegacyModeEnabled() const noexcept;
Range<int> getLegacyModeChannelRange() const noexcept;
void setLegacyModeChannelRange (Range<int> channelRange);
int getLegacyModePitchbendRange() const noexcept;
void setLegacyModePitchbendRange (int pitchbendRange);
protected:
//==============================================================================
CriticalSection lock;
private:
//==============================================================================
Array<MPENote> notes;
MPEZoneLayout zoneLayout;
ListenerList<Listener> listeners;
uint8 lastPressureLowerBitReceivedOnChannel[16];
uint8 lastTimbreLowerBitReceivedOnChannel[16];
bool isMemberChannelSustained[16];
struct LegacyMode
{
bool isEnabled = false;
Range<int> channelRange;
int pitchbendRange = 2;
};
struct MPEDimension
{
TrackingMode trackingMode = lastNotePlayedOnChannel;
MPEValue lastValueReceivedOnChannel[16];
MPEValue MPENote::* value;
MPEValue& getValue (MPENote& note) noexcept { return note.*(value); }
};
LegacyMode legacyMode;
MPEDimension pitchbendDimension, pressureDimension, timbreDimension;
void resetLastReceivedValues();
void updateDimension (int midiChannel, MPEDimension&, MPEValue);
void updateDimensionMaster (bool, MPEDimension&, MPEValue);
void updateDimensionForNote (MPENote&, MPEDimension&, MPEValue);
void callListenersDimensionChanged (const MPENote&, const MPEDimension&);
MPEValue getInitialValueForNewNote (int midiChannel, MPEDimension&) const;
void processMidiNoteOnMessage (const MidiMessage&);
void processMidiNoteOffMessage (const MidiMessage&);
void processMidiPitchWheelMessage (const MidiMessage&);
void processMidiChannelPressureMessage (const MidiMessage&);
void processMidiControllerMessage (const MidiMessage&);
void processMidiResetAllControllersMessage (const MidiMessage&);
void processMidiAfterTouchMessage (const MidiMessage&);
void handlePressureMSB (int midiChannel, int value) noexcept;
void handlePressureLSB (int midiChannel, int value) noexcept;
void handleTimbreMSB (int midiChannel, int value) noexcept;
void handleTimbreLSB (int midiChannel, int value) noexcept;
void handleSustainOrSostenuto (int midiChannel, bool isDown, bool isSostenuto);
const MPENote* getNotePtr (int midiChannel, int midiNoteNumber) const noexcept;
MPENote* getNotePtr (int midiChannel, int midiNoteNumber) noexcept;
const MPENote* getNotePtr (int midiChannel, TrackingMode) const noexcept;
MPENote* getNotePtr (int midiChannel, TrackingMode) noexcept;
const MPENote* getLastNotePlayedPtr (int midiChannel) const noexcept;
MPENote* getLastNotePlayedPtr (int midiChannel) noexcept;
const MPENote* getHighestNotePtr (int midiChannel) const noexcept;
MPENote* getHighestNotePtr (int midiChannel) noexcept;
const MPENote* getLowestNotePtr (int midiChannel) const noexcept;
MPENote* getLowestNotePtr (int midiChannel) noexcept;
void updateNoteTotalPitchbend (MPENote&);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MPEInstrument)
};
} // 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::noteAdded
virtual void noteAdded(MPENote newNote)
Definition juce_MPEInstrument.cpp:857
juce::MPEInstrument::Listener::noteReleased
virtual void noteReleased(MPENote finishedNote)
Definition juce_MPEInstrument.cpp:862
juce::MPEInstrument::Listener::zoneLayoutChanged
virtual void zoneLayoutChanged()
Definition juce_MPEInstrument.cpp:863
juce::MPEInstrument::Listener::noteKeyStateChanged
virtual void noteKeyStateChanged(MPENote changedNote)
Definition juce_MPEInstrument.cpp:861
juce::MPEInstrument::Listener::notePitchbendChanged
virtual void notePitchbendChanged(MPENote changedNote)
Definition juce_MPEInstrument.cpp:859
juce::MPEInstrument::Listener::notePressureChanged
virtual void notePressureChanged(MPENote changedNote)
Definition juce_MPEInstrument.cpp:858
juce::MPEInstrument::Listener::noteTimbreChanged
virtual void noteTimbreChanged(MPENote changedNote)
Definition juce_MPEInstrument.cpp:860
juce::MPEInstrument::Listener::~Listener
virtual ~Listener()=default
juce::MPEInstrument::setLegacyModeChannelRange
void setLegacyModeChannelRange(Range< int > channelRange)
Definition juce_MPEInstrument.cpp:127
juce::MPEInstrument::getZoneLayout
MPEZoneLayout getZoneLayout() const noexcept
Definition juce_MPEInstrument.cpp:63
juce::MPEInstrument::isMemberChannel
bool isMemberChannel(int midiChannel) const noexcept
Definition juce_MPEInstrument.cpp:645
juce::MPEInstrument::~MPEInstrument
virtual ~MPEInstrument()
juce::MPEInstrument::enableLegacyMode
void enableLegacyMode(int pitchbendRange=2, Range< int > channelRange=Range< int >(1, 17))
Definition juce_MPEInstrument.cpp:100
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::MPEInstrument::allNotesOnChannel
@ allNotesOnChannel
Definition juce_MPEInstrument.h:124
juce::MPEInstrument::MPEInstrument
MPEInstrument() noexcept
Definition juce_MPEInstrument.cpp:39
juce::MPEInstrument::setZoneLayout
void setZoneLayout(MPEZoneLayout newLayout)
Definition juce_MPEInstrument.cpp:85
juce::MPEInstrument::setLegacyModePitchbendRange
void setLegacyModePitchbendRange(int pitchbendRange)
Definition juce_MPEInstrument.cpp:146
juce::MPEInstrument::isLegacyModeEnabled
bool isLegacyModeEnabled() const noexcept
Definition juce_MPEInstrument.cpp:117
juce::MPEInstrument::addListener
void addListener(Listener *listenerToAdd)
Definition juce_MPEInstrument.cpp:177
juce::MPEInstrument::removeListener
void removeListener(Listener *listenerToRemove)
Definition juce_MPEInstrument.cpp:182
juce::MPEInstrument::getLegacyModeChannelRange
Range< int > getLegacyModeChannelRange() const noexcept
Definition juce_MPEInstrument.cpp:122
juce::MPEInstrument::getLegacyModePitchbendRange
int getLegacyModePitchbendRange() const noexcept
Definition juce_MPEInstrument.cpp:141
juce::MPEInstrument::isMasterChannel
bool isMasterChannel(int midiChannel) const noexcept
Definition juce_MPEInstrument.cpp:654
juce::MPEInstrument::isUsingChannel
bool isUsingChannel(int midiChannel) const noexcept
Definition juce_MPEInstrument.cpp:666
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