Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/sfizz/Voice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions tests/PolyphonyT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" } );
}