From 61619ec0d52ac79e3d5d57674b80161096fb6dc1 Mon Sep 17 00:00:00 2001 From: Attila Szarvas Date: Wed, 16 Jun 2021 17:36:26 +0200 Subject: [PATCH] SamplerPluginDemo: Use both velocity and pressure to control note volumes --- examples/Plugins/SamplerPluginDemo.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/Plugins/SamplerPluginDemo.h b/examples/Plugins/SamplerPluginDemo.h index 852093e7fb..c03c901840 100644 --- a/examples/Plugins/SamplerPluginDemo.h +++ b/examples/Plugins/SamplerPluginDemo.h @@ -272,7 +272,7 @@ public: jassert (currentlyPlayingNote.keyState == MPENote::keyDown || currentlyPlayingNote.keyState == MPENote::keyDownAndSustained); - level .setTargetValue (currentlyPlayingNote.pressure.asUnsignedFloat()); + level .setTargetValue (currentlyPlayingNote.noteOnVelocity.asUnsignedFloat()); frequency.setTargetValue (currentlyPlayingNote.getFrequencyInHertz()); auto loopPoints = samplerSound->getLoopPointsInSeconds(); @@ -282,6 +282,7 @@ public: for (auto smoothed : { &level, &frequency, &loopBegin, &loopEnd }) smoothed->reset (currentSampleRate, smoothingLengthInSeconds); + previousPressure = currentlyPlayingNote.pressure.asUnsignedFloat(); currentSamplePos = 0.0; tailOff = 0.0; } @@ -298,7 +299,10 @@ public: void notePressureChanged() override { - level.setTargetValue (currentlyPlayingNote.pressure.asUnsignedFloat()); + const auto currentPressure = static_cast (currentlyPlayingNote.pressure.asUnsignedFloat()); + const auto deltaPressure = currentPressure - previousPressure; + level.setTargetValue (jlimit (0.0, 1.0, level.getCurrentValue() + deltaPressure)); + previousPressure = currentPressure; } void notePitchbendChanged() override @@ -489,6 +493,7 @@ private: SmoothedValue frequency { 0 }; SmoothedValue loopBegin; SmoothedValue loopEnd; + double previousPressure { 0 }; double currentSamplePos { 0 }; double tailOff { 0 }; Direction currentDirection { Direction::forward };