+void
+MackieControlProtocolGUI::connection_handler ()
+{
+ /* ignore all changes to combobox active strings here, because we're
+ updating them to match a new ("external") reality - we were called
+ because port connections have changed.
+ */
+
+ PBD::Unwinder<bool> ici (ignore_active_change, true);
+
+ vector<Gtk::ComboBox*>::iterator ic;
+ vector<Gtk::ComboBox*>::iterator oc;
+
+ vector<string> midi_inputs;
+ vector<string> midi_outputs;
+
+ ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsTerminal), midi_inputs);
+ ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsTerminal), midi_outputs);
+
+ for (ic = input_combos.begin(), oc = output_combos.begin(); ic != input_combos.end() && oc != output_combos.end(); ++ic, ++oc) {
+
+ boost::shared_ptr<Surface> surface = _cp.get_surface_by_raw_pointer ((*ic)->get_data ("surface"));
+
+ if (surface) {
+ update_port_combos (midi_inputs, midi_outputs, *ic, *oc, surface);
+ }
+ }
+}
+
+void
+MackieControlProtocolGUI::update_port_combos (vector<string> const& midi_inputs, vector<string> const& midi_outputs,
+ Gtk::ComboBox* input_combo,
+ Gtk::ComboBox* output_combo,
+ boost::shared_ptr<Surface> surface)
+{
+ Glib::RefPtr<Gtk::ListStore> input = build_midi_port_list (midi_inputs, true);
+ Glib::RefPtr<Gtk::ListStore> output = build_midi_port_list (midi_outputs, false);
+ bool input_found = false;
+ bool output_found = false;
+ int n;
+
+ input_combo->set_model (input);
+ output_combo->set_model (output);
+
+ Gtk::TreeModel::Children children = input->children();
+ Gtk::TreeModel::Children::iterator i;
+ i = children.begin();
+ ++i; /* skip "Disconnected" */
+
+
+ for (n = 1; i != children.end(); ++i, ++n) {
+ string port_name = (*i)[midi_port_columns.full_name];
+ if (surface->port().input().connected_to (port_name)) {
+ input_combo->set_active (n);
+ input_found = true;
+ break;
+ }
+ }
+
+ if (!input_found) {
+ input_combo->set_active (0); /* disconnected */
+ }
+
+ children = output->children();
+ i = children.begin();
+ ++i; /* skip "Disconnected" */
+
+ for (n = 1; i != children.end(); ++i, ++n) {
+ string port_name = (*i)[midi_port_columns.full_name];
+ if (surface->port().output().connected_to (port_name)) {
+ output_combo->set_active (n);
+ output_found = true;
+ break;
+ }
+ }
+
+ if (!output_found) {
+ output_combo->set_active (0); /* disconnected */
+ }
+}
+
+Gtk::Widget*
+MackieControlProtocolGUI::device_dependent_widget ()
+{
+ Gtk::Table* dd_table;
+ Gtk::Label* l;
+ int row = 0;
+
+ uint32_t n_surfaces = 1 + _cp.device_info().extenders();
+
+ if (!_cp.device_info().uses_ipmidi()) {
+ dd_table = Gtk::manage (new Gtk::Table (n_surfaces, 2));
+ } else {
+ dd_table = Gtk::manage (new Gtk::Table (1, 2));
+ }
+
+ dd_table = Gtk::manage (new Gtk::Table (2, n_surfaces));
+ dd_table->set_row_spacings (4);
+ dd_table->set_col_spacings (6);
+ dd_table->set_border_width (12);
+
+ _surface_combo.set_active_text (_cp.device_info().name());
+
+ vector<string> midi_inputs;
+ vector<string> midi_outputs;
+
+ ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsOutput|ARDOUR::IsPhysical), midi_inputs);
+ ARDOUR::AudioEngine::instance()->get_ports ("", ARDOUR::DataType::MIDI, ARDOUR::PortFlags (ARDOUR::IsInput|ARDOUR::IsPhysical), midi_outputs);
+
+ input_combos.clear ();
+ output_combos.clear ();
+
+ if (!_cp.device_info().uses_ipmidi()) {
+
+ for (uint32_t n = 0; n < n_surfaces; ++n) {
+
+ boost::shared_ptr<Surface> surface = _cp.nth_surface (n);
+
+ if (!surface) {
+ PBD::fatal << string_compose (_("programming error: %1\n"), string_compose ("n=%1 surface not found!", n)) << endmsg;
+ /*NOTREACHED*/
+ }
+
+ Gtk::ComboBox* input_combo = manage (new Gtk::ComboBox);
+ Gtk::ComboBox* output_combo = manage (new Gtk::ComboBox);
+
+ update_port_combos (midi_inputs, midi_outputs, input_combo, output_combo, surface);
+
+ input_combo->pack_start (midi_port_columns.short_name);
+ input_combo->set_data ("surface", surface.get());
+ input_combos.push_back (input_combo);
+ output_combo->pack_start (midi_port_columns.short_name);
+ output_combo->set_data ("surface", surface.get());
+ output_combos.push_back (output_combo);
+
+ boost::weak_ptr<Surface> ws (surface);
+ input_combo->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &MackieControlProtocolGUI::active_port_changed), input_combo, ws, true));
+ output_combo->signal_changed().connect (sigc::bind (sigc::mem_fun (*this, &MackieControlProtocolGUI::active_port_changed), output_combo, ws, false));
+
+ string send_string;
+ string receive_string;
+
+ if (n_surfaces > 1) {
+ if (n == 0) {
+ send_string = _("Main surface sends via:");
+ receive_string = _("Main surface receives via:");
+ } else {
+ send_string = string_compose (_("Extender %1 sends via:"), n);
+ receive_string = string_compose (_("Extender %1 receives via:"), n);
+ }
+ } else {
+ send_string = _("Surface sends via:");
+ receive_string = _("Surface receives via:");
+ }
+
+ l = manage (new Gtk::Label (send_string));
+ l->set_alignment (1.0, 0.5);
+ dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+ dd_table->attach (*input_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+ row++;
+
+ l = manage (new Gtk::Label (receive_string));
+ l->set_alignment (1.0, 0.5);
+ dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0));
+ dd_table->attach (*output_combo, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions(0), 0, 0);
+ row++;
+ }
+
+ } else {
+
+ l = manage (new Gtk::Label (_("ipMIDI Port (lowest)")));
+ l->set_alignment (1.0, 0.5);
+
+ Gtk::SpinButton* ipmidi_base_port_spinner = manage (new Gtk::SpinButton (ipmidi_base_port_adjustment));
+ dd_table->attach (*l, 0, 1, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+ dd_table->attach (*ipmidi_base_port_spinner, 1, 2, row, row+1, AttachOptions(FILL|EXPAND), AttachOptions (0));
+ row++;
+ }
+
+ return dd_table;
+}
+