add left/right side trim cursors and use them for region trimming, as appropriate
[ardour.git] / libs / ardour / utils.cc
index 18194678ed0284743d1dddc806b2b65d888b9699..2bfe16222d1ca5c8ec9ce71aab45b39291e396f6 100644 (file)
 
 */
 
+#ifdef WAF_BUILD
+#include "libardour-config.h"
+#endif
+
 #define __STDC_FORMAT_MACROS 1
 #include <stdint.h>
 
 #include <wordexp.h>
 #endif
 
-#include <pbd/error.h>
-#include <pbd/stacktrace.h>
-#include <pbd/xml++.h>
-#include <pbd/basename.h>
-#include <ardour/utils.h>
+#include "pbd/error.h"
+#include "pbd/stacktrace.h"
+#include "pbd/xml++.h"
+#include "pbd/basename.h"
+#include "ardour/utils.h"
 
 #include "i18n.h"
 
@@ -68,17 +72,19 @@ legalize_for_path (ustring str)
        return legal;
 }
 
-string bump_name_once(std::string name)
+string 
+bump_name_once (const std::string& name, char delimiter)
 {
-       string::size_type period;
+       string::size_type delim;
        string newname;
 
-       if ((period = name.find_last_of ('.')) == string::npos) {
+       if ((delim = name.find_last_of (delimiter)) == string::npos) {
                newname  = name;
-               newname += ".1";
+               newname += delimiter;
+               newname += "1";
        } else {
                int isnumber = 1;
-               const char *last_element = name.c_str() + period + 1;
+               const char *last_element = name.c_str() + delim + 1;
                for (size_t i = 0; i < strlen(last_element); i++) {
                        if (!isdigit(last_element[i])) {
                                isnumber = 0;
@@ -87,18 +93,19 @@ string bump_name_once(std::string name)
                }
 
                errno = 0;
-               long int version = strtol (name.c_str()+period+1, (char **)NULL, 10);
+               long int version = strtol (name.c_str()+delim+1, (char **)NULL, 10);
 
                if (isnumber == 0 || errno != 0) {
                        // last_element is not a number, or is too large
                        newname  = name;
-                       newname += ".1";
+                       newname  += delimiter;
+                       newname += "1";
                } else {
                        char buf[32];
 
                        snprintf (buf, sizeof(buf), "%ld", version+1);
 
-                       newname  = name.substr (0, period+1);
+                       newname  = name.substr (0, delim+1);
                        newname += buf;
                }
        }
@@ -107,13 +114,6 @@ string bump_name_once(std::string name)
 
 }
 
-ostream&
-operator<< (ostream& o, const BBT_Time& bbt)
-{
-       o << bbt.bars << '|' << bbt.beats << '|' << bbt.ticks;
-       return o;
-}
-
 XMLNode *
 find_named_node (const XMLNode& node, string name)
 {
@@ -206,7 +206,7 @@ path_is_paired (ustring path, ustring& pair_base)
                path = path.substr(pos+1);
        }
 
-       /* remove filename suffixes etc. */
+       /* remove filename suffixes etc. */
 
        if ((pos = path.find_last_of ('.')) != string::npos) {
                path = path.substr (0, pos);
@@ -334,14 +334,10 @@ edit_mode_to_string (EditMode mode)
        }
 }
 
-SlaveSource
-string_to_slave_source (string str)
+SyncSource
+string_to_sync_source (string str)
 {
-       if (str == _("Internal")) {
-               return None;
-       }
-
-       if (str == _("MTC")) {
+       if (str == _("MIDI Timecode")) {
                return MTC;
        }
 
@@ -353,44 +349,28 @@ string_to_slave_source (string str)
                return JACK;
        }
 
-       fatal << string_compose (_("programming error: unknown slave source string \"%1\""), str) << endmsg;
+       fatal << string_compose (_("programming error: unknown sync source string \"%1\""), str) << endmsg;
        /*NOTREACHED*/
-       return None;
+       return JACK;
 }
 
 const char*
-slave_source_to_string (SlaveSource src)
+sync_source_to_string (SyncSource src)
 {
        switch (src) {
        case JACK:
                return _("JACK");
 
        case MTC:
-               return _("MTC");
+               return _("MIDI Timecode");
 
        case MIDIClock:
                return _("MIDI Clock");
-
-       default:
-       case None:
-               return _("Internal");
-
        }
+       /* GRRRR .... stupid, stupid gcc - you can't get here from there, all enum values are handled */
+       return _("JACK");
 }
 
-/* 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)
 {
@@ -434,28 +414,12 @@ meter_falloff_from_float (float val)
        }
        else if (val <= METER_FALLOFF_FASTER) {
                return MeterFalloffFaster;
-       }
+       }
        else {
                return MeterFalloffFastest;
        }
 }
 
-float
-meter_hold_to_float (MeterHold hold)
-{
-       switch (hold) {
-       case MeterHoldOff:
-               return 0.0f;
-       case MeterHoldShort:
-               return 40.0f;
-       case MeterHoldMedium:
-               return 100.0f;
-       case MeterHoldLong:
-       default:
-               return 200.0f;
-       }
-}
-
 AutoState
 ARDOUR::string_to_auto_state (std::string str)
 {
@@ -531,6 +495,20 @@ ARDOUR::auto_style_to_string (AutoStyle as)
        return "";
 }
 
+std::string
+bool_as_string (bool yn)
+{
+       return (yn ? "yes" : "no");
+}
+
+bool
+string_is_affirmative (const std::string& str)
+{
+       /* to be used only with XML data - not intended to handle user input */
+
+       return str == "1" || str == "y" || str == "Y" || (!g_strncasecmp(str.c_str(), "yes", str.length()));
+}
+
 extern "C" {
        void c_stacktrace() { stacktrace (cerr); }
 }