diff --git a/src/sfizz/Region.cpp b/src/sfizz/Region.cpp index cad035b8..8843ce5c 100644 --- a/src/sfizz/Region.cpp +++ b/src/sfizz/Region.cpp @@ -92,11 +92,7 @@ bool sfz::Region::parseOpcode(const Opcode& rawOpcode) offsetCC[opcode.parameters.back()] = *value; break; case hash("end"): - if (opcode.value == "-1") { - disabled = true; - } else { - setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange); - } + setValueFromOpcode(opcode, sampleEnd, Default::sampleEndRange); break; case hash("count"): setValueFromOpcode(opcode, sampleCount, Default::sampleCountRange); @@ -1462,7 +1458,10 @@ float sfz::Region::getDelay() const noexcept uint32_t sfz::Region::trueSampleEnd(Oversampling factor) const noexcept { - return min(sampleEnd, loopRange.getEnd()) * static_cast(factor); + if (sampleEnd <= 0) + return 0; + + return min(static_cast(sampleEnd), loopRange.getEnd()) * static_cast(factor); } 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); return connections.back(); } + +bool sfz::Region::disabled() const noexcept +{ + return (sampleEnd == 0); +} diff --git a/src/sfizz/Region.h b/src/sfizz/Region.h index 4dc5cdef..e5fbb6c0 100644 --- a/src/sfizz/Region.h +++ b/src/sfizz/Region.h @@ -261,6 +261,11 @@ struct Region { */ 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 id; // Sound source: sample playback @@ -272,7 +277,6 @@ struct Region { int64_t offsetRandom { Default::offsetRandom }; // offset_random CCMap offsetCC { Default::offset }; uint32_t sampleEnd { Default::sampleEndRange.getEnd() }; // end - bool disabled { false }; // end=-1 and other disabling events absl::optional sampleCount {}; // count absl::optional loopMode {}; // loopmode Range loopRange { Default::loopRange }; //loopstart and loopend diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 86dd1cd4..3321d761 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -52,7 +52,7 @@ void sfz::Voice::startVoice(Region* region, int delay, int number, float value, this->region = region; - if (region->disabled) + if (region->disabled()) return; switchState(State::playing); diff --git a/tests/RegionT.cpp b/tests/RegionT.cpp index d4e68982..fa3f8f4c 100644 --- a/tests/RegionT.cpp +++ b/tests/RegionT.cpp @@ -95,7 +95,12 @@ TEST_CASE("[Region] Parsing opcodes") region.parseOpcode({ "end", "184" }); REQUIRE(region.sampleEnd == 184); 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")