00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_JACK_DRIVER_HPP
00019 #define RAUL_JACK_DRIVER_HPP
00020
00021 #include <iostream>
00022 #include <string>
00023 #include <jack/jack.h>
00024 #include <jack/statistics.h>
00025
00026 namespace Raul {
00027
00028
00034 class JackDriver
00035 {
00036 public:
00037 JackDriver();
00038 virtual ~JackDriver();
00039
00040 void attach(const std::string& client_name, std::string server_name="");
00041 void detach();
00042
00043 void activate();
00044 void deactivate();
00045
00046 bool is_activated() const { return _is_activated; }
00047 bool is_attached() const { return (_client != NULL); }
00048 bool is_realtime() const { return _client && jack_is_realtime(_client); }
00049
00050 void start_transport() { jack_transport_start(_client); }
00051 void stop_transport() { jack_transport_stop(_client); }
00052
00053 void rewind_transport() {
00054 jack_position_t zero;
00055 zero.frame = 0;
00056 zero.valid = (jack_position_bits_t)0;
00057 jack_transport_reposition(_client, &zero);
00058 }
00059
00060 jack_nframes_t buffer_size();
00061 bool set_buffer_size(jack_nframes_t size);
00062
00063 inline jack_nframes_t sample_rate() { return jack_get_sample_rate(_client); }
00064
00065 inline size_t xruns() { return _xruns; }
00066 void reset_xruns();
00067
00068 inline float max_delay() { return jack_get_max_delayed_usecs(_client); }
00069 inline void reset_delay() { jack_reset_max_delayed_usecs(_client); }
00070
00071 jack_client_t* jack_client() { return _client; }
00072
00073
00074 protected:
00076 virtual void on_process(jack_nframes_t ) {}
00077
00079 virtual void on_graph_order_changed() {}
00080
00085 virtual void on_buffer_size_changed(jack_nframes_t ) {}
00086
00087 virtual void on_xrun() {}
00088 virtual void on_shutdown() {}
00089 virtual void on_error() {}
00090
00091 protected:
00092 jack_client_t* _client;
00093
00094 private:
00095
00096 static void error_cb(const char* msg);
00097
00098 void destroy_all_ports();
00099
00100 void update_time();
00101
00102 static void jack_port_registration_cb(jack_port_id_t port_id, int registered, void* me);
00103 static int jack_graph_order_cb(void* me);
00104 static int jack_xrun_cb(void* me);
00105 static int jack_buffer_size_cb(jack_nframes_t buffer_size, void* me);
00106 static int jack_process_cb(jack_nframes_t nframes, void* me);
00107
00108 static void jack_shutdown_cb(void* me);
00109
00110 bool _is_activated;
00111 jack_position_t _last_pos;
00112 jack_nframes_t _buffer_size;
00113 size_t _xruns;
00114 float _xrun_delay;
00115 };
00116
00117
00118 }
00119
00120 #endif // RAUL_JACK_DRIVER_HPP