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 #include <cstdio> /* for sprintf */
27 #include <sys/types.h>
33 #include <pbd/error.h>
34 #include <pbd/xml++.h>
35 #include <ardour/utils.h>
39 using namespace ARDOUR;
43 elapsed_time_to_str (char *buf, uint32_t seconds)
52 days = s / (3600 * 24);
53 s -= (days * 3600 * 24);
60 snprintf (buf, sizeof (buf), "%" PRIu32 " day%s %" PRIu32 " hour%s",
64 hours > 1 ? "s" : "");
66 snprintf (buf, sizeof (buf), "%" PRIu32 " hour%s %" PRIu32 " minute%s",
70 minutes > 1 ? "s" : "");
72 snprintf (buf, sizeof (buf), "%" PRIu32 " minute%s",
74 minutes > 1 ? "s" : "");
76 snprintf (buf, sizeof (buf), "%" PRIu32 " second%s",
78 seconds > 1 ? "s" : "");
80 snprintf (buf, sizeof (buf), "no time");
85 legalize_for_path (string str)
87 string::size_type pos;
88 string legal_chars = "abcdefghijklmnopqrtsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_+=: ";
94 while ((pos = legal.find_first_not_of (legal_chars, pos)) != string::npos) {
95 legal.replace (pos, 1, "_");
103 operator<< (ostream& o, const BBT_Time& bbt)
105 o << bbt.bars << '|' << bbt.beats << '|' << bbt.ticks;
110 find_named_node (const XMLNode& node, string name)
113 XMLNodeConstIterator niter;
116 nlist = node.children();
118 for (niter = nlist.begin(); niter != nlist.end(); ++niter) {
122 if (child->name() == name) {
131 cmp_nocase (const string& s, const string& s2)
133 string::const_iterator p = s.begin();
134 string::const_iterator p2 = s2.begin();
136 while (p != s.end() && p2 != s2.end()) {
137 if (toupper(*p) != toupper(*p2)) {
138 return (toupper(*p) < toupper(*p2)) ? -1 : 1;
144 return (s2.size() == s.size()) ? 0 : (s.size() < s2.size()) ? -1 : 1;
148 tokenize_fullpath (string fullpath, string& path, string& name)
150 string::size_type m = fullpath.find_last_of("/");
152 if (m == string::npos) {
158 // does it look like just a directory?
159 if (m == fullpath.length()-1) {
162 path = fullpath.substr(0, m+1);
164 string::size_type n = fullpath.find(".ardour", m);
166 if (n == string::npos) {
169 name = fullpath.substr(m+1, n - m - 1);
174 touch_file(string path)
176 FILE* file = fopen(path.c_str(), "a");
185 gettimeofday(&tv, 0);
187 return (uint32_t long) tv.tv_sec * 1000000 + tv.tv_usec;
191 placement_as_string (Placement p)
196 default: /* to get g++ to realize we have all the cases covered */
203 region_name_from_path (string path)
205 string::size_type pos;
207 /* remove filename suffixes etc. */
209 if ((pos = path.find_last_of ('.')) != string::npos) {
210 path = path.substr (0, pos);
213 /* remove any "?R", "?L" or "?[a-z]" channel identifier */
215 string::size_type len = path.length();
217 if (len > 3 && (path[len-2] == '%' || path[len-2] == '?') &&
218 (path[len-1] == 'R' || path[len-1] == 'L' || (islower (path[len-1])))) {
220 path = path.substr (0, path.length() - 2);