Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sw_default in <region> #531

Merged
merged 1 commit into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sfizz/Region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/sfizz/Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions tests/RegionActivationT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}