diff --git a/libs/ardour/midi_state_tracker.cc b/libs/ardour/midi_state_tracker.cc index e1e012e37a..2b713d8c9e 100644 --- a/libs/ardour/midi_state_tracker.cc +++ b/libs/ardour/midi_state_tracker.cc @@ -346,17 +346,6 @@ MidiStateTracker::flush (MidiBuffer& dst, samplepos_t time, bool reset) flush_notes (dst, time, reset); - for (size_t chn = 0; chn < n_channels; ++chn) { - if ((program[chn] & 0x80) == 0) { - buf[0] = MIDI_CMD_PGM_CHANGE|chn; - buf[1] = program[chn] & 0x7f; - dst.write (time, Evoral::MIDI_EVENT, 2, buf); - if (reset) { - program[chn] = 0x80; - } - } - } - for (size_t chn = 0; chn < n_channels; ++chn) { for (size_t ctl = 0; ctl < n_controls; ++ctl) { if ((control[chn][ctl] & 0x80) == 0) { @@ -369,5 +358,14 @@ MidiStateTracker::flush (MidiBuffer& dst, samplepos_t time, bool reset) } } } + + if ((program[chn] & 0x80) == 0) { + buf[0] = MIDI_CMD_PGM_CHANGE|chn; + buf[1] = program[chn] & 0x7f; + dst.write (time, Evoral::MIDI_EVENT, 2, buf); + if (reset) { + program[chn] = 0x80; + } + } } }