Disable with sampleEnd == 0

This commit is contained in:
Paul Ferrand 2020-08-19 11:06:16 +02:00
parent cef44cbdb6
commit 17568510ac
4 changed files with 22 additions and 9 deletions

View file

@ -92,11 +92,7 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode)
offsetCC[opcode.parameters.back()] = *value; offsetCC[opcode.parameters.back()] = *value;
break; break;
case hash("end"): case hash("end"):
if (opcode.value == "-1") { setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange);
disabled = true;
} else {
setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange);
}
break; break;
case hash("count"): case hash("count"):
setValueFromOpcode(opcode, sampleCount, Default::sampleCountRange); setValueFromOpcode(opcode, sampleCount, Default::sampleCountRange);
@ -1462,7 +1458,10 @@ float sfz::Region::getDelay() const noexcept
uint32_t sfz::Region::trueSampleEnd(Oversampling factor) const noexcept uint32_t sfz::Region::trueSampleEnd(Oversampling factor) const noexcept
{ {
return min(sampleEnd, loopRange.getEnd()) * static_cast<uint32_t>(factor); if (sampleEnd <= 0)
return 0;
return min(static_cast<uint32_t>(sampleEnd), loopRange.getEnd()) * static_cast<uint32_t>(factor);
} }
uint32_t sfz::Region::loopStart(Oversampling factor) const noexcept uint32_t sfz::Region::loopStart(Oversampling factor) const noexcept
@ -1619,3 +1618,8 @@ sfz::Region::Connection& sfz::Region::getOrCreateConnection(const ModKey& source
connections.push_back(c); connections.push_back(c);
return connections.back(); return connections.back();
} }
bool sfz::Region::disabled() const noexcept
{
return (sampleEnd == 0);
}

View file

@ -261,6 +261,11 @@ struct Region {
*/ */
float getGainToEffectBus(unsigned number) const noexcept; float getGainToEffectBus(unsigned number) const noexcept;
/**
* @brief Check if a region is disabled, if its sample end is weakly negative for example.
*/
bool disabled() const noexcept;
const NumericId<Region> id; const NumericId<Region> id;
// Sound source: sample playback // Sound source: sample playback
@ -272,7 +277,6 @@ struct Region {
int64_t offsetRandom { Default::offsetRandom }; // offset_random int64_t offsetRandom { Default::offsetRandom }; // offset_random
CCMap<int64_t> offsetCC { Default::offset }; CCMap<int64_t> offsetCC { Default::offset };
uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end
bool disabled { false }; // end=-1 and other disabling events
absl::optional<uint32_t> sampleCount {}; // count absl::optional<uint32_t> sampleCount {}; // count
absl::optional<SfzLoopMode> loopMode {}; // loopmode absl::optional<SfzLoopMode> loopMode {}; // loopmode
Range<uint32_t> loopRange { Default::loopRange }; //loopstart and loopend Range<uint32_t> loopRange { Default::loopRange }; //loopstart and loopend

View file

@ -52,7 +52,7 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, float value,
this->region = region; this->region = region;
if (region->disabled) if (region->disabled())
return; return;
switchState(State::playing); switchState(State::playing);

View file

@ -95,7 +95,12 @@ TEST_CASE("[Region] Parsing opcodes")
region.parseOpcode({ "end", "184" }); region.parseOpcode({ "end", "184" });
REQUIRE(region.sampleEnd == 184); REQUIRE(region.sampleEnd == 184);
region.parseOpcode({ "end", "-1" }); region.parseOpcode({ "end", "-1" });
REQUIRE(region.disabled); REQUIRE(region.disabled());
region.parseOpcode({ "end", "2" });
REQUIRE(!region.disabled());
REQUIRE(region.sampleEnd == 2);
region.parseOpcode({ "end", "0" });
REQUIRE(region.disabled());
} }
SECTION("count") SECTION("count")