summaryrefslogtreecommitdiff
path: root/src/jackclient.cc
diff options
context:
space:
mode:
authordeva <deva>2008-07-20 21:14:10 +0000
committerdeva <deva>2008-07-20 21:14:10 +0000
commitad01025218b7883fcec1e9ef9f6df5b5f6f698e8 (patch)
tree76083f1744c327a9ab3582fc534d7cff6c6941c1 /src/jackclient.cc
parentdd2fef8f90adf05991d2bd37b0ecfeb12cd191bf (diff)
Added foundation for at jack client class.
Diffstat (limited to 'src/jackclient.cc')
-rw-r--r--src/jackclient.cc183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/jackclient.cc b/src/jackclient.cc
new file mode 100644
index 0000000..af25da0
--- /dev/null
+++ b/src/jackclient.cc
@@ -0,0 +1,183 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/***************************************************************************
+ * jackclient.cc
+ *
+ * Sun Jul 20 21:48:44 CEST 2008
+ * Copyright 2008 Bent Bisballe Nyeng
+ * deva@aasimon.org
+ ****************************************************************************/
+
+/*
+ * This file is part of DrumGizmo.
+ *
+ * DrumGizmo is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * DrumGizmo is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * 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"
+
+extern "C"
+{
+ void _wrap_jack_shutdown(void *arg){
+ ((JackClient*)arg)->shutdown();}
+ int _wrap_jack_process(jack_nframes_t nframes, void *arg){
+ return ((JackClient*)arg)->process(nframes);}
+ void _wrap_jack_thread_init(void *arg){
+ ((JackClient*)arg)->thread_init();}
+ void _wrap_jack_freewheel_mode(int freewheel_mode, void *arg){
+ ((JackClient*)arg)->freewheel_mode(freewheel_mode);}
+ int _wrap_jack_buffer_size(jack_nframes_t nframes, void *arg){
+ return ((JackClient*)arg)->buffer_size(nframes);}
+ int _wrap_jack_sample_rate(jack_nframes_t nframes, void *arg){
+ return ((JackClient*)arg)->sample_rate(nframes);}
+ void _wrap_jack_port_registration(jack_port_id_t port, int i, void *arg){
+ ((JackClient*)arg)->port_registration(port, i);}
+ int _wrap_jack_graph_order(void *arg){
+ return ((JackClient*)arg)->graph_order();}
+ int _wrap_jack_xrun(void *arg){
+ return ((JackClient*)arg)->xrun();}
+} // extern "C"
+
+JackClient::JackClient(size_t num_inputs, size_t num_outputs)
+{
+ jack_status_t status;
+
+ jack_client = jack_client_open("DrumGizmo", JackNullOption, &status);
+
+ // Setup input port
+ midi_port = jack_port_register(jack_client,
+ "Midi in",
+ JACK_DEFAULT_MIDI_TYPE,
+ JackPortIsInput,// | JackPortIsTerminal,
+ 0);
+
+ // Setup input ports
+ for(size_t i = 0; i < num_inputs; i++) {
+ char port_name[32];
+ sprintf(port_name, "Port %i", i);
+ jack_port_t *port = jack_port_register(jack_client,
+ port_name,
+ JACK_DEFAULT_AUDIO_TYPE,
+ JackPortIsInput | JackPortIsTerminal,
+ 0);
+ input_ports.push_back(port);
+ }
+
+ // Setup output ports
+ for(size_t i = 0; i < num_outputs; i++) {
+ char port_name[32];
+ sprintf(port_name, "Port %i", i);
+ jack_port_t *port = jack_port_register(jack_client,
+ port_name,
+ JACK_DEFAULT_AUDIO_TYPE,
+ JackPortIsOutput | JackPortIsTerminal,
+ 0);
+ output_ports.push_back(port);
+ }
+
+ jack_on_shutdown(jack_client, _wrap_jack_shutdown, this);
+ jack_set_process_callback(jack_client, _wrap_jack_process, this);
+ jack_set_thread_init_callback(jack_client, _wrap_jack_thread_init, this);
+ jack_set_freewheel_callback(jack_client, _wrap_jack_freewheel_mode, this);
+ jack_set_buffer_size_callback(jack_client, _wrap_jack_buffer_size, this);
+ jack_set_sample_rate_callback(jack_client, _wrap_jack_sample_rate, this);
+ jack_set_port_registration_callback(jack_client, _wrap_jack_port_registration, this);
+ jack_set_graph_order_callback(jack_client, _wrap_jack_graph_order, this);
+ jack_set_xrun_callback(jack_client, _wrap_jack_xrun, this);
+}
+
+JackClient::~JackClient()
+{
+ jack_client_close(jack_client);
+}
+
+void JackClient::activate()
+{
+ jack_activate(jack_client);
+}
+
+void JackClient::shutdown()
+{
+}
+
+int JackClient::process(jack_nframes_t nframes)
+{
+ /*
+ int pos = -1;
+ Params *params = (Params*)arg;
+
+ void *midibuffer = jack_port_get_buffer(params->midi_port, nframes);
+ jack_nframes_t midievents = jack_midi_get_event_count(midibuffer);
+ for(jack_nframes_t i = 0; i < midievents; i++) {
+ jack_midi_event_t event;
+ jack_midi_event_get(&event, midibuffer, i);
+ printf("[ Time: %d Size: %d ", event.time, event.size);
+ for(int j = 0; j < event.size; j++) {
+ jack_midi_data_t m = event.buffer[j];
+ printf(" Data: %d ", m);
+ }
+ printf("]\n");
+ for(int i = 0; i < NUM_PORTS; i++) {
+ pos = event.time;
+ }
+ }
+
+ for(int i = 0; i < NUM_PORTS; i++) {
+ jack_default_audio_sample_t *buffer;
+ buffer = (jack_default_audio_sample_t *)jack_port_get_buffer(params->drums[i].port, nframes);
+ for(int j = 0; j < nframes; j++) {
+ if(j == pos) params->drums[i].samples[0].p = -j;
+ offset_t p = params->drums[i].samples[0].p;
+ size_t data_size = params->drums[i].samples[0].data_size;
+ jack_default_audio_sample_t *samples = params->drums[i].samples[0].data;
+ if(p+j > data_size) buffer[j] = 0;
+ else buffer[j] = samples[(j + p) % data_size];
+ // params->drums[i].samples[0].p ++;
+ }
+ params->drums[i].samples[0].p += nframes;
+ }
+ */
+ return 0;
+}
+
+void JackClient::thread_init()
+{
+}
+
+void JackClient::freewheel_mode(int freewheel_mode)
+{
+}
+
+int JackClient::buffer_size(jack_nframes_t nframes)
+{
+ return 0;
+}
+
+int JackClient::sample_rate(jack_nframes_t nframes)
+{
+ return 0;
+}
+
+void JackClient::port_registration(jack_port_id_t port, int i)
+{
+}
+
+int JackClient::graph_order()
+{
+ return 0;
+}
+
+int JackClient::xrun()
+{
+ return 0;
+}