+
+ for (int chn = 0; chn < 16; ++chn) {
+ if (self->program_state[chn].program < 0) {
+ continue;
+ }
+ /* cannot direcly call fluid_channel_set_bank_msb/fluid_channel_set_bank_lsb, use CCs */
+ fluid_midi_event_set_type (self->fmidi_event, 0xb0 /* CC */);
+ fluid_midi_event_set_channel (self->fmidi_event, chn);
+
+ fluid_midi_event_set_control (self->fmidi_event, 0x00); // BANK_SELECT_MSB
+ fluid_midi_event_set_value (self->fmidi_event, (self->program_state[chn].bank >> 7) & 0x7f);
+ fluid_synth_handle_midi_event (self->synth, self->fmidi_event);
+
+ fluid_midi_event_set_control (self->fmidi_event, 0x20); // BANK_SELECT_LSB
+ fluid_midi_event_set_value (self->fmidi_event, self->program_state[chn].bank & 0x7f);
+ fluid_synth_handle_midi_event (self->synth, self->fmidi_event);
+
+ fluid_synth_program_change (self->synth, chn, self->program_state[chn].program);
+ }
+
+ for (int chn = 0; chn < 16; ++chn) {
+ unsigned int sfid = 0;
+ unsigned int bank = 0;
+ unsigned int program = -1;
+ if (FLUID_OK == fluid_synth_get_program (self->synth, chn, &sfid, &bank, &program)) {
+ self->program_state[chn].bank = bank;
+ self->program_state[chn].program = program;
+ }
+ }
+