skeleton dummy audio-engine
[ardour.git] / libs / backends / dummy / dummy_audiobackend.cc
1 /*
2  * Copyright (C) 2014 Robin Gareus <robin@gareus.org>
3  * Copyright (C) 2013 Paul Davis
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */
19
20 #include "dummy_audiobackend.h"
21 #include "pbd/error.h"
22 #include "i18n.h"
23
24 using namespace ARDOUR;
25
26 static std::string s_instance_name;
27 DummyAudioBackend::DummyAudioBackend (AudioEngine& e)
28         : AudioBackend (e)
29 {
30         _instance_name = s_instance_name;
31 }
32
33 DummyAudioBackend::~DummyAudioBackend ()
34 {
35 }
36
37 /* AUDIOBACKEND API */
38
39 std::string
40 DummyAudioBackend::name () const
41 {
42         return X_("Dummy");
43 }
44
45 bool
46 DummyAudioBackend::is_realtime () const
47 {
48         return false;
49 }
50
51 std::vector<AudioBackend::DeviceStatus>
52 DummyAudioBackend::enumerate_devices () const
53 {
54         std::vector<AudioBackend::DeviceStatus> s;
55         s.push_back (DeviceStatus (_("Dummy"), true));
56         return s;
57 }
58
59 std::vector<float>
60 DummyAudioBackend::available_sample_rates (const std::string&) const
61 {
62         std::vector<float> sr;
63         sr.push_back (44100.0);
64         sr.push_back (48000.0);
65         return sr;
66 }
67
68 std::vector<uint32_t>
69 DummyAudioBackend::available_buffer_sizes (const std::string&) const
70 {
71         std::vector<uint32_t> bs;
72         bs.push_back (64);
73         bs.push_back (1024);
74         return bs;
75 }
76
77 uint32_t
78 DummyAudioBackend::available_input_channel_count (const std::string&) const
79 {
80         return 128;
81 }
82
83 uint32_t
84 DummyAudioBackend::available_output_channel_count (const std::string&) const
85 {
86         return 128;
87 }
88
89 bool
90 DummyAudioBackend::can_change_sample_rate_when_running () const
91 {
92         return false;
93 }
94
95 bool
96 DummyAudioBackend::can_change_buffer_size_when_running () const
97 {
98         return false;
99 }
100
101 int
102 DummyAudioBackend::set_device_name (const std::string&)
103 {
104         return -1;
105 }
106
107 int
108 DummyAudioBackend::set_sample_rate (float)
109 {
110         return -1;
111 }
112
113 int
114 DummyAudioBackend::set_buffer_size (uint32_t)
115 {
116         return -1;
117 }
118
119 int
120 DummyAudioBackend::set_interleaved (bool yn)
121 {
122         if (!yn) { return 0; }
123         return -1;
124 }
125
126 int
127 DummyAudioBackend::set_input_channels (uint32_t)
128 {
129         return -1;
130 }
131
132 int
133 DummyAudioBackend::set_output_channels (uint32_t)
134 {
135         return -1;
136 }
137
138 int
139 DummyAudioBackend::set_systemic_input_latency (uint32_t)
140 {
141         return -1;
142 }
143
144 int
145 DummyAudioBackend::set_systemic_output_latency (uint32_t)
146 {
147         return -1;
148 }
149
150 /* Retrieving parameters */
151 std::string
152 DummyAudioBackend::device_name () const
153 {
154         return _("Dummy Device");
155 }
156
157 float
158 DummyAudioBackend::sample_rate () const
159 {
160         return 0;
161 }
162
163 uint32_t
164 DummyAudioBackend::buffer_size () const
165 {
166         return 0;
167 }
168
169 bool
170 DummyAudioBackend::interleaved () const
171 {
172         return false;
173 }
174
175 uint32_t
176 DummyAudioBackend::input_channels () const
177 {
178         return 0;
179 }
180
181 uint32_t
182 DummyAudioBackend::output_channels () const
183 {
184         return 0;
185 }
186
187 uint32_t
188 DummyAudioBackend::systemic_input_latency () const
189 {
190         return 0;
191 }
192
193 uint32_t
194 DummyAudioBackend::systemic_output_latency () const
195 {
196         return 0;
197 }
198
199 /* MIDI */
200 std::vector<std::string>
201 DummyAudioBackend::enumerate_midi_options () const
202 {
203         std::vector<std::string> m;
204         m.push_back (_("None"));
205         return m;
206 }
207
208 int
209 DummyAudioBackend::set_midi_option (const std::string&)
210 {
211         return -1;
212 }
213
214 std::string
215 DummyAudioBackend::midi_option () const
216 {
217         return "";
218 }
219
220 /* State Control */
221
222 int
223 DummyAudioBackend::_start (bool /*for_latency_measurement*/)
224 {
225         return -1;
226 }
227
228 int
229 DummyAudioBackend::stop ()
230 {
231         return -1;
232 }
233
234 int
235 DummyAudioBackend::freewheel (bool)
236 {
237         return 0;
238 }
239
240 float
241 DummyAudioBackend::dsp_load () const
242 {
243         return 0.0;
244 }
245
246 size_t
247 DummyAudioBackend::raw_buffer_size (DataType t)
248 {
249         return 0;
250 }
251
252 /* Process time */
253 pframes_t
254 DummyAudioBackend::sample_time ()
255 {
256         return 0;
257 }
258
259 pframes_t
260 DummyAudioBackend::sample_time_at_cycle_start ()
261 {
262         return 0;
263 }
264
265 pframes_t
266 DummyAudioBackend::samples_since_cycle_start ()
267 {
268         return 0;
269 }
270
271 int
272 DummyAudioBackend::create_process_thread (boost::function<void()> func)
273 {
274         return -1;
275 }
276
277 int
278 DummyAudioBackend::join_process_threads ()
279 {
280         return -1;
281 }
282
283 bool
284 DummyAudioBackend::in_process_thread ()
285 {
286         return false;
287 }
288
289 uint32_t
290 DummyAudioBackend::process_thread_count ()
291 {
292         return 0;
293 }
294
295 void
296 DummyAudioBackend::update_latencies ()
297 {
298 }
299
300 /* PORTENGINE API */
301
302 void*
303 DummyAudioBackend::private_handle () const
304 {
305         return NULL;
306 }
307
308 const std::string&
309 DummyAudioBackend::my_name () const
310 {
311         return _instance_name;
312 }
313
314 bool
315 DummyAudioBackend::available () const
316 {
317         return true;
318 }
319
320 uint32_t
321 DummyAudioBackend::port_name_size () const
322 {
323         return 256;
324 }
325
326 int
327 DummyAudioBackend::set_port_name (PortEngine::PortHandle, const std::string&)
328 {
329         return -1;
330 }
331
332 std::string
333 DummyAudioBackend::get_port_name (PortEngine::PortHandle) const
334 {
335         return "port:XXX";
336 }
337
338 PortEngine::PortHandle
339 DummyAudioBackend::get_port_by_name (const std::string&) const
340 {
341         PortEngine::PortHandle port_handle = 0;
342         return port_handle;
343 }
344
345 int
346 DummyAudioBackend::get_ports (
347                 const std::string& port_name_pattern,
348                 DataType type, PortFlags flags,
349                 std::vector<std::string>&) const
350 {
351         return 0;
352 }
353
354 DataType
355 DummyAudioBackend::port_data_type (PortEngine::PortHandle) const
356 {
357         return DataType::AUDIO;
358 }
359
360 PortEngine::PortHandle
361 DummyAudioBackend::register_port (
362                 const std::string&,
363                 ARDOUR::DataType,
364                 ARDOUR::PortFlags)
365 {
366         PortEngine::PortHandle port_handle = 0;
367         return port_handle;
368 }
369
370 void
371 DummyAudioBackend::unregister_port (PortEngine::PortHandle)
372 {
373 }
374
375 int
376 DummyAudioBackend::connect (const std::string& src, const std::string& dst)
377 {
378         return -1;
379 }
380
381 int
382 DummyAudioBackend::disconnect (const std::string& src, const std::string& dst)
383 {
384         return -1;
385 }
386
387 int
388 DummyAudioBackend::connect (PortEngine::PortHandle, const std::string&)
389 {
390         return -1;
391 }
392
393 int
394 DummyAudioBackend::disconnect (PortEngine::PortHandle, const std::string&)
395 {
396         return -1;
397 }
398
399 int
400 DummyAudioBackend::disconnect_all (PortEngine::PortHandle)
401 {
402         return -1;
403 }
404
405 bool
406 DummyAudioBackend::connected (PortEngine::PortHandle, bool process_callback_safe)
407 {
408         return false;
409 }
410
411 bool
412 DummyAudioBackend::connected_to (PortEngine::PortHandle, const std::string&, bool process_callback_safe)
413 {
414         return false;
415 }
416
417 bool
418 DummyAudioBackend::physically_connected (PortEngine::PortHandle, bool process_callback_safe)
419 {
420         return false;
421 }
422
423 int
424 DummyAudioBackend::get_connections (PortEngine::PortHandle, std::vector<std::string>&, bool process_callback_safe)
425 {
426         return false;
427 }
428
429 /* MIDI */
430 int
431 DummyAudioBackend::midi_event_get (pframes_t& timestamp, size_t& size, uint8_t** buf, void* port_buffer, uint32_t event_index)
432 {
433         return -1;
434 }
435
436 int
437 DummyAudioBackend::midi_event_put (void* port_buffer, pframes_t timestamp, const uint8_t* buffer, size_t size)
438 {
439         return -1;
440 }
441
442 uint32_t
443 DummyAudioBackend::get_midi_event_count (void* port_buffer)
444 {
445         return -1;
446 }
447
448 void
449 DummyAudioBackend::midi_clear (void* port_buffer)
450 {
451 }
452
453 /* Monitoring */
454
455 bool
456 DummyAudioBackend::can_monitor_input () const
457 {
458         return false;
459 }
460
461 int
462 DummyAudioBackend::request_input_monitoring (PortEngine::PortHandle, bool)
463 {
464         return -1;
465 }
466
467 int
468 DummyAudioBackend::ensure_input_monitoring (PortEngine::PortHandle, bool)
469 {
470         return -1;
471 }
472
473 bool
474 DummyAudioBackend::monitoring_input (PortEngine::PortHandle)
475 {
476         return false;
477 }
478
479 /* Latency management */
480
481 void
482 DummyAudioBackend::set_latency_range (PortEngine::PortHandle, bool for_playback, LatencyRange)
483 {
484 }
485
486 LatencyRange
487 DummyAudioBackend::get_latency_range (PortEngine::PortHandle, bool for_playback)
488 {
489         LatencyRange r;
490         r.min = 0;
491         r.max = 0;
492         return r;
493 }
494
495 /* Discovering physical ports */
496
497 bool
498 DummyAudioBackend::port_is_physical (PortEngine::PortHandle) const
499 {
500         return false;
501 }
502
503 void
504 DummyAudioBackend::get_physical_outputs (DataType type, std::vector<std::string>&)
505 {
506 }
507
508 void
509 DummyAudioBackend::get_physical_inputs (DataType type, std::vector<std::string>&)
510 {
511 }
512
513 ChanCount
514 DummyAudioBackend::n_physical_outputs () const
515 {
516         ChanCount cc;
517         cc.set (DataType::AUDIO, 0);
518         cc.set (DataType::MIDI, 0);
519         return cc;
520 }
521
522 ChanCount
523 DummyAudioBackend::n_physical_inputs () const
524 {
525         ChanCount cc;
526         cc.set (DataType::AUDIO, 0);
527         cc.set (DataType::MIDI, 0);
528         return cc;
529 }
530
531 /* Getting access to the data buffer for a port */
532
533 void*
534 DummyAudioBackend::get_buffer (PortEngine::PortHandle, pframes_t)
535 {
536         return 0;
537 }
538
539 /******************************************************************************/
540
541 static boost::shared_ptr<DummyAudioBackend> _instance;
542
543 static boost::shared_ptr<AudioBackend>
544 backend_factory (AudioEngine& e)
545 {
546         if (!_instance) {
547                 _instance.reset (new DummyAudioBackend (e));
548         }
549         return _instance;
550 }
551
552 static int
553 instantiate (const std::string& arg1, const std::string& /* arg2 */)
554 {
555         s_instance_name = arg1;
556         return 0;
557 }
558
559 static int
560 deinstantiate ()
561 {
562         _instance.reset ();
563         return 0;
564 }
565
566 static bool
567 already_configured ()
568 {
569         return false;
570 }
571
572 static ARDOUR::AudioBackendInfo _descriptor = {
573         "Dummy",
574         instantiate,
575         deinstantiate,
576         backend_factory,
577         already_configured,
578 };
579
580 extern "C" ARDOURBACKEND_API ARDOUR::AudioBackendInfo* descriptor ()
581 {
582         return &_descriptor;
583 }