Handle sw_default in <region>

This commit is contained in:
Paul Ferrand 2020-10-28 16:12:42 +01:00
parent a654458c55
commit 8dd169c9d2
4 changed files with 37 additions and 1 deletions

View file

@ -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;

View file

@ -353,6 +353,7 @@ struct Region {
absl::optional<uint8_t> upKeyswitch {}; // sw_up
absl::optional<uint8_t> downKeyswitch {}; // sw_down
absl::optional<uint8_t> previousKeyswitch {}; // sw_previous
absl::optional<uint8_t> defaultSwitch {};
SfzVelocityOverride velocityOverride { Default::velocityOverride }; // sw_vel
bool checkSustain { Default::checkSustain }; // sustain_sw
bool checkSostenuto { Default::checkSostenuto }; // sostenuto_sw

View file

@ -193,6 +193,9 @@ void sfz::Synth::buildRegion(const std::vector<Opcode>& 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);

View file

@ -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"(
<global> sw_default=60
<region> sw_last=60 key=70 sample=*saw
<group> sw_default=58
<region> sw_last=59 key=72 sample=*saw
<master> sw_default=59
<region> 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"(
<global> sw_default=60
<region> sw_last=58 key=70 sample=*saw
<region> sw_default=58 sw_last=59 key=72 sample=*saw
)");
REQUIRE(synth.getRegionView(0)->isSwitchedOn());
REQUIRE(!synth.getRegionView(1)->isSwitchedOn());
}