From 097d6c9fc43807e2cf457b3b5d2b39a406c4ae42 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 6 Jul 2022 18:03:05 +0200 Subject: [PATCH] Terminate all matches voices in PolyModSynth This is needed for a single NoteOff followed by multiple NoteOns for the same key/channel with different note IDs. --- plugins/examples/poly_mod_synth/src/lib.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugins/examples/poly_mod_synth/src/lib.rs b/plugins/examples/poly_mod_synth/src/lib.rs index bc58acb0..701ddf6e 100644 --- a/plugins/examples/poly_mod_synth/src/lib.rs +++ b/plugins/examples/poly_mod_synth/src/lib.rs @@ -289,8 +289,8 @@ impl PolyModSynth { } } - /// Terminate a voice, removing it from the pool and informing the host that the voice has - /// ended. Returns whether a voice has actually been terminated. + /// Terminate one or more voice, removing it from the pool and informing the host that the voice + /// has ended. If `voice_id` is not provided, then this will terminate all matching voices. fn terminate_voice( &mut self, context: &mut impl ProcessContext, @@ -298,7 +298,8 @@ impl PolyModSynth { voice_id: Option, channel: u8, note: u8, - ) -> bool { + ) { + // TODO: If voice ID = none, terminate all matching voices for voice in self.voices.iter_mut() { match voice { Some(Voice { @@ -320,13 +321,16 @@ impl PolyModSynth { }); *voice = None; - return true; + // If this targetted a single voice ID, we're done here. Otherwise there may be + // multiple overlapping voices as we enabled support for that in the + // `PolyModulationConfig`. + if voice_id.is_some() { + return; + } } _ => (), } } - - false } }