summaryrefslogtreecommitdiff
path: root/libs/ardour/test/jack_utils_test.cc
blob: d8a21ceb49e3fa4018519263ad614d9b151e637b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

#include <stdexcept>

#ifdef PLATFORM_WINDOWS
#include <windows.h> // only for Sleep
#endif

#include <glibmm/miscutils.h>

#include "ardour/jack_utils.h"

#include "jack_utils_test.h"

CPPUNIT_TEST_SUITE_REGISTRATION (JackUtilsTest);

using namespace std;
using namespace ARDOUR;

void
JackUtilsTest::test_driver_names ()
{
	vector<string> driver_names;

	get_jack_audio_driver_names (driver_names);

	CPPUNIT_ASSERT(!driver_names.empty());

	cout << endl;
	cout << "Number of possible JACK Audio drivers found on this system: " << driver_names.size () << endl;

	for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
		cout << "JACK Audio driver found: " << *i << endl;
	}

	string default_audio_driver;
	get_jack_default_audio_driver_name (default_audio_driver);

	cout << "The default audio driver on this system is: " << default_audio_driver << endl;

	driver_names.clear();

	get_jack_midi_system_names (default_audio_driver, driver_names);

	CPPUNIT_ASSERT(!driver_names.empty());

	cout << "Number of possible JACK MIDI drivers found on this system for default audio driver: " << driver_names.size () << endl;

	for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
		cout << "JACK MIDI driver found: " << *i << endl;
	}

	string default_midi_driver;
	get_jack_default_midi_system_name (default_audio_driver, default_midi_driver);

	cout << "The default midi driver on this system is: " << default_midi_driver << endl;
}

string
devices_string (const vector<string>& devices)
{
	std::string str;
	for (vector<string>::const_iterator i = devices.begin(); i != devices.end();) {
		str += *i;
		if (++i != devices.end()) str += ", ";
	}
	return str;
}

void
JackUtilsTest::test_device_names ()
{
	vector<string> driver_names;

	get_jack_audio_driver_names (driver_names);

	CPPUNIT_ASSERT(!driver_names.empty());

	cout << endl;

	for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
		string devices = devices_string (get_jack_device_names_for_audio_driver (*i));
		cout << "JACK Audio driver found: " << *i << " with devices: " << devices << endl;
	}
}

void
JackUtilsTest::test_samplerates ()
{
	vector<string> samplerates;

	get_jack_sample_rate_strings (samplerates);
	cout << endl;
	cout << "Number of possible Samplerates supported by JACK: " << samplerates.size () << endl;

	for (vector<string>::const_iterator i = samplerates.begin(); i != samplerates.end(); ++i) {
		cout << "Samplerate: " << *i << endl;
	}
}

void
JackUtilsTest::test_period_sizes ()
{
	vector<string> period_sizes;

	get_jack_period_size_strings (period_sizes);
	cout << endl;
	cout << "Number of possible Period sizes supported by JACK: " << period_sizes.size () << endl;

	for (vector<string>::const_iterator i = period_sizes.begin(); i != period_sizes.end(); ++i) {
		cout << "Period size: " << *i << endl;
	}
}

void
JackUtilsTest::test_dither_modes ()
{
	vector<string> driver_names;

	get_jack_audio_driver_names (driver_names);

	CPPUNIT_ASSERT(!driver_names.empty());

	cout << endl;

	for (vector<string>::const_iterator i = driver_names.begin(); i != driver_names.end(); ++i) {
		vector<string> dither_modes;

		get_jack_dither_mode_strings (*i, dither_modes);
		cout << "Number of possible Dither Modes supported by JACK driver " << *i <<
			": " << dither_modes.size () << endl;
		for (vector<string>::const_iterator j = dither_modes.begin(); j != dither_modes.end(); ++j) {
			cout << "Dither Mode: " << *j << endl;
		}
		cout << endl;
	}

}

void
JackUtilsTest::test_connect_server ()
{
	cout << endl;
	if (jack_server_running ()) {
		cout << "Jack server running " << endl;
	} else {
		cout << "Jack server not running " << endl;
	}
}

void
JackUtilsTest::test_set_jack_path_env ()
{
	cout << endl;

	bool path_env_set = false;

	string path_env = Glib::getenv ("PATH", path_env_set);

	if (path_env_set) {
		cout << "PATH env set to: " << path_env << endl;
	} else {
		cout << "PATH env not set" << endl;
	}
	vector<string> server_dirs;
	get_jack_server_dir_paths (server_dirs);
	set_path_env_for_jack_autostart (server_dirs);

	path_env_set = false;

	path_env = Glib::getenv ("PATH", path_env_set);

	CPPUNIT_ASSERT (path_env_set);

	cout << "After set_jack_path_env PATH env set to: " << path_env << endl;
}

void
JackUtilsTest::test_server_paths ()
{
	cout << endl;

	vector<std::string> server_dirs;

	CPPUNIT_ASSERT (get_jack_server_dir_paths (server_dirs));

	cout << "Number of Directories that may contain JACK servers: " << server_dirs.size () << endl;

	for (vector<std::string>::const_iterator i = server_dirs.begin(); i != server_dirs.end(); ++i) {
		cout << "JACK server directory path: " << *i << endl;
	}

	vector<string> server_names;

	CPPUNIT_ASSERT (get_jack_server_application_names (server_names));

	cout << "Number of possible JACK server names on this system: " << server_names.size () << endl;

	for (vector<string>::const_iterator i = server_names.begin(); i != server_names.end(); ++i) {
		cout << "JACK server name: " << *i << endl;
	}

	vector<std::string> server_paths;

	CPPUNIT_ASSERT (get_jack_server_paths (server_dirs, server_names, server_paths));

	cout << "Number of JACK servers on this system: " << server_paths.size () << endl;

	for (vector<std::string>::const_iterator i = server_paths.begin(); i != server_paths.end(); ++i) {
		cout << "JACK server path: " << *i << endl;
	}

	vector<std::string> server_paths2;

	CPPUNIT_ASSERT (get_jack_server_paths (server_paths2));

	CPPUNIT_ASSERT (server_paths.size () == server_paths2.size ());

	std::string default_server_path;

	CPPUNIT_ASSERT (get_jack_default_server_path (default_server_path));

	cout << "The default JACK server on this system: " << default_server_path << endl;
}

bool
get_default_jack_command_line (std::string& command_line)
{
	cout << endl;

	JackCommandLineOptions options;

	CPPUNIT_ASSERT (get_jack_default_server_path (options.server_path));

	get_jack_default_audio_driver_name (options.driver);


	// should fail, haven't set any device yet
	CPPUNIT_ASSERT (!get_jack_command_line_string (options, command_line));

	vector<string> devices = get_jack_device_names_for_audio_driver (options.driver);

	if (!devices.empty()) {
		options.input_device = devices.front ();
		options.output_device = devices.front ();
	} else {
		cout << "No audio devices available using default JACK driver using Dummy driver" << endl;
		options.driver = dummy_driver_name;
		devices = get_jack_device_names_for_audio_driver (options.driver);
		CPPUNIT_ASSERT (!devices.empty ());
		options.input_device = devices.front ();
		options.output_device = devices.front ();
	}

	options.input_device = devices.front ();
	options.output_device = devices.front ();

	string midi_driver;

	get_jack_default_midi_system_name (options.driver, options.midi_driver);
	//
	// this at least should create a valid jack command line
	return get_jack_command_line_string (options, command_line);

}

void
JackUtilsTest::test_config ()
{
	std::string config_path(get_jack_server_user_config_file_path());

	cout << "Jack server config file path: " << config_path << endl;

	std::string command_line;

	CPPUNIT_ASSERT (get_default_jack_command_line (command_line));

	CPPUNIT_ASSERT (write_jack_config_file (config_path, command_line));
}


void
JackUtilsTest::test_command_line ()
{
	string command_line;

	// this at least should create a valid jack command line
	CPPUNIT_ASSERT (get_default_jack_command_line (command_line));

	cout << "Default JACK command line: " << command_line << endl;
}