From 1a22a3fafb329c9c1fe399ff4e58a88f38f8cf66 Mon Sep 17 00:00:00 2001 From: ed Date: Mon, 11 Mar 2019 16:22:13 +0000 Subject: [PATCH] Allow simulating poly-aftertouch messages in MPEInstrument --- .../mpe/juce_MPEInstrument.cpp | 32 ++++++++++++------- .../mpe/juce_MPEInstrument.h | 7 ++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp index 423167c73b..75a2b01a87 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp +++ b/modules/juce_audio_basics/mpe/juce_MPEInstrument.cpp @@ -258,18 +258,8 @@ void MPEInstrument::processMidiAfterTouchMessage (const MidiMessage& message) if (! isMasterChannel (message.getChannel())) return; - const ScopedLock sl (lock); - - for (auto i = notes.size(); --i >= 0;) - { - auto& note = notes.getReference (i); - - if (note.midiChannel == message.getChannel() && note.initialNote == message.getNoteNumber()) - { - pressureDimension.getValue (note) = MPEValue::from7BitInt (message.getAfterTouchValue()); - listeners.call ([&] (Listener& l) { l.notePressureChanged (note); }); - } - } + polyAftertouch (message.getChannel(), message.getNoteNumber(), + MPEValue::from7BitInt (message.getAfterTouchValue())); } //============================================================================== @@ -385,6 +375,24 @@ void MPEInstrument::timbre (int midiChannel, MPEValue value) updateDimension (midiChannel, timbreDimension, value); } +void MPEInstrument::polyAftertouch (int midiChannel, int midiNoteNumber, MPEValue value) +{ + const ScopedLock sl (lock); + + for (auto i = notes.size(); --i >= 0;) + { + auto& note = notes.getReference (i); + + if (note.midiChannel == midiChannel + && note.initialNote == midiNoteNumber + && pressureDimension.getValue (note) != value) + { + pressureDimension.getValue (note) = value; + callListenersDimensionChanged (note, pressureDimension); + } + } +} + MPEValue MPEInstrument::getInitialValueForNewNote (int midiChannel, MPEDimension& dimension) const { if (getLastNotePlayedPtr (midiChannel) != nullptr) diff --git a/modules/juce_audio_basics/mpe/juce_MPEInstrument.h b/modules/juce_audio_basics/mpe/juce_MPEInstrument.h index 4062c9f7bc..d5ab49ab49 100644 --- a/modules/juce_audio_basics/mpe/juce_MPEInstrument.h +++ b/modules/juce_audio_basics/mpe/juce_MPEInstrument.h @@ -185,6 +185,13 @@ public: */ virtual void timbre (int midiChannel, MPEValue value); + /** Request a poly-aftertouch change for a given note number. + + The change will be broadcast to all notes sharing the channel and note + number of the change message. + */ + virtual void polyAftertouch (int midiChannel, int midiNoteNumber, MPEValue value); + /** Request a sustain pedal press or release. If midiChannel is a zone's master channel, this will act on all notes in