summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2015-07-30 18:22:16 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2016-01-20 13:31:10 +0100
commitc3841a8cec9d239bca27a113c013a032dfc658bd (patch)
treec5ce7fab48505ac383ac72acd80de030c8f18a2d
parent91f5d293bce4a15a1883d0693f478917bb256b40 (diff)
Add free-wheel mode for Jack (untested).
-rw-r--r--drumgizmo/audioinputenginedl.cc75
-rw-r--r--drumgizmo/audioinputenginedl.h4
-rw-r--r--drumgizmo/audiooutputenginedl.cc5
-rw-r--r--drumgizmo/audiooutputenginedl.h4
-rw-r--r--drumgizmo/drumgizmoc.cc4
-rw-r--r--drumgizmo/jackclient.cc31
-rw-r--r--drumgizmo/jackclient.h7
-rw-r--r--drumgizmo/output/jackaudio/jackaudio.cc1
8 files changed, 54 insertions, 77 deletions
diff --git a/drumgizmo/audioinputenginedl.cc b/drumgizmo/audioinputenginedl.cc
index cba59fa..e13bdd1 100644
--- a/drumgizmo/audioinputenginedl.cc
+++ b/drumgizmo/audioinputenginedl.cc
@@ -176,76 +176,7 @@ void AudioInputEngineDL::post()
return i_post(ptr);
}
-//#include "audioinputenginedummy.h"
-//#include "audioinputenginejackmidi.h"
-//#include "audioinputenginemidifile.h"
-
-/*
-
-typedef Device* (*create_func_t)(void);
-typedef void (*destroy_func_t)(Device*);
-
-struct device_t {
- Device* dev;
- destroy_func_t destroyer;
- void* lib;
-};
-
-int load_shared_device(device_t &dev, std::string devlib,
- std::string devfile, ConfMap devconfmap) {
- // load library
- dev.lib = dlopen(devlib.c_str(), RTLD_LAZY);
- if(!dev.lib ) {
- printf("Cannot load device: %s\n", dlerror());
- return -1;
- }
-
- create_func_t create_device = (create_func_t) dlsym(dev.lib, "create");
- const char* dlsym_error = dlerror();
- if(dlsym_error) {
- printf("Cannot load symbol create: %s\n", dlsym_error);
- return -1;
- }
-
- dev.destroyer = (destroy_func_t) dlsym(dev.lib, "destroy");
- dlsym_error = dlerror();
- if(dlsym_error) {
- printf("Cannot load symbol destroy: %s\n", dlsym_error);
- return -1;
- }
-
- dev.dev = create_device();
-
- // initialize device
- DevData devdata = dev.dev->init(devfile, devconfmap);
- if(devdata.retval != DevData::VALUE_SUCCESS) {
- printf("Error while initializing device: %s\n", devdata.msg.c_str());
- return -1;
- }
-
- return 0;
-}
-
-void unload_shared_device(device_t &dev) {
-
- dev.destroyer(dev.dev);
- dlclose(dev.lib);
+void AudioInputEngineDL::setEngine(DrumGizmo* drumgizmo)
+{
+ jackclient->setEngine(drumgizmo);
}
-*/
-
-#ifdef TEST_AUDIOINPUTENGINEDL
-//Additional dependency files
-//deps:
-//Required cflags (autoconf vars may be used)
-//cflags:
-//Required link options (autoconf vars may be used)
-//libs:
-#include "test.h"
-
-TEST_BEGIN;
-
-// TODO: Put some testcode here (see test.h for usable macros).
-
-TEST_END;
-
-#endif/*TEST_AUDIOINPUTENGINEDL*/
diff --git a/drumgizmo/audioinputenginedl.h b/drumgizmo/audioinputenginedl.h
index 94bd89d..1cf2c1d 100644
--- a/drumgizmo/audioinputenginedl.h
+++ b/drumgizmo/audioinputenginedl.h
@@ -40,6 +40,8 @@ typedef void (*input_pre_func_t)(void*);
typedef event_t* (*input_run_func_t)(void*,size_t,size_t,size_t*);
typedef void (*input_post_func_t)(void*);
+class DrumGizmo;
+
class AudioInputEngineDL : public AudioInputEngine {
public:
AudioInputEngineDL(std::string name);
@@ -56,6 +58,8 @@ public:
event_t *run(size_t pos, size_t len, size_t *nevents);
void post();
+ void setEngine(DrumGizmo* drumgizmo);
+
private:
void *ptr{nullptr};
input_create_func_t i_create{nullptr};
diff --git a/drumgizmo/audiooutputenginedl.cc b/drumgizmo/audiooutputenginedl.cc
index 042db4a..2e573cd 100644
--- a/drumgizmo/audiooutputenginedl.cc
+++ b/drumgizmo/audiooutputenginedl.cc
@@ -195,3 +195,8 @@ size_t AudioOutputEngineDL::samplerate()
if(o_samplerate) return o_samplerate(ptr);
return 44100;
}
+
+void AudioOutputEngineDL::setEngine(DrumGizmo* drumgizmo)
+{
+ jackclient->setEngine(drumgizmo);
+}
diff --git a/drumgizmo/audiooutputenginedl.h b/drumgizmo/audiooutputenginedl.h
index 4b31015..39525fa 100644
--- a/drumgizmo/audiooutputenginedl.h
+++ b/drumgizmo/audiooutputenginedl.h
@@ -48,6 +48,8 @@ typedef void (*output_post_func_t)(void*, size_t);
typedef size_t (*output_bufsize_func_t)(void*);
typedef size_t (*output_samplerate_func_t)(void*);
+class DrumGizmo;
+
class AudioOutputEngineDL : public AudioOutputEngine {
public:
AudioOutputEngineDL(std::string name);
@@ -67,6 +69,8 @@ public:
size_t getBufferSize();
size_t samplerate();
+ void setEngine(DrumGizmo* drumgizmo);
+
private:
void *ptr{nullptr};
output_create_func_t o_create{nullptr};
diff --git a/drumgizmo/drumgizmoc.cc b/drumgizmo/drumgizmoc.cc
index fba9575..8983aa3 100644
--- a/drumgizmo/drumgizmoc.cc
+++ b/drumgizmo/drumgizmoc.cc
@@ -228,7 +228,7 @@ int CliMain::run(int argc, char *argv[])
return 1;
}
- AudioInputEngine *ie = new AudioInputEngineDL(inputengine);
+ AudioInputEngineDL *ie = new AudioInputEngineDL(inputengine);
if(ie == NULL) {
printf("Invalid input engine: %s\n", inputengine.c_str());
@@ -327,6 +327,8 @@ int CliMain::run(int argc, char *argv[])
printf("Using kitfile: %s\n", kitfile.c_str());
DrumGizmo gizmo(oe, ie);
+ oe->setEngine(&gizmo);
+ ie->setEngine(&gizmo);
gizmo.setFrameSize(oe->getBufferSize());
diff --git a/drumgizmo/jackclient.cc b/drumgizmo/jackclient.cc
index e4af141..a24d53a 100644
--- a/drumgizmo/jackclient.cc
+++ b/drumgizmo/jackclient.cc
@@ -26,20 +26,33 @@
*/
#include "jackclient.h"
+#include <drumgizmo.h>
+
extern "C"
{
- int _wrap_jack_process(jack_nframes_t nframes, void *arg){
- return ((JackClient*)arg)->process(nframes);}
+
+static int jack_process_callback(jack_nframes_t nframes, void *arg)
+{
+ return ((JackClient*)arg)->process(nframes);
+}
+
+static void jack_free_wheel_callback(int starting, void *arg)
+{
+ ((JackClient*)arg)->setFreeWheel(starting);
+}
+
} // extern "C"
JackClient::JackClient()
: refcnt(0)
+ , drumgizmo(NULL)
{
jack_status_t status;
jack_client = jack_client_open("DrumGizmo", JackNullOption, &status);
- jack_set_process_callback(jack_client, _wrap_jack_process, this);
+ jack_set_process_callback(jack_client, jack_process_callback, this);
+ jack_set_freewheel_callback(jack_client, jack_free_wheel_callback, this);
active = false;
}
@@ -79,6 +92,18 @@ int JackClient::process(jack_nframes_t nframes)
return 0;
}
+void JackClient::setFreeWheel(bool freewheel)
+{
+ if(drumgizmo) {
+ drumgizmo->setFreeWheel(freewheel);
+ }
+}
+
+void JackClient::setEngine(DrumGizmo* drumgizmo)
+{
+ this->drumgizmo = drumgizmo;
+}
+
JackClient *jackclient = NULL;
JackClient *init_jack_client()
diff --git a/drumgizmo/jackclient.h b/drumgizmo/jackclient.h
index f093220..8c5954d 100644
--- a/drumgizmo/jackclient.h
+++ b/drumgizmo/jackclient.h
@@ -36,6 +36,8 @@ public:
virtual void jack_process(jack_nframes_t nframes) = 0;
};
+class DrumGizmo;
+
class JackClient {
public:
JackClient();
@@ -51,12 +53,17 @@ public:
void activate();
int process(jack_nframes_t nframes);
+ void setFreeWheel(bool freewheel);
+
jack_client_t *jack_client;
+ void setEngine(DrumGizmo* drumgizmo);
+
// Sort of private...
int refcnt;
private:
+ DrumGizmo* drumgizmo;
std::set<JackProcess *> jack_processes;
bool active;
};
diff --git a/drumgizmo/output/jackaudio/jackaudio.cc b/drumgizmo/output/jackaudio/jackaudio.cc
index 511c145..e027742 100644
--- a/drumgizmo/output/jackaudio/jackaudio.cc
+++ b/drumgizmo/output/jackaudio/jackaudio.cc
@@ -130,7 +130,6 @@ void JackAudio::post(size_t size)
void JackAudio::jack_process(jack_nframes_t nframes)
{
- //printf("o"); fflush(stdout);
for(size_t c = 0; c < nchannels; c++) {
jack_default_audio_sample_t *out =
(jack_default_audio_sample_t *) jack_port_get_buffer(output_port[c],