small steps toward getting this all working - add new JackConnection object to share...
[ardour.git] / libs / ardour / ardour / jack_audiobackend.h
1 /*
2     Copyright (C) 2013 Paul Davis
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_jack_audiobackend_h__
21 #define __libardour_jack_audiobackend_h__
22
23 #include <string>
24 #include <vector>
25
26 #include <stdint.h>
27
28 #include <jack/jack.h>
29 #ifdef HAVE_JACK_SESSION
30 #include <jack/session.h>
31 #endif
32
33 #include "ardour/audio_backend.h"
34
35 namespace ARDOUR {
36
37 class JackConnection;
38
39 class JACKAudioBackend : public AudioBackend {
40   public:
41     JACKAudioBackend (AudioEngine& e);
42     ~JACKAudioBackend ();
43
44     std::string name() const;
45     bool connected() const;
46     bool is_realtime () const;
47
48     std::vector<std::string> enumerate_devices () const;
49     std::vector<float> available_sample_rates (const std::string& device) const;
50     std::vector<uint32_t> available_buffer_sizes (const std::string& device) const;
51     uint32_t available_input_channel_count (const std::string& device) const;
52     uint32_t available_output_channel_count (const std::string& device) const;
53
54     int set_device_name (const std::string&);
55     int set_sample_rate (float);
56     int set_buffer_size (uint32_t);
57     int set_sample_format (SampleFormat);
58     int set_interleaved (bool yn);
59     int set_input_channels (uint32_t);
60     int set_output_channels (uint32_t);
61     int set_systemic_input_latency (uint32_t);
62     int set_systemic_output_latency (uint32_t);
63
64     std::string  get_device_name () const;
65     float        get_sample_rate () const;
66     uint32_t     get_buffer_size () const;
67     SampleFormat get_sample_format () const;
68     bool         get_interleaved () const;
69     uint32_t     get_input_channels () const;
70     uint32_t     get_output_channels () const;
71     uint32_t     get_systemic_input_latency () const;
72     uint32_t     get_systemic_output_latency () const;
73
74     int start ();
75     int stop ();
76     int pause ();
77     int freewheel (bool);
78
79   private:
80     JackConnection* _jack_connection;
81
82     static int  _xrun_callback (void *arg);
83     static int  _graph_order_callback (void *arg);
84     static void* _process_thread (void *arg);
85     static int  _sample_rate_callback (pframes_t nframes, void *arg);
86     static int  _bufsize_callback (pframes_t nframes, void *arg);
87     static void _jack_timebase_callback (jack_transport_state_t, pframes_t, jack_position_t*, int, void*);
88     static int  _jack_sync_callback (jack_transport_state_t, jack_position_t*, void *arg);
89     static void _freewheel_callback (int , void *arg);
90     static void _registration_callback (jack_port_id_t, int, void *);
91     static void _connect_callback (jack_port_id_t, jack_port_id_t, int, void *);
92     static void _latency_callback (jack_latency_callback_mode_t, void*);
93 #ifdef HAVE_JACK_SESSION
94     static void _session_callback (jack_session_event_t *event, void *arg);
95 #endif
96     
97     void jack_timebase_callback (jack_transport_state_t, pframes_t, jack_position_t*, int);
98     int  jack_sync_callback (jack_transport_state_t, jack_position_t*);
99     int  jack_bufsize_callback (pframes_t);
100     int  jack_sample_rate_callback (pframes_t);
101     void freewheel_callback (int);
102     void connect_callback (jack_port_id_t, jack_port_id_t, int);
103     int  process_callback (pframes_t nframes);
104     void jack_latency_callback (jack_latency_callback_mode_t);
105     
106     void set_jack_callbacks ();
107     int connect_to_jack (std::string client_name, std::string session_uuid);
108     
109     struct ThreadData {
110         JACKAudioBackend* engine;
111         boost::function<void()> f;
112         size_t stacksize;
113         
114         ThreadData (JACKAudioBackend* e, boost::function<void()> fp, size_t stacksz)
115                 : engine (e) , f (fp) , stacksize (stacksz) {}
116     };
117     
118     void*  process_thread ();
119     static void* _start_process_thread (void*);
120
121     ChanCount n_physical (unsigned long) const;
122     void get_physical (DataType, unsigned long, std::vector<std::string> &);
123
124     /* pffooo */
125
126     std::string  _target_device;
127     float        _target_sample_rate;
128     uint32_t     _target_buffer_size;
129     SampleFormat _target_sample_format;
130     bool         _target_interleaved;
131     uint32_t     _target_input_channels;
132     uint32_t     _target_output_channels;
133     uint32_t      _target_systemic_input_latency;
134     uint32_t      _target_systemic_output_latency;
135
136     uint32_t _current_sample_rate;
137     uint32_t _current_buffer_size;
138     uint32_t _current_usecs_per_cycle;
139     
140 };
141
142 } // namespace
143
144 #endif /* __ardour_audiobackend_h__ */
145