X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Futils.cc;h=f7a4e1431604a68797c9872602811a44fbfbe3b7;hb=c35eae34c39c9962ac93110f67e9ea40f24834b6;hp=f30f568f9d810ef3eaafb2bfcab3b7486d8b1302;hpb=da45f489dd3d923bbba8f1cee39ab445c4bf1b64;p=ardour.git diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index f30f568f9d..f7a4e14316 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2000-2003 Paul Davis + Copyright (C) 2000-2003 Paul Davis This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,6 +17,10 @@ */ +#ifdef WAF_BUILD +#include "libardour-config.h" +#endif + #define __STDC_FORMAT_MACROS 1 #include @@ -24,7 +28,7 @@ #include #include #include -#include +#include #include #include #include @@ -37,11 +41,11 @@ #include #endif -#include -#include -#include -#include -#include +#include "pbd/error.h" +#include "pbd/stacktrace.h" +#include "pbd/xml++.h" +#include "pbd/basename.h" +#include "ardour/utils.h" #include "i18n.h" @@ -50,7 +54,7 @@ using namespace std; using namespace PBD; using Glib::ustring; -ustring +ustring legalize_for_path (ustring str) { ustring::size_type pos; @@ -97,7 +101,7 @@ string bump_name_once(std::string name) char buf[32]; snprintf (buf, sizeof(buf), "%ld", version+1); - + newname = name.substr (0, period+1); newname += buf; } @@ -140,7 +144,7 @@ cmp_nocase (const string& s, const string& s2) { string::const_iterator p = s.begin(); string::const_iterator p2 = s2.begin(); - + while (p != s.end() && p2 != s2.end()) { if (toupper(*p) != toupper(*p2)) { return (toupper(*p) < toupper(*p2)) ? -1 : 1; @@ -148,7 +152,7 @@ cmp_nocase (const string& s, const string& s2) ++p; ++p2; } - + return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1; } @@ -171,12 +175,12 @@ region_name_from_path (ustring path, bool strip_channels, bool add_channel_suffi if (strip_channels) { /* remove any "?R", "?L" or "?[a-z]" channel identifier */ - + ustring::size_type len = path.length(); - - if (len > 3 && (path[len-2] == '%' || path[len-2] == '?' || path[len-2] == '.') && + + if (len > 3 && (path[len-2] == '%' || path[len-2] == '?' || path[len-2] == '.') && (path[len-1] == 'R' || path[len-1] == 'L' || (islower (path[len-1])))) { - + path = path.substr (0, path.length() - 2); } } @@ -184,7 +188,7 @@ region_name_from_path (ustring path, bool strip_channels, bool add_channel_suffi if (add_channel_suffix) { path += '%'; - + if (total > 2) { path += (char) ('a' + this_one); } else { @@ -193,7 +197,7 @@ region_name_from_path (ustring path, bool strip_channels, bool add_channel_suffi } return path; -} +} bool path_is_paired (ustring path, ustring& pair_base) @@ -206,8 +210,8 @@ 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); } @@ -216,13 +220,13 @@ path_is_paired (ustring path, ustring& pair_base) /* look for possible channel identifier: "?R", "%R", ".L" etc. */ - if (len > 3 && (path[len-2] == '%' || path[len-2] == '?' || path[len-2] == '.') && + if (len > 3 && (path[len-2] == '%' || path[len-2] == '?' || path[len-2] == '.') && (path[len-1] == 'R' || path[len-1] == 'L' || (islower (path[len-1])))) { - + pair_base = path.substr (0, len-2); return true; - } + } return false; } @@ -253,20 +257,20 @@ path_expand (ustring path) wordfree (&expansion); return ret; -#else +#else return path; #endif } #if defined(HAVE_COREAUDIO) || defined(HAVE_AUDIOUNITS) -string +string CFStringRefToStdString(CFStringRef stringRef) { - CFIndex size = - CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , + CFIndex size = + CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , kCFStringEncodingUTF8); char *buf = new char[size]; - + std::string result; if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingUTF8)) { @@ -282,14 +286,14 @@ 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; - + for (nframes_t i = 1; i < nframes - 1; ++i) { in[i] = in[i-1] + step; } - + in[nframes-1] = 1.0; const float pan_law_attenuation = -3.0f; @@ -340,11 +344,15 @@ string_to_slave_source (string str) if (str == _("Internal")) { return None; } - + if (str == _("MTC")) { return MTC; } + if (str == _("MIDI Clock")) { + return MIDIClock; + } + if (str == _("JACK")) { return JACK; } @@ -363,27 +371,17 @@ slave_source_to_string (SlaveSource src) case MTC: return _("MTC"); - + + case MIDIClock: + return _("MIDI Clock"); + default: case None: return _("Internal"); - + } } -/* 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) { @@ -427,29 +425,13 @@ 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 +AutoState ARDOUR::string_to_auto_state (std::string str) { if (str == X_("Off")) { @@ -467,7 +449,7 @@ ARDOUR::string_to_auto_state (std::string str) return Touch; } -string +string ARDOUR::auto_state_to_string (AutoState as) { /* to be used only for XML serialization, no i18n done */ @@ -491,7 +473,7 @@ ARDOUR::auto_state_to_string (AutoState as) return ""; } -AutoStyle +AutoStyle ARDOUR::string_to_auto_style (std::string str) { if (str == X_("Absolute")) { @@ -505,7 +487,7 @@ ARDOUR::string_to_auto_style (std::string str) return Trim; } -string +string ARDOUR::auto_style_to_string (AutoStyle as) { /* to be used only for XML serialization, no i18n done */ @@ -524,6 +506,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); } }