MCP:maybe functioning button binding stuff, plus save-to-disk-on-change (still needs...
authorPaul Davis <paul@linuxaudiosystems.com>
Wed, 18 Apr 2012 03:24:59 +0000 (03:24 +0000)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 18 Apr 2012 03:24:59 +0000 (03:24 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@12000 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/surfaces/mackie/device_profile.cc
libs/surfaces/mackie/device_profile.h
libs/surfaces/mackie/gui.cc
libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/mackie/mackie_control_protocol.h
mcp/paul-nucleus.profile

index 860da3ca2a249c0979f70a479942d0341ce56dc3..462c43b6789bbae99115feb71e861b3cab6265e0 100644 (file)
@@ -17,6 +17,7 @@
        Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#include <cerrno>
 #include <cstdlib>
 #include <cstring>
 #include <glibmm/miscutils.h>
@@ -24,6 +25,7 @@
 #include "pbd/xml++.h"
 #include "pbd/error.h"
 #include "pbd/pathscanner.h"
+#include "pbd/replace_all.h"
 
 #include "ardour/filesystem_paths.h"
 
@@ -123,18 +125,16 @@ DeviceProfile::reload_device_profiles ()
                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;
                }
        }
@@ -149,18 +149,15 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
        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) {
@@ -171,8 +168,6 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
 
                        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;
@@ -192,10 +187,7 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
                                        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) {
@@ -215,8 +207,6 @@ DeviceProfile::set_state (const XMLNode& node, int /* version */)
                                }
                        }
                }
-       } else {
-               std::cerr << " no buttons\n";
        }
 
        return 0;
@@ -226,8 +216,10 @@ XMLNode&
 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;
@@ -239,7 +231,7 @@ DeviceProfile::get_state () const
        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);
@@ -291,7 +283,7 @@ DeviceProfile::get_button_action (Button::ID id, int modifier_state) const
 }
 
 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);
 
@@ -299,6 +291,9 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin
                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) {
@@ -314,6 +309,8 @@ DeviceProfile::set_button_action (Button::ID id, int modifier_state, const strin
        if (modifier_state == 0) {
                i->second.plain = action;
        }
+
+       save ();
 }
 
 const string&
@@ -321,3 +318,50 @@ DeviceProfile::name() const
 {
        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;
+       }
+}
+
index da63d97f4843c93710a70b929011062f8841da5b..65aba486924734339e634d7c532a56497a068285 100644 (file)
@@ -40,7 +40,8 @@ class DeviceProfile
        void set_button_action (Button::ID, int modifier_state, const std::string&);
        
        const std::string& name() const;
-       
+       void set_path (const std::string&);
+
        static void reload_device_profiles ();
        static std::map<std::string,DeviceProfile> device_profiles;
        
@@ -57,10 +58,13 @@ class DeviceProfile
        typedef std::map<Button::ID,ButtonActions> ButtonActionMap;
        
        std::string _name;
+       std::string _path;
        ButtonActionMap _button_map;
        
        int set_state (const XMLNode&, int version);
        XMLNode& get_state () const;
+
+       void save ();
 };
 
 }
index acb4779b7f6928e6d21e39f7d2b953cb8d25701c..7bcd7681e132cc695d6a62004e79d6a5fdb1a429 100644 (file)
@@ -361,6 +361,8 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
        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;
@@ -369,7 +371,39 @@ MackieControlProtocolGUI::action_changed (const Glib::ustring &sPath, const Glib
                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);
                }
                        
        }
index 8698391646e60748f645c201a54b09e4df56c178..e75d1824e2f2afb8551340f1d90bc1ec2a10294b 100644 (file)
@@ -81,8 +81,8 @@ using namespace Glib;
 
 const int MackieControlProtocol::MODIFIER_OPTION = 0x1;
 const int MackieControlProtocol::MODIFIER_CONTROL = 0x2;
-const int MackieControlProtocol::MODIFIER_SHIFT = 0x3;
-const int MackieControlProtocol::MODIFIER_CMDALT = 0x4;
+const int MackieControlProtocol::MODIFIER_SHIFT = 0x4;
+const int MackieControlProtocol::MODIFIER_CMDALT = 0x8;
 
 MackieControlProtocol* MackieControlProtocol::_instance = 0;
 
index 238c9c4aa5bcba10c0ce01b467bd519748b8da93..d1075e25cec7e628de31a2b0f468bd0c33511552 100644 (file)
@@ -119,7 +119,7 @@ class MackieControlProtocol
        static MackieControlProtocol* instance() { return _instance; }
        
        const Mackie::DeviceInfo& device_info() const { return _device_info; }
-       const Mackie::DeviceProfile& device_profile() const { return _device_profile; }
+       Mackie::DeviceProfile& device_profile() { return _device_profile; }
 
        int set_active (bool yn);
        void set_device (const std::string&);
index 68fe09bca35daf36227cd338f05167fcacbd8e1c..91073da6b5aaf1b06b7e16c9deaedf98dbb0479b 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <MackieDeviceProfile>
-  <Name value="SSL Nucleus"/>
+  <Name value="Basic SSL Nucleus"/>
   <MasterOn value="14"/>
   <MonitorOn value="15"/>
   <Buttons>