mackie: try to improve logic and management of device profiles

This commit is contained in:
Paul Davis 2016-02-04 11:23:54 -05:00
parent d3081fd816
commit 37d6265e13
4 changed files with 70 additions and 10 deletions

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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);
}
}
}

View file

@ -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;