From 5d8eda74285f4ce999469a76c61e17b9bd63d695 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Fri, 5 Mar 2021 13:03:52 +0100 Subject: [PATCH] Better messaging --- src/sfizz/SynthMessaging.cpp | 10 ++++++++++ tests/RegionValuesT.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/sfizz/SynthMessaging.cpp b/src/sfizz/SynthMessaging.cpp index 0c73a454..3b4b18bf 100644 --- a/src/sfizz/SynthMessaging.cpp +++ b/src/sfizz/SynthMessaging.cpp @@ -188,6 +188,8 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co GET_REGION_OR_BREAK(indices[0]) if (region.sampleCount) client.receive<'h'>(delay, path, *region.sampleCount); + else + client.receive<'N'>(delay, path, {}); } break; MATCH("/region&/loop_range", "") { @@ -226,6 +228,14 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co client.receive<'f'>(delay, path, region.loopCrossfade); } break; + MATCH("/region&/loop_count", "") { + GET_REGION_OR_BREAK(indices[0]) + if (region.loopCount) + client.receive<'h'>(delay, path, *region.loopCount); + else + client.receive<'N'>(delay, path, {}); + } break; + MATCH("/region&/group", "") { GET_REGION_OR_BREAK(indices[0]) client.receive<'h'>(delay, path, region.group); diff --git a/tests/RegionValuesT.cpp b/tests/RegionValuesT.cpp index e321d558..91df9ba0 100644 --- a/tests/RegionValuesT.cpp +++ b/tests/RegionValuesT.cpp @@ -237,7 +237,9 @@ TEST_CASE("[Values] Count") synth.dispatchMessage(client, 0, "/region1/count", "", nullptr); synth.dispatchMessage(client, 0, "/region2/count", "", nullptr); std::vector expected { + "/region0/count,N : { }", "/region1/count,h : { 2 }", + "/region2/count,N : { }", }; REQUIRE(messageList == expected); } @@ -348,6 +350,29 @@ TEST_CASE("[Values] Loop crossfade") REQUIRE(messageList == expected); } +TEST_CASE("[Values] Loop count") +{ + Synth synth; + std::vector messageList; + Client client(&messageList); + client.setReceiveCallback(&simpleMessageReceiver); + synth.loadSfzString(fs::current_path() / "tests/TestFiles/value_tests.sfz", R"( + sample=kick.wav + sample=kick.wav loop_count=2 + sample=kick.wav loop_count=-1 + )"); + synth.dispatchMessage(client, 0, "/region0/loop_count", "", nullptr); + synth.dispatchMessage(client, 0, "/region1/loop_count", "", nullptr); + synth.dispatchMessage(client, 0, "/region2/loop_count", "", nullptr); + std::vector expected { + "/region0/loop_count,N : { }", + "/region1/loop_count,h : { 2 }", + "/region2/loop_count,N : { }", + }; + REQUIRE(messageList == expected); +} + + TEST_CASE("[Values] Group") { Synth synth;