Add delay_cc and delay_oncc
This commit is contained in:
parent
c5c7e2bb63
commit
d112cfaf2d
6 changed files with 43 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ constexpr auto uint32_t_max = std::numeric_limits<uint32_t>::max();
|
|||
|
||||
extern const OpcodeSpec<float> delay { 0.0f, Range<float>(0.0f, 100.0f), 0 };
|
||||
extern const OpcodeSpec<float> delayRandom { 0.0f, Range<float>(0.0f, 100.0f), 0 };
|
||||
extern const OpcodeSpec<float> delayMod { 0.0f, Range<float>(0.0f, 100.0f), 0 };
|
||||
extern const OpcodeSpec<int64_t> offset { 0, Range<int64_t>(0, uint32_t_max), 0 };
|
||||
extern const OpcodeSpec<int64_t> offsetMod { 0, Range<int64_t>(0, uint32_t_max), 0 };
|
||||
extern const OpcodeSpec<int64_t> offsetRandom { 0, Range<int64_t>(0, uint32_t_max), 0 };
|
||||
|
|
|
|||
|
|
@ -126,6 +126,7 @@ namespace Default
|
|||
{
|
||||
extern const OpcodeSpec<float> delay;
|
||||
extern const OpcodeSpec<float> delayRandom;
|
||||
extern const OpcodeSpec<float> delayMod;
|
||||
extern const OpcodeSpec<int64_t> offset;
|
||||
extern const OpcodeSpec<int64_t> offsetMod;
|
||||
extern const OpcodeSpec<int64_t> offsetRandom;
|
||||
|
|
|
|||
|
|
@ -97,6 +97,12 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode)
|
|||
case hash("delay"):
|
||||
delay = opcode.read(Default::delay);
|
||||
break;
|
||||
case hash("delay_oncc&"): // also delay_cc&
|
||||
if (opcode.parameters.back() > config::numCCs)
|
||||
return false;
|
||||
|
||||
delayCC[opcode.parameters.back()] = opcode.read(Default::delayMod);
|
||||
break;
|
||||
case hash("delay_random"):
|
||||
delayRandom = opcode.read(Default::delayRandom);
|
||||
break;
|
||||
|
|
@ -1636,7 +1642,11 @@ uint64_t sfz::Region::getOffset(Oversampling factor) const noexcept
|
|||
float sfz::Region::getDelay() const noexcept
|
||||
{
|
||||
fast_real_distribution<float> delayDistribution { 0, delayRandom };
|
||||
return delay + delayDistribution(Random::randomGenerator);
|
||||
float finalDelay { delay };
|
||||
finalDelay += delayDistribution(Random::randomGenerator);
|
||||
for (const auto& mod: delayCC)
|
||||
finalDelay += mod.data * midiState.getCCValue(mod.cc);
|
||||
return Default::delay.bounds.clamp(finalDelay);
|
||||
}
|
||||
|
||||
uint32_t sfz::Region::trueSampleEnd(Oversampling factor) const noexcept
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ struct Region {
|
|||
absl::optional<int> sampleQuality {};
|
||||
float delay { Default::delay }; // delay
|
||||
float delayRandom { Default::delayRandom }; // delay_random
|
||||
CCMap<float> delayCC { Default::delayMod };
|
||||
int64_t offset { Default::offset }; // offset
|
||||
int64_t offsetRandom { Default::offsetRandom }; // offset_random
|
||||
CCMap<int64_t> offsetCC { Default::offsetMod };
|
||||
|
|
|
|||
|
|
@ -103,6 +103,11 @@ void sfz::Synth::dispatchMessage(Client& client, int delay, const char* path, co
|
|||
client.receive<'f'>(delay, path, region.delayRandom);
|
||||
} break;
|
||||
|
||||
MATCH("/region&/delay_cc&", "") {
|
||||
GET_REGION_OR_BREAK(indices[0])
|
||||
client.receive<'f'>(delay, path, region.delayCC.getWithDefault(indices[1]));
|
||||
} break;
|
||||
|
||||
MATCH("/region&/offset", "") {
|
||||
GET_REGION_OR_BREAK(indices[0])
|
||||
client.receive<'h'>(delay, path, region.offset);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,30 @@ TEST_CASE("[Values] Delay")
|
|||
};
|
||||
REQUIRE(messageList == expected);
|
||||
}
|
||||
|
||||
SECTION("CC")
|
||||
{
|
||||
synth.loadSfzString(fs::current_path() / "tests/TestFiles/value_tests.sfz", R"(
|
||||
<region> sample=kick.wav
|
||||
<region> sample=kick.wav delay_cc12=1.5
|
||||
<region> sample=kick.wav delay_cc12=-1.5
|
||||
<region> sample=kick.wav delay_cc14=3 delay_cc12=2 delay_cc12=-12
|
||||
)");
|
||||
synth.dispatchMessage(client, 0, "/region0/delay_cc12", "", nullptr);
|
||||
synth.dispatchMessage(client, 0, "/region1/delay_cc12", "", nullptr);
|
||||
synth.dispatchMessage(client, 0, "/region2/delay_cc12", "", nullptr);
|
||||
synth.dispatchMessage(client, 0, "/region3/delay_cc14", "", nullptr);
|
||||
// TODO: activate for the new region parser ; ignore the second value
|
||||
// synth.dispatchMessage(client, 0, "/region3/delay_cc12", "", nullptr);
|
||||
std::vector<std::string> expected {
|
||||
"/region0/delay_cc12,f : { 0 }",
|
||||
"/region1/delay_cc12,f : { 1.5 }",
|
||||
"/region2/delay_cc12,f : { 0 }",
|
||||
"/region3/delay_cc14,f : { 3 }",
|
||||
// "/region3/delay_cc12,f : { 2 }",
|
||||
};
|
||||
REQUIRE(messageList == expected);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("[Values] Sample and direction")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue