diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index ba5c109d..b15e8adb 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -628,6 +628,17 @@ void sfz::Synth::finalizeSfzLoad() insertPairUniquely(keyswitchLabels, *region->lastKeyswitch, *region->keyswitchLabel); } + if (region->lastKeyswitchRange) { + auto& range = *region->lastKeyswitchRange; + if (currentSwitch) + region->keySwitched = range.containsWithEnd(*currentSwitch); + + if (region->keyswitchLabel) { + for (uint8_t note = range.getStart(), end = range.getEnd(); note <= end; note++) + insertPairUniquely(keyswitchLabels, note, *region->keyswitchLabel); + } + } + // Some regions had group number but no "group-level" opcodes handled the polyphony while (polyphonyGroups.size() <= region->group) { polyphonyGroups.emplace_back(); @@ -1176,7 +1187,6 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc region->keySwitched = true; for (auto& region : noteActivationLists[noteNumber]) { - if (region->registerNoteOn(noteNumber, velocity, randValue)) { for (auto& voice : voices) { if (voice->checkOffGroup(region, delay, noteNumber)) { diff --git a/tests/RegionActivationT.cpp b/tests/RegionActivationT.cpp index 6c5a3ed9..be5c808c 100644 --- a/tests/RegionActivationT.cpp +++ b/tests/RegionActivationT.cpp @@ -427,7 +427,6 @@ TEST_CASE("[Keyswitches] sw_previous out of range") TEST_CASE("[Keyswitches] sw_lolast and sw_hilast") { - // The behavior is the same in this case, regardless of the keyrange sfz::Synth synth; synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"( sw_lolast=57 sw_hilast=59 key=70 sample=*saw @@ -460,7 +459,6 @@ TEST_CASE("[Keyswitches] sw_lolast and sw_hilast") TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_last") { - // The behavior is the same in this case, regardless of the keyrange sfz::Synth synth; synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"( sw_last=40 sw_lolast=57 sw_hilast=59 key=70 sample=*saw @@ -487,3 +485,15 @@ TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_last") REQUIRE(!synth.getRegionView(0)->isSwitchedOn()); REQUIRE(synth.getRegionView(1)->isSwitchedOn()); } + +TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_default") +{ + sfz::Synth synth; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"( + sw_default=58 + sw_lolast=57 sw_hilast=59 key=70 sample=*saw + sw_lolast=60 sw_hilast=62 key=72 sample=*sine + )"); + REQUIRE(synth.getRegionView(0)->isSwitchedOn()); + REQUIRE(!synth.getRegionView(1)->isSwitchedOn()); +}