diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2016-02-04 11:23:54 -0500 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2016-02-04 11:24:26 -0500 |
commit | 37d6265e13d7870b81bd5d01d7082f80a8eb0291 (patch) | |
tree | 366bf74fd3508b1cbef30db1e1d614901ba895b9 /libs/surfaces | |
parent | d3081fd816be3e9bb639ff0ba9a415fa2fa5fbdd (diff) |
mackie: try to improve logic and management of device profiles
Diffstat (limited to 'libs/surfaces')
-rw-r--r-- | libs/surfaces/mackie/device_profile.cc | 32 | ||||
-rw-r--r-- | libs/surfaces/mackie/device_profile.h | 7 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.cc | 39 | ||||
-rw-r--r-- | libs/surfaces/mackie/mackie_control_protocol.h | 2 |
4 files changed, 70 insertions, 10 deletions
diff --git a/libs/surfaces/mackie/device_profile.cc b/libs/surfaces/mackie/device_profile.cc index 2b9cbd5edb..f67aa3cddd 100644 --- a/libs/surfaces/mackie/device_profile.cc +++ b/libs/surfaces/mackie/device_profile.cc @@ -44,9 +44,12 @@ using std::string; using std::vector; std::map<std::string,DeviceProfile> DeviceProfile::device_profiles; +const std::string DeviceProfile::edited_indicator (" (edited)"); +const std::string DeviceProfile::default_profile_name ("User"); DeviceProfile::DeviceProfile (const string& n) : _name (n) + , edited (false) { } @@ -191,6 +194,8 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */) } } + edited = false; + return 0; } @@ -200,7 +205,7 @@ DeviceProfile::get_state () const XMLNode* node = new XMLNode ("MackieDeviceProfile"); XMLNode* child = new XMLNode ("Name"); - child->add_property ("value", _name); + child->add_property ("value", name()); node->add_child_nocopy (*child); if (_button_map.empty()) { @@ -292,13 +297,31 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin i->second.plain = action; } + edited = true; + save (); } -const string& +string +DeviceProfile::name_when_edited (string const& base) +{ + return string_compose ("%1 %2", base, edited_indicator); +} + +string DeviceProfile::name() const { - return _name; + if (edited) { + if (_name.find (edited_indicator) == string::npos) { + /* modify name to included edited indicator */ + return name_when_edited (_name); + } else { + /* name already contains edited indicator */ + return _name; + } + } else { + return _name; + } } void @@ -338,7 +361,7 @@ DeviceProfile::save () return; } - fullpath = Glib::build_filename (fullpath, legalize_for_path (_name) + ".profile"); + fullpath = Glib::build_filename (fullpath, string_compose ("%1%2", legalize_for_path (name()), devprofile_suffix)); XMLTree tree; tree.set_root (&get_state()); @@ -347,4 +370,3 @@ DeviceProfile::save () error << string_compose ("MCP profile not saved to %1", fullpath) << endmsg; } } - diff --git a/libs/surfaces/mackie/device_profile.h b/libs/surfaces/mackie/device_profile.h index ab1e645e56..3224b074ad 100644 --- a/libs/surfaces/mackie/device_profile.h +++ b/libs/surfaces/mackie/device_profile.h @@ -41,11 +41,13 @@ class DeviceProfile std::string get_button_action (Button::ID, int modifier_state) const; void set_button_action (Button::ID, int modifier_state, const std::string&); - const std::string& name() const; + std::string name() const; void set_path (const std::string&); static void reload_device_profiles (); static std::map<std::string,DeviceProfile> device_profiles; + static std::string name_when_edited (std::string const& name); + static const std::string default_profile_name; private: struct ButtonActions { @@ -62,6 +64,9 @@ class DeviceProfile std::string _name; std::string _path; ButtonActionMap _button_map; + bool edited; + + static const std::string edited_indicator; int set_state (const XMLNode&, int version); XMLNode& get_state () const; diff --git a/libs/surfaces/mackie/mackie_control_protocol.cc b/libs/surfaces/mackie/mackie_control_protocol.cc index d9fa3340c7..a898746112 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.cc +++ b/libs/surfaces/mackie/mackie_control_protocol.cc @@ -1031,6 +1031,12 @@ MackieControlProtocol::get_state() return node; } +bool +MackieControlProtocol::profile_exists (string const & name) const +{ + return DeviceProfile::device_profiles.find (name) != DeviceProfile::device_profiles.end(); +} + int MackieControlProtocol::set_state (const XMLNode & node, int version) { @@ -1061,13 +1067,38 @@ MackieControlProtocol::set_state (const XMLNode & node, int version) if (prop->value().empty()) { string default_profile_name; - default_profile_name = Glib::get_user_name(); - default_profile_name += ' '; - default_profile_name += _device_info.name(); + /* start by looking for a user-edited profile for the current device name */ + + default_profile_name = DeviceProfile::name_when_edited (_device_info.name()); + + if (!profile_exists (default_profile_name)) { + + /* no user-edited profile for this device name, so try the user-edited default profile */ + + default_profile_name = DeviceProfile::name_when_edited (DeviceProfile::default_profile_name); + + if (!profile_exists (default_profile_name)) { + + /* no user-edited version, so just try the device name */ + + default_profile_name = _device_info.name(); + + if (!profile_exists (default_profile_name)) { + + /* no generic device specific profile, just try the fixed default */ + default_profile_name = DeviceProfile::default_profile_name; + } + } + } set_profile (default_profile_name); + } else { - set_profile (prop->value()); + if (profile_exists (prop->value())) { + set_profile (prop->value()); + } else { + set_profile (DeviceProfile::default_profile_name); + } } } diff --git a/libs/surfaces/mackie/mackie_control_protocol.h b/libs/surfaces/mackie/mackie_control_protocol.h index d3e17d0fcc..667f0c36cf 100644 --- a/libs/surfaces/mackie/mackie_control_protocol.h +++ b/libs/surfaces/mackie/mackie_control_protocol.h @@ -314,6 +314,8 @@ class MackieControlProtocol static MackieControlProtocol* _instance; + bool profile_exists (std::string const&) const; + Mackie::DeviceInfo _device_info; Mackie::DeviceProfile _device_profile; sigc::connection periodic_connection; |