From 8dd169c9d2c5e510d0ba761c4c526c87e097c8ee Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Wed, 28 Oct 2020 16:12:42 +0100 Subject: [PATCH] Handle sw_default in --- src/sfizz/Region.cpp | 4 +++- src/sfizz/Region.h | 1 + src/sfizz/Synth.cpp | 3 +++ tests/RegionActivationT.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index 42be5f79..f131febf 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -1390,11 +1390,13 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode) gainToEffect[effectNumber] = *value / 100; break; } + case hash("sw_default"): + setValueFromOpcode(opcode, defaultSwitch, Default::keyRange); + break; // Ignored opcodes case hash("hichan"): case hash("lochan"): - case hash("sw_default"): case hash("ampeg_depth"): case hash("ampeg_vel&depth"): break; diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 7fb0b695..932aecf4 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -353,6 +353,7 @@ struct Region { absl::optional upKeyswitch {}; // sw_up absl::optional downKeyswitch {}; // sw_down absl::optional previousKeyswitch {}; // sw_previous + absl::optional defaultSwitch {}; SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel bool checkSustain { Default::checkSustain }; // sustain_sw bool checkSostenuto { Default::checkSostenuto }; // sostenuto_sw diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index b15e8adb..271e1e3e 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -193,6 +193,9 @@ void sfz::Synth::buildRegion(const std::vector& regionOpcodes) if (lastRegion->previousKeyswitch) previousKeyswitchLists.push_back(lastRegion.get()); + if (lastRegion->defaultSwitch) + currentSwitch = *lastRegion->defaultSwitch; + // There was a combination of group= and polyphony= on a region, so set the group polyphony if (lastRegion->group != Default::group && lastRegion->polyphony != config::maxVoices) setGroupPolyphony(lastRegion->group, lastRegion->polyphony); diff --git a/tests/RegionActivationT.cpp b/tests/RegionActivationT.cpp index be5c808c..b67690ee 100644 --- a/tests/RegionActivationT.cpp +++ b/tests/RegionActivationT.cpp @@ -497,3 +497,33 @@ TEST_CASE("[Keyswitches] sw_lolast and sw_hilast with sw_default") REQUIRE(synth.getRegionView(0)->isSwitchedOn()); REQUIRE(!synth.getRegionView(1)->isSwitchedOn()); } + +TEST_CASE("[Keyswitches] Multiple sw_default") +{ + sfz::Synth synth; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"( + sw_default=60 + sw_last=60 key=70 sample=*saw + sw_default=58 + sw_last=59 key=72 sample=*saw + sw_default=59 + sw_last=62 key=73 sample=*saw + )"); + REQUIRE(!synth.getRegionView(0)->isSwitchedOn()); + // Only the last one is taken into account + REQUIRE(synth.getRegionView(1)->isSwitchedOn()); + REQUIRE(!synth.getRegionView(2)->isSwitchedOn()); +} + +TEST_CASE("[Keyswitches] Multiple sw_default, in region") +{ + sfz::Synth synth; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/sw_previous.sfz", R"( + sw_default=60 + sw_last=58 key=70 sample=*saw + sw_default=58 sw_last=59 key=72 sample=*saw + )"); + REQUIRE(synth.getRegionView(0)->isSwitchedOn()); + REQUIRE(!synth.getRegionView(1)->isSwitchedOn()); +} +