Remove beat entry from meter dialog (beats are not allowed in API), clean up some...
[ardour.git] / libs / ardour / utils.cc
index fbea468682c4d0dc9c878d7d0ee9a671bf9dcf99..f98b24a4f2379636a399fe3ae295d7cfbf6d04c5 100644 (file)
@@ -15,7 +15,6 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #include <cstdio> /* for sprintf */
@@ -126,6 +125,45 @@ legalize_for_path (string str)
 }
 #endif
 
+string bump_name_once(std::string name)
+{
+       string::size_type period;
+       string newname;
+
+       if ((period = name.find_last_of ('.')) == string::npos) {
+               newname  = name;
+               newname += ".1";
+       } else {
+               int isnumber = 1;
+               const char *last_element = name.c_str() + period + 1;
+               for (size_t i = 0; i < strlen(last_element); i++) {
+                       if (!isdigit(last_element[i])) {
+                               isnumber = 0;
+                               break;
+                       }
+               }
+
+               errno = 0;
+               long int version = strtol (name.c_str()+period+1, (char **)NULL, 10);
+
+               if (isnumber == 0 || errno != 0) {
+                       // last_element is not a number, or is too large
+                       newname  = name;
+                       newname += ".1";
+               } else {
+                       char buf[32];
+
+                       snprintf (buf, sizeof(buf), "%ld", version+1);
+               
+                       newname  = name.substr (0, period+1);
+                       newname += buf;
+               }
+       }
+
+       return newname;
+
+}
+
 ostream&
 operator<< (ostream& o, const BBT_Time& bbt)
 {
@@ -208,20 +246,8 @@ touch_file (ustring path)
        return 1;
 }
 
-string
-placement_as_string (Placement p)
-{
-       switch (p) {
-       case PreFader:
-               return _("pre");
-       default: /* to get g++ to realize we have all the cases covered */
-       case PostFader:
-               return _("post");
-       }
-}
-
 ustring
-region_name_from_path (ustring path, bool strip_channels)
+region_name_from_path (ustring path, bool strip_channels, bool add_channel_suffix, uint32_t total, uint32_t this_one)
 {
        path = PBD::basename_nosuffix (path);
 
@@ -238,6 +264,17 @@ region_name_from_path (ustring path, bool strip_channels)
                }
        }
 
+       if (add_channel_suffix) {
+
+               path += '%';
+               
+               if (total > 2) {
+                       path += (char) ('a' + this_one);
+               } else {
+                       path += (char) (this_one == 0 ? 'L' : 'R');
+               }
+       }
+
        return path;
 }      
 
@@ -350,6 +387,8 @@ string_to_edit_mode (string str)
                return Splice;
        } else if (str == _("Slide Edit")) {
                return Slide;
+       } else if (str == _("Lock Edit")) {
+               return Lock;
        }
        fatal << string_compose (_("programming error: unknown edit mode string \"%1\""), str) << endmsg;
        /*NOTREACHED*/
@@ -363,6 +402,9 @@ edit_mode_to_string (EditMode mode)
        case Slide:
                return _("Slide Edit");
 
+       case Lock:
+               return _("Lock Edit");
+
        default:
        case Splice:
                return _("Splice Edit");
@@ -406,25 +448,65 @@ slave_source_to_string (SlaveSource src)
        }
 }
 
+/* I don't really like hard-coding these falloff rates here
+ * Probably should use a map of some kind that could be configured
+ * These rates are db/sec.
+*/
+
+#define METER_FALLOFF_OFF     0.0f
+#define METER_FALLOFF_SLOWEST 6.6f // BBC standard
+#define METER_FALLOFF_SLOW    8.6f // BBC standard
+#define METER_FALLOFF_MEDIUM  20.0f
+#define METER_FALLOFF_FAST    32.0f
+#define METER_FALLOFF_FASTER  46.0f
+#define METER_FALLOFF_FASTEST 70.0f
+
 float
 meter_falloff_to_float (MeterFalloff falloff)
 {
        switch (falloff) {
        case MeterFalloffOff:
-               return 0.0f;
+               return METER_FALLOFF_OFF;
        case MeterFalloffSlowest:
-               return 1.0f;
+               return METER_FALLOFF_SLOWEST;
        case MeterFalloffSlow:
-               return 2.0f;
+               return METER_FALLOFF_SLOW;
        case MeterFalloffMedium:
-               return 3.0f;
+               return METER_FALLOFF_MEDIUM;
        case MeterFalloffFast:
-               return 4.0f;
+               return METER_FALLOFF_FAST;
        case MeterFalloffFaster:
-               return 5.0f;
+               return METER_FALLOFF_FASTER;
        case MeterFalloffFastest:
+               return METER_FALLOFF_FASTEST;
        default:
-               return 6.0f;
+               return METER_FALLOFF_FAST;
+       }
+}
+
+MeterFalloff
+meter_falloff_from_float (float val)
+{
+       if (val == METER_FALLOFF_OFF) {
+               return MeterFalloffOff;
+       }
+       else if (val <= METER_FALLOFF_SLOWEST) {
+               return MeterFalloffSlowest;
+       }
+       else if (val <= METER_FALLOFF_SLOW) {
+               return MeterFalloffSlow;
+       }
+       else if (val <= METER_FALLOFF_MEDIUM) {
+               return MeterFalloffMedium;
+       }
+       else if (val <= METER_FALLOFF_FAST) {
+               return MeterFalloffFast;
+       }
+       else if (val <= METER_FALLOFF_FASTER) {
+               return MeterFalloffFaster;
+       }
+       else {
+               return MeterFalloffFastest;
        }
 }