diff --git a/src/midi.rs b/src/midi.rs index c2a674e9..0bd9e221 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -256,14 +256,6 @@ pub enum NoteEvent { /// The note's brightness amount, from 0 to 1. brightness: f32, }, - /// A MIDI program change event, available on [`MidiConfig::MidiCCs`] and up. - MidiProgramChange { - timing: u32, - /// The affected channel, from 0 to 16. - channel: u8, - /// The program number. - program: u8, - }, /// A MIDI channel pressure event, available on [`MidiConfig::MidiCCs`] and up. MidiChannelPressure { timing: u32, @@ -296,6 +288,14 @@ pub enum NoteEvent { /// The CC's value, normalized to `[0, 1]`. Multiply by 127 to get the original raw value. value: f32, }, + /// A MIDI program change event, available on [`MidiConfig::MidiCCs`] and up. + MidiProgramChange { + timing: u32, + /// The affected channel, from 0 to 16. + channel: u8, + /// The program number. + program: u8, + }, } impl NoteEvent { @@ -315,10 +315,10 @@ impl NoteEvent { NoteEvent::PolyVibrato { timing, .. } => *timing, NoteEvent::PolyExpression { timing, .. } => *timing, NoteEvent::PolyBrightness { timing, .. } => *timing, - NoteEvent::MidiProgramChange { timing, .. } => *timing, NoteEvent::MidiChannelPressure { timing, .. } => *timing, NoteEvent::MidiPitchBend { timing, .. } => *timing, NoteEvent::MidiCC { timing, .. } => *timing, + NoteEvent::MidiProgramChange { timing, .. } => *timing, } } @@ -338,10 +338,10 @@ impl NoteEvent { NoteEvent::PolyVibrato { voice_id, .. } => *voice_id, NoteEvent::PolyExpression { voice_id, .. } => *voice_id, NoteEvent::PolyBrightness { voice_id, .. } => *voice_id, - NoteEvent::MidiProgramChange { .. } => None, NoteEvent::MidiChannelPressure { .. } => None, NoteEvent::MidiPitchBend { .. } => None, NoteEvent::MidiCC { .. } => None, + NoteEvent::MidiProgramChange { .. } => None, } } @@ -373,11 +373,6 @@ impl NoteEvent { note: midi_data[1], pressure: midi_data[2] as f32 / 127.0, }), - midi::PROGRAM_CHANGE => Ok(NoteEvent::MidiProgramChange { - timing, - channel, - program: midi_data[1], - }), midi::CHANNEL_KEY_PRESSURE => Ok(NoteEvent::MidiChannelPressure { timing, channel, @@ -395,6 +390,11 @@ impl NoteEvent { cc: midi_data[1], value: midi_data[2] as f32 / 127.0, }), + midi::PROGRAM_CHANGE => Ok(NoteEvent::MidiProgramChange { + timing, + channel, + program: midi_data[1], + }), n => Err(n), } } @@ -437,15 +437,6 @@ impl NoteEvent { note, (pressure * 127.0).round().clamp(0.0, 127.0) as u8, ]), - NoteEvent::MidiProgramChange { - timing: _, - channel, - program, - } => Some([ - midi::PROGRAM_CHANGE | channel, - program, - 0, - ]), NoteEvent::MidiChannelPressure { timing: _, channel, @@ -481,6 +472,11 @@ impl NoteEvent { cc, (value * 127.0).round().clamp(0.0, 127.0) as u8, ]), + NoteEvent::MidiProgramChange { + timing: _, + channel, + program, + } => Some([midi::PROGRAM_CHANGE | channel, program, 0]), NoteEvent::Choke { .. } | NoteEvent::VoiceTerminated { .. } | NoteEvent::PolyModulation { .. } @@ -511,10 +507,10 @@ impl NoteEvent { NoteEvent::PolyVibrato { timing, .. } => *timing -= samples, NoteEvent::PolyExpression { timing, .. } => *timing -= samples, NoteEvent::PolyBrightness { timing, .. } => *timing -= samples, - NoteEvent::MidiProgramChange { timing, .. } => *timing -= samples, NoteEvent::MidiChannelPressure { timing, .. } => *timing -= samples, NoteEvent::MidiPitchBend { timing, .. } => *timing -= samples, NoteEvent::MidiCC { timing, .. } => *timing -= samples, + NoteEvent::MidiProgramChange { timing, .. } => *timing -= samples, } } } @@ -574,20 +570,6 @@ mod tests { ); } - #[test] - fn test_program_change_midi_conversion() { - let event = NoteEvent::MidiProgramChange { - timing: TIMING, - channel: 1, - program: 42, - }; - - assert_eq!( - NoteEvent::from_midi(TIMING, event.as_midi().unwrap()).unwrap(), - event - ); - } - #[test] fn test_channel_pressure_midi_conversion() { let event = NoteEvent::MidiChannelPressure { @@ -630,4 +612,18 @@ mod tests { event ); } + + #[test] + fn test_program_change_midi_conversion() { + let event = NoteEvent::MidiProgramChange { + timing: TIMING, + channel: 1, + program: 42, + }; + + assert_eq!( + NoteEvent::from_midi(TIMING, event.as_midi().unwrap()).unwrap(), + event + ); + } } diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs index 1ffb1efa..a5884d79 100644 --- a/src/wrapper/clap/wrapper.rs +++ b/src/wrapper/clap/wrapper.rs @@ -1212,29 +1212,6 @@ impl Wrapper

{ clap_call! { out=>try_push(out, &event.header) } } - NoteEvent::MidiProgramChange { - timing: _, - channel, - program, - } if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => { - let event = clap_event_midi { - header: clap_event_header { - size: mem::size_of::() as u32, - time, - space_id: CLAP_CORE_EVENT_SPACE_ID, - type_: CLAP_EVENT_MIDI, - flags: 0, - }, - port_index: 0, - data: [ - midi::PROGRAM_CHANGE | channel as u8, - program, - 0, - ], - }; - - clap_call! { out=>try_push(out, &event.header) } - } NoteEvent::MidiChannelPressure { timing: _, channel, @@ -1307,6 +1284,25 @@ impl Wrapper

{ clap_call! { out=>try_push(out, &event.header) } } + NoteEvent::MidiProgramChange { + timing: _, + channel, + program, + } if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => { + let event = clap_event_midi { + header: clap_event_header { + size: mem::size_of::() as u32, + time, + space_id: CLAP_CORE_EVENT_SPACE_ID, + type_: CLAP_EVENT_MIDI, + flags: 0, + }, + port_index: 0, + data: [midi::PROGRAM_CHANGE | channel as u8, program, 0], + }; + + clap_call! { out=>try_push(out, &event.header) } + } _ => { nih_debug_assert_failure!( "Invalid output event for the current MIDI_OUTPUT setting" diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs index 5559c1a2..349dd684 100644 --- a/src/wrapper/vst3/wrapper.rs +++ b/src/wrapper/vst3/wrapper.rs @@ -1667,19 +1667,6 @@ impl IAudioProcessor for Wrapper

{ } } } - NoteEvent::MidiProgramChange { - timing: _, - channel, - program, - } if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => { - vst3_event.type_ = EventTypes::kLegacyMIDICCOutEvent as u16; - vst3_event.event.legacy_midi_cc_out = LegacyMidiCCOutEvent { - control_number: 130, // kCtrlProgramChange - channel: channel as i8, - value: program as i8, - value2: 0, - }; - } NoteEvent::MidiChannelPressure { timing: _, channel, @@ -1722,6 +1709,19 @@ impl IAudioProcessor for Wrapper

{ value2: 0, }; } + NoteEvent::MidiProgramChange { + timing: _, + channel, + program, + } if P::MIDI_OUTPUT >= MidiConfig::MidiCCs => { + vst3_event.type_ = EventTypes::kLegacyMIDICCOutEvent as u16; + vst3_event.event.legacy_midi_cc_out = LegacyMidiCCOutEvent { + control_number: 130, // kCtrlProgramChange + channel: channel as i8, + value: program as i8, + value2: 0, + }; + } _ => { nih_debug_assert_failure!( "Invalid output event for the current MIDI_OUTPUT setting"