Correctly dispatch the CC to the region if it's a sustain
...with some tests
This commit is contained in:
parent
c4e8675c04
commit
6d56aaaa6c
3 changed files with 66 additions and 3 deletions
|
|
@ -366,6 +366,7 @@ struct Region {
|
||||||
// Modifiers
|
// Modifiers
|
||||||
ModifierArray<CCMap<Modifier>> modifiers;
|
ModifierArray<CCMap<Modifier>> modifiers;
|
||||||
|
|
||||||
|
bool triggerOnCC { false }; // whether the region triggers on CC events or note events
|
||||||
private:
|
private:
|
||||||
const MidiState& midiState;
|
const MidiState& midiState;
|
||||||
bool keySwitched { true };
|
bool keySwitched { true };
|
||||||
|
|
@ -376,7 +377,6 @@ private:
|
||||||
bool aftertouchSwitched { true };
|
bool aftertouchSwitched { true };
|
||||||
bool noteIsOff { false };
|
bool noteIsOff { false };
|
||||||
std::bitset<config::numCCs> ccSwitched;
|
std::bitset<config::numCCs> ccSwitched;
|
||||||
bool triggerOnCC { false };
|
|
||||||
absl::string_view defaultPath { "" };
|
absl::string_view defaultPath { "" };
|
||||||
|
|
||||||
int sequenceCounter { 0 };
|
int sequenceCounter { 0 };
|
||||||
|
|
|
||||||
|
|
@ -446,7 +446,9 @@ void sfz::Synth::finalizeSfzLoad()
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int cc = 0; cc < config::numCCs; cc++) {
|
for (int cc = 0; cc < config::numCCs; cc++) {
|
||||||
if (region->ccTriggers.contains(cc) || region->ccConditions.contains(cc))
|
if (region->ccTriggers.contains(cc)
|
||||||
|
|| region->ccConditions.contains(cc)
|
||||||
|
|| (cc == region->sustainCC && region->trigger == SfzTrigger::release))
|
||||||
ccActivationLists[cc].push_back(region);
|
ccActivationLists[cc].push_back(region);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -915,7 +917,14 @@ void sfz::Synth::hdcc(int delay, int ccNumber, float normValue) noexcept
|
||||||
if (voice == nullptr)
|
if (voice == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
voice->startVoice(region, delay, ccNumber, normValue, Voice::TriggerType::CC);
|
if (!region->triggerOnCC) {
|
||||||
|
// This is a sustain trigger
|
||||||
|
const auto replacedVelocity = resources.midiState.getNoteVelocity(region->pitchKeycenter);
|
||||||
|
voice->startVoice(region, delay, region->pitchKeycenter, replacedVelocity, Voice::TriggerType::NoteOff);
|
||||||
|
} else {
|
||||||
|
voice->startVoice(region, delay, ccNumber, normValue, Voice::TriggerType::CC);
|
||||||
|
}
|
||||||
|
|
||||||
ring.addVoiceToRing(voice);
|
ring.addVoiceToRing(voice);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -609,3 +609,57 @@ TEST_CASE("[Synth] Sisters and off-by")
|
||||||
REQUIRE( synth.getNumActiveVoices() == 2 );
|
REQUIRE( synth.getNumActiveVoices() == 2 );
|
||||||
REQUIRE( sfz::SisterVoiceRing::countSisterVoices(synth.getVoiceView(0)) == 1 );
|
REQUIRE( sfz::SisterVoiceRing::countSisterVoices(synth.getVoiceView(0)) == 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Synth] Release key")
|
||||||
|
{
|
||||||
|
sfz::Synth synth;
|
||||||
|
synth.loadSfzString(fs::current_path(), R"(
|
||||||
|
<region> key=62 sample=*sine trigger=release_key
|
||||||
|
)");
|
||||||
|
synth.noteOn(0, 62, 85);
|
||||||
|
synth.cc(0, 64, 127);
|
||||||
|
synth.noteOff(0, 62, 85);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Synth] Release")
|
||||||
|
{
|
||||||
|
sfz::Synth synth;
|
||||||
|
synth.loadSfzString(fs::current_path(), R"(
|
||||||
|
<region> key=62 sample=*sine trigger=release
|
||||||
|
)");
|
||||||
|
synth.noteOn(0, 62, 85);
|
||||||
|
synth.cc(0, 64, 127);
|
||||||
|
synth.noteOff(0, 62, 85);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
||||||
|
synth.cc(0, 64, 0);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Synth] Release key (Different sustain CC)")
|
||||||
|
{
|
||||||
|
sfz::Synth synth;
|
||||||
|
synth.loadSfzString(fs::current_path(), R"(
|
||||||
|
<global>sustain_cc=54
|
||||||
|
<region> key=62 sample=*sine trigger=release_key
|
||||||
|
)");
|
||||||
|
synth.noteOn(0, 62, 85);
|
||||||
|
synth.cc(0, 54, 127);
|
||||||
|
synth.noteOff(0, 62, 85);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("[Synth] Release (Different sustain CC)")
|
||||||
|
{
|
||||||
|
sfz::Synth synth;
|
||||||
|
synth.loadSfzString(fs::current_path(), R"(
|
||||||
|
<global>sustain_cc=54
|
||||||
|
<region> key=62 sample=*sine trigger=release
|
||||||
|
)");
|
||||||
|
synth.noteOn(0, 62, 85);
|
||||||
|
synth.cc(0, 54, 127);
|
||||||
|
synth.noteOff(0, 62, 85);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 0 );
|
||||||
|
synth.cc(0, 54, 0);
|
||||||
|
REQUIRE( synth.getNumActiveVoices() == 1 );
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue