2 Copyright (C) 2013 Paul Davis
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.
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.
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.
20 #ifndef __libardour_jack_audiobackend_h__
21 #define __libardour_jack_audiobackend_h__
29 #include <boost/shared_ptr.hpp>
31 #include <jack/jack.h>
32 #ifdef HAVE_JACK_SESSION
33 #include <jack/session.h>
36 #include "ardour/audio_backend.h"
42 class JACKAudioBackend : public AudioBackend {
44 JACKAudioBackend (AudioEngine& e, boost::shared_ptr<JackConnection>);
47 std::string name() const;
48 void* private_handle() const;
49 bool connected() const;
50 bool is_realtime () const;
52 bool requires_driver_selection() const;
53 std::vector<std::string> enumerate_drivers () const;
54 int set_driver (const std::string&);
56 std::vector<std::string> enumerate_devices () const;
58 std::vector<float> available_sample_rates (const std::string& device) const;
59 std::vector<uint32_t> available_buffer_sizes (const std::string& device) const;
60 uint32_t available_input_channel_count (const std::string& device) const;
61 uint32_t available_output_channel_count (const std::string& device) const;
63 int set_device_name (const std::string&);
64 int set_sample_rate (float);
65 int set_buffer_size (uint32_t);
66 int set_sample_format (SampleFormat);
67 int set_interleaved (bool yn);
68 int set_input_channels (uint32_t);
69 int set_output_channels (uint32_t);
70 int set_systemic_input_latency (uint32_t);
71 int set_systemic_output_latency (uint32_t);
73 std::string device_name () const;
74 float sample_rate () const;
75 uint32_t buffer_size () const;
76 SampleFormat sample_format () const;
77 bool interleaved () const;
78 uint32_t input_channels () const;
79 uint32_t output_channels () const;
80 uint32_t systemic_input_latency () const;
81 uint32_t systemic_output_latency () const;
88 float cpu_load() const;
90 pframes_t sample_time ();
91 pframes_t sample_time_at_cycle_start ();
92 pframes_t samples_since_cycle_start ();
94 size_t raw_buffer_size (DataType t);
96 int create_process_thread (boost::function<void()> func, pthread_t*, size_t stacksize);
98 void transport_start ();
99 void transport_stop ();
100 void transport_locate (framepos_t /*pos*/);
101 TransportState transport_state () const;
102 framepos_t transport_frame() const;
104 int set_time_master (bool /*yn*/);
105 bool get_sync_offset (pframes_t& /*offset*/) const;
107 void update_latencies ();
109 static bool already_configured();
112 boost::shared_ptr<JackConnection> _jack_connection; //< shared with JACKPortEngine
115 std::map<DataType,size_t> _raw_buffer_sizes;
117 static int _xrun_callback (void *arg);
118 static void* _process_thread (void *arg);
119 static int _sample_rate_callback (pframes_t nframes, void *arg);
120 static int _bufsize_callback (pframes_t nframes, void *arg);
121 static void _jack_timebase_callback (jack_transport_state_t, pframes_t, jack_position_t*, int, void*);
122 static int _jack_sync_callback (jack_transport_state_t, jack_position_t*, void *arg);
123 static void _freewheel_callback (int , void *arg);
124 static void _latency_callback (jack_latency_callback_mode_t, void*);
125 #ifdef HAVE_JACK_SESSION
126 static void _session_callback (jack_session_event_t *event, void *arg);
129 void jack_timebase_callback (jack_transport_state_t, pframes_t, jack_position_t*, int);
130 int jack_sync_callback (jack_transport_state_t, jack_position_t*);
131 int jack_bufsize_callback (pframes_t);
132 int jack_sample_rate_callback (pframes_t);
133 void freewheel_callback (int);
134 int process_callback (pframes_t nframes);
135 void jack_latency_callback (jack_latency_callback_mode_t);
136 void disconnected (const char*);
138 void set_jack_callbacks ();
139 int reconnect_to_jack ();
142 JACKAudioBackend* engine;
143 boost::function<void()> f;
146 ThreadData (JACKAudioBackend* e, boost::function<void()> fp, size_t stacksz)
147 : engine (e) , f (fp) , stacksize (stacksz) {}
150 void* process_thread ();
151 static void* _start_process_thread (void*);
153 ChanCount n_physical (unsigned long) const;
155 void setup_jack_startup_command ();
159 std::string _target_driver;
160 std::string _target_device;
161 float _target_sample_rate;
162 uint32_t _target_buffer_size;
163 SampleFormat _target_sample_format;
164 bool _target_interleaved;
165 uint32_t _target_input_channels;
166 uint32_t _target_output_channels;
167 uint32_t _target_systemic_input_latency;
168 uint32_t _target_systemic_output_latency;
170 uint32_t _current_sample_rate;
171 uint32_t _current_buffer_size;
172 uint32_t _current_usecs_per_cycle;
173 uint32_t _current_systemic_input_latency;
174 uint32_t _current_systemic_output_latency;
180 #endif /* __ardour_audiobackend_h__ */