Choke notes when the layer is disabled, even if the group and note are the same

This commit is contained in:
Paul Fd 2021-11-13 01:16:30 +01:00
parent 37613d528c
commit 7ae0b4b043
2 changed files with 23 additions and 1 deletions

View file

@ -218,6 +218,7 @@ struct Voice::Impl
const NumericId<Voice> id_;
StateListener* stateListener_ = nullptr;
const Layer* layer_ { nullptr };
const Region* region_ { nullptr };
State state_ { State::idle };
@ -411,6 +412,7 @@ bool Voice::startVoice(Layer* layer, int delay, const TriggerEvent& event) noexc
MidiState& midiState = resources.getMidiState();
CurveSet& curveSet = resources.getCurves();
impl.layer_ = layer;
const Region& region = layer->getRegion();
impl.region_ = &region;
@ -1663,6 +1665,7 @@ bool Voice::Impl::released() const noexcept
bool Voice::checkOffGroup(const Region* other, int delay, int noteNumber) noexcept
{
Impl& impl = *impl_;
const Layer* layer = impl.layer_;
const Region* region = impl.region_;
if (region == nullptr || other == nullptr)
return false;
@ -1673,7 +1676,7 @@ bool Voice::checkOffGroup(const Region* other, int delay, int noteNumber) noexce
if ((impl.triggerEvent_.type == TriggerEventType::NoteOn
|| impl.triggerEvent_.type == TriggerEventType::CC)
&& region->offBy && *region->offBy == other->group
&& (region->group != other->group || noteNumber != impl.triggerEvent_.number)) {
&& (region->group != other->group || !layer->ccSwitched_.all() || noteNumber != impl.triggerEvent_.number)) {
off(delay);
return true;
}
@ -1685,6 +1688,7 @@ void Voice::reset() noexcept
{
Impl& impl = *impl_;
impl.switchState(State::idle);
impl.layer_ = nullptr;
impl.region_ = nullptr;
impl.currentPromise_.reset();
impl.sourcePosition_ = 0;

View file

@ -570,3 +570,21 @@ TEST_CASE("[Polyphony] Choke long release tails with note_polyphony")
REQUIRE( numPlayingVoices(synth) == 1 ); // Not released, attack phase
REQUIRE( numActiveVoices(synth) == 1 );
}
TEST_CASE("[Polyphony] Choke same group and note if the region is switched off (e.g. by a CC switch)")
{
sfz::Synth synth;
sfz::AudioBuffer<float> buffer { 2, static_cast<unsigned>(synth.getSamplesPerBlock()) };
synth.loadSfzString(fs::current_path() / "tests/TestFiles/polyphony.sfz", R"(
<global> group=1 off_by=1
<region> locc1=0 hicc1=63 sample=*saw
<region> locc1=64 hicc1=127 sample=*sine
)");
synth.noteOn(0, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*saw" } );
synth.cc(0, 1, 127);
synth.noteOn(0, 60, 63 );
synth.renderBlock(buffer);
REQUIRE( playingSamples(synth) == std::vector<std::string> { "*sine" } );
}