diff options
author | Christian Glöckner <cgloeckner@freenet.de> | 2016-01-22 11:59:00 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-02-09 09:03:16 +0100 |
commit | ef3a90f4ba8d65e8c210898c48acd3a07eafaf4c (patch) | |
tree | 0fdfe740b33f8f85eccb588f4577c1115a5d54be /drumgizmo/jackclient.cc | |
parent | 06d43e27c412083cf704af48ea40e5c589504240 (diff) |
added JackaudioOutputEngine
Diffstat (limited to 'drumgizmo/jackclient.cc')
-rw-r--r-- | drumgizmo/jackclient.cc | 112 |
1 files changed, 60 insertions, 52 deletions
diff --git a/drumgizmo/jackclient.cc b/drumgizmo/jackclient.cc index e4af141..8d422cb 100644 --- a/drumgizmo/jackclient.cc +++ b/drumgizmo/jackclient.cc @@ -24,77 +24,85 @@ * along with DrumGizmo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -#include "jackclient.h" +#include <cassert> -extern "C" -{ - int _wrap_jack_process(jack_nframes_t nframes, void *arg){ - return ((JackClient*)arg)->process(nframes);} -} // extern "C" +#include "jackclient.h" -JackClient::JackClient() - : refcnt(0) -{ - jack_status_t status; +JackProcess::~JackProcess() { +} - jack_client = jack_client_open("DrumGizmo", JackNullOption, &status); +// -------------------------------------------------------------------- - jack_set_process_callback(jack_client, _wrap_jack_process, this); +JackChannel::JackChannel() + : samples{} + , client{nullptr} + , port{nullptr} { +} - active = false; +JackChannel::JackChannel(JackClient& client, std::size_t buffer_size, + std::string const & name) + : samples{} + , client{client.client} + // register jack port for given client + , port{jack_port_register(this->client, name.c_str(), + JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)} { + samples.resize(buffer_size); } -JackClient::~JackClient() -{ - jack_client_close(jack_client); +JackChannel::~JackChannel() { + if (port != nullptr) { + assert(client != nullptr); + jack_port_unregister(client, port); + } } -/* -void JackClient::addJackProcess(JackProcess *process) -{ - jack_processes.insert(process); +// -------------------------------------------------------------------- + +int _wrap_jack_process(jack_nframes_t nframes, void* arg){ + return static_cast<JackClient*>(arg)->process(nframes); } -*/ -void JackClient::removeJackProcess(JackProcess *process) -{ - jack_processes.erase(process); +JackClient::JackClient() + : client{nullptr} + , processes{} + , is_active{false} { + jack_status_t status; + client = jack_client_open("DrumGizmo", JackNullOption, &status); + jack_set_process_callback(client, _wrap_jack_process, this); } -void JackClient::activate() -{ - if(!active) jack_activate(jack_client); - active = true; +JackClient::~JackClient() { + if (client != nullptr) { + jack_client_close(client); + } } -int JackClient::process(jack_nframes_t nframes) -{ - std::set<JackProcess *>::iterator i = jack_processes.begin(); - while(i != jack_processes.end()) { - JackProcess *jp = *i; - jp->jack_process(nframes); - i++; - } +void JackClient::add(JackProcess& process) { + processes.insert(&process); +} - return 0; +void JackClient::remove(JackProcess& process) { + processes.erase(&process); } -JackClient *jackclient = NULL; +void JackClient::activate() { + if (!is_active) { + jack_activate(client); + } + is_active = true; +} -JackClient *init_jack_client() -{ - if(jackclient == NULL) jackclient = new JackClient(); - jackclient->refcnt++; - return jackclient; +int JackClient::process(jack_nframes_t num_frames) { + for (auto& ptr: processes) { + ptr->process(num_frames); + } + return 0; +} +std::size_t JackClient::getBufferSize() const { + return jack_get_buffer_size(client); } -void close_jack_client() -{ - if(jackclient) { - jackclient->refcnt--; - if(jackclient->refcnt == 0) { - delete jackclient; - jackclient = NULL; - } - } + +std::size_t JackClient::getSampleRate() const { + return jack_get_sample_rate(client); } |