+ 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;
+}
+
+CellRendererCombo*
+MackieControlProtocolGUI::make_action_renderer (Glib::RefPtr<TreeStore> model, Gtk::TreeModelColumnBase column)
+{
+ CellRendererCombo* renderer = manage (new CellRendererCombo);
+ renderer->property_model() = model;
+ renderer->property_editable() = true;
+ renderer->property_text_column() = 0;
+ renderer->property_has_entry() = false;
+ renderer->signal_edited().connect (sigc::bind (sigc::mem_fun(*this, &MackieControlProtocolGUI::action_changed), column));
+
+ return renderer;
+}
+
+void
+MackieControlProtocolGUI::build_available_action_menu ()
+{
+ /* build a model of all available actions (needs to be tree structured
+ * more)
+ */
+
+ available_action_model = TreeStore::create (available_action_columns);
+
+ vector<string> paths;
+ vector<string> labels;
+ vector<string> tooltips;
+ vector<string> keys;
+ vector<AccelKey> bindings;
+ typedef std::map<string,TreeIter> NodeMap;
+ NodeMap nodes;
+ NodeMap::iterator r;
+
+ ActionManager::get_all_actions (labels, paths, tooltips, keys, bindings);
+
+ vector<string>::iterator k;
+ vector<string>::iterator p;
+ vector<string>::iterator t;
+ vector<string>::iterator l;
+
+ available_action_model->clear ();
+
+ /* Because there are button bindings built in that are not
+ in the key binding map, there needs to be a way to undo
+ a profile edit. */
+ TreeIter rowp;
+ TreeModel::Row parent;
+ rowp = available_action_model->append();
+ parent = *(rowp);
+ parent[available_action_columns.name] = _("Remove Binding");
+
+ /* Key aliasing */
+
+ rowp = available_action_model->append();
+ parent = *(rowp);
+ parent[available_action_columns.name] = _("Shift");
+ rowp = available_action_model->append();
+ parent = *(rowp);
+ parent[available_action_columns.name] = _("Control");
+ rowp = available_action_model->append();
+ parent = *(rowp);
+ parent[available_action_columns.name] = _("Option");
+ rowp = available_action_model->append();
+ parent = *(rowp);
+ parent[available_action_columns.name] = _("CmdAlt");
+
+
+ for (l = labels.begin(), k = keys.begin(), p = paths.begin(), t = tooltips.begin(); l != labels.end(); ++k, ++p, ++t, ++l) {
+
+ TreeModel::Row row;
+ vector<string> parts;
+
+ parts.clear ();
+
+ split (*p, parts, '/');
+
+ if (parts.empty()) {
+ continue;
+ }
+
+ //kinda kludgy way to avoid displaying menu items as mappable
+ if ( parts[1] == _("Main_menu") )
+ continue;
+ if ( parts[1] == _("JACK") )
+ continue;
+ if ( parts[1] == _("redirectmenu") )
+ continue;
+ if ( parts[1] == _("Editor_menus") )
+ continue;
+ if ( parts[1] == _("RegionList") )
+ continue;
+ if ( parts[1] == _("ProcessorMenu") )
+ continue;
+
+ if ((r = nodes.find (parts[1])) == nodes.end()) {
+
+ /* top level is missing */
+
+ TreeIter rowp;
+ TreeModel::Row parent;
+ rowp = available_action_model->append();
+ nodes[parts[1]] = rowp;
+ parent = *(rowp);
+ parent[available_action_columns.name] = parts[1];
+
+ row = *(available_action_model->append (parent.children()));
+
+ } else {
+
+ row = *(available_action_model->append ((*r->second)->children()));
+
+ }
+
+ /* add this action */
+
+ if (l->empty ()) {
+ row[available_action_columns.name] = *t;
+ action_map[*t] = *p;
+ } else {
+ row[available_action_columns.name] = *l;
+ action_map[*l] = *p;
+ }
+
+ row[available_action_columns.path] = (*p);
+ }
+}
+
+void
+MackieControlProtocolGUI::build_function_key_editor ()
+{
+ function_key_editor.append_column (_("Key"), function_key_columns.name);
+
+ TreeViewColumn* col;
+ CellRendererCombo* renderer;
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.plain);
+ col = manage (new TreeViewColumn (_("Plain"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.plain);
+ function_key_editor.append_column (*col);
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.shift);
+ col = manage (new TreeViewColumn (_("Shift"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.shift);
+ function_key_editor.append_column (*col);
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.control);
+ col = manage (new TreeViewColumn (_("Control"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.control);
+ function_key_editor.append_column (*col);
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.option);
+ col = manage (new TreeViewColumn (_("Option"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.option);
+ function_key_editor.append_column (*col);
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.cmdalt);
+ col = manage (new TreeViewColumn (_("Cmd/Alt"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.cmdalt);
+ function_key_editor.append_column (*col);
+
+ renderer = make_action_renderer (available_action_model, function_key_columns.shiftcontrol);
+ col = manage (new TreeViewColumn (_("Shift+Control"), *renderer));
+ col->add_attribute (renderer->property_text(), function_key_columns.shiftcontrol);
+ function_key_editor.append_column (*col);
+
+ function_key_model = ListStore::create (function_key_columns);
+ function_key_editor.set_model (function_key_model);
+}
+
+void
+MackieControlProtocolGUI::refresh_function_key_editor ()
+{
+ function_key_editor.set_model (Glib::RefPtr<TreeModel>());
+ function_key_model->clear ();
+
+ /* now fill with data */
+
+ TreeModel::Row row;
+ DeviceProfile dp (_cp.device_profile());
+ DeviceInfo di;
+
+ for (int n = 0; n < Mackie::Button::FinalGlobalButton; ++n) {
+
+ Mackie::Button::ID bid = (Mackie::Button::ID) n;
+
+ row = *(function_key_model->append());
+ if (di.global_buttons().find (bid) == di.global_buttons().end()) {
+ row[function_key_columns.name] = Mackie::Button::id_to_name (bid);
+ } else {
+ row[function_key_columns.name] = di.get_global_button_name (bid) + "*";
+ }
+ row[function_key_columns.id] = bid;
+
+ Glib::RefPtr<Gtk::Action> act;
+ string action;
+ const string defstring = "\u2022";
+
+ action = dp.get_button_action (bid, 0);
+ if (action.empty()) {
+ row[function_key_columns.plain] = defstring;
+ } else {
+ if (action.find ('/') == string::npos) {
+ /* Probably a key alias */
+ row[function_key_columns.plain] = action;
+ } else {
+
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.plain] = act->get_label();
+ } else {
+ row[function_key_columns.plain] = defstring;
+ }
+ }
+ }
+
+ action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CONTROL);
+ if (action.empty()) {
+ row[function_key_columns.control] = defstring;
+ } else {
+ if (action.find ('/') == string::npos) {
+ /* Probably a key alias */
+ row[function_key_columns.control] = action;
+ } else {
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.control] = act->get_label();
+ } else {
+ row[function_key_columns.control] = defstring;
+ }
+ }
+ }
+
+ action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_SHIFT);
+ if (action.empty()) {
+ row[function_key_columns.shift] = defstring;
+ } else {
+ if (action.find ('/') == string::npos) {
+ /* Probably a key alias */
+ row[function_key_columns.shift] = action;
+ } else {
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.shift] = act->get_label();
+ } else {
+ row[function_key_columns.shift] = defstring;
+ }
+ }
+ }
+
+ action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_OPTION);
+ if (action.empty()) {
+ row[function_key_columns.option] = defstring;
+ } else {
+ if (action.find ('/') == string::npos) {
+ /* Probably a key alias */
+ row[function_key_columns.option] = action;
+ } else {
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.option] = act->get_label();
+ } else {
+ row[function_key_columns.option] = defstring;
+ }
+ }
+ }
+
+ action = dp.get_button_action (bid, MackieControlProtocol::MODIFIER_CMDALT);
+ if (action.empty()) {
+ row[function_key_columns.cmdalt] = defstring;
+ } else {
+ if (action.find ('/') == string::npos) {
+ /* Probably a key alias */
+ row[function_key_columns.cmdalt] = action;
+ } else {
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.cmdalt] = act->get_label();
+ } else {
+ row[function_key_columns.cmdalt] = defstring;
+ }
+ }
+ }
+
+ action = dp.get_button_action (bid, (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL));
+ if (action.empty()) {
+ row[function_key_columns.shiftcontrol] = defstring;
+ } else {
+ act = ActionManager::get_action (action.c_str());
+ if (act) {
+ row[function_key_columns.shiftcontrol] = act->get_label();
+ } else {
+ row[function_key_columns.shiftcontrol] = defstring;
+ }
+ }
+ }
+
+ function_key_editor.set_model (function_key_model);
+}
+
+void
+MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib::ustring &text, TreeModelColumnBase col)
+{
+ // Remove Binding is not in the action map but still valid
+ bool remove (false);
+ if ( text == "Remove Binding") {
+ remove = true;
+ }
+ Gtk::TreePath path(sPath);
+ Gtk::TreeModel::iterator row = function_key_model->get_iter(path);
+
+ if (row) {
+
+ std::map<std::string,std::string>::iterator i = action_map.find (text);
+
+ if (i == action_map.end()) {
+ if (!remove) {
+ return;
+ }
+ }
+ Glib::RefPtr<Gtk::Action> act = ActionManager::get_action (i->second.c_str());
+
+ if (act || remove) {
+ /* update visible text, using string supplied by
+ available action model so that it matches and is found
+ within the model.
+ */
+ if (remove) {
+ Glib::ustring dot = "\u2022";
+ (*row).set_value (col.index(), dot);
+ } else {
+ (*row).set_value (col.index(), text);
+ }
+
+ /* update the current DeviceProfile, using the full
+ * path
+ */
+
+ int modifier;
+
+ switch (col.index()) {
+ case 3:
+ modifier = MackieControlProtocol::MODIFIER_SHIFT;
+ break;
+ case 4:
+ modifier = MackieControlProtocol::MODIFIER_CONTROL;
+ break;
+ case 5:
+ modifier = MackieControlProtocol::MODIFIER_OPTION;
+ break;
+ case 6:
+ modifier = MackieControlProtocol::MODIFIER_CMDALT;
+ break;
+ case 7:
+ modifier = (MackieControlProtocol::MODIFIER_SHIFT|MackieControlProtocol::MODIFIER_CONTROL);
+ break;
+ default:
+ modifier = 0;
+ }
+
+ if (remove) {
+ _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, "");
+ } else {
+ _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second);
+ }
+
+ } else {
+ std::cerr << "no such action\n";
+ }
+ }