Parse CC modifiers for flex EGs

This commit is contained in:
Paul Fd 2021-06-23 12:32:54 +02:00
parent ba7cb52b9c
commit 5da331cf18
3 changed files with 97 additions and 0 deletions

View file

@ -2045,6 +2045,7 @@ void Synth::Impl::collectUsedCCsFromRegion(BitArray<config::numCCs>& 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<config::numCCs>& 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<config::numCCs>& 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);

View file

@ -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<int32_t>(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

View file

@ -3251,3 +3251,53 @@ TEST_CASE("[Values] EQ value bounds")
REQUIRE(messageList == expected);
}
}
TEST_CASE("[Values] Flex EGs")
{
Synth synth;
std::vector<std::string> messageList;
Client client(&messageList);
client.setReceiveCallback(&simpleMessageReceiver);
synth.loadSfzString(fs::current_path() / "tests/TestFiles/value_tests.sfz", R"(
<region> 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<std::string> 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<std::string> messageList;
Client client(&messageList);
client.setReceiveCallback(&simpleMessageReceiver);
synth.loadSfzString(fs::current_path() / "tests/TestFiles/value_tests.sfz", R"(
<region> 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<std::string> 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);
}