jack-tools

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

jack.cpp (1969B)


      1 #include "jack.hpp"
      2 
      3 #include <cassert>
      4 
      5 namespace jack {
      6 
      7 // client
      8 
      9 client::client(char const* name, jack_options_t options)
     10 :	handle(create(name, options), deleter)
     11 {}
     12 
     13 void client::activate(void)
     14 {
     15 	assert(not jack_activate(**this));
     16 }
     17 
     18 void client::set_process_callback(JackProcessCallback cb, void* arg)
     19 {
     20 	jack_set_process_callback(**this, cb, arg);
     21 }
     22 void client::set_buffer_size_callback(JackBufferSizeCallback cb, void* arg)
     23 {
     24 	jack_set_buffer_size_callback(**this, cb, arg);
     25 }
     26 void client::set_sample_rate_callback(JackSampleRateCallback cb, void* arg)
     27 {
     28 	jack_set_sample_rate_callback(**this, cb, arg);
     29 }
     30 
     31 jack_client_t* client::create(char const* name, jack_options_t options)
     32 {
     33 	jack_status_t status;
     34 	jack_client_t *ptr = jack_client_open(name, options, &status);;
     35 	if (ptr)
     36 		return ptr;
     37 
     38 	std::exit(1);
     39 }
     40 
     41 void client::deleter(jack_client_t* const p)
     42 {
     43 	assert(not jack_deactivate(p));
     44 }
     45 
     46 jack_client_t* client::operator *(void)
     47 {
     48 	return handle.get();
     49 }
     50 
     51 // port
     52 
     53 port::port(client& _c, char const* name, char const* type, unsigned long flags, unsigned long buffer_size)
     54 :	c(*_c)
     55 ,	p(jack_port_register(c, name, type, flags, buffer_size))
     56 {
     57 	assert(p);
     58 }
     59 port::~port()
     60 {
     61 	if (p)
     62 		jack_port_unregister(c, p);
     63 }
     64 
     65 port::port(port&& old)
     66 :	c(old.c)
     67 ,	p(old.p)
     68 {
     69 	old.p = nullptr;
     70 }
     71 
     72 port& port::operator =(port&& old)
     73 {
     74 	if (this != &old)
     75 	{
     76 		if (p)
     77 			jack_port_unregister(c, p);
     78 
     79 		c = old.c;
     80 		p = old.p;
     81 
     82 		old.p = nullptr;
     83 	}
     84 	return *this;
     85 }
     86 
     87 jack_port_t* port::operator *(void)
     88 {
     89 	return p;
     90 }
     91 
     92 // ringbuffer
     93 
     94 ringbuffer::ringbuffer(size_t size)
     95 :	handle(jack_ringbuffer_create(size), jack_ringbuffer_free)
     96 {}
     97 
     98 size_t ringbuffer::write(void const* src, size_t size)
     99 {
    100 	return jack_ringbuffer_write(**this, static_cast<char const*>(src), size);
    101 }
    102 
    103 size_t ringbuffer::read(void* dst, size_t size)
    104 {
    105 	return jack_ringbuffer_read(**this, static_cast<char*>(dst), size);
    106 }
    107 
    108 jack_ringbuffer_t* ringbuffer::operator *(void)
    109 {
    110 	return handle.get();
    111 }
    112 
    113 
    114 }