Skip to content

Commit

Permalink
Make the matching function a free one
Browse files Browse the repository at this point in the history
  • Loading branch information
paulfd committed Aug 9, 2020
1 parent 39abff2 commit cb367d3
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/sfizz/Synth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,15 @@ void sfz::Synth::noteOff(int delay, int noteNumber, uint8_t velocity) noexcept
noteOffDispatch(delay, noteNumber, replacedVelocity);
}

bool matchReleaseRegionAndVoice(const sfz::Region& region, const sfz::Voice& voice) {
return (
!voice.isFree()
&& voice.getTriggerType() == sfz::Voice::TriggerType::NoteOn
&& region.keyRange.containsWithEnd(voice.getTriggerNumber())
&& region.velocityRange.containsWithEnd(voice.getTriggerValue())
);
}

void sfz::Synth::noteOffDispatch(int delay, int noteNumber, float velocity) noexcept
{
const auto randValue = randNoteDistribution(Random::randomGenerator);
Expand All @@ -851,12 +860,7 @@ void sfz::Synth::noteOffDispatch(int delay, int noteNumber, float velocity) noex
// should be overhauled, also to include voice stealing on
// all events
const auto compatibleVoice = [region](const VoicePtr& v) -> bool {
return (
!v->isFree()
&& v->getTriggerType() == Voice::TriggerType::NoteOn
&& region->keyRange.containsWithEnd(v->getTriggerNumber())
&& region->velocityRange.containsWithEnd(v->getTriggerValue())
);
return matchReleaseRegionAndVoice(*region, *v);
};

if (absl::c_find_if(voices, compatibleVoice) == voices.end())
Expand Down Expand Up @@ -1028,12 +1032,7 @@ void sfz::Synth::hdcc(int delay, int ccNumber, float normValue) noexcept
// should be overhauled, also to include voice stealing on
// all events
const auto compatibleVoice = [region](const VoicePtr& v) -> bool {
return (
!v->isFree()
&& v->getTriggerType() == Voice::TriggerType::NoteOn
&& region->keyRange.containsWithEnd(v->getTriggerNumber())
&& region->velocityRange.containsWithEnd(v->getTriggerValue())
);
return matchReleaseRegionAndVoice(*region, *v);
};

if (absl::c_find_if(voices, compatibleVoice) == voices.end()) {
Expand Down

0 comments on commit cb367d3

Please sign in to comment.