From 5da331cf18e71512ac64b79f1a609ac51dabdb06 Mon Sep 17 00:00:00 2001 From: Paul Fd Date: Wed, 23 Jun 2021 12:32:54 +0200 Subject: [PATCH] Parse CC modifiers for flex EGs --- src/sfizz/Synth.cpp | 3 +++ src/sfizz/SynthMessaging.cpp | 44 +++++++++++++++++++++++++++++++ tests/RegionValuesT.cpp | 50 ++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+) diff --git a/src/sfizz/Synth.cpp b/src/sfizz/Synth.cpp index 0e7f4dbe..1e200b58 100644 --- a/src/sfizz/Synth.cpp +++ b/src/sfizz/Synth.cpp @@ -2045,6 +2045,7 @@ void Synth::Impl::collectUsedCCsFromRegion(BitArray& usedCCs, co collectUsedCCsFromCCMap(usedCCs, region.amplitudeEG.ccHold); collectUsedCCsFromCCMap(usedCCs, region.amplitudeEG.ccStart); collectUsedCCsFromCCMap(usedCCs, region.amplitudeEG.ccSustain); + if (region.pitchEG) { collectUsedCCsFromCCMap(usedCCs, region.pitchEG->ccAttack); collectUsedCCsFromCCMap(usedCCs, region.pitchEG->ccRelease); @@ -2054,6 +2055,7 @@ void Synth::Impl::collectUsedCCsFromRegion(BitArray& usedCCs, co collectUsedCCsFromCCMap(usedCCs, region.pitchEG->ccStart); collectUsedCCsFromCCMap(usedCCs, region.pitchEG->ccSustain); } + if (region.filterEG) { collectUsedCCsFromCCMap(usedCCs, region.filterEG->ccAttack); collectUsedCCsFromCCMap(usedCCs, region.filterEG->ccRelease); @@ -2063,6 +2065,7 @@ void Synth::Impl::collectUsedCCsFromRegion(BitArray& usedCCs, co collectUsedCCsFromCCMap(usedCCs, region.filterEG->ccStart); collectUsedCCsFromCCMap(usedCCs, region.filterEG->ccSustain); } + for (const LFODescription& lfo : region.lfos) { collectUsedCCsFromCCMap(usedCCs, lfo.phaseCC); collectUsedCCsFromCCMap(usedCCs, lfo.delayCC); diff --git a/src/sfizz/SynthMessaging.cpp b/src/sfizz/SynthMessaging.cpp index b53cf1a0..3e6a87f2 100644 --- a/src/sfizz/SynthMessaging.cpp +++ b/src/sfizz/SynthMessaging.cpp @@ -51,6 +51,16 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co break; \ const auto& lfo = region.lfos[idx]; + #define GET_EG_OR_BREAK(idx) \ + if (idx >= region.flexEGs.size()) \ + break; \ + auto& eg = region.flexEGs[idx]; + + #define GET_EG_POINT_OR_BREAK(idx) \ + if (idx >= eg.points.size()) \ + break; \ + auto& point = eg.points[idx]; + MATCH("/hello", "") { client.receive(delay, "/hello", "", nullptr); } break; @@ -1352,10 +1362,44 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co client.receive<'i'>(delay, path, static_cast(lfo.sub[0].wave)); } break; + MATCH("/region&/eg&/point&/time", "") { + GET_REGION_OR_BREAK(indices[0]) + GET_EG_OR_BREAK(indices[1]) + GET_EG_POINT_OR_BREAK(indices[2] + 1) + + client.receive<'f'>(delay, path, point.time); + } break; + + MATCH("/region&/eg&/point&/time_cc&", "") { + GET_REGION_OR_BREAK(indices[0]) + GET_EG_OR_BREAK(indices[1]) + GET_EG_POINT_OR_BREAK(indices[2] + 1) + + client.receive<'f'>(delay, path, point.ccTime.getWithDefault(indices[3])); + } break; + + MATCH("/region&/eg&/point&/level", "") { + GET_REGION_OR_BREAK(indices[0]) + GET_EG_OR_BREAK(indices[1]) + GET_EG_POINT_OR_BREAK(indices[2] + 1) + + client.receive<'f'>(delay, path, point.level); + } break; + + MATCH("/region&/eg&/point&/level_cc&", "") { + GET_REGION_OR_BREAK(indices[0]) + GET_EG_OR_BREAK(indices[1]) + GET_EG_POINT_OR_BREAK(indices[2] + 1) + + client.receive<'f'>(delay, path, point.ccLevel.getWithDefault(indices[3])); + } break; + #undef GET_REGION_OR_BREAK #undef GET_FILTER_OR_BREAK #undef GET_EQ_OR_BREAK #undef GET_LFO_OR_BREAK + #undef GET_EG_OR_BREAK + #undef GET_EG_POINT_OR_BREAK //---------------------------------------------------------------------- // Setting values diff --git a/tests/RegionValuesT.cpp b/tests/RegionValuesT.cpp index a6fc4dd7..970a259e 100644 --- a/tests/RegionValuesT.cpp +++ b/tests/RegionValuesT.cpp @@ -3251,3 +3251,53 @@ TEST_CASE("[Values] EQ value bounds") REQUIRE(messageList == expected); } } + +TEST_CASE("[Values] Flex EGs") +{ + 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 eg1_time1=0.1 eg1_level1=0.5 eg1_time2=0.4 eg1_level2=2 eg2_time1=4 eg2_level1=0.1 + )"); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/time", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/level", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point1/time", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point1/level", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg1/point0/time", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg1/point0/level", "", nullptr); + std::vector expected { + "/region0/eg0/point0/time,f : { 0.1 }", + "/region0/eg0/point0/level,f : { 0.5 }", + "/region0/eg0/point1/time,f : { 0.4 }", + "/region0/eg0/point1/level,f : { 2 }", + "/region0/eg1/point0/time,f : { 4 }", + "/region0/eg1/point0/level,f : { 0.1 }", + }; + REQUIRE(messageList == expected); +} + +TEST_CASE("[Values] Flex EGs CC") +{ + 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 eg1_time1_cc2=0.1 eg1_level1_oncc3=0.5 + )"); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/time_cc2", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/time_cc4", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/level_cc3", "", nullptr); + synth.dispatchMessage(client, 0, "/region0/eg0/point0/level_cc12", "", nullptr); + std::vector expected { + "/region0/eg0/point0/time_cc2,f : { 0.1 }", + "/region0/eg0/point0/time_cc4,f : { 0 }", + "/region0/eg0/point0/level_cc3,f : { 0.5 }", + "/region0/eg0/point0/level_cc12,f : { 0 }", + }; + REQUIRE(messageList == expected); +}