Make Region's _beat a PBD::Property.
[ardour.git] / libs / ardour / ardour / jack_utils.h
1 /*
2     Copyright (C) 2011 Tim Mayberry
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 #include <stdint.h>
21
22 #include <vector>
23 #include <map>
24 #include <string>
25
26 namespace ARDOUR {
27
28         // Names for the drivers on all possible systems
29         extern const char * const portaudio_driver_name;
30         extern const char * const coreaudio_driver_name;
31         extern const char * const alsa_driver_name;
32         extern const char * const oss_driver_name;
33         extern const char * const freebob_driver_name;
34         extern const char * const ffado_driver_name;
35         extern const char * const netjack_driver_name;
36         extern const char * const dummy_driver_name;
37
38         /**
39          * Get a list of possible JACK audio driver names based on platform
40          */
41         void get_jack_audio_driver_names (std::vector<std::string>& driver_names);
42
43         /**
44          * Get the default JACK audio driver based on platform
45          */
46         void get_jack_default_audio_driver_name (std::string& driver_name);
47
48         /**
49          * Get a list of possible JACK midi driver names based on platform
50          */
51         void get_jack_midi_system_names (const std::string& driver, std::vector<std::string>& driver_names);
52
53         /**
54          * Get the default JACK midi driver based on platform
55          */
56         void get_jack_default_midi_system_name (const std::string& driver_name, std::string& midi_system);
57
58         /**
59          * Get a list of possible samplerates supported be JACK
60          */
61         void get_jack_sample_rate_strings (std::vector<std::string>& sample_rates);
62
63         /**
64          * @return The default samplerate
65          */
66         std::string get_jack_default_sample_rate ();
67
68         /**
69          * @return true if sample rate string was able to be converted
70          */
71         bool get_jack_sample_rate_value_from_string (const std::string& srs, uint32_t& srv);
72
73         /**
74          * Get a list of possible period sizes supported be JACK
75          */
76         void get_jack_period_size_strings (std::vector<std::string>& samplerates);
77
78         /**
79          * @return The default period size
80          */
81         std::string get_jack_default_period_size ();
82
83         /**
84          * @return true if period size string was able to be converted
85          */
86         bool get_jack_period_size_value_from_string (const std::string& pss, uint32_t& psv);
87
88         /**
89          * These are driver specific I think, so it may require a driver arg
90          * in future
91          */
92         void get_jack_dither_mode_strings (const std::string& driver, std::vector<std::string>& dither_modes);
93
94         /**
95          * @return The default dither mode
96          */
97         std::string get_jack_default_dither_mode (const std::string& driver);
98
99         /**
100          * @return Estimate of latency
101          *
102          * API matches current use in GUI
103          */
104         std::string get_jack_latency_string (std::string samplerate, float periods, std::string period_size);
105
106         /**
107          * @return true if a JACK server is running
108          */
109         bool jack_server_running ();
110
111         /**
112          * Key being a readable name to display in a GUI
113          * Value being name used in a jack commandline
114          */
115         typedef std::map<std::string, std::string> device_map_t;
116
117         /**
118          * Use library specific code to find out what what devices exist for a given
119          * driver that might work in JACK. There is no easy way to find out what
120          * modules the JACK server supports so guess based on platform. For instance
121          * portaudio is cross-platform but we only return devices if built for
122          * windows etc
123          */
124         void get_jack_alsa_device_names (device_map_t& devices);
125         void get_jack_portaudio_device_names (device_map_t& devices);
126         void get_jack_coreaudio_device_names (device_map_t& devices);
127         void get_jack_oss_device_names (device_map_t& devices);
128         void get_jack_freebob_device_names (device_map_t& devices);
129         void get_jack_ffado_device_names (device_map_t& devices);
130         void get_jack_netjack_device_names (device_map_t& devices);
131         void get_jack_dummy_device_names (device_map_t& devices);
132
133         /*
134          * @return true if there were devices found for the driver
135          *
136          * @param driver The driver name returned by get_jack_audio_driver_names
137          * @param devices The map used to insert the drivers into, devices will be cleared before
138          * adding the available drivers
139          */
140         bool get_jack_device_names_for_audio_driver (const std::string& driver, device_map_t& devices);
141
142         /*
143          * @return a list of readable device names for a specific driver.
144          */
145         std::vector<std::string> get_jack_device_names_for_audio_driver (const std::string& driver);
146
147         /**
148          * @return true if the driver supports playback and recording
149          * on separate devices
150          */
151         bool get_jack_audio_driver_supports_two_devices (const std::string& driver);
152
153         bool get_jack_audio_driver_supports_latency_adjustment (const std::string& driver);
154
155         bool get_jack_audio_driver_supports_setting_period_count (const std::string& driver);
156
157         /**
158          * The possible names to use to try and find servers, this includes
159          * any file extensions like .exe on Windows
160          *
161          * @return true if the JACK application names for this platform could be guessed
162          */
163         bool get_jack_server_application_names (std::vector<std::string>& server_names);
164
165         /**
166          * Sets the PATH environment variable to contain directories likely to contain
167          * JACK servers so that if the JACK server is auto-started it can find the server
168          * executable.
169          *
170          * This is only modifies PATH on the mac at the moment.
171          */
172         void set_path_env_for_jack_autostart (const std::vector<std::string>&);
173
174         /**
175          * Get absolute paths to directories that might contain JACK servers on the system
176          *
177          * @return true if !server_paths.empty()
178          */
179         bool get_jack_server_dir_paths (std::vector<std::string>& server_dir_paths);
180
181         /**
182          * Get absolute paths to JACK servers on the system
183          *
184          * @return true if a server was found
185          */
186         bool get_jack_server_paths (const std::vector<std::string>& server_dir_paths,
187                         const std::vector<std::string>& server_names,
188                         std::vector<std::string>& server_paths);
189
190
191         bool get_jack_server_paths (std::vector<std::string>& server_paths);
192
193         /**
194          * Get absolute path to default JACK server
195          */
196         bool get_jack_default_server_path (std::string& server_path);
197
198         /**
199          * @return The name of the jack server config file
200          */
201         std::string get_jack_server_config_file_name ();
202
203         std::string get_jack_server_user_config_dir_path ();
204
205         std::string get_jack_server_user_config_file_path ();
206
207         bool write_jack_config_file (const std::string& config_file_path, const std::string& command_line);
208
209         struct JackCommandLineOptions {
210
211                 // see implementation for defaults
212                 JackCommandLineOptions ();
213
214                 //operator bool
215                 //operator ostream
216
217                 std::string      server_path;
218                 uint32_t         timeout;
219                 bool             no_mlock;
220                 uint32_t         ports_max;
221                 bool             realtime;
222                 uint32_t         priority;
223                 bool             unlock_gui_libs;
224                 bool             verbose;
225                 bool             temporary;
226                 bool             playback_only;
227                 bool             capture_only;
228                 std::string      driver;
229                 std::string      input_device;
230                 std::string      output_device;
231                 uint32_t         num_periods;
232                 uint32_t         period_size;
233                 uint32_t         samplerate;
234                 uint32_t         input_latency;
235                 uint32_t         output_latency;
236                 bool             hardware_metering;
237                 bool             hardware_monitoring;
238                 std::string      dither_mode;
239                 bool             force16_bit;
240                 bool             soft_mode;
241                 std::string      midi_driver;
242         };
243
244         /**
245          * @return true if able to build a valid command line based on options
246          */
247         bool get_jack_command_line_string (const JackCommandLineOptions& options, std::string& command_line);
248
249         /**
250          * We don't need this at the moment because the gui stores all its settings
251          */
252         //std::string get_jack_command_line_from_config_file (const std::string& config_file_path);
253 }