summaryrefslogtreecommitdiff
path: root/drumgizmo/jackclient.cc
diff options
context:
space:
mode:
Diffstat (limited to 'drumgizmo/jackclient.cc')
-rw-r--r--drumgizmo/jackclient.cc112
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);
}