JUCE
Classes | Public Types | Public Member Functions | List of all members
MPEInstrument Class Reference

Classes

class  Listener
 Derive from this class to be informed about any changes in the expressive MIDI notes played by this instrument. More...
 

Public Types

enum  TrackingMode { lastNotePlayedOnChannel, lowestNoteOnChannel, highestNoteOnChannel, allNotesOnChannel }
 The MPE note tracking mode. More...
 

Public Member Functions

 MPEInstrument () noexcept
 Constructor. More...
 
virtual ~MPEInstrument ()
 Destructor. More...
 
MPEZoneLayout getZoneLayout () const noexcept
 Returns the current zone layout of the instrument. More...
 
void setZoneLayout (MPEZoneLayout newLayout)
 Re-sets the zone layout of the instrument to the one passed in. More...
 
bool isNoteChannel (int midiChannel) const noexcept
 Returns true if the given MIDI channel (1-16) is a note channel in any of the MPEInstrument's MPE zones; false otherwise. More...
 
bool isMasterChannel (int midiChannel) const noexcept
 Returns true if the given MIDI channel (1-16) is a master channel in any of the MPEInstrument's MPE zones; false otherwise. More...
 
void setPressureTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the pressure dimension. More...
 
void setPitchbendTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the pitchbend dimension. More...
 
void setTimbreTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the timbre dimension. More...
 
virtual void processNextMidiEvent (const MidiMessage &message)
 Process a MIDI message and trigger the appropriate method calls (noteOn, noteOff etc.) More...
 
virtual void noteOn (int midiChannel, int midiNoteNumber, MPEValue midiNoteOnVelocity)
 Request a note-on on the given channel, with the given initial note number and velocity. More...
 
virtual void noteOff (int midiChannel, int midiNoteNumber, MPEValue midiNoteOffVelocity)
 Request a note-off. More...
 
virtual void pitchbend (int midiChannel, MPEValue pitchbend)
 Request a pitchbend on the given channel with the given value (in units of MIDI pitchwheel position). More...
 
virtual void pressure (int midiChannel, MPEValue value)
 Request a pressure change on the given channel with the given value. More...
 
virtual void timbre (int midiChannel, MPEValue value)
 Request a third dimension (timbre) change on the given channel with the given value. More...
 
virtual void sustainPedal (int midiChannel, bool isDown)
 Request a sustain pedal press or release. More...
 
virtual void sostenutoPedal (int midiChannel, bool isDown)
 Request a sostenuto pedal press or release. More...
 
void releaseAllNotes ()
 Discard all currently playing notes. More...
 
int getNumPlayingNotes () const noexcept
 Returns the number of MPE notes currently played by the instrument. More...
 
MPENote getNote (int index) const noexcept
 Returns the note at the given index. More...
 
MPENote getNote (int midiChannel, int midiNoteNumber) const noexcept
 Returns the note currently playing on the given midiChannel with the specified initial MIDI note number, if there is such a note. More...
 
MPENote getMostRecentNote (int midiChannel) const noexcept
 Returns the most recent note that is playing on the given midiChannel (this will be the note which has received the most recent note-on without a corresponding note-off), if there is such a note. More...
 
MPENote getMostRecentNoteOtherThan (MPENote otherThanThisNote) const noexcept
 Returns the most recent note that is not the note passed in. More...
 
void addListener (Listener *listenerToAdd) noexcept
 Adds a listener. More...
 
void removeListener (Listener *listenerToRemove) noexcept
 Removes a listener. More...
 
void enableLegacyMode (int pitchbendRange=2, Range< int > channelRange=Range< int >(1, 17))
 Puts the instrument into legacy mode. More...
 
bool isLegacyModeEnabled () const noexcept
 Returns true if the instrument is in legacy mode, false otherwise. More...
 
Range< int > getLegacyModeChannelRange () const noexcept
 Returns the range of MIDI channels (1-16) to be used for notes when in legacy mode. More...
 
void setLegacyModeChannelRange (Range< int > channelRange)
 Re-sets the range of MIDI channels (1-16) to be used for notes when in legacy mode. More...
 
int getLegacyModePitchbendRange () const noexcept
 Returns the pitchbend range in semitones (0-96) to be used for notes when in legacy mode. More...
 
void setLegacyModePitchbendRange (int pitchbendRange)
 Re-sets the pitchbend range in semitones (0-96) to be used for notes when in legacy mode. More...
 

Member Enumeration Documentation

The MPE note tracking mode.

In case there is more than one note playing simultaneously on the same MIDI channel, this determines which of these notes will be modulated by an incoming MPE message on that channel (pressure, pitchbend, or timbre).

The default is lastNotePlayedOnChannel.

Enumerator
lastNotePlayedOnChannel 
lowestNoteOnChannel 

The most recent note on the channel that is still played (key down and/or sustained)

highestNoteOnChannel 

The lowest note (by initialNote) on the channel with the note key still down.

allNotesOnChannel 

The highest note (by initialNote) on the channel with the note key still down.

All notes on the channel (key down and/or sustained)

Constructor & Destructor Documentation

MPEInstrument::MPEInstrument ( )
noexcept

Constructor.

This will construct an MPE instrument with initially no MPE zones.

In order to process incoming MIDI, call setZoneLayout, define the layout via MIDI RPN messages, or set the instrument to legacy mode.

virtual MPEInstrument::~MPEInstrument ( )
virtual

Destructor.

Member Function Documentation

MPEZoneLayout MPEInstrument::getZoneLayout ( ) const
noexcept

Returns the current zone layout of the instrument.

This happens by value, to enforce thread-safety and class invariants.

Note: If the instrument is in legacy mode, the return value of this method is unspecified.

void MPEInstrument::setZoneLayout ( MPEZoneLayout  newLayout)

Re-sets the zone layout of the instrument to the one passed in.

As a side effect, this will discard all currently playing notes, and call noteReleased for all of them.

This will also disable legacy mode in case it was enabled previously.

bool MPEInstrument::isNoteChannel ( int  midiChannel) const
noexcept

Returns true if the given MIDI channel (1-16) is a note channel in any of the MPEInstrument's MPE zones; false otherwise.

When in legacy mode, this will return true if the given channel is contained in the current legacy mode channel range; false otherwise.

bool MPEInstrument::isMasterChannel ( int  midiChannel) const
noexcept

Returns true if the given MIDI channel (1-16) is a master channel in any of the MPEInstrument's MPE zones; false otherwise.

When in legacy mode, this will always return false.

void MPEInstrument::setPressureTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the pressure dimension.

void MPEInstrument::setPitchbendTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the pitchbend dimension.

void MPEInstrument::setTimbreTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the timbre dimension.

virtual void MPEInstrument::processNextMidiEvent ( const MidiMessage message)
virtual

Process a MIDI message and trigger the appropriate method calls (noteOn, noteOff etc.)

You can override this method if you need some special MIDI message treatment on top of the standard MPE logic implemented here.

virtual void MPEInstrument::noteOn ( int  midiChannel,
int  midiNoteNumber,
MPEValue  midiNoteOnVelocity 
)
virtual

Request a note-on on the given channel, with the given initial note number and velocity.

If the message arrives on a valid note channel, this will create a new MPENote and call the noteAdded callback.

virtual void MPEInstrument::noteOff ( int  midiChannel,
int  midiNoteNumber,
MPEValue  midiNoteOffVelocity 
)
virtual

Request a note-off.

If there is a matching playing note, this will release the note (except if it is sustained by a sustain or sostenuto pedal) and call the noteReleased callback.

virtual void MPEInstrument::pitchbend ( int  midiChannel,
MPEValue  pitchbend 
)
virtual

Request a pitchbend on the given channel with the given value (in units of MIDI pitchwheel position).

Internally, this will determine whether the pitchwheel move is a per-note pitchbend or a master pitchbend (depending on midiChannel), take the correct per-note or master pitchbend range of the affected MPE zone, and apply the resulting pitchbend to the affected note(s) (if any).

virtual void MPEInstrument::pressure ( int  midiChannel,
MPEValue  value 
)
virtual

Request a pressure change on the given channel with the given value.

This will modify the pressure dimension of the note currently held down on this channel (if any). If the channel is a zone master channel, the pressure change will be broadcast to all notes in this zone.

virtual void MPEInstrument::timbre ( int  midiChannel,
MPEValue  value 
)
virtual

Request a third dimension (timbre) change on the given channel with the given value.

This will modify the timbre dimension of the note currently held down on this channel (if any). If the channel is a zone master channel, the timbre change will be broadcast to all notes in this zone.

virtual void MPEInstrument::sustainPedal ( int  midiChannel,
bool  isDown 
)
virtual

Request a sustain pedal press or release.

If midiChannel is a zone's master channel, this will act on all notes in that zone; otherwise, nothing will happen.

virtual void MPEInstrument::sostenutoPedal ( int  midiChannel,
bool  isDown 
)
virtual

Request a sostenuto pedal press or release.

If midiChannel is a zone's master channel, this will act on all notes in that zone; otherwise, nothing will happen.

void MPEInstrument::releaseAllNotes ( )

Discard all currently playing notes.

This will also call the noteReleased listener callback for all of them.

int MPEInstrument::getNumPlayingNotes ( ) const
noexcept

Returns the number of MPE notes currently played by the instrument.

MPENote MPEInstrument::getNote ( int  index) const
noexcept

Returns the note at the given index.

If there is no such note, returns an invalid MPENote. The notes are sorted such that the most recently added note is the last element.

MPENote MPEInstrument::getNote ( int  midiChannel,
int  midiNoteNumber 
) const
noexcept

Returns the note currently playing on the given midiChannel with the specified initial MIDI note number, if there is such a note.

Otherwise, this returns an invalid MPENote (check with note.isValid() before use!)

MPENote MPEInstrument::getMostRecentNote ( int  midiChannel) const
noexcept

Returns the most recent note that is playing on the given midiChannel (this will be the note which has received the most recent note-on without a corresponding note-off), if there is such a note.

Otherwise, this returns an invalid MPENote (check with note.isValid() before use!)

MPENote MPEInstrument::getMostRecentNoteOtherThan ( MPENote  otherThanThisNote) const
noexcept

Returns the most recent note that is not the note passed in.

If there is no such note, this returns an invalid MPENote (check with note.isValid() before use!) This helper method might be useful for some custom voice handling algorithms.

void MPEInstrument::addListener ( Listener listenerToAdd)
noexcept

Adds a listener.

void MPEInstrument::removeListener ( Listener listenerToRemove)
noexcept

Removes a listener.

void MPEInstrument::enableLegacyMode ( int  pitchbendRange = 2,
Range< int >  channelRange = Range< int >(1, 17) 
)

Puts the instrument into legacy mode.

As a side effect, this will discard all currently playing notes, and call noteReleased for all of them.

This special zone layout mode is for backwards compatibility with non-MPE MIDI devices. In this mode, the instrument will ignore the current MPE zone layout. It will instead take a range of MIDI channels (default: all channels 1-16) and treat them as note channels, with no master channel. MIDI channels outside of this range will be ignored.

Parameters
pitchbendRangeThe note pitchbend range in semitones to use when in legacy mode. Must be between 0 and 96, otherwise behaviour is undefined. The default pitchbend range in legacy mode is +/- 2 semitones.
channelRangeThe range of MIDI channels to use for notes when in legacy mode. The default is to use all MIDI channels (1-16).

To get out of legacy mode, set a new MPE zone layout using setZoneLayout.

Referenced by MPESynthesiserBase::getSampleRate().

bool MPEInstrument::isLegacyModeEnabled ( ) const
noexcept

Returns true if the instrument is in legacy mode, false otherwise.

Referenced by MPESynthesiserBase::getSampleRate().

Range<int> MPEInstrument::getLegacyModeChannelRange ( ) const
noexcept

Returns the range of MIDI channels (1-16) to be used for notes when in legacy mode.

Referenced by MPESynthesiserBase::getSampleRate().

void MPEInstrument::setLegacyModeChannelRange ( Range< int >  channelRange)

Re-sets the range of MIDI channels (1-16) to be used for notes when in legacy mode.

Referenced by MPESynthesiserBase::getSampleRate().

int MPEInstrument::getLegacyModePitchbendRange ( ) const
noexcept

Returns the pitchbend range in semitones (0-96) to be used for notes when in legacy mode.

Referenced by MPESynthesiserBase::getSampleRate().

void MPEInstrument::setLegacyModePitchbendRange ( int  pitchbendRange)

Re-sets the pitchbend range in semitones (0-96) to be used for notes when in legacy mode.

Referenced by MPESynthesiserBase::getSampleRate().


The documentation for this class was generated from the following file: