Parse off time

This commit is contained in:
Paul Ferrand 2020-08-10 16:14:03 +02:00
parent 7a1a2c9381
commit d3cc4281d9
4 changed files with 23 additions and 1 deletions

View file

@ -31,7 +31,7 @@
enum class SfzTrigger { attack, release, release_key, first, legato }; enum class SfzTrigger { attack, release, release_key, first, legato };
enum class SfzLoopMode { no_loop, one_shot, loop_continuous, loop_sustain }; enum class SfzLoopMode { no_loop, one_shot, loop_continuous, loop_sustain };
enum class SfzOffMode { fast, normal }; enum class SfzOffMode { fast, normal, time };
enum class SfzVelocityOverride { current, previous }; enum class SfzVelocityOverride { current, previous };
enum class SfzCrossfadeCurve { gain, power }; enum class SfzCrossfadeCurve { gain, power };
enum class SfzSelfMask { mask, dontMask }; enum class SfzSelfMask { mask, dontMask };
@ -75,6 +75,7 @@ namespace Default
constexpr uint32_t group { 0 }; constexpr uint32_t group { 0 };
constexpr Range<uint32_t> groupRange { 0, std::numeric_limits<uint32_t>::max() }; constexpr Range<uint32_t> groupRange { 0, std::numeric_limits<uint32_t>::max() };
constexpr SfzOffMode offMode { SfzOffMode::fast }; constexpr SfzOffMode offMode { SfzOffMode::fast };
constexpr float offTime { 6e-3f };
constexpr Range<uint32_t> polyphonyRange { 0, config::maxVoices }; constexpr Range<uint32_t> polyphonyRange { 0, config::maxVoices };
constexpr SfzSelfMask selfMask { SfzSelfMask::mask }; constexpr SfzSelfMask selfMask { SfzSelfMask::mask };

View file

@ -161,10 +161,16 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode)
case hash("normal"): case hash("normal"):
offMode = SfzOffMode::normal; offMode = SfzOffMode::normal;
break; break;
case hash("time"):
offMode = SfzOffMode::time;
break;
default: default:
DBG("Unkown off mode:" << opcode.value); DBG("Unkown off mode:" << opcode.value);
} }
break; break;
case hash("off_time"):
setValueFromOpcode(opcode, offTime, Default::egTimeRange);
break;
case hash("polyphony"): case hash("polyphony"):
if (auto value = readOpcode(opcode.value, Default::polyphonyRange)) if (auto value = readOpcode(opcode.value, Default::polyphonyRange))
polyphony = *value; polyphony = *value;

View file

@ -286,6 +286,7 @@ struct Region {
uint32_t group { Default::group }; // group uint32_t group { Default::group }; // group
absl::optional<uint32_t> offBy {}; // off_by absl::optional<uint32_t> offBy {}; // off_by
SfzOffMode offMode { Default::offMode }; // off_mode SfzOffMode offMode { Default::offMode }; // off_mode
float offTime { Default::offTime }; // off_mode
absl::optional<uint32_t> notePolyphony {}; // note_polyphony absl::optional<uint32_t> notePolyphony {}; // note_polyphony
unsigned polyphony { config::maxVoices }; // polyphony unsigned polyphony { config::maxVoices }; // polyphony
SfzSelfMask selfMask { Default::selfMask }; SfzSelfMask selfMask { Default::selfMask };

View file

@ -195,6 +195,20 @@ TEST_CASE("[Region] Parsing opcodes")
REQUIRE(region.offMode == SfzOffMode::fast); REQUIRE(region.offMode == SfzOffMode::fast);
region.parseOpcode({ "off_mode", "normal" }); region.parseOpcode({ "off_mode", "normal" });
REQUIRE(region.offMode == SfzOffMode::normal); REQUIRE(region.offMode == SfzOffMode::normal);
region.parseOpcode({ "off_mode", "time" });
REQUIRE(region.offMode == SfzOffMode::time);
}
SECTION("off_time")
{
REQUIRE(region.offTime == 0.006f);
region.parseOpcode({ "off_time", "0.1" });
REQUIRE(region.offTime == 0.1f);
region.parseOpcode({ "off_time", "0" });
REQUIRE(region.offTime == 0.0f);
region.parseOpcode({ "off_time", "0.1" });
region.parseOpcode({ "off_time", "-1" });
REQUIRE(region.offTime == 0.0f);
} }
SECTION("lokey, hikey, and key") SECTION("lokey, hikey, and key")