diff --git a/libs/surfaces/mackie/device_profile.cc b/libs/surfaces/mackie/device_profile.cc index 860da3ca2a..462c43b678 100644 --- a/libs/surfaces/mackie/device_profile.cc +++ b/libs/surfaces/mackie/device_profile.cc @@ -17,6 +17,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include #include #include #include @@ -24,6 +25,7 @@ #include "pbd/xml++.h" #include "pbd/error.h" #include "pbd/pathscanner.h" +#include "pbd/replace_all.h" #include "ardour/filesystem_paths.h" @@ -123,18 +125,16 @@ DeviceProfile::reload_device_profiles () std::cerr << "Loading " << fullpath << std::endl; if (!tree.read (fullpath.c_str())) { - std::cerr << "XML read failed\n"; continue; } XMLNode* root = tree.root (); if (!root) { - std::cerr << "no root\n"; continue; } if (dp.set_state (*root, 3000) == 0) { /* version is ignored for now */ - std::cerr << "saved profile " << dp.name() << std::endl; + dp.set_path (fullpath); device_profiles[dp.name()] = dp; } } @@ -149,18 +149,15 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */) const XMLNode* child; if (node.name() != "MackieDeviceProfile") { - std::cerr << "wrong root\n"; return -1; } /* name is mandatory */ if ((child = node.child ("Name")) == 0 || (prop = child->property ("value")) == 0) { - std::cerr << "no name\n"; return -1; } else { _name = prop->value(); - std::cerr << "got name " << _name << std::endl; } if ((child = node.child ("Buttons")) != 0) { @@ -171,8 +168,6 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */) if ((*i)->name() == "Button") { - std::cerr << "foudn a button\n"; - if ((prop = (*i)->property ("name")) == 0) { error << string_compose ("Button without name in device profile \"%1\" - ignored", _name) << endmsg; continue; @@ -192,10 +187,7 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */) b = _button_map.insert (_button_map.end(), std::pair (bid, ButtonActions())); } - std::cerr << "checking bindings for button " << bid << std::endl; - if ((prop = (*i)->property ("plain")) != 0) { - std::cerr << "Loaded binding between " << bid << " and " << prop->value() << std::endl; b->second.plain = prop->value (); } if ((prop = (*i)->property ("control")) != 0) { @@ -215,8 +207,6 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */) } } } - } else { - std::cerr << " no buttons\n"; } return 0; @@ -226,8 +216,10 @@ XMLNode& DeviceProfile::get_state () const { XMLNode* node = new XMLNode ("MackieDeviceProfile"); + XMLNode* child = new XMLNode ("Name"); - node->add_property ("name", _name); + child->add_property ("value", _name); + node->add_child_nocopy (*child); if (_button_map.empty()) { return *node; @@ -239,7 +231,7 @@ DeviceProfile::get_state () const for (ButtonActionMap::const_iterator b = _button_map.begin(); b != _button_map.end(); ++b) { XMLNode* n = new XMLNode ("Button"); - n->add_property ("name", b->first); + n->add_property ("name", Button::id_to_name (b->first)); if (!b->second.plain.empty()) { n->add_property ("plain", b->second.plain); @@ -291,7 +283,7 @@ DeviceProfile::get_button_action (Button::ID id, int modifier_state) const } void -DeviceProfile::set_button_action (Button::ID id, int modifier_state, const string& action) +DeviceProfile::set_button_action (Button::ID id, int modifier_state, const string& act) { ButtonActionMap::iterator i = _button_map.find (id); @@ -299,6 +291,9 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin return; } + string action (act); + replace_all (action, "/", ""); + if (modifier_state == MackieControlProtocol::MODIFIER_CONTROL) { i->second.control = action; } else if (modifier_state == MackieControlProtocol::MODIFIER_SHIFT) { @@ -314,6 +309,8 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin if (modifier_state == 0) { i->second.plain = action; } + + save (); } const string& @@ -321,3 +318,50 @@ DeviceProfile::name() const { return _name; } + +void +DeviceProfile::set_path (const string& p) +{ + _path = p; +} + +/* XXX copied from libs/ardour/utils.cc */ + +static string +legalize_for_path (const string& str) +{ + string::size_type pos; + string illegal_chars = "/\\"; /* DOS, POSIX. Yes, we're going to ignore HFS */ + string legal; + + legal = str; + pos = 0; + + while ((pos = legal.find_first_of (illegal_chars, pos)) != string::npos) { + legal.replace (pos, 1, "_"); + pos += 1; + } + + return string (legal); +} + + +void +DeviceProfile::save () +{ + sys::path fullpath = user_devprofile_directory(); + + if (g_mkdir_with_parents (fullpath.to_string().c_str(), 0755) < 0) { + error << string_compose(_("Session: cannot create user MCP profile folder \"%1\" (%2)"), fullpath.to_string(), strerror (errno)) << endmsg; + return; + } + + fullpath /= legalize_for_path (_name) + ".profile"; + + XMLTree tree; + tree.set_root (&get_state()); + if (!tree.write (fullpath.to_string())) { + error << string_compose ("MCP profile not saved to %1", fullpath.to_string()) << endmsg; + } +} + diff --git a/libs/surfaces/mackie/device_profile.h b/libs/surfaces/mackie/device_profile.h index da63d97f48..65aba48692 100644 --- a/libs/surfaces/mackie/device_profile.h +++ b/libs/surfaces/mackie/device_profile.h @@ -40,7 +40,8 @@ class DeviceProfile void set_button_action (Button::ID, int modifier_state, const std::string&); const std::string& name() const; - + void set_path (const std::string&); + static void reload_device_profiles (); static std::map device_profiles; @@ -57,10 +58,13 @@ class DeviceProfile typedef std::map ButtonActionMap; std::string _name; + std::string _path; ButtonActionMap _button_map; int set_state (const XMLNode&, int version); XMLNode& get_state () const; + + void save (); }; } diff --git a/libs/surfaces/mackie/gui.cc b/libs/surfaces/mackie/gui.cc index acb4779b7f..7bcd7681e1 100644 --- a/libs/surfaces/mackie/gui.cc +++ b/libs/surfaces/mackie/gui.cc @@ -361,6 +361,8 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib if (row) { std::map::iterator i = action_map.find (text); + + cerr << "Changed to " << text << endl; if (i == action_map.end()) { return; @@ -369,7 +371,39 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib Glib::RefPtr act = ActionManager::get_action (i->second.c_str()); if (act) { + /* update visible text, using string supplied by + available action model so that it matches and is found + within the model. + */ (*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; + } + + _cp.device_profile().set_button_action ((*row)[function_key_columns.id], modifier, i->second); } } diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index 8698391646..e75d1824e2 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -81,8 +81,8 @@ using namespace Glib; const int MackieControlProtocol::MODIFIER_OPTION = 0x1; const int MackieControlProtocol::MODIFIER_CONTROL = 0x2; -const int MackieControlProtocol::MODIFIER_SHIFT = 0x3; -const int MackieControlProtocol::MODIFIER_CMDALT = 0x4; +const int MackieControlProtocol::MODIFIER_SHIFT = 0x4; +const int MackieControlProtocol::MODIFIER_CMDALT = 0x8; MackieControlProtocol* MackieControlProtocol::_instance = 0; diff --git a/libs/surfaces/mackie/mackie_control_protocol.h b/libs/surfaces/mackie/mackie_control_protocol.h index 238c9c4aa5..d1075e25ce 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.h +++ b/libs/surfaces/mackie/mackie_control_protocol.h @@ -119,7 +119,7 @@ class MackieControlProtocol static MackieControlProtocol* instance() { return _instance; } const Mackie::DeviceInfo& device_info() const { return _device_info; } - const Mackie::DeviceProfile& device_profile() const { return _device_profile; } + Mackie::DeviceProfile& device_profile() { return _device_profile; } int set_active (bool yn); void set_device (const std::string&); diff --git a/mcp/paul-nucleus.profile b/mcp/paul-nucleus.profile index 68fe09bca3..91073da6b5 100644 --- a/mcp/paul-nucleus.profile +++ b/mcp/paul-nucleus.profile @@ -1,6 +1,6 @@ - +