2 Copyright (C) 2000-2003 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define __STDC_FORMAT_MACROS 1
24 #include <cstdio> /* for sprintf */
30 #include <sys/types.h>
40 #include <pbd/error.h>
41 #include <pbd/xml++.h>
42 #include <ardour/utils.h>
46 using namespace ARDOUR;
51 elapsed_time_to_str (char *buf, uint32_t seconds)
60 days = s / (3600 * 24);
61 s -= (days * 3600 * 24);
68 snprintf (buf, sizeof (buf), "%" PRIu32 " day%s %" PRIu32 " hour%s",
72 hours > 1 ? "s" : "");
74 snprintf (buf, sizeof (buf), "%" PRIu32 " hour%s %" PRIu32 " minute%s",
78 minutes > 1 ? "s" : "");
80 snprintf (buf, sizeof (buf), "%" PRIu32 " minute%s",
82 minutes > 1 ? "s" : "");
84 snprintf (buf, sizeof (buf), "%" PRIu32 " second%s",
86 seconds > 1 ? "s" : "");
88 snprintf (buf, sizeof (buf), "no time");
93 legalize_for_path (string str)
95 string::size_type pos;
96 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: ";
102 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
103 legal.replace (pos, 1, "_");
111 operator<< (ostream& o, const BBT_Time& bbt)
113 o << bbt.bars << '|' << bbt.beats << '|' << bbt.ticks;
118 find_named_node (const XMLNode& node, string name)
121 XMLNodeConstIterator niter;
124 nlist = node.children();
126 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
130 if (child->name() == name) {
139 cmp_nocase (const string& s, const string& s2)
141 string::const_iterator p = s.begin();
142 string::const_iterator p2 = s2.begin();
144 while (p != s.end() && p2 != s2.end()) {
145 if (toupper(*p) != toupper(*p2)) {
146 return (toupper(*p) < toupper(*p2)) ? -1 : 1;
152 return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1;
156 tokenize_fullpath (string fullpath, string& path, string& name)
158 string::size_type m = fullpath.find_last_of("/");
160 if (m == string::npos) {
166 // does it look like just a directory?
167 if (m == fullpath.length()-1) {
170 path = fullpath.substr(0, m+1);
172 string::size_type n = fullpath.find(".ardour", m);
174 if (n == string::npos) {
177 name = fullpath.substr(m+1, n - m - 1);
182 touch_file (string path)
184 int fd = open (path.c_str(), O_RDWR|O_CREAT, 0660);
193 placement_as_string (Placement p)
198 default: /* to get g++ to realize we have all the cases covered */
205 region_name_from_path (string path)
207 string::size_type pos;
209 /* remove any leading path */
211 if ((pos = path.find_last_of ('/')) != string::npos) {
212 path = path.substr(pos+1);
215 /* remove filename suffixes etc. */
217 if ((pos = path.find_last_of ('.')) != string::npos) {
218 path = path.substr (0, pos);
221 /* remove any "?R", "?L" or "?[a-z]" channel identifier */
223 string::size_type len = path.length();
225 if (len > 3 && (path[len-2] == '%' || path[len-2] == '?') &&
226 (path[len-1] == 'R' || path[len-1] == 'L' || (islower (path[len-1])))) {
228 path = path.substr (0, path.length() - 2);
235 path_expand (string path)
238 /* Handle tilde and environment variable expansion in session path */
242 switch (wordexp (path.c_str(), &expansion, WRDE_NOCMD|WRDE_UNDEF)) {
246 error << string_compose (_("illegal or badly-formed string used for path (%1)"), path) << endmsg;
250 if (expansion.we_wordc > 1) {
251 error << string_compose (_("path (%1) is ambiguous"), path) << endmsg;
255 ret = expansion.we_wordv[0];
257 wordfree (&expansion);
265 #if defined(HAVE_COREAUDIO) || defined(HAVE_AUDIOUNITS)
267 CFStringRefToStdString(CFStringRef stringRef)
270 CFStringGetMaximumSizeForEncoding(CFStringGetLength(stringRef) ,
271 kCFStringEncodingUTF8);
272 char *buf = new char[size];
276 if(CFStringGetCString(stringRef, buf, size, kCFStringEncodingUTF8)) {
282 #endif // HAVE_COREAUDIO
285 compute_equal_power_fades (nframes_t nframes, float* in, float* out)
293 for (nframes_t i = 1; i < nframes - 1; ++i) {
294 in[i] = in[i-1] + step;
299 const float pan_law_attenuation = -3.0f;
300 const float scale = 2.0f - 4.0f * powf (10.0f,pan_law_attenuation/20.0f);
302 for (unsigned long n = 0; n < nframes; ++n) {
304 float outVal = 1 - inVal;
305 out[n] = outVal * (scale * outVal + 1.0f - scale);
306 in[n] = inVal * (scale * inVal + 1.0f - scale);
311 string_to_edit_mode (string str)
313 if (str == _("Splice Edit")) {
315 } else if (str == _("Slide Edit")) {
318 fatal << string_compose (_("programming error: unknown edit mode string \"%1\""), str) << endmsg;
324 edit_mode_to_string (EditMode mode)
328 return _("Slide Edit");
332 return _("Splice Edit");
337 string_to_slave_source (string str)
339 if (str == _("Internal")) {
343 if (str == _("MTC")) {
347 if (str == _("JACK")) {
351 fatal << string_compose (_("programming error: unknown slave source string \"%1\""), str) << endmsg;
357 slave_source_to_string (SlaveSource src)
368 return _("Internal");
374 meter_falloff_to_float (MeterFalloff falloff)
377 case MeterFalloffOff:
379 case MeterFalloffSlowest:
381 case MeterFalloffSlow:
383 case MeterFalloffMedium:
385 case MeterFalloffFast:
387 case MeterFalloffFaster:
389 case MeterFalloffFastest:
396 meter_hold_to_float (MeterHold hold)
403 case MeterHoldMedium: