Browse Source

Add the change_program function

develop
Damien Goutte-Gattat 8 years ago
parent
commit
0d11a6f922
  1. 27
      src/midi.c
  2. 6
      src/midi.h

27
src/midi.c

@ -277,3 +277,30 @@ midi_error(midi_io_t *midi)
/* TODO: Support for others MIDI APIs (JackMIDI?, WinAPI?, ...) */
#endif
int
midi_change_program(midi_io_t *midi,
unsigned char channel,
unsigned short bank,
unsigned char program)
{
unsigned char msg[] = { 0xB0, /* Control Change */
0x00, /* CC Bank Select MSB */
0x00, /* Bank number MSB */
0xB0, /* Control Change */
0x20, /* CC Bank Select LSB */
0x00, /* Bank number LSB */
0xC0, /* Program Change */
0x00 /* Program number */ };
assert(midi != NULL);
msg[0] |= (channel & 0x0F);
msg[3] |= (channel & 0x0F);
msg[6] |= (channel & 0x0F);
msg[2] |= ((bank >> 7) & 0x7F);
msg[5] |= (bank & 0x7F);
msg[7] |= (program & 0x7F);
return midi_write(midi, msg, sizeof(msg));
}

6
src/midi.h

@ -48,6 +48,12 @@ midi_status(midi_io_t *);
const char *
midi_error(midi_io_t *);
int
midi_change_program(midi_io_t *,
unsigned char,
unsigned short,
unsigned char);
#ifdef __cplusplus
}
#endif

Loading…
Cancel
Save