mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-07 07:14:56 +01:00
mackie: try to improve logic and management of device profiles
This commit is contained in:
parent
d3081fd816
commit
37d6265e13
4 changed files with 70 additions and 10 deletions
|
|
@ -44,9 +44,12 @@ using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
std::map<std::string,DeviceProfile> DeviceProfile::device_profiles;
|
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)
|
DeviceProfile::DeviceProfile (const string& n)
|
||||||
: _name (n)
|
: _name (n)
|
||||||
|
, edited (false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -191,6 +194,8 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edited = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,7 +205,7 @@ DeviceProfile::get_state () const
|
||||||
XMLNode* node = new XMLNode ("MackieDeviceProfile");
|
XMLNode* node = new XMLNode ("MackieDeviceProfile");
|
||||||
XMLNode* child = new XMLNode ("Name");
|
XMLNode* child = new XMLNode ("Name");
|
||||||
|
|
||||||
child->add_property ("value", _name);
|
child->add_property ("value", name());
|
||||||
node->add_child_nocopy (*child);
|
node->add_child_nocopy (*child);
|
||||||
|
|
||||||
if (_button_map.empty()) {
|
if (_button_map.empty()) {
|
||||||
|
|
@ -292,13 +297,31 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin
|
||||||
i->second.plain = action;
|
i->second.plain = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edited = true;
|
||||||
|
|
||||||
save ();
|
save ();
|
||||||
}
|
}
|
||||||
|
|
||||||
const string&
|
string
|
||||||
|
DeviceProfile::name_when_edited (string const& base)
|
||||||
|
{
|
||||||
|
return string_compose ("%1 %2", base, edited_indicator);
|
||||||
|
}
|
||||||
|
|
||||||
|
string
|
||||||
DeviceProfile::name() const
|
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
|
void
|
||||||
|
|
@ -338,7 +361,7 @@ DeviceProfile::save ()
|
||||||
return;
|
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;
|
XMLTree tree;
|
||||||
tree.set_root (&get_state());
|
tree.set_root (&get_state());
|
||||||
|
|
@ -347,4 +370,3 @@ DeviceProfile::save ()
|
||||||
error << string_compose ("MCP profile not saved to %1", fullpath) << endmsg;
|
error << string_compose ("MCP profile not saved to %1", fullpath) << endmsg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -41,11 +41,13 @@ class DeviceProfile
|
||||||
std::string get_button_action (Button::ID, int modifier_state) const;
|
std::string get_button_action (Button::ID, int modifier_state) const;
|
||||||
void set_button_action (Button::ID, int modifier_state, const std::string&);
|
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&);
|
void set_path (const std::string&);
|
||||||
|
|
||||||
static void reload_device_profiles ();
|
static void reload_device_profiles ();
|
||||||
static std::map<std::string,DeviceProfile> 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:
|
private:
|
||||||
struct ButtonActions {
|
struct ButtonActions {
|
||||||
|
|
@ -62,6 +64,9 @@ class DeviceProfile
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::string _path;
|
std::string _path;
|
||||||
ButtonActionMap _button_map;
|
ButtonActionMap _button_map;
|
||||||
|
bool edited;
|
||||||
|
|
||||||
|
static const std::string edited_indicator;
|
||||||
|
|
||||||
int set_state (const XMLNode&, int version);
|
int set_state (const XMLNode&, int version);
|
||||||
XMLNode& get_state () const;
|
XMLNode& get_state () const;
|
||||||
|
|
|
||||||
|
|
@ -1031,6 +1031,12 @@ MackieControlProtocol::get_state()
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
MackieControlProtocol::profile_exists (string const & name) const
|
||||||
|
{
|
||||||
|
return DeviceProfile::device_profiles.find (name) != DeviceProfile::device_profiles.end();
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
MackieControlProtocol::set_state (const XMLNode & node, int version)
|
MackieControlProtocol::set_state (const XMLNode & node, int version)
|
||||||
{
|
{
|
||||||
|
|
@ -1061,13 +1067,38 @@ MackieControlProtocol::set_state (const XMLNode & node, int version)
|
||||||
if (prop->value().empty()) {
|
if (prop->value().empty()) {
|
||||||
string default_profile_name;
|
string default_profile_name;
|
||||||
|
|
||||||
default_profile_name = Glib::get_user_name();
|
/* start by looking for a user-edited profile for the current device name */
|
||||||
default_profile_name += ' ';
|
|
||||||
default_profile_name += _device_info.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);
|
set_profile (default_profile_name);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
set_profile (prop->value());
|
if (profile_exists (prop->value())) {
|
||||||
|
set_profile (prop->value());
|
||||||
|
} else {
|
||||||
|
set_profile (DeviceProfile::default_profile_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -314,6 +314,8 @@ class MackieControlProtocol
|
||||||
|
|
||||||
static MackieControlProtocol* _instance;
|
static MackieControlProtocol* _instance;
|
||||||
|
|
||||||
|
bool profile_exists (std::string const&) const;
|
||||||
|
|
||||||
Mackie::DeviceInfo _device_info;
|
Mackie::DeviceInfo _device_info;
|
||||||
Mackie::DeviceProfile _device_profile;
|
Mackie::DeviceProfile _device_profile;
|
||||||
sigc::connection periodic_connection;
|
sigc::connection periodic_connection;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue