X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Futils.cc;h=af90c935c918cce68c0b54f4cf78354d2bbc0a16;hb=405def9215a2fc7b70dd2999a06d16e704ddd058;hp=f30f568f9d810ef3eaafb2bfcab3b7486d8b1302;hpb=da45f489dd3d923bbba8f1cee39ab445c4bf1b64;p=ardour.git diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index f30f568f9d..af90c935c9 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; } @@ -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) { @@ -140,7 +137,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 +145,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 +168,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 +181,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 +190,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 +203,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 +213,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 +250,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 +279,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; @@ -334,56 +331,43 @@ 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; } + if (str == _("MIDI Clock")) { + return MIDIClock; + } + if (str == _("JACK")) { 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"); - - default: - case None: - return _("Internal"); - + return _("MIDI Timecode"); + + case MIDIClock: + return _("MIDI Clock"); } + /* 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) { @@ -427,29 +411,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 +435,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 +459,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 +473,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 +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); } }