haxo-rs icon indicating copy to clipboard operation
haxo-rs copied to clipboard

Send MIDI Program Change over USB MIDI

Open Ekolide opened this issue 1 year ago • 1 comments

Hiya.

The Haxophone has a Control Mode where you can change the Program on the Soundfont that FluidSynth has loaded. Currently, it does not send MIDI Program Change messages over USB MIDI at the same time. So changing the instrument +1 on the FluidSynth side does not change the instrument on the USB MIDI side.

I don't know how it's currently implemented in code, but libfluidsynth documentation states it uses MIDI Program Change. My suggestion is that this gets passed along to the USB MIDI service.

Let me know if there's any questions or anything that needs to be clarified.

Ekolide avatar Jan 16 '24 21:01 Ekolide

It make sense to send the program change to the MIDI host, yes. If anyone wants to work on this, the required changes are small:

  1. Add a midi_out reference to https://github.com/cardonabits/haxo-rs/blob/5b79df017d0f79c2391a4b875e9183cbda226a90/src/commands.rs#L30-L34

  2. Add program_change() here: https://github.com/cardonabits/haxo-rs/blob/5b79df017d0f79c2391a4b875e9183cbda226a90/src/midi.rs#L49-L52 That is...

        let _ = self.conn_out.send(&[NOTE_OFF_MSG, note as u8, 0u8]); 
     } 
+    pub fn prog_chng(&mut self, prog: i32) {
+       const PROG_CHNG_MSG: u8 = 0xC0;
+        let _ = self.conn_out.send(&[PROG_CHNG_MSG, prog as u8]);
+    }
  }
  1. Send the midi command from the function that implements the instrument change: https://github.com/cardonabits/haxo-rs/blob/5b79df017d0f79c2391a4b875e9183cbda226a90/src/commands.rs#L62
  self.synth.program_change(0, self.prog_number);
+ #[cfg(feature = "midi")]
+ self.midi_out.prog_chng(self.prog_number);
  info!("New MIDI program number {}", self.prog_number);

jcard0na avatar Jan 17 '24 15:01 jcard0na