MidiClock_SlaveTest: add basic framework
[ardour.git] / libs / ardour / utils.cc
index c598a3d27965c060bfad00d9e5f2ff8c710a12ab..af90c935c918cce68c0b54f4cf78354d2bbc0a16 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"
 
@@ -107,13 +111,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 +203,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);
@@ -282,7 +279,7 @@ compute_equal_power_fades (nframes_t nframes, float* in, float* out)
 {
        double step;
 
-       step = 1.0/nframes;
+       step = 1.0/(nframes-1);
 
        in[0] = 0.0f;
 
@@ -334,14 +331,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 +346,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 +411,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 +492,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); }
 }