ardour
jack_utils_test.cc
Go to the documentation of this file.
1 
2 #include <stdexcept>
3 
4 #ifdef PLATFORM_WINDOWS
5 #include <windows.h> // only for Sleep
6 #endif
7 
8 #include <glibmm/miscutils.h>
9 
10 #include "ardour/jack_utils.h"
11 
12 #include "jack_utils_test.h"
13 
15 
16 using namespace std;
17 using namespace ARDOUR;
18 
19 void
21 {
22  vector<string> driver_names;
23 
24  get_jack_audio_driver_names (driver_names);
25 
26  CPPUNIT_ASSERT(!driver_names.empty());
27 
28  cout << endl;
29  cout << "Number of possible JACK Audio drivers found on this system: " << driver_names.size () << endl;
30 
31  for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
32  cout << "JACK Audio driver found: " << *i << endl;
33  }
34 
35  string default_audio_driver;
36  get_jack_default_audio_driver_name (default_audio_driver);
37 
38  cout << "The default audio driver on this system is: " << default_audio_driver << endl;
39 
40  driver_names.clear();
41 
42  get_jack_midi_system_names (default_audio_driver, driver_names);
43 
44  CPPUNIT_ASSERT(!driver_names.empty());
45 
46  cout << "Number of possible JACK MIDI drivers found on this system for default audio driver: " << driver_names.size () << endl;
47 
48  for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
49  cout << "JACK MIDI driver found: " << *i << endl;
50  }
51 
52  string default_midi_driver;
53  get_jack_default_midi_system_name (default_audio_driver, default_midi_driver);
54 
55  cout << "The default midi driver on this system is: " << default_midi_driver << endl;
56 }
57 
58 string
59 devices_string (const vector<string>& devices)
60 {
61  std::string str;
62  for (vector<string>::const_iterator i = devices.begin(); i != devices.end();) {
63  str += *i;
64  if (++i != devices.end()) str += ", ";
65  }
66  return str;
67 }
68 
69 void
71 {
72  vector<string> driver_names;
73 
74  get_jack_audio_driver_names (driver_names);
75 
76  CPPUNIT_ASSERT(!driver_names.empty());
77 
78  cout << endl;
79 
80  for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
82  cout << "JACK Audio driver found: " << *i << " with devices: " << devices << endl;
83  }
84 }
85 
86 void
88 {
89  vector<string> samplerates;
90 
91  get_jack_sample_rate_strings (samplerates);
92  cout << endl;
93  cout << "Number of possible Samplerates supported by JACK: " << samplerates.size () << endl;
94 
95  for (vector<string>::const_iterator i = samplerates.begin(); i != samplerates.end(); ++i) {
96  cout << "Samplerate: " << *i << endl;
97  }
98 }
99 
100 void
102 {
103  vector<string> period_sizes;
104 
105  get_jack_period_size_strings (period_sizes);
106  cout << endl;
107  cout << "Number of possible Period sizes supported by JACK: " << period_sizes.size () << endl;
108 
109  for (vector<string>::const_iterator i = period_sizes.begin(); i != period_sizes.end(); ++i) {
110  cout << "Period size: " << *i << endl;
111  }
112 }
113 
114 void
116 {
117  vector<string> driver_names;
118 
119  get_jack_audio_driver_names (driver_names);
120 
121  CPPUNIT_ASSERT(!driver_names.empty());
122 
123  cout << endl;
124 
125  for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
126  vector<string> dither_modes;
127 
128  get_jack_dither_mode_strings (*i, dither_modes);
129  cout << "Number of possible Dither Modes supported by JACK driver " << *i <<
130  ": " << dither_modes.size () << endl;
131  for (vector<string>::const_iterator j = dither_modes.begin(); j != dither_modes.end(); ++j) {
132  cout << "Dither Mode: " << *j << endl;
133  }
134  cout << endl;
135  }
136 
137 }
138 
139 void
141 {
142  cout << endl;
143  if (jack_server_running ()) {
144  cout << "Jack server running " << endl;
145  } else {
146  cout << "Jack server not running " << endl;
147  }
148 }
149 
150 void
152 {
153  cout << endl;
154 
155  bool path_env_set = false;
156 
157  string path_env = Glib::getenv ("PATH", path_env_set);
158 
159  if (path_env_set) {
160  cout << "PATH env set to: " << path_env << endl;
161  } else {
162  cout << "PATH env not set" << endl;
163  }
164  vector<string> server_dirs;
165  get_jack_server_dir_paths (server_dirs);
166  set_path_env_for_jack_autostart (server_dirs);
167 
168  path_env_set = false;
169 
170  path_env = Glib::getenv ("PATH", path_env_set);
171 
172  CPPUNIT_ASSERT (path_env_set);
173 
174  cout << "After set_jack_path_env PATH env set to: " << path_env << endl;
175 }
176 
177 void
179 {
180  cout << endl;
181 
182  vector<std::string> server_dirs;
183 
184  CPPUNIT_ASSERT (get_jack_server_dir_paths (server_dirs));
185 
186  cout << "Number of Directories that may contain JACK servers: " << server_dirs.size () << endl;
187 
188  for (vector<std::string>::const_iterator i = server_dirs.begin(); i != server_dirs.end(); ++i) {
189  cout << "JACK server directory path: " << *i << endl;
190  }
191 
192  vector<string> server_names;
193 
194  CPPUNIT_ASSERT (get_jack_server_application_names (server_names));
195 
196  cout << "Number of possible JACK server names on this system: " << server_names.size () << endl;
197 
198  for (vector<string>::const_iterator i = server_names.begin(); i != server_names.end(); ++i) {
199  cout << "JACK server name: " << *i << endl;
200  }
201 
202  vector<std::string> server_paths;
203 
204  CPPUNIT_ASSERT (get_jack_server_paths (server_dirs, server_names, server_paths));
205 
206  cout << "Number of JACK servers on this system: " << server_paths.size () << endl;
207 
208  for (vector<std::string>::const_iterator i = server_paths.begin(); i != server_paths.end(); ++i) {
209  cout << "JACK server path: " << *i << endl;
210  }
211 
212  vector<std::string> server_paths2;
213 
214  CPPUNIT_ASSERT (get_jack_server_paths (server_paths2));
215 
216  CPPUNIT_ASSERT (server_paths.size () == server_paths2.size ());
217 
218  std::string default_server_path;
219 
220  CPPUNIT_ASSERT (get_jack_default_server_path (default_server_path));
221 
222  cout << "The default JACK server on this system: " << default_server_path << endl;
223 }
224 
225 bool
226 get_default_jack_command_line (std::string& command_line)
227 {
228  cout << endl;
229 
230  JackCommandLineOptions options;
231 
232  CPPUNIT_ASSERT (get_jack_default_server_path (options.server_path));
233 
235 
236 
237  // should fail, haven't set any device yet
238  CPPUNIT_ASSERT (!get_jack_command_line_string (options, command_line));
239 
240  vector<string> devices = get_jack_device_names_for_audio_driver (options.driver);
241 
242  if (!devices.empty()) {
243  options.input_device = devices.front ();
244  options.output_device = devices.front ();
245  } else {
246  cout << "No audio devices available using default JACK driver using Dummy driver" << endl;
247  options.driver = dummy_driver_name;
249  CPPUNIT_ASSERT (!devices.empty ());
250  options.input_device = devices.front ();
251  options.output_device = devices.front ();
252  }
253 
254  options.input_device = devices.front ();
255  options.output_device = devices.front ();
256 
257  string midi_driver;
258 
260  //
261  // this at least should create a valid jack command line
262  return get_jack_command_line_string (options, command_line);
263 
264 }
265 
266 void
268 {
269  std::string config_path(get_jack_server_user_config_file_path());
270 
271  cout << "Jack server config file path: " << config_path << endl;
272 
273  std::string command_line;
274 
275  CPPUNIT_ASSERT (get_default_jack_command_line (command_line));
276 
277  CPPUNIT_ASSERT (write_jack_config_file (config_path, command_line));
278 }
279 
280 
281 void
283 {
284  string command_line;
285 
286  // this at least should create a valid jack command line
287  CPPUNIT_ASSERT (get_default_jack_command_line (command_line));
288 
289  cout << "Default JACK command line: " << command_line << endl;
290 }
void get_jack_default_audio_driver_name(std::string &driver_name)
void get_jack_audio_driver_names(std::vector< std::string > &driver_names)
bool get_jack_default_server_path(std::string &server_path)
void set_path_env_for_jack_autostart(const std::vector< std::string > &)
void test_command_line()
void test_driver_names()
Definition: Beats.hpp:239
bool get_jack_command_line_string(const JackCommandLineOptions &options, std::string &command_line)
void get_jack_period_size_strings(std::vector< std::string > &samplerates)
CPPUNIT_TEST_SUITE_REGISTRATION(JackUtilsTest)
void get_jack_midi_system_names(const std::string &driver, std::vector< std::string > &driver_names)
const char *const dummy_driver_name
void get_jack_sample_rate_strings(std::vector< std::string > &sample_rates)
std::string get_jack_server_user_config_file_path()
string devices_string(const vector< string > &devices)
void get_jack_dither_mode_strings(const std::string &driver, std::vector< std::string > &dither_modes)
bool get_jack_server_application_names(std::vector< std::string > &server_names)
bool get_jack_server_paths(const std::vector< std::string > &server_dir_paths, const std::vector< std::string > &server_names, std::vector< std::string > &server_paths)
void test_server_paths()
Definition: amp.h:29
bool get_default_jack_command_line(std::string &command_line)
void get_jack_default_midi_system_name(const std::string &driver_name, std::string &midi_system)
void test_samplerates()
bool write_jack_config_file(const std::string &config_file_path, const std::string &command_line)
bool get_jack_server_dir_paths(std::vector< std::string > &server_dir_paths)
void test_dither_modes()
bool get_jack_device_names_for_audio_driver(const std::string &driver, device_map_t &devices)
bool jack_server_running()
void test_device_names()
void test_period_sizes()
void test_connect_server()
void test_set_jack_path_env()