Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <cerrno>
#include <cstdlib>
#include <cstring>
#include <glibmm/miscutils.h>
#include "pbd/xml++.h"
#include "pbd/error.h"
#include "pbd/pathscanner.h"
+#include "pbd/replace_all.h"
#include "ardour/filesystem_paths.h"
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;
}
}
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) {
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;
b = _button_map.insert (_button_map.end(), std::pair<Button::ID,ButtonActions> (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) {
}
}
}
- } else {
- std::cerr << " no buttons\n";
}
return 0;
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;
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);
}
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);
return;
}
+ string action (act);
+ replace_all (action, "<Actions>/", "");
+
if (modifier_state == MackieControlProtocol::MODIFIER_CONTROL) {
i->second.control = action;
} else if (modifier_state == MackieControlProtocol::MODIFIER_SHIFT) {
if (modifier_state == 0) {
i->second.plain = action;
}
+
+ save ();
}
const string&
{
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;
+ }
+}
+
if (row) {
std::map<std::string,std::string>::iterator i = action_map.find (text);
+
+ cerr << "Changed to " << text << endl;
if (i == action_map.end()) {
return;
Glib::RefPtr<Gtk::Action> 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);
}
}