Parse offset_cc

This commit is contained in:
Paul Fd 2020-04-07 17:38:31 +02:00 committed by Jean Pierre Cimalando
parent 6eb71b288e
commit 64a591fb7a
4 changed files with 21 additions and 0 deletions

View file

@ -49,6 +49,7 @@ namespace Default
constexpr uint32_t offset { 0 };
constexpr uint32_t offsetRandom { 0 };
constexpr Range<uint32_t> offsetRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<uint32_t> offsetCCRange = offsetRange;
constexpr Range<uint32_t> sampleEndRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr Range<uint32_t> sampleCountRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr SfzLoopMode loopMode { SfzLoopMode::no_loop };

View file

@ -59,6 +59,12 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
case hash("offset_random"):
setValueFromOpcode(opcode, offsetRandom, Default::offsetRange);
break;
case hash("offset_cc&"):
if (opcode.parameters.back() > config::numCCs)
return false;
if (auto value = readOpcode(opcode.value, Default::offsetCCRange))
offsetCC[opcode.parameters.back()] = *value;
break;
case hash("end"):
setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange);
break;

View file

@ -232,6 +232,7 @@ struct Region {
float delayRandom { Default::delayRandom }; // delay_random
uint32_t offset { Default::offset }; // offset
uint32_t offsetRandom { Default::offsetRandom }; // offset_random
CCMap<uint32_t> offsetCC { Default::offset };
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
absl::optional<uint32_t> sampleCount {}; // count
absl::optional<SfzLoopMode> loopMode {}; // loopmode

View file

@ -53,6 +53,19 @@ TEST_CASE("[Region] Parsing opcodes")
region.parseOpcode({ "offset", "-1" });
REQUIRE(region.offset == 0);
}
SECTION("offset_cc")
{
REQUIRE(region.offsetCC.empty());
region.parseOpcode({ "offset_cc1", "1" });
REQUIRE(region.offsetCC.contains(1));
REQUIRE(region.offsetCC[1] == 1);
region.parseOpcode({ "offset_cc2", "15420" });
REQUIRE(region.offsetCC.contains(2));
REQUIRE(region.offsetCC[2] == 15420);
region.parseOpcode({ "offset_cc2", "-1" });
REQUIRE(region.offsetCC[2] == 0);
}
SECTION("offset_random")
{