Ardour  9.0-pre0-1699-gfaebc7ab35
libs/ardour/ardour/utils.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2018 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2005-2006 Taybin Rutkin <taybin@taybin.com>
4  * Copyright (C) 2007-2015 Tim Mayberry <mojofunk@gmail.com>
5  * Copyright (C) 2008-2013 David Robillard <d@drobilla.net>
6  * Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
7  * Copyright (C) 2013-2017 Robin Gareus <robin@gareus.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 #pragma once
25 
26 #ifdef WAF_BUILD
27 #include "libardour-config.h"
28 #endif
29 
30 #include <iostream>
31 #include <string>
32 #include <cmath>
33 
34 #if __APPLE__
35 #include <CoreFoundation/CoreFoundation.h>
36 #endif /* __APPLE__ */
37 
38 #include "ardour/ardour.h"
39 #include "ardour/data_type.h"
40 #include "ardour/dB.h"
41 #include "ardour/types.h"
42 
44 
45 class XMLNode;
46 
47 namespace Temporal {
48  class Meter;
49 }
50 
51 namespace ARDOUR {
52 
53 class Route;
54 class Track;
55 class Region;
56 
57 LIBARDOUR_API std::string legalize_for_path (const std::string& str);
58 LIBARDOUR_API std::string legalize_for_universal_path (const std::string& str);
59 LIBARDOUR_API std::string legalize_for_uri (const std::string& str);
60 LIBARDOUR_API std::string legalize_for_path_2X (const std::string& str);
61 LIBARDOUR_API XMLNode* find_named_node (const XMLNode& node, std::string name);
62 LIBARDOUR_API std::string bool_as_string (bool);
63 
64 static inline float f_max(float x, float a) {
65  x -= a;
66  x += fabsf (x);
67  x *= 0.5f;
68  x += a;
69 
70  return (x);
71 }
72 
73 LIBARDOUR_API std::string bump_name_once(const std::string& s, char delimiter);
74 LIBARDOUR_API std::string bump_name_number(const std::string& s);
75 LIBARDOUR_API std::string bump_name_abc(const std::string& s);
76 
77 LIBARDOUR_API int cmp_nocase (const std::string& s, const std::string& s2);
78 LIBARDOUR_API int cmp_nocase_utf8 (const std::string& s1, const std::string& s2);
79 
80 LIBARDOUR_API 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);
81 LIBARDOUR_API bool path_is_paired (std::string path, std::string& pair_base);
82 
83 LIBARDOUR_API void compute_equal_power_fades (ARDOUR::samplecnt_t nframes, float* in, float* out);
84 
87 
90 
91 LIBARDOUR_API double gain_to_slider_position_with_max (double g, double max_gain = 2.0);
92 LIBARDOUR_API double slider_position_to_gain_with_max (double g, double max_gain = 2.0);
93 
94 /* I don't really like hard-coding these falloff rates here
95  * Probably should use a map of some kind that could be configured
96  * These rates are db/sec.
97 */
98 
99 #define METER_FALLOFF_OFF 0.0f
100 #define METER_FALLOFF_SLOWEST 6.6f // BBC standard
101 #define METER_FALLOFF_SLOW 8.6f // BBC standard, EBU 24dB / 2.8sec
102 #define METER_FALLOFF_SLOWISH 12.0f // DIN 20dB / 1.7 sec
103 #define METER_FALLOFF_MODERATE 13.3f // EBU-PPM, IRT PPM- 20dB / 1.5 sec
104 #define METER_FALLOFF_MEDIUM 20.0f
105 #define METER_FALLOFF_FAST 32.0f
106 
110 
112 LIBARDOUR_API bool matching_unsuffixed_filename_exists_in (const std::string& dir, const std::string& name);
113 
116 
117 LIBARDOUR_API std::string compute_sha1_of_file (std::string path);
118 
119 template<typename T> std::shared_ptr<AutomationControlList> route_list_to_control_list (std::shared_ptr<RouteList const> rl, std::shared_ptr<T> (Stripable::*get_control)() const) {
120  std::shared_ptr<AutomationControlList> cl (new AutomationControlList);
121  if (!rl) { return cl; }
122  for (auto const& r : *rl) {
123  std::shared_ptr<AutomationControl> ac = (r.get()->*get_control)();
124  if (ac) {
125  cl->push_back (ac);
126  }
127  }
128  return cl;
129 }
130 
131 template<typename T> std::shared_ptr<AutomationControlList> stripable_list_to_control_list (StripableList& sl, std::shared_ptr<T> (Stripable::*get_control)() const) {
132  std::shared_ptr<AutomationControlList> cl (new AutomationControlList);
133  for (auto const & s : sl) {
134  std::shared_ptr<AutomationControl> ac = (s.get()->*get_control)();
135  if (ac) {
136  cl->push_back (ac);
137  }
138  }
139  return cl;
140 }
141 
142 template<typename T> std::shared_ptr<AutomationControlList> stripable_list_to_control_list (std::shared_ptr<StripableList const> sl, std::shared_ptr<T> (Stripable::*get_control)() const) {
143  std::shared_ptr<AutomationControlList> cl (new AutomationControlList);
144  if (!sl) { return cl; }
145  for (auto const & s : *sl) {
146  std::shared_ptr<AutomationControl> ac = (s.get()->*get_control)();
147  if (ac) {
148  cl->push_back (ac);
149  }
150  }
151  return cl;
152 }
153 
154 LIBARDOUR_API bool estimate_audio_tempo (std::shared_ptr<Region> region, Sample* data, samplecnt_t data_length, samplecnt_t sample_rate, double& qpm, Temporal::Meter& meter, double& beatcount);
155 
156 #if __APPLE__
157 LIBARDOUR_API std::string CFStringRefToStdString(CFStringRef stringRef);
158 #endif // __APPLE__
159 
160 } //namespave
161 
Definition: xml++.h:114
GtkImageIconNameData name
Definition: gtkimage.h:6
#define LIBARDOUR_API
static const MIDISequence s2[]
static const MIDISequence s1[]
PBD::PropertyDescriptor< bool > region
const char * native_header_format_extension(ARDOUR::HeaderFormat, const ARDOUR::DataType &type)
std::shared_ptr< AutomationControlList > route_list_to_control_list(std::shared_ptr< RouteList const > rl, std::shared_ptr< T >(Stripable::*get_control)() const)
bool path_is_paired(std::string path, std::string &pair_base)
std::string compute_sha1_of_file(std::string path)
std::string bump_name_number(const std::string &s)
std::list< std::shared_ptr< AutomationControl > > AutomationControlList
int cmp_nocase_utf8(const std::string &s1, const std::string &s2)
double gain_to_slider_position_with_max(double g, double max_gain=2.0)
std::list< std::shared_ptr< Stripable > > StripableList
std::string bool_as_string(bool)
uint32_t how_many_dsp_threads()
ARDOUR::RippleMode string_to_ripple_mode(std::string)
Temporal::samplecnt_t samplecnt_t
std::string legalize_for_path(const std::string &str)
uint32_t how_many_io_threads()
double slider_position_to_gain_with_max(double g, double max_gain=2.0)
XMLNode * find_named_node(const XMLNode &node, std::string name)
std::string legalize_for_uri(const std::string &str)
std::string legalize_for_universal_path(const std::string &str)
ARDOUR::EditMode string_to_edit_mode(std::string)
std::string bump_name_abc(const std::string &s)
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)
void compute_equal_power_fades(ARDOUR::samplecnt_t nframes, float *in, float *out)
std::string legalize_for_path_2X(const std::string &str)
ARDOUR::MeterFalloff meter_falloff_from_float(float)
std::shared_ptr< AutomationControlList > stripable_list_to_control_list(StripableList &sl, std::shared_ptr< T >(Stripable::*get_control)() const)
int cmp_nocase(const std::string &s, const std::string &s2)
const char * ripple_mode_to_string(ARDOUR::RippleMode)
float meter_falloff_to_db_per_sec(float)
static float f_max(float x, float a)
bool matching_unsuffixed_filename_exists_in(const std::string &dir, const std::string &name)
bool estimate_audio_tempo(std::shared_ptr< Region > region, Sample *data, samplecnt_t data_length, samplecnt_t sample_rate, double &qpm, Temporal::Meter &meter, double &beatcount)
float meter_falloff_to_float(ARDOUR::MeterFalloff)
std::string bump_name_once(const std::string &s, char delimiter)
const char * edit_mode_to_string(ARDOUR::EditMode)