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

Set loop_mode to one_shot for release regions #379

Merged
merged 2 commits into from
Aug 19, 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
3 changes: 3 additions & 0 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ void sfz::Synth::finalizeSfzLoad()
region->loopMode = SfzLoopMode::loop_continuous;
}

if (region->isRelease() && !region->loopMode)
region->loopMode = SfzLoopMode::one_shot;

if (region->loopRange.getEnd() == Default::loopRange.getEnd())
region->loopRange.setEnd(region->sampleEnd);

Expand Down
22 changes: 22 additions & 0 deletions tests/FilesT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,28 @@ TEST_CASE("[Files] Looped regions can start at 0")
REQUIRE( synth.getRegionView(0)->loopRange == Range<uint32_t> { 0, synth.getRegionView(0)->sampleEnd } );
}

TEST_CASE("[Synth] Release triggers automatically sets the loop mode")
{
sfz::Synth synth;
synth.loadSfzString(fs::current_path() / "tests/TestFiles/triggers_setting_loops.sfz", R"(
<region> sample=kick.wav pitch_keycenter=69 loop_mode=loop_sustain trigger=release
<region> sample=kick.wav pitch_keycenter=69 loop_mode=loop_sustain trigger=release_key
<region> sample=kick.wav pitch_keycenter=69 trigger=release loop_mode=loop_sustain
<region> sample=kick.wav pitch_keycenter=69 trigger=release_key loop_mode=loop_sustain
<region> sample=looped_flute.wav pitch_keycenter=69 trigger=release_key
<region> sample=kick.wav pitch_keycenter=69 trigger=release_key // These are normal and set to one_shot
<region> sample=kick.wav pitch_keycenter=69 trigger=release
)");
REQUIRE( synth.getNumRegions() == 7 );
REQUIRE( synth.getRegionView(0)->loopMode == SfzLoopMode::loop_sustain );
REQUIRE( synth.getRegionView(1)->loopMode == SfzLoopMode::loop_sustain );
REQUIRE( synth.getRegionView(2)->loopMode == SfzLoopMode::loop_sustain );
REQUIRE( synth.getRegionView(3)->loopMode == SfzLoopMode::loop_sustain );
REQUIRE( synth.getRegionView(4)->loopMode == SfzLoopMode::loop_continuous );
REQUIRE( synth.getRegionView(5)->loopMode == SfzLoopMode::one_shot );
REQUIRE( synth.getRegionView(6)->loopMode == SfzLoopMode::one_shot );
}

TEST_CASE("[Files] Case sentitiveness")
{
const fs::path sfzFilePath = fs::current_path() / "tests/TestFiles/case_insensitive.sfz";
Expand Down
2 changes: 2 additions & 0 deletions tests/RegionT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,8 @@ TEST_CASE("[Region] Parsing opcodes")
REQUIRE(region.trigger == SfzTrigger::attack);
region.parseOpcode({ "trigger", "release" });
REQUIRE(region.trigger == SfzTrigger::release);
region.parseOpcode({ "trigger", "release_key" });
REQUIRE(region.trigger == SfzTrigger::release_key);
region.parseOpcode({ "trigger", "first" });
REQUIRE(region.trigger == SfzTrigger::first);
region.parseOpcode({ "trigger", "legato" });
Expand Down