diff --git a/src/sfizz/Layer.cpp b/src/sfizz/Layer.cpp index 1e3a43d0..183339c9 100644 --- a/src/sfizz/Layer.cpp +++ b/src/sfizz/Layer.cpp @@ -184,7 +184,7 @@ bool Layer::registerCC(int ccNumber, float ccValue, float randValue, int extende sequenceSwitched_ = ((sequenceCounter_++ % region.sequenceLength) == region.sequencePosition - 1); - if (isSwitchedOn() && (ccValue != midiState_.getCCValue(ccNumber))) + if (isSwitchedOn() && (ccNumber == ExtendedCCs::polyphonicAftertouch || ccValue != midiState_.getCCValue(ccNumber))) return true; } diff --git a/tests/PolyphonyT.cpp b/tests/PolyphonyT.cpp index b1b10eee..4dec7381 100644 --- a/tests/PolyphonyT.cpp +++ b/tests/PolyphonyT.cpp @@ -632,3 +632,28 @@ TEST_CASE("[Polyphony] A note coming one sample before another note cannot choke synth.renderBlock(buffer); REQUIRE( playingSamples(synth) == std::vector { "kick.wav", "snare.wav" } ); } + +TEST_CASE("[Polyphony] Choking on poly-aftertouch respects the note number") +{ + sfz::Synth synth; + sfz::AudioBuffer buffer { 2, static_cast(synth.getSamplesPerBlock()) }; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyat_choke.sfz", R"( + key=55 group=1 off_by=2 sample=*saw + key=55 group=2 on_locc130=127 on_hicc130=127 trigger=release polyphony=1 sample=*sine + )"); + synth.noteOn(0, 55, 63 ); + synth.renderBlock(buffer); + REQUIRE( playingSamples(synth) == std::vector { "*saw" } ); + synth.hdPolyAftertouch(0, 54, 1.0f); + synth.renderBlock(buffer); + REQUIRE( playingSamples(synth) == std::vector { "*saw" } ); + synth.hdPolyAftertouch(0, 57, 1.0f); + synth.renderBlock(buffer); + REQUIRE( playingSamples(synth) == std::vector { "*saw" } ); + synth.hdPolyAftertouch(0, 55, 1.0f); + synth.renderBlock(buffer); + REQUIRE( playingSamples(synth) == std::vector { "*sine"} ); + synth.hdPolyAftertouch(0, 55, 0.0f); + synth.renderBlock(buffer); + REQUIRE( playingSamples(synth) == std::vector { "*sine"} ); +} diff --git a/tests/RegionTriggersT.cpp b/tests/RegionTriggersT.cpp index a53a700a..ec6d0cd8 100644 --- a/tests/RegionTriggersT.cpp +++ b/tests/RegionTriggersT.cpp @@ -550,3 +550,23 @@ TEST_CASE("[Triggers] hitimer (with group)") synth.noteOn(0, 41, 100); REQUIRE(playingSamples(synth) == std::vector { "snare.wav", "kick.wav", "kick.wav" }); } + +TEST_CASE("[Triggers] Respect poly-aftertouch note values when triggering on cc130") +{ + Synth synth; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/poly_at_trigger.sfz", R"( + key=55 on_locc130=127 on_hicc130=127 sample=*saw + key=57 on_locc130=127 on_hicc130=127 sample=*sine + )"); + + synth.polyAftertouch(0, 54, 127); + REQUIRE(playingSamples(synth) == std::vector { }); + synth.polyAftertouch(0, 56, 127); + REQUIRE(playingSamples(synth) == std::vector { }); + synth.polyAftertouch(0, 58, 127); + REQUIRE(playingSamples(synth) == std::vector { }); + synth.polyAftertouch(0, 55, 127); + REQUIRE(playingSamples(synth) == std::vector { "*saw" }); + synth.polyAftertouch(10, 57, 127); + REQUIRE(playingSamples(synth) == std::vector { "*saw", "*sine" }); +}