new PBD::ControllableDescriptor class to encapsulate parsing of binding URIs and...
[ardour.git] / libs / surfaces / generic_midi / midicontrollable.cc
index 2942a94ad21d083351aaf6a0a410adc3dbc9de67..d960140958d7d6939375f73e6acc1cb46d174aec 100644 (file)
@@ -24,6 +24,7 @@
 #include <climits>
 
 #include "pbd/error.h"
+#include "pbd/controllable_descriptor.h"
 #include "pbd/xml++.h"
 
 #include "midi++/port.h"
@@ -41,6 +42,7 @@ using namespace ARDOUR;
 
 MIDIControllable::MIDIControllable (Port& p, bool is_bistate)
        : controllable (0)
+       , _descriptor (0)
        , _port (p)
        , bistate (is_bistate)
 {
@@ -55,8 +57,10 @@ MIDIControllable::MIDIControllable (Port& p, bool is_bistate)
 
 MIDIControllable::MIDIControllable (Port& p, Controllable& c, bool is_bistate)
        : controllable (&c)
+       , _descriptor (0)
        , _port (p)
        , bistate (is_bistate)
+
 {
        _learned = true; /* from controllable */
        setting = false;
@@ -76,48 +80,9 @@ int
 MIDIControllable::init (const std::string& s)
 {
        _current_uri = s;
-
-       if (!_current_uri.empty()) {
-
-               /* parse URI to get remote control ID and "what" is to be controlled */
-               
-               string::size_type last_slash;
-               string useful_part;
-               
-               if ((last_slash = _current_uri.find_last_of ('/')) == string::npos) {
-                       return -1;
-               }
-               
-               useful_part = _current_uri.substr (last_slash+1);
-               
-               char ridstr[64];
-               char what[64];
-               
-               if (sscanf (useful_part.c_str(), "rid=%63[^?]?%63s", ridstr, what) != 2) {
-                       return -1;
-               }
-               
-               _what = what;
-
-               /* now parse RID string and determine if its a bank-driven ID */
-               
-               if (strncmp (ridstr, "B-", 2) == 0) {
-                       
-                       if (sscanf (&ridstr[2], "%" PRIu32, &_rid) != 1) {
-                               return -1;
-                       }
-                       
-                       _bank_relative = true;
-
-               } else {
-                       if (sscanf (&ridstr[2], "%" PRIu32, &_rid) != 1) {
-                               return -1;
-                       }
-                       _bank_relative = false;
-               }
-       }
-
-       return 0;
+       delete _descriptor;
+       _descriptor = new ControllableDescriptor;
+       return _descriptor->set (s);
 }
 
 void