RAUL  0.5.1
JackDriver.hpp
1 /* This file is part of Raul.
2  * Copyright (C) 2007 Dave Robillard <http://drobilla.net>
3  *
4  * Raul is free software; you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18 #ifndef RAUL_JACK_DRIVER_HPP
19 #define RAUL_JACK_DRIVER_HPP
20 
21 #include <iostream>
22 #include <string>
23 #include <jack/jack.h>
24 #include <jack/statistics.h>
25 
26 namespace Raul {
27 
28 
35 {
36 public:
37  JackDriver();
38  virtual ~JackDriver();
39 
40  void attach(const std::string& client_name, std::string server_name="");
41  void detach();
42 
43  void activate();
44  void deactivate();
45 
46  bool is_activated() const { return _is_activated; }
47  bool is_attached() const { return (_client != NULL); }
48  bool is_realtime() const { return _client && jack_is_realtime(_client); }
49 
50  void start_transport() { jack_transport_start(_client); }
51  void stop_transport() { jack_transport_stop(_client); }
52 
53  void rewind_transport() {
54  jack_position_t zero;
55  zero.frame = 0;
56  zero.valid = (jack_position_bits_t)0;
57  jack_transport_reposition(_client, &zero);
58  }
59 
60  jack_nframes_t buffer_size();
61  bool set_buffer_size(jack_nframes_t size);
62 
63  inline jack_nframes_t sample_rate() { return jack_get_sample_rate(_client); }
64 
65  inline size_t xruns() { return _xruns; }
66  void reset_xruns();
67 
68  inline float max_delay() { return jack_get_max_delayed_usecs(_client); }
69  inline void reset_delay() { jack_reset_max_delayed_usecs(_client); }
70 
71  jack_client_t* jack_client() { return _client; }
72 
73 
74 protected:
76  virtual void on_process(jack_nframes_t /*nframes*/) {}
77 
79  virtual void on_graph_order_changed() {}
80 
85  virtual void on_buffer_size_changed(jack_nframes_t /*size*/) {}
86 
87  virtual void on_xrun() {}
88  virtual void on_shutdown() {}
89  virtual void on_error() {}
90 
91 protected:
92  jack_client_t* _client;
93 
94 private:
95 
96  static void error_cb(const char* msg);
97 
98  void destroy_all_ports();
99 
100  void update_time();
101 
102  static void jack_port_registration_cb(jack_port_id_t port_id, int registered, void* me);
103  static int jack_graph_order_cb(void* me);
104  static int jack_xrun_cb(void* me);
105  static int jack_buffer_size_cb(jack_nframes_t buffer_size, void* me);
106  static int jack_process_cb(jack_nframes_t nframes, void* me);
107 
108  static void jack_shutdown_cb(void* me);
109 
110  bool _is_activated;
111  jack_position_t _last_pos;
112  jack_nframes_t _buffer_size;
113  size_t _xruns;
114  float _xrun_delay;
115 };
116 
117 
118 } // namespace Raul
119 
120 #endif // RAUL_JACK_DRIVER_HPP
virtual void on_buffer_size_changed(jack_nframes_t)
Buffer size changed callback.
Definition: JackDriver.hpp:85
Jack based driver for an audio context.
Definition: JackDriver.hpp:34
Definition: Array.hpp:26
virtual void on_graph_order_changed()
Graph order change callback.
Definition: JackDriver.hpp:79
virtual void on_process(jack_nframes_t)
Process callback.
Definition: JackDriver.hpp:76