+void
+MidiRegionView::find_and_insert_program_change_flags()
+{
+ // Draw program change 'flags'
+ for (Automatable::Controls::iterator control = _model->controls().begin();
+ control != _model->controls().end(); ++control) {
+ if (control->first.type() == MidiPgmChangeAutomation) {
+ Glib::Mutex::Lock list_lock (control->second->list()->lock());
+
+ uint8_t channel = control->first.channel();
+
+ for (AutomationList::const_iterator event = control->second->list()->begin();
+ event != control->second->list()->end(); ++event) {
+ double event_time = (*event)->when;
+ double program_number = (*event)->value;
+
+ //cerr << " got program change on channel " << int(channel) << " time: " << event_time << " number: " << program_number << endl;
+
+ // find bank select msb and lsb for the program change
+ Evoral::Parameter bank_select_msb(MidiCCAutomation, channel, MIDI_CTL_MSB_BANK);
+ Evoral::Parameter bank_select_lsb(MidiCCAutomation, channel, MIDI_CTL_LSB_BANK);
+
+ boost::shared_ptr<Evoral::Control> lsb_control = _model->control(bank_select_lsb);
+ boost::shared_ptr<Evoral::Control> msb_control = _model->control(bank_select_msb);
+
+ boost::shared_ptr<MIDI::Name::MasterDeviceNames> master_device
+ = MIDI::Name::MidiPatchManager::instance().master_device_by_model(_model_name);
+
+ MIDI::Name::Patch patch;
+
+ if (master_device != 0 && _custom_device_mode != "") {
+ uint8_t msb = 0;
+ if (msb_control != 0) {
+ msb = uint8_t(msb_control->get_float(true, event_time));
+ }
+
+ uint8_t lsb = 0;
+ if (lsb_control != 0) {
+ lsb = uint8_t(lsb_control->get_float(true, event_time));
+ }
+
+ //cerr << " got msb " << int(msb) << " and lsb " << int(lsb) << endl;
+
+ patch = master_device->find_patch(
+ _custom_device_mode,
+ channel,
+ msb,
+ lsb,
+ uint8_t(program_number)
+ );
+
+ //cerr << " got patch with name " << patch.name() << " number " << patch.number() << endl;
+ }
+ if (patch.name() != "") {
+ add_pgm_change(event_time, patch.name());
+ } else {
+ char buf[4];
+ snprintf(buf, 4, "%d", int(program_number));
+ add_pgm_change(event_time, buf);
+ }
+ }
+ break;
+ } else if (control->first.type() == MidiCCAutomation) {
+ //cerr << " found CC Automation of channel " << int(control->first.channel()) << " and id " << control->first.id() << endl;
+ }
+ }
+}
+