In export format dialog, show preview of generated part of description. Fix to #0004941
[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 #include "ardour/ardour.h"
36 #include "ardour/data_type.h"
37 #include "ardour/dB.h"
38
39 class XMLNode;
40
41 std::string legalize_for_path (const std::string& str);
42 XMLNode* find_named_node (const XMLNode& node, std::string name);
43 std::string bool_as_string (bool);
44
45 static inline float f_max(float x, float a) {
46         x -= a;
47         x += fabsf (x);
48         x *= 0.5f;
49         x += a;
50
51         return (x);
52 }
53
54 std::string bump_name_once(const std::string& s, char delimiter);
55
56 int cmp_nocase (const std::string& s, const std::string& s2);
57
58 int touch_file(std::string path);
59
60 std::string path_expand (std::string);        /* single file path */
61 std::string search_path_expand (std::string); /* colon-separated search path */
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::framecnt_t nframes, float* in, float* out);
66
67 const char* sync_source_to_string (ARDOUR::SyncSource src, bool sh = false);
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 #undef  OLD_GAIN_MATH
74 #define OLD_GAIN_MATH
75
76 static inline double
77 gain_to_slider_position (ARDOUR::gain_t g)
78 {
79         if (g == 0) return 0;
80
81 #ifndef OLD_GAIN_MATH
82         /* Power Law With Exponential Cutoff 2D, fit to data from TC Spectra
83            console (image of fader gradations
84
85            y = C * x(-T) * exp(-x/K)
86
87            C =  8.2857630370864188E-01
88            T = -5.1526743785019269E-01
89            K =  7.8990885960495589E+00
90
91          */
92         
93         return 8.2857630370864188E-01 * pow(g,5.1526743785019269E-01) * exp (-g/7.8990885960495589E+00);
94 #else
95         return pow((6.0*log(g)/log(2.0)+192.0)/198.0, 8.0);
96 #endif
97 }
98
99 static inline ARDOUR::gain_t
100 slider_position_to_gain (double pos)
101 {
102         if (pos == 0.0) {
103                 return 0.0;
104         }
105
106 #ifndef OLD_GAIN_MATH
107         /* 5th order polynomial function fit to data from a TC Spectra console
108            fader (image of fader gradations).
109          
110            y = a + bx1 + cx2 + dx3 + fx4 + gx5
111            
112            a = -1.1945480381045521E-02
113            b =  1.5809476525537265E+00
114            c = -1.5850710838966151E+01
115            d =  6.1643128605961991E+01
116            f = -8.5525246160607693E+01
117            g =  4.1312725896188283E+01
118
119         */
120
121         double p = pos;
122         double g = -1.1945480381045521E-02;
123
124         g +=  1.5809476525537265E+00 * pos;
125         pos *= p;
126         g += -1.5850710838966151E+01 * pos;
127         pos *= p;
128         g += 6.1643128605961991E+01 * pos;
129         pos *= p;
130         g += -8.5525246160607693E+01 * pos;
131         pos *= p;
132         g += 4.1312725896188283E+01 * pos;
133
134         return g;
135 #else
136         /* XXX Marcus writes: this doesn't seem right to me. but i don't have a better answer ... */
137         if (pos == 0.0) return 0;
138         return pow (2.0,(sqrt(sqrt(sqrt(pos)))*198.0-192.0)/6.0);
139 #endif
140 }
141 #undef OLD_GAIN_MATH
142
143 double gain_to_slider_position_with_max (double g, double max_gain = 2.0);
144 double slider_position_to_gain_with_max (double g, double max_gain = 2.0);
145
146 /* I don't really like hard-coding these falloff rates here
147  * Probably should use a map of some kind that could be configured
148  * These rates are db/sec.
149 */
150
151 #define METER_FALLOFF_OFF     0.0f
152 #define METER_FALLOFF_SLOWEST 6.6f // BBC standard
153 #define METER_FALLOFF_SLOW    8.6f // BBC standard
154 #define METER_FALLOFF_MEDIUM  20.0f
155 #define METER_FALLOFF_FAST    32.0f
156 #define METER_FALLOFF_FASTER  46.0f
157 #define METER_FALLOFF_FASTEST 70.0f
158
159 float meter_falloff_to_float (ARDOUR::MeterFalloff);
160 ARDOUR::MeterFalloff meter_falloff_from_float (float);
161 float meter_falloff_to_db_per_sec (float);
162
163 const char* native_header_format_extension (ARDOUR::HeaderFormat, const ARDOUR::DataType& type);
164 bool matching_unsuffixed_filename_exists_in (const std::string& dir, const std::string& name);
165
166 uint32_t how_many_dsp_threads ();
167
168 #if __APPLE__
169 std::string CFStringRefToStdString(CFStringRef stringRef);
170 #endif // __APPLE__
171
172 #endif /* __ardour_utils_h__ */
173