JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::MPESynthesiserBase Struct Referenceabstract

Derive from this class to create a basic audio generator capable of MPE. More...

#include <juce_MPESynthesiserBase.h>

Inheritance diagram for juce::MPESynthesiserBase:
Collaboration diagram for juce::MPESynthesiserBase:

Public Types

using TrackingMode = MPEInstrument::TrackingMode
 

Public Member Functions

 MPESynthesiserBase ()
 Constructor. More...
 
 MPESynthesiserBase (MPEInstrument &instrument)
 Constructor. More...
 
void enableLegacyMode (int pitchbendRange=2, Range< int > channelRange=Range< int >(1, 17))
 Puts the synthesiser into legacy mode. More...
 
Range< intgetLegacyModeChannelRange () const noexcept
 Returns 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...
 
double getSampleRate () const noexcept
 Returns the current target sample rate at which rendering is being done. More...
 
MPEZoneLayout getZoneLayout () const noexcept
 Returns the synthesiser's internal MPE zone layout. More...
 
virtual void handleMidiEvent (const MidiMessage &)
 Handle incoming MIDI events (called from renderNextBlock). More...
 
bool isLegacyModeEnabled () const noexcept
 Returns true if the instrument is in legacy mode, false otherwise. More...
 
virtual void noteAdded (MPENote newNote)
 Implement this callback to be informed whenever a new expressive MIDI note is triggered. More...
 
virtual void noteKeyStateChanged (MPENote changedNote)
 Implement this callback to be informed whether a currently playing MPE note's key state (whether the key is down and/or the note is sustained) has changed. More...
 
virtual void notePitchbendChanged (MPENote changedNote)
 Implement this callback to be informed whenever a currently playing MPE note's pitchbend value changes. More...
 
virtual void notePressureChanged (MPENote changedNote)
 Implement this callback to be informed whenever a currently playing MPE note's pressure value changes. More...
 
virtual void noteReleased (MPENote finishedNote)
 Implement this callback to be informed whenever an MPE note is released (either by a note-off message, or by a sustain/sostenuto pedal release for a note that already received a note-off), and should therefore stop playing. More...
 
virtual void noteTimbreChanged (MPENote changedNote)
 Implement this callback to be informed whenever a currently playing MPE note's timbre value changes. More...
 
template<typename floatType >
void renderNextBlock (AudioBuffer< floatType > &outputAudio, const MidiBuffer &inputMidi, int startSample, int numSamples)
 Creates the next block of audio output. More...
 
virtual void setCurrentPlaybackSampleRate (double sampleRate)
 Tells the synthesiser what the sample rate is for the audio it's being used to render. 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...
 
void setLegacyModePitchbendRange (int pitchbendRange)
 Re-sets the pitchbend range in semitones (0-96) to be used for notes when in legacy mode. More...
 
void setMinimumRenderingSubdivisionSize (int numSamples, bool shouldBeStrict=false) noexcept
 Sets a minimum limit on the size to which audio sub-blocks will be divided when rendering. More...
 
void setPitchbendTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the pitchbend dimension. More...
 
void setPressureTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the pressure dimension. More...
 
void setTimbreTrackingMode (TrackingMode modeToUse)
 Set the MPE tracking mode for the timbre dimension. More...
 
void setZoneLayout (MPEZoneLayout newLayout)
 Re-sets the synthesiser's internal MPE zone layout to the one passed in. More...
 
virtual void zoneLayoutChanged ()
 Implement this callback to be informed whenever the MPE zone layout or legacy mode settings of this instrument have been changed. More...
 

Protected Member Functions

virtual void renderNextSubBlock (AudioBuffer< double > &, int, int)
 Implement this method if you want to render 64-bit audio as well; otherwise leave blank. More...
 
virtual void renderNextSubBlock (AudioBuffer< float > &outputAudio, int startSample, int numSamples)=0
 Implement this method to render your audio inside. More...
 

Protected Attributes

MPEInstrumentinstrument
 

Private Attributes

MPEInstrument defaultInstrument { MPEZone (MPEZone::Type::lower, 15) }
 
int minimumSubBlockSize = 32
 
CriticalSection noteStateLock
 
double sampleRate = 0.0
 
bool subBlockSubdivisionIsStrict = false
 

Detailed Description

Derive from this class to create a basic audio generator capable of MPE.

Implement the callbacks of MPEInstrument::Listener (noteAdded, notePressureChanged etc.) to let your audio generator know that MPE notes were triggered, modulated, or released. What to do inside them, and how that influences your audio generator, is up to you!

This class uses an instance of MPEInstrument internally to handle the MPE note state logic.

This class is a very low-level base class for an MPE instrument. If you need something more sophisticated, have a look at MPESynthesiser. This class extends MPESynthesiserBase by adding the concept of voices that can play notes, a voice stealing algorithm, and much more.

See also
MPESynthesiser, MPEInstrument

@tags{Audio}

Member Typedef Documentation

◆ TrackingMode

Constructor & Destructor Documentation

◆ MPESynthesiserBase() [1/2]

juce::MPESynthesiserBase::MPESynthesiserBase ( )

Constructor.

◆ MPESynthesiserBase() [2/2]

juce::MPESynthesiserBase::MPESynthesiserBase ( MPEInstrument instrument)

Constructor.

If you use this constructor, the synthesiser will use the provided instrument object to handle the MPE note state logic. This is useful if you want to use an instance of your own class derived from MPEInstrument for the MPE logic.

Member Function Documentation

◆ enableLegacyMode()

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

Puts the synthesiser into legacy mode.

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.

◆ getLegacyModeChannelRange()

Range<int> juce::MPESynthesiserBase::getLegacyModeChannelRange ( ) const
noexcept

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

◆ getLegacyModePitchbendRange()

int juce::MPESynthesiserBase::getLegacyModePitchbendRange ( ) const
noexcept

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

◆ getSampleRate()

double juce::MPESynthesiserBase::getSampleRate ( ) const
inlinenoexcept

Returns the current target sample rate at which rendering is being done.

Subclasses may need to know this so that they can pitch things correctly.

◆ getZoneLayout()

MPEZoneLayout juce::MPESynthesiserBase::getZoneLayout ( ) const
noexcept

Returns the synthesiser's internal MPE zone layout.

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

◆ handleMidiEvent()

virtual void juce::MPESynthesiserBase::handleMidiEvent ( const MidiMessage )
virtual

Handle incoming MIDI events (called from renderNextBlock).

The default implementation provided here simply forwards everything to MPEInstrument::processNextMidiEvent, where it is used to update the MPE notes, zones etc. MIDI messages not relevant for MPE are ignored.

This method can be overridden if you need to do custom MIDI handling on top of MPE. The MPESynthesiser class overrides this to implement callbacks for MIDI program changes and non-MPE-related MIDI controller messages.

Reimplemented in juce::MPESynthesiser.

◆ isLegacyModeEnabled()

bool juce::MPESynthesiserBase::isLegacyModeEnabled ( ) const
noexcept

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

◆ noteAdded()

virtual void juce::MPEInstrument::Listener::noteAdded ( MPENote  newNote)
inlinevirtualinherited

Implement this callback to be informed whenever a new expressive MIDI note is triggered.

Reimplemented in juce::MPEKeyboardComponent, and juce::MPESynthesiser.

References juce::ignoreUnused().

◆ noteKeyStateChanged()

virtual void juce::MPEInstrument::Listener::noteKeyStateChanged ( MPENote  changedNote)
inlinevirtualinherited

Implement this callback to be informed whether a currently playing MPE note's key state (whether the key is down and/or the note is sustained) has changed.

Note: If the key state changes to MPENote::off, noteReleased is called instead.

Reimplemented in juce::MPESynthesiser.

References juce::ignoreUnused().

◆ notePitchbendChanged()

virtual void juce::MPEInstrument::Listener::notePitchbendChanged ( MPENote  changedNote)
inlinevirtualinherited

Implement this callback to be informed whenever a currently playing MPE note's pitchbend value changes.

Note: This can happen if the note itself is bent, if there is a master channel pitchbend event, or if both occur simultaneously. Call MPENote::getFrequencyInHertz to get the effective note frequency.

Reimplemented in juce::MPEKeyboardComponent, and juce::MPESynthesiser.

References juce::ignoreUnused().

◆ notePressureChanged()

virtual void juce::MPEInstrument::Listener::notePressureChanged ( MPENote  changedNote)
inlinevirtualinherited

Implement this callback to be informed whenever a currently playing MPE note's pressure value changes.

Reimplemented in juce::MPEKeyboardComponent, and juce::MPESynthesiser.

References juce::ignoreUnused().

◆ noteReleased()

virtual void juce::MPEInstrument::Listener::noteReleased ( MPENote  finishedNote)
inlinevirtualinherited

Implement this callback to be informed whenever an MPE note is released (either by a note-off message, or by a sustain/sostenuto pedal release for a note that already received a note-off), and should therefore stop playing.

Reimplemented in juce::MPEKeyboardComponent, and juce::MPESynthesiser.

References juce::ignoreUnused().

◆ noteTimbreChanged()

virtual void juce::MPEInstrument::Listener::noteTimbreChanged ( MPENote  changedNote)
inlinevirtualinherited

Implement this callback to be informed whenever a currently playing MPE note's timbre value changes.

Reimplemented in juce::MPEKeyboardComponent, and juce::MPESynthesiser.

References juce::ignoreUnused().

◆ renderNextBlock()

template<typename floatType >
void juce::MPESynthesiserBase::renderNextBlock ( AudioBuffer< floatType > &  outputAudio,
const MidiBuffer inputMidi,
int  startSample,
int  numSamples 
)

Creates the next block of audio output.

Call this to make sound. This will chop up the AudioBuffer into subBlock pieces separated by events in the MIDI buffer, and then call renderNextSubBlock on each one of them. In between you will get calls to noteAdded/Changed/Finished, where you can update parameters that depend on those notes to use for your audio rendering.

Parameters
outputAudioBuffer into which audio will be rendered
inputMidiMIDI events to process
startSampleThe first sample to process in both buffers
numSamplesThe number of samples to process

◆ renderNextSubBlock() [1/2]

virtual void juce::MPESynthesiserBase::renderNextSubBlock ( AudioBuffer< double > &  ,
int  ,
int   
)
inlineprotectedvirtual

Implement this method if you want to render 64-bit audio as well; otherwise leave blank.

Reimplemented in juce::MPESynthesiser.

◆ renderNextSubBlock() [2/2]

virtual void juce::MPESynthesiserBase::renderNextSubBlock ( AudioBuffer< float > &  outputAudio,
int  startSample,
int  numSamples 
)
protectedpure virtual

Implement this method to render your audio inside.

See also
renderNextBlock

Implemented in juce::MPESynthesiser.

◆ setCurrentPlaybackSampleRate()

virtual void juce::MPESynthesiserBase::setCurrentPlaybackSampleRate ( double  sampleRate)
virtual

Tells the synthesiser what the sample rate is for the audio it's being used to render.

Reimplemented in juce::MPESynthesiser.

◆ setLegacyModeChannelRange()

void juce::MPESynthesiserBase::setLegacyModeChannelRange ( Range< int channelRange)

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

◆ setLegacyModePitchbendRange()

void juce::MPESynthesiserBase::setLegacyModePitchbendRange ( int  pitchbendRange)

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

◆ setMinimumRenderingSubdivisionSize()

void juce::MPESynthesiserBase::setMinimumRenderingSubdivisionSize ( int  numSamples,
bool  shouldBeStrict = false 
)
noexcept

Sets a minimum limit on the size to which audio sub-blocks will be divided when rendering.

When rendering, the audio blocks that are passed into renderNextBlock() will be split up into smaller blocks that lie between all the incoming midi messages, and it is these smaller sub-blocks that are rendered with multiple calls to renderVoices().

Obviously in a pathological case where there are midi messages on every sample, then renderVoices() could be called once per sample and lead to poor performance, so this setting allows you to set a lower limit on the block size.

The default setting is 32, which means that midi messages are accurate to about < 1ms accuracy, which is probably fine for most purposes, but you may want to increase or decrease this value for your synth.

If shouldBeStrict is true, the audio sub-blocks will strictly never be smaller than numSamples.

If shouldBeStrict is false (default), the first audio sub-block in the buffer is allowed to be smaller, to make sure that the first MIDI event in a buffer will always be sample-accurate (this can sometimes help to avoid quantisation or phasing issues).

◆ setPitchbendTrackingMode()

void juce::MPESynthesiserBase::setPitchbendTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the pitchbend dimension.

◆ setPressureTrackingMode()

void juce::MPESynthesiserBase::setPressureTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the pressure dimension.

◆ setTimbreTrackingMode()

void juce::MPESynthesiserBase::setTimbreTrackingMode ( TrackingMode  modeToUse)

Set the MPE tracking mode for the timbre dimension.

◆ setZoneLayout()

void juce::MPESynthesiserBase::setZoneLayout ( MPEZoneLayout  newLayout)

Re-sets the synthesiser's internal MPE zone layout to the one passed in.

As a side effect, this will discard all currently playing notes, call noteReleased for all of them, and disable legacy mode (if previously enabled).

◆ zoneLayoutChanged()

virtual void juce::MPEInstrument::Listener::zoneLayoutChanged ( )
inlinevirtualinherited

Implement this callback to be informed whenever the MPE zone layout or legacy mode settings of this instrument have been changed.

Reimplemented in juce::MPEKeyboardComponent.

Member Data Documentation

◆ defaultInstrument

MPEInstrument juce::MPESynthesiserBase::defaultInstrument { MPEZone (MPEZone::Type::lower, 15) }
private

◆ instrument

MPEInstrument& juce::MPESynthesiserBase::instrument
protected

◆ minimumSubBlockSize

int juce::MPESynthesiserBase::minimumSubBlockSize = 32
private

◆ noteStateLock

CriticalSection juce::MPESynthesiserBase::noteStateLock
private

◆ sampleRate

double juce::MPESynthesiserBase::sampleRate = 0.0
private

◆ subBlockSubdivisionIsStrict

bool juce::MPESynthesiserBase::subBlockSubdivisionIsStrict = false
private

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