Reset note and octave offset when resetting the synth

This commit is contained in:
Paul Fd 2021-10-14 23:48:23 +02:00
parent 956b0c9c13
commit cd6bba5378
3 changed files with 37 additions and 0 deletions

View file

@ -263,6 +263,8 @@ void Synth::Impl::clear()
rootPath_.clear(); rootPath_.clear();
numGroups_ = 0; numGroups_ = 0;
numMasters_ = 0; numMasters_ = 0;
noteOffset_ = 0;
octaveOffset_ = 0;
currentSwitch_ = absl::nullopt; currentSwitch_ = absl::nullopt;
defaultPath_ = ""; defaultPath_ = "";
image_ = ""; image_ = "";

View file

@ -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())); client.receive<'i'>(delay, path, int(impl.resources_.getFilePool().getNumPreloadedSamples()));
} break; } 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", "") { MATCH("/key/slots", "") {

View file

@ -1937,3 +1937,30 @@ TEST_CASE("[Synth] Sequences also work on cc triggers")
synth.renderBlock(buffer); synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine", "*saw", "*sine" } ); REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine", "*saw", "*sine" } );
} }
TEST_CASE("[Synth] Loading resets note and octave offsets")
{
sfz::Synth synth;
std::vector<std::string> messageList;
sfz::Client client(&messageList);
client.setReceiveCallback(&simpleMessageReceiver);
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/octave_offset.sfz", R"(
<control> note_offset=1 octave_offset=-1
<region> 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"(
<region> sample=*sine
)");
synth.dispatchMessage(client, 0, "/note_offset", "", nullptr);
synth.dispatchMessage(client, 0, "/octave_offset", "", nullptr);
std::vector<std::string> expected {
"/note_offset,i : { 1 }",
"/octave_offset,i : { -1 }",
"/note_offset,i : { 0 }",
"/octave_offset,i : { 0 }",
};
REQUIRE(messageList == expected);
}