CC events can also off notes

Same as note-on events
This commit is contained in:
Paul Fd 2021-04-04 21:54:19 +02:00
parent 7f02c413c1
commit f189292a60
3 changed files with 24 additions and 1 deletions

View file

@ -1215,6 +1215,12 @@ void Synth::Impl::ccDispatch(int delay, int ccNumber, float value) noexcept
}
if (layer->registerCC(ccNumber, value)) {
for (auto& voice : voiceManager_) {
if (voice.checkOffGroup(&region, delay, ccNumber)) {
const TriggerEvent& event = voice.getTriggerEvent();
noteOffDispatch(delay, event.number, event.value);
}
}
startVoice(layer, delay, triggerEvent, ring);
}
}

View file

@ -1572,7 +1572,7 @@ bool Voice::checkOffGroup(const Region* other, int delay, int noteNumber) noexce
return false;
if (impl.triggerEvent_.type == TriggerEventType::NoteOn
&& region->offBy == other->group
&& region->offBy && *region->offBy == other->group
&& (region->group != other->group || noteNumber != impl.triggerEvent_.number)) {
off(delay);
return true;

View file

@ -1609,6 +1609,23 @@ TEST_CASE("[Synth] Off by with CC switches")
REQUIRE( getPlayingVoices(synth).front()->getRegion()->sampleId->filename() == "*saw" );
}
TEST_CASE("[Synth] Off by a CC event")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path(), R"(
<region> group=1 off_by=2 sample=*saw
<region> group=2 hikey=-1 on_locc67=127 on_hicc67=127 sample=*sine
)");
synth.noteOn(0, 60, 85);
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 1 );
synth.cc(10, 67, 127);
synth.renderBlock(buffer);
REQUIRE( numPlayingVoices(synth) == 1 );
}
TEST_CASE("[Synth] Initial values of CC")
{
sfz::Synth synth;