From 6886040535727ba498070469de722010f68c2ac6 Mon Sep 17 00:00:00 2001 From: ashley Date: Mon, 28 Aug 2023 22:37:34 -0400 Subject: [PATCH] Prohibit trigger of note on instrument-less FM channel --- src/reskit/soundtrack/engines/echo/engine.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/reskit/soundtrack/engines/echo/engine.rs b/src/reskit/soundtrack/engines/echo/engine.rs index cc50e87..9275dbf 100644 --- a/src/reskit/soundtrack/engines/echo/engine.rs +++ b/src/reskit/soundtrack/engines/echo/engine.rs @@ -312,7 +312,18 @@ pub fn get_events_for_channel( channels: &mut [Channel], active_channel: usize, channels[ active_channel ].note_keyed = false; events.push( vec![ ESF_NOTE_OFF | channels[ active_channel ].id ] ); } else { - channels[ active_channel ].note_keyed = true; + // Determine if we can key on. We can't key on if we are in FM1..FM6, and no instrument was ever set + // on the channel either here or previously. (We can do that for psg, using the default instrument.) + channels[ active_channel ].note_keyed = if ( ESF_FM_1..=ESF_FM_3 ).contains( &channels[ active_channel ].id ) | ( ESF_FM_4..=ESF_FM_6 ).contains( &channels[ active_channel ].id ) { + if channels[ active_channel ].active_instrument.is_none() { + print_warning( "no instrument set on this fm channel - cannot trigger the note!" ); + false + } else { + true + } + } else { + true + }; channels[ active_channel ].active_note = Some( OctaveFrequency { octave: note.get_octave()?,