#include "pbd/xml++.h"
#include "pbd/error.h"
-#include "pbd/pathscanner.h"
+#include "pbd/file_utils.h"
+#include "pbd/stl_delete.h"
#include "pbd/replace_all.h"
#include "ardour/filesystem_paths.h"
#include "mackie_control_protocol.h"
#include "device_profile.h"
-#include "i18n.h"
+#include "pbd/i18n.h"
-using namespace Mackie;
using namespace PBD;
using namespace ARDOUR;
+using namespace ArdourSurface;
+using namespace Mackie;
+
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)
{
}
static const char* const devprofile_dir_name = "mcp";
static const char* const devprofile_suffix = ".profile";
-static SearchPath
+static Searchpath
devprofile_search_path ()
{
bool devprofile_path_defined = false;
return spath_env;
}
- SearchPath spath (ardour_data_search_path());
+ Searchpath spath (ardour_data_search_path());
spath.add_subdirectory_to_paths(devprofile_dir_name);
return spath;
}
static bool
-devprofile_filter (const string &str, void */*arg*/)
+devprofile_filter (const string &str, void* /*arg*/)
{
return (str.length() > strlen(devprofile_suffix) &&
str.find (devprofile_suffix) == (str.length() - strlen (devprofile_suffix)));
void
DeviceProfile::reload_device_profiles ()
{
- DeviceProfile dp;
vector<string> s;
- vector<string *> *devprofiles;
- PathScanner scanner;
- SearchPath spath (devprofile_search_path());
+ vector<string> devprofiles;
+ Searchpath spath (devprofile_search_path());
- devprofiles = scanner (spath.to_string(), devprofile_filter, 0, false, true);
+ find_files_matching_filter (devprofiles, spath, devprofile_filter, 0, false, true);
device_profiles.clear ();
- if (!devprofiles) {
- error << "No MCP device info files found using " << spath.to_string() << endmsg;
- return;
- }
-
- if (devprofiles->empty()) {
+ if (devprofiles.empty()) {
error << "No MCP device info files found using " << spath.to_string() << endmsg;
return;
}
- for (vector<string*>::iterator i = devprofiles->begin(); i != devprofiles->end(); ++i) {
- string fullpath = *(*i);
+ for (vector<string>::iterator i = devprofiles.begin(); i != devprofiles.end(); ++i) {
+ string fullpath = *i;
+ DeviceProfile dp; // has to be initial every loop or info from last added.
XMLTree tree;
device_profiles[dp.name()] = dp;
}
}
-
- delete devprofiles;
}
int
}
/* name is mandatory */
-
+
if ((child = node.child ("Name")) == 0 || (prop = child->property ("value")) == 0) {
return -1;
} else {
int id = Button::name_to_id (prop->value());
if (id < 0) {
- error << string_compose ("Unknow button ID \"%1\"", prop->value()) << endmsg;
+ error << string_compose ("Unknown button ID \"%1\"", prop->value()) << endmsg;
continue;
}
b = _button_map.insert (_button_map.end(), std::pair<Button::ID,ButtonActions> (bid, ButtonActions()));
}
- if ((prop = (*i)->property ("plain")) != 0) {
- b->second.plain = prop->value ();
- }
- if ((prop = (*i)->property ("control")) != 0) {
- b->second.control = prop->value ();
- }
- if ((prop = (*i)->property ("shift")) != 0) {
- b->second.shift = prop->value ();
- }
- if ((prop = (*i)->property ("option")) != 0) {
- b->second.option = prop->value ();
- }
- if ((prop = (*i)->property ("cmdalt")) != 0) {
- b->second.cmdalt = prop->value ();
- }
- if ((prop = (*i)->property ("shiftcontrol")) != 0) {
- b->second.shiftcontrol = prop->value ();
- }
+ (*i)->get_property ("plain", b->second.plain);
+ (*i)->get_property ("control", b->second.control);
+ (*i)->get_property ("shift", b->second.shift);
+ (*i)->get_property ("option", b->second.option);
+ (*i)->get_property ("cmdalt", b->second.cmdalt);
+ (*i)->get_property ("shiftcontrol", b->second.shiftcontrol);
}
}
}
+ edited = false;
+
return 0;
}
XMLNode* node = new XMLNode ("MackieDeviceProfile");
XMLNode* child = new XMLNode ("Name");
- child->add_property ("value", _name);
+ child->set_property ("value", name());
node->add_child_nocopy (*child);
if (_button_map.empty()) {
for (ButtonActionMap::const_iterator b = _button_map.begin(); b != _button_map.end(); ++b) {
XMLNode* n = new XMLNode ("Button");
- n->add_property ("name", Button::id_to_name (b->first));
+ n->set_property ("name", Button::id_to_name (b->first));
if (!b->second.plain.empty()) {
- n->add_property ("plain", b->second.plain);
+ n->set_property ("plain", b->second.plain);
}
if (!b->second.control.empty()) {
- n->add_property ("control", b->second.control);
+ n->set_property ("control", b->second.control);
}
if (!b->second.shift.empty()) {
- n->add_property ("shift", b->second.shift);
+ n->set_property ("shift", b->second.shift);
}
if (!b->second.option.empty()) {
- n->add_property ("option", b->second.option);
+ n->set_property ("option", b->second.option);
}
if (!b->second.cmdalt.empty()) {
- n->add_property ("cmdalt", b->second.cmdalt);
+ n->set_property ("cmdalt", b->second.cmdalt);
}
if (!b->second.shiftcontrol.empty()) {
- n->add_property ("shiftcontrol", b->second.shiftcontrol);
+ n->set_property ("shiftcontrol", b->second.shiftcontrol);
}
buttons->add_child_nocopy (*n);
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
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());
error << string_compose ("MCP profile not saved to %1", fullpath) << endmsg;
}
}
-