X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=libs%2Fardour%2Futils.cc;h=d8642486d9e9fb9d15a3c238103dae38b4507c82;hb=1bd4c5b3a212460eed1773f6b049d18c89625565;hp=2d9fccf9d74691c289f52171b9b5c1c5dd8768d3;hpb=78889b0958c72e8b52e297e27e2c1ed2bf522602;p=ardour.git diff --git a/libs/ardour/utils.cc b/libs/ardour/utils.cc index 2d9fccf9d7..d8642486d9 100644 --- a/libs/ardour/utils.cc +++ b/libs/ardour/utils.cc @@ -42,6 +42,7 @@ using namespace ARDOUR; using namespace std; +using namespace PBD; void elapsed_time_to_str (char *buf, uint32_t seconds) @@ -185,15 +186,6 @@ touch_file (string path) return 1; } -uint32_t long -get_uid() -{ - struct timeval tv; - gettimeofday(&tv, 0); - - return (uint32_t long) tv.tv_sec * 1000000 + tv.tv_usec; -} - string placement_as_string (Placement p) { @@ -261,3 +253,148 @@ path_expand (string path) #endif } +#if defined(HAVE_COREAUDIO) || defined(HAVE_AUDIOUNITS) +string +CFStringRefToStdString(CFStringRef stringRef) +{ + CFIndex size = + CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) , + kCFStringEncodingUTF8); + char *buf = new char[size]; + + std::string result; + + if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingUTF8)) { + result = buf; + } + delete [] buf; + return result; +} +#endif // HAVE_COREAUDIO + +void +compute_equal_power_fades (nframes_t nframes, float* in, float* out) +{ + double step; + + step = 1.0/nframes; + + 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; + const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f); + + for (unsigned long n = 0; n < nframes; ++n) { + float inVal = in[n]; + float outVal = 1 - inVal; + out[n] = outVal * (scale * outVal + 1.0f - scale); + in[n] = inVal * (scale * inVal + 1.0f - scale); + } +} + +EditMode +string_to_edit_mode (string str) +{ + if (str == _("Splice Edit")) { + return Splice; + } else if (str == _("Slide Edit")) { + return Slide; + } + fatal << string_compose (_("programming error: unknown edit mode string \"%1\""), str) << endmsg; + /*NOTREACHED*/ + return Slide; +} + +const char* +edit_mode_to_string (EditMode mode) +{ + switch (mode) { + case Slide: + return _("Slide Edit"); + + default: + case Splice: + return _("Splice Edit"); + } +} + +SlaveSource +string_to_slave_source (string str) +{ + if (str == _("Internal")) { + return None; + } + + if (str == _("MTC")) { + return MTC; + } + + if (str == _("JACK")) { + return JACK; + } + + fatal << string_compose (_("programming error: unknown slave source string \"%1\""), str) << endmsg; + /*NOTREACHED*/ + return None; +} + +const char* +slave_source_to_string (SlaveSource src) +{ + switch (src) { + case JACK: + return _("JACK"); + + case MTC: + return _("MTC"); + + default: + case None: + return _("Internal"); + + } +} + +float +meter_falloff_to_float (MeterFalloff falloff) +{ + switch (falloff) { + case MeterFalloffOff: + return 0.0f; + case MeterFalloffSlowest: + return 1.0f; + case MeterFalloffSlow: + return 2.0f; + case MeterFalloffMedium: + return 3.0f; + case MeterFalloffFast: + return 4.0f; + case MeterFalloffFaster: + return 5.0f; + case MeterFalloffFastest: + default: + return 6.0f; + } +} + +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; + } +}