+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";
+ }
+ }
+}
+
+void
+MackieControlProtocolGUI::surface_combo_changed ()
+{
+ _cp.not_session_load();
+ _cp.set_device (_surface_combo.get_active_text());
+
+ /* update ipMIDI field */
+
+ ipmidi_base_port_spinner.set_sensitive (_cp.device_info().uses_ipmidi());
+}
+
+void
+MackieControlProtocolGUI::profile_combo_changed ()
+{
+ string profile = _profile_combo.get_active_text();
+
+ _cp.set_profile (profile);
+
+ refresh_function_key_editor ();
+}
+
+void
+MackieControlProtocolGUI::ipmidi_spinner_changed ()
+{
+ _cp.set_ipmidi_base ((int16_t) lrintf (ipmidi_base_port_spinner.get_value()));
+}
+
+void
+MackieControlProtocolGUI::discover_clicked ()
+{
+ /* this should help to get things started */
+ _cp.midi_connectivity_established ();
+}
+
+void
+MackieControlProtocolGUI::recalibrate_faders ()
+{
+ _cp.recalibrate_faders ();
+}
+
+void
+MackieControlProtocolGUI::toggle_backlight ()
+{
+ _cp.toggle_backlight ();
+}
+
+void
+MackieControlProtocolGUI::touch_sensitive_change ()