jack-tools

A handful of JACK audio tools
git clone git://henryandlizzy.uk/jack-tools
Log | Files | Refs

jack.hpp (1357B)


      1 #pragma once
      2 #include <memory>
      3 #include <jack/jack.h>
      4 #include <jack/ringbuffer.h>
      5 
      6 namespace jack {
      7 
      8 struct client
      9 {
     10 	client() = default;
     11 	client(char const* name, jack_options_t options);
     12 
     13 	void activate(void);
     14 	void set_process_callback(JackProcessCallback cb, void* arg);
     15 	void set_buffer_size_callback(JackBufferSizeCallback cb, void* arg);
     16 	void set_sample_rate_callback(JackSampleRateCallback cb, void* arg);
     17 
     18 private:
     19 	jack_client_t* operator *(void);
     20 
     21 	static jack_client_t* create(char const* name, jack_options_t options);
     22 	static void deleter(jack_client_t* const p);
     23 
     24 	std::unique_ptr<jack_client_t, void (*)(jack_client_t*)> handle = {nullptr, deleter};
     25 
     26 	friend struct port;
     27 };
     28 
     29 struct port
     30 {
     31 	port() = default;
     32 	port(client& _c, char const* name, char const* type, unsigned long flags, unsigned long buffer_size);
     33 	~port();
     34 	port(port const&) = delete;
     35 	port& operator =(port const&) = delete;
     36 
     37 	port(port&& old);
     38 	port& operator =(port&& old);
     39 
     40 	jack_port_t* operator *(void);
     41 
     42 private:
     43 	jack_client_t* c = nullptr;
     44 	jack_port_t* p = nullptr;
     45 };
     46 
     47 struct ringbuffer
     48 {
     49 	ringbuffer(size_t size);
     50 
     51 	size_t write(void const* src, size_t size);
     52 	size_t read(void* dst, size_t size);
     53 
     54 private:
     55 	std::unique_ptr<jack_ringbuffer_t, void (*)(jack_ringbuffer_t*)> handle = {nullptr, jack_ringbuffer_free};
     56 
     57 	jack_ringbuffer_t* operator *(void);
     58 };
     59 
     60 }