add initial midi sidechain if plugin has one.
[ardour.git] / libs / ardour / controllable_descriptor.cc
index 05aa1845a3d8a0929a9437960391929fdcee1af0..fff8b0050be365d926e8dcc5ae0fbacc10201e93 100644 (file)
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
+#ifdef COMPILER_MSVC
+#include <io.h> // Microsoft's nearest equivalent to <unistd.h>
+#include <ardourext/misc.h>
+#else
+#include <regex.h>
+#endif
+
 #include "pbd/strsplit.h"
 #include "pbd/convert.h"
 
@@ -51,28 +58,68 @@ ControllableDescriptor::set (const std::string& str)
                return -1;
        }
 
+       bool stripable = false;
+       regex_t compiled_pattern;
+       const char * const pattern = "^[BS]?[0-9]+";
+
        if (path[0] == "route" || path[0] == "rid") {
 
-               _top_level_type = PresentationOrderRoute;
+               /* this is not going to fail */
+               regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
+               bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
+               regfree (&compiled_pattern);
 
-               if (rest[0][0] == 'B') {
-                       _banked = true;
-                       _presentation_order = atoi (rest[0].substr (1));
-               } else if (rest[0][0] == 'S') {
-                       _top_level_type = SelectionCount;
-                       _banked = true;
-                       _selection_id = atoi (rest[0].substr (1));
-               } else if (isdigit (rest[0][0])) {
-                       _banked = false;
-                       _presentation_order = atoi (rest[0]);
+               if (matched) {
+                       _top_level_type = PresentationOrderRoute;
+                       stripable = true;
                } else {
-                       return -1;
+                       _top_level_type = NamedRoute;
+                       _top_level_name = rest[0];
                }
 
        } else if (path[0] == "vca") {
-
                _top_level_type = PresentationOrderVCA;
+               stripable = true;
+       } else if (path[0] == "bus") {
+               /* digits, or B<digits> or S<digits> will be used as for route;
+                  anything else will be treated as a track name.
+               */
 
+               /* this is not going to fail */
+
+               regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
+               bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
+               regfree (&compiled_pattern);
+
+               if (matched) {
+                       _top_level_type = PresentationOrderBus;
+                       stripable = true;
+               } else {
+                       _top_level_type = NamedRoute;
+                       _top_level_name = rest[0];
+               }
+
+       } else if (path[0] == "track") {
+
+               /* digits, or B<digits> or S<digits> will be used as for route;
+                  anything else will be treated as a track name.
+               */
+
+               /* this is not going to fail */
+               regcomp (&compiled_pattern, pattern, REG_EXTENDED|REG_NOSUB);
+               bool matched = (regexec (&compiled_pattern, rest[0].c_str(), 0, 0, 0) == 0);
+               regfree (&compiled_pattern);
+
+               if (matched) {
+                       _top_level_type = PresentationOrderTrack;
+                       stripable = true;
+               } else {
+                       _top_level_type = NamedRoute;
+                       _top_level_name = rest[0];
+               }
+       }
+
+       if (stripable) {
                if (rest[0][0] == 'B') {
                        _banked = true;
                        _presentation_order = atoi (rest[0].substr (1));
@@ -87,10 +134,7 @@ ControllableDescriptor::set (const std::string& str)
                        return -1;
                }
 
-       } else if (path[0] == "bus" || path[0] == "track") {
-
-               _top_level_type = NamedRoute;
-               _top_level_name = rest[0];
+               _presentation_order -= 1; /* order is zero-based, but maps use 1-based */
        }
 
        if (path[1] == "gain") {