Browse Source

Add a midi_set_controller function

Add a function to facilitate sending a Control Change message
to a MIDI device.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
f68921a31f
  1. 33
      src/midi.c
  2. 6
      src/midi.h

33
src/midi.c

@ -615,6 +615,39 @@ midi_change_program(midi_io_t *midi,
return midi_write(midi, msg, sizeof(msg)) == sizeof(msg) ? 0 : -1;
}
/**
* Set a MIDI controller to a specified value.
* This function emits a Control Change message to set a MIDI
* controller to a specified value.
*
* @param[in] midi The MIDI port to write to.
* @param[in] channel The MIDI channel to write to.
* @param[in] controller The controller number to assign.
* @param[in] value The value to assign to the controller.
*
* @return
* - 0 if the message was successfully sent;
* - -1 if an error occured.
*/
int
midi_set_controller(midi_io_t *midi,
unsigned char channel,
unsigned char controller,
unsigned char value)
{
unsigned char msg[] = { 0xB0, /* Control change */
0x00, /* Controller */
0x00, /* Value */ };
assert(midi != NULL);
msg[0] |= (channel & 0x0F);
msg[1] |= (controller & 0x7F);
msg[2] |= (value & 0x7F);
return midi_write(midi, msg, sizeof(msg)) == sizeof(msg) ? 0 : -1;
}
/**
* General MIDI patches.
* This array contains the names of the standard GM patches.

6
src/midi.h

@ -56,6 +56,12 @@ midi_change_program(midi_io_t *,
unsigned short,
unsigned char);
int
midi_set_controller(midi_io_t *,
unsigned char,
unsigned char,
unsigned char);
char **
midi_get_ports(void);

Loading…
Cancel
Save