Handle pitch_cc and tune_cc

This commit is contained in:
Paul Fd 2020-03-31 10:36:41 +02:00
parent c92e78b3f2
commit bf4bdad656
4 changed files with 25 additions and 0 deletions

View file

@ -189,6 +189,7 @@ namespace Default
constexpr Range<int> transposeRange { -127, 127 };
constexpr int tune { 0 };
constexpr Range<int> tuneRange { -9600, 9600 }; // ±100 in SFZv1, more in ARIA
constexpr Range<int> tuneCCRange { -9600, 9600 };
constexpr Range<int> bendBoundRange { -9600, 9600 };
constexpr Range<int> bendStepRange { 1, 1200 };
constexpr int bendUp { 200 }; // No range here because the bounds can be inverted

View file

@ -719,6 +719,15 @@ bool sfz::Region::parseOpcode(const Opcode& opcode)
case hash("pitch"):
setValueFromOpcode(opcode, tune, Default::tuneRange);
break;
case hash("tune_cc&"):
case hash("tune_oncc&"):
case hash("pitch_cc&"):
case hash("pitch_oncc&"):
if (opcode.parameters.back() > config::numCCs)
return false;
if (auto value = readOpcode(opcode.value, Default::tuneCCRange))
tuneCC[opcode.parameters.back()] = *value;
break;
case hash("bend_up"):
setValueFromOpcode(opcode, bendUp, Default::bendBoundRange);
break;

View file

@ -308,6 +308,7 @@ struct Region {
int pitchVeltrack { Default::pitchVeltrack }; // pitch_veltrack
int transpose { Default::transpose }; // transpose
int tune { Default::tune }; // tune
CCMap<int> tuneCC { Default::tune };
int bendUp { Default::bendUp };
int bendDown { Default::bendDown };
int bendStep { Default::bendStep };

View file

@ -1467,6 +1467,20 @@ TEST_CASE("[Region] Parsing opcodes")
REQUIRE(region.volumeCC.contains(4));
REQUIRE(region.volumeCC[4] == -1.0_a);
}
SECTION("tune_cc/pitch_cc")
{
REQUIRE(region.tuneCC.empty());
region.parseOpcode({ "pitch_cc1", "40" });
REQUIRE(region.tuneCC.contains(1));
REQUIRE(region.tuneCC[1] == 40);
region.parseOpcode({ "tune_oncc2", "-76" });
REQUIRE(region.tuneCC.contains(2));
REQUIRE(region.tuneCC[2] == -76.0);
region.parseOpcode({ "pitch_oncc4", "-1" });
REQUIRE(region.tuneCC.contains(4));
REQUIRE(region.tuneCC[4] == -1.0);
}
}
// Specific region bugs