Skip to content

Commit

Permalink
Don't send note offs when CCs are choking
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Dec 26, 2023
1 parent 590fe3e commit 8cdca09
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
6 changes: 3 additions & 3 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1309,12 +1309,12 @@ void Synth::Impl::startVoice(Layer* layer, int delay, const TriggerEvent& trigge
ring.addVoiceToRing(selectedVoice);
}

void Synth::Impl::checkOffGroups(const Region* region, int delay, int number)
void Synth::Impl::checkOffGroups(const Region* region, int delay, int number, bool chokedByCC)
{
for (auto& voice : voiceManager_) {
if (voice.checkOffGroup(region, delay, number)) {
const TriggerEvent& event = voice.getTriggerEvent();
if (event.type == TriggerEventType::NoteOn)
if (event.type == TriggerEventType::NoteOn && !chokedByCC)
noteOffDispatch(delay, event.number, event.value);
}
}
Expand Down Expand Up @@ -1451,7 +1451,7 @@ void Synth::Impl::ccDispatch(int delay, int ccNumber, float value, int extendedA
if (region.useTimerRange && ! voiceManager_.withinValidTimerRange(&region, midiState.getInternalClock() + delay, sampleRate_))
continue;

checkOffGroups(&region, delay, ccNumber);
checkOffGroups(&region, delay, ccNumber, true);
startVoice(layer, delay, triggerEvent, ring);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sfizz/SynthPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ struct Synth::Impl final: public Parser::Listener {
* @param delay
* @param number
*/
void checkOffGroups(const Region* region, int delay, int number);
void checkOffGroups(const Region* region, int delay, int number, bool chokedByCC = false);

/**
* @brief Resets the callback duration breakdown to 0
Expand Down
50 changes: 25 additions & 25 deletions tests/PolyphonyT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,31 @@ TEST_CASE("[Polyphony] Choke same group and note if the region is switched off (
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine" } );
}

TEST_CASE("[Polyphony] Choking on poly-aftertouch respects the note number")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyat_choke.sfz", R"(
<region> key=55 group=1 off_by=2 sample=*saw
<region> key=55 group=2 on_locc130=127 on_hicc130=127 trigger=release sample=*sine
)");
synth.noteOn(0, 55, 63 );
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 54, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 57, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 55, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine"} );
synth.hdPolyAftertouch(0, 55, 0.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine"} );
}

TEST_CASE("[Polyphony] A note coming at the same time as another can choke it")
{
sfz::Synth synth;
Expand Down Expand Up @@ -632,28 +657,3 @@ TEST_CASE("[Polyphony] A note coming one sample before another note cannot choke
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "kick.wav", "snare.wav" } );
}

TEST_CASE("[Polyphony] Choking on poly-aftertouch respects the note number")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyat_choke.sfz", R"(
<region> key=55 group=1 off_by=2 sample=*saw
<region> 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<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 54, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 57, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.hdPolyAftertouch(0, 55, 1.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine"} );
synth.hdPolyAftertouch(0, 55, 0.0f);
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine"} );
}

0 comments on commit 8cdca09

Please sign in to comment.