make ardour3 build and link on OS X (tiger, at least)
[ardour.git] / libs / ardour / ardour / utils.h
1 /*
2     Copyright (C) 1999 Paul Davis
3
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.
8
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.
13
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.
17
18 */
19
20 #ifndef __ardour_utils_h__
21 #define __ardour_utils_h__
22
23 #ifdef WAF_BUILD
24 #include "libardour-config.h"
25 #endif
26
27 #include <iostream>
28 #include <string>
29 #include <cmath>
30
31 #if __APPLE__
32 #include <CoreFoundation/CoreFoundation.h>
33 #endif /* __APPLE__ */
34
35 bool string_is_affirmative (const std::string&);
36
37 #include "ardour/ardour.h"
38 #include "ardour/data_type.h"
39
40 class XMLNode;
41
42 std::string legalize_for_path (const std::string& str);
43 XMLNode* find_named_node (const XMLNode& node, std::string name);
44 std::string bool_as_string (bool);
45
46 static inline float f_max(float x, float a) {
47         x -= a;
48         x += fabsf (x);
49         x *= 0.5f;
50         x += a;
51
52         return (x);
53 }
54
55 std::string bump_name_once(const std::string& s, char delimiter);
56
57 int cmp_nocase (const std::string& s, const std::string& s2);
58
59 int touch_file(std::string path);
60
61 std::string path_expand (std::string);
62 std::string region_name_from_path (std::string path, bool strip_channels, bool add_channel_suffix = false, uint32_t total = 0, uint32_t this_one = 0);
63 bool path_is_paired (std::string path, std::string& pair_base);
64
65 void compute_equal_power_fades (ARDOUR::nframes_t nframes, float* in, float* out);
66
67 const char* sync_source_to_string (ARDOUR::SyncSource src);
68 ARDOUR::SyncSource string_to_sync_source (std::string str);
69
70 const char* edit_mode_to_string (ARDOUR::EditMode);
71 ARDOUR::EditMode string_to_edit_mode (std::string);
72
73
74 static inline double
75 gain_to_slider_position (ARDOUR::gain_t g)
76 {
77         if (g == 0) return 0;
78         return pow((6.0*log(g)/log(2.0)+192.0)/198.0, 8.0);
79
80 }
81
82 static inline ARDOUR::gain_t
83 slider_position_to_gain (double pos)
84 {
85         /* XXX Marcus writes: this doesn't seem right to me. but i don't have a better answer ... */
86         if (pos == 0.0) return 0;
87         return pow (2.0,(sqrt(sqrt(sqrt(pos)))*198.0-192.0)/6.0);
88 }
89
90 /* I don't really like hard-coding these falloff rates here
91  * Probably should use a map of some kind that could be configured
92  * These rates are db/sec.
93 */
94
95 #define METER_FALLOFF_OFF     0.0f
96 #define METER_FALLOFF_SLOWEST 6.6f // BBC standard
97 #define METER_FALLOFF_SLOW    8.6f // BBC standard
98 #define METER_FALLOFF_MEDIUM  20.0f
99 #define METER_FALLOFF_FAST    32.0f
100 #define METER_FALLOFF_FASTER  46.0f
101 #define METER_FALLOFF_FASTEST 70.0f
102
103 float meter_falloff_to_float (ARDOUR::MeterFalloff);
104 ARDOUR::MeterFalloff meter_falloff_from_float (float);
105 float meter_falloff_to_db_per_sec (float);
106
107 const char* native_header_format_extension (ARDOUR::HeaderFormat, const ARDOUR::DataType& type);
108 bool matching_unsuffixed_filename_exists_in (const std::string& dir, const std::string& name);
109
110 #if __APPLE__
111 std::string CFStringRefToStdString(CFStringRef stringRef);
112 #endif // __APPLE__
113
114 #endif /* __ardour_utils_h__ */
115