Return meaningful error codes when PortaudioBackend fails to start
[ardour.git] / libs / backends / wavesaudio / waves_midi_device_manager.h
1 /*
2     Copyright (C) 2013 Waves Audio Ltd.
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 #ifndef __libardour_waves_midi_device_manager_h__
21 #define __libardour_waves_midi_device_manager_h__
22
23 #include "waves_midi_device.h"
24
25 namespace ARDOUR {
26
27 class WavesAudioBackend;
28
29 class WavesMidiDeviceManager {
30 public:
31     WavesMidiDeviceManager (WavesAudioBackend& audiobackend);
32     ~WavesMidiDeviceManager ();
33
34     inline const std::vector<WavesMidiDevice *>& devices () const 
35     {
36         return _devices;
37     }
38
39     int start ();
40     int stop ();
41     int stream (bool yn);
42     int is_streaming () { return _streaming; }
43     void do_read ();
44     void do_write ();
45
46 private:
47
48     int _create_devices ();
49     int _delete_devices ();
50     static void __portmidi_callback (PtTimestamp timestamp, void * userData);
51     void _portmidi_callback (PtTimestamp timestamp);
52     /** __get_time_ms is given to Pm_Open functions (see WavesMidiDevice.cc)
53      *  to provide the time in milliseconds using the time of audio
54      *  transport. 
55      *  time_info is a pointer on the backend instance, which agregates the
56      *  audio and miditransports. It's not checked for correctness to consume
57      *  no time. 
58      */
59     static PmTimestamp __get_time_ms (void *time_info);
60
61     WavesMidiDevice* _get_device (const std::string& name);
62
63     std::vector<WavesMidiDevice*> _devices; // Vector for midi devices
64     bool _active;
65     bool _streaming;
66
67     size_t _input_device_count;
68     size_t _output_device_count;
69     WavesAudioBackend& _audiobackend;
70 };
71
72 } // namespace
73
74 #endif /* __libardour_waves_midi_device_manager_h__ */
75