Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send MIDI Program Change over USB MIDI #31

Open
Ekolide opened this issue Jan 16, 2024 · 1 comment
Open

Send MIDI Program Change over USB MIDI #31

Ekolide opened this issue Jan 16, 2024 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Ekolide
Copy link

Ekolide commented Jan 16, 2024

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.

@jcard0na jcard0na added enhancement New feature or request good first issue Good for newcomers labels Jan 17, 2024
@jcard0na
Copy link
Collaborator

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

    haxo-rs/src/commands.rs

    Lines 30 to 34 in 5b79df0

    pub(crate) struct Command<'a> {
    synth: &'a Synth,
    prog_number: i32,
    last_cmd_key: CommandKeys,
    }

  2. Add program_change() here:

    haxo-rs/src/midi.rs

    Lines 49 to 52 in 5b79df0

    pub fn noteoff(&mut self, note: i32) {
    const NOTE_OFF_MSG: u8 = 0x80;
    let _ = self.conn_out.send(&[NOTE_OFF_MSG, note as u8, 0u8]);
    }

    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:
    self.synth.program_change(0, self.prog_number);
  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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants