From cd6bba53788151e71bf36d8b0534a69dcedfefa6 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Thu, 14 Oct 2021 23:48:23 +0200 Subject: [PATCH] Reset note and octave offset when resetting the synth --- src/sfizz/Synth.cpp | 2 ++ src/sfizz/SynthMessaging.cpp | 8 ++++++++ tests/SynthT.cpp | 27 +++++++++++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index c7893385..055ec82d 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -263,6 +263,8 @@ void Synth::Impl::clear() rootPath_.clear(); numGroups_ = 0; numMasters_ = 0; + noteOffset_ = 0; + octaveOffset_ = 0; currentSwitch_ = absl::nullopt; defaultPath_ = ""; image_ = ""; diff --git a/src/sfizz/SynthMessaging.cpp b/src/sfizz/SynthMessaging.cpp index 9b00799f..e2ff06f9 100644 --- a/src/sfizz/SynthMessaging.cpp +++ b/src/sfizz/SynthMessaging.cpp @@ -87,6 +87,14 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co client.receive<'i'>(delay, path, int(impl.resources_.getFilePool().getNumPreloadedSamples())); } break; + MATCH("/octave_offset", "") { + client.receive<'i'>(delay, path, impl.octaveOffset_); + } break; + + MATCH("/note_offset", "") { + client.receive<'i'>(delay, path, impl.noteOffset_); + } break; + //---------------------------------------------------------------------- MATCH("/key/slots", "") { diff --git a/tests/SynthT.cpp b/tests/SynthT.cpp index b3f32f1a..b0f3feda 100644 --- a/tests/SynthT.cpp +++ b/tests/SynthT.cpp @@ -1937,3 +1937,30 @@ TEST_CASE("[Synth] Sequences also work on cc triggers") synth.renderBlock(buffer); REQUIRE( playingSamples(synth) == std::vector { "*sine", "*saw", "*sine" } ); } + +TEST_CASE("[Synth] Loading resets note and octave offsets") +{ + sfz::Synth synth; + std::vector messageList; + sfz::Client client(&messageList); + client.setReceiveCallback(&simpleMessageReceiver); + sfz::AudioBuffer buffer { 2, static_cast(synth.getSamplesPerBlock()) }; + synth.loadSfzString(fs::current_path() / "tests/TestFiles/octave_offset.sfz", R"( + note_offset=1 octave_offset=-1 + sample=*sine + )"); + synth.dispatchMessage(client, 0, "/note_offset", "", nullptr); + synth.dispatchMessage(client, 0, "/octave_offset", "", nullptr); + synth.loadSfzString(fs::current_path() / "tests/TestFiles/octave_offset.sfz", R"( + sample=*sine + )"); + synth.dispatchMessage(client, 0, "/note_offset", "", nullptr); + synth.dispatchMessage(client, 0, "/octave_offset", "", nullptr); + std::vector expected { + "/note_offset,i : { 1 }", + "/octave_offset,i : { -1 }", + "/note_offset,i : { 0 }", + "/octave_offset,i : { 0 }", + }; + REQUIRE(messageList == expected); +}