aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/engine/JackDriver.cpp78
-rw-r--r--src/engine/RaulJackDriver.cpp248
-rw-r--r--src/engine/RaulJackDriver.hpp120
-rw-r--r--src/engine/machina/JackDriver.hpp44
-rw-r--r--src/engine/wscript1
5 files changed, 110 insertions, 381 deletions
diff --git a/src/engine/JackDriver.cpp b/src/engine/JackDriver.cpp
index 3f705a9..020d833 100644
--- a/src/engine/JackDriver.cpp
+++ b/src/engine/JackDriver.cpp
@@ -30,6 +30,7 @@ namespace Machina {
JackDriver::JackDriver(SharedPtr<Machine> machine)
: Driver(machine)
+ , _client(NULL)
, _machine_changed(0)
, _input_port(NULL)
, _output_port(NULL)
@@ -40,6 +41,7 @@ JackDriver::JackDriver(SharedPtr<Machine> machine)
, _quantization(0.0f)
, _record_dur(_frames_unit) // = 0
, _recording(0)
+ , _is_activated(false)
{
}
@@ -53,7 +55,21 @@ JackDriver::~JackDriver()
void
JackDriver::attach(const std::string& client_name)
{
- Raul::JackDriver::attach(client_name);
+ // Already connected
+ if (_client)
+ return;
+
+ jack_set_error_function(jack_error_cb);
+
+ _client = jack_client_open(client_name.c_str(), JackNullOption, NULL, NULL);
+
+ if (_client == NULL) {
+ _is_activated = false;
+ } else {
+ jack_set_error_function(jack_error_cb);
+ jack_on_shutdown(_client, jack_shutdown_cb, this);
+ jack_set_process_callback(_client, jack_process_cb, this);
+ }
if (jack_client()) {
@@ -98,7 +114,34 @@ JackDriver::detach()
jack_port_unregister(jack_client(), _output_port);
_output_port = NULL;
}
- Raul::JackDriver::detach();
+
+ if (_client) {
+ deactivate();
+ jack_client_close(_client);
+ _client = NULL;
+ _is_activated = false;
+ }
+}
+
+
+void
+JackDriver::activate()
+{
+ if (!jack_activate(_client)) {
+ _is_activated = true;
+ } else {
+ _is_activated = false;
+ }
+}
+
+
+void
+JackDriver::deactivate()
+{
+ if (_client)
+ jack_deactivate(_client);
+
+ _is_activated = false;
}
@@ -108,7 +151,6 @@ JackDriver::set_machine(SharedPtr<Machine> machine)
if (machine == _machine)
return;
- cout << "DRIVER MACHINE: " << machine.get() << endl;
SharedPtr<Machine> last_machine = _last_machine; // Keep a reference
_machine_changed.reset(0);
assert(!last_machine.unique());
@@ -354,4 +396,34 @@ JackDriver::finish_record()
}
+int
+JackDriver::jack_process_cb(jack_nframes_t nframes, void* jack_driver)
+{
+ JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
+
+ assert(me);
+
+ me->on_process(nframes);
+
+ return 0;
+}
+
+
+void
+JackDriver::jack_shutdown_cb(void* jack_driver)
+{
+ JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
+ assert(me);
+
+ me->_client = NULL;
+}
+
+
+void
+JackDriver::jack_error_cb(const char* msg)
+{
+ cerr << "[JACK] Error: " << msg << endl;
+}
+
+
} // namespace Machina
diff --git a/src/engine/RaulJackDriver.cpp b/src/engine/RaulJackDriver.cpp
deleted file mode 100644
index fcc0c4e..0000000
--- a/src/engine/RaulJackDriver.cpp
+++ /dev/null
@@ -1,248 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <cassert>
-#include <cstring>
-#include <string>
-#include <iostream>
-#include <jack/jack.h>
-#include <jack/statistics.h>
-#include <jack/thread.h>
-#include "RaulJackDriver.hpp"
-
-using std::cerr; using std::endl;
-using std::string;
-
-namespace Raul {
-
-
-JackDriver::JackDriver()
-: _client(NULL)
-, _is_activated(false)
-, _xruns(0)
-, _xrun_delay(0)
-{
- _last_pos.frame = 0;
- _last_pos.valid = (jack_position_bits_t)0;
-}
-
-
-JackDriver::~JackDriver()
-{
- detach();
-}
-
-
-/** Connect to Jack.
- */
-void
-JackDriver::attach(const string& client_name, string server_name)
-{
- // Already connected
- if (_client)
- return;
-
- jack_set_error_function(error_cb);
-
- if (server_name.length() > 0)
- _client = jack_client_open(client_name.c_str(), JackServerName, NULL,
- server_name.c_str(), NULL);
- else
- _client = jack_client_open(client_name.c_str(), JackNullOption, NULL, NULL);
-
- if (_client == NULL) {
- //_app->status_message("[JACK] Unable to create client");
- _is_activated = false;
- } else {
- jack_set_error_function(error_cb);
- jack_on_shutdown(_client, jack_shutdown_cb, this);
- jack_set_port_registration_callback(_client, jack_port_registration_cb, this);
- jack_set_graph_order_callback(_client, jack_graph_order_cb, this);
- jack_set_buffer_size_callback(_client, jack_buffer_size_cb, this);
- jack_set_xrun_callback(_client, jack_xrun_cb, this);
- jack_set_process_callback(_client, jack_process_cb, this);
-
- //_is_dirty = true;
- _buffer_size = jack_get_buffer_size(_client);
- }
-}
-
-
-void
-JackDriver::detach()
-{
- if (_client) {
- deactivate();
- jack_client_close(_client);
- _client = NULL;
- _is_activated = false;
- //signal_detached.emit();
- }
-}
-
-
-void
-JackDriver::activate()
-{
- if (!jack_activate(_client)) {
- _is_activated = true;
- //signal_attached.emit();
- //_app->status_message("[JACK] Attached");
- } else {
- //_app->status_message("[JACK] ERROR: Failed to attach");
- _is_activated = false;
- }
-}
-
-
-void
-JackDriver::deactivate()
-{
- if (_client)
- jack_deactivate(_client);
-
- _is_activated = false;
-}
-
-
-void
-JackDriver::jack_port_registration_cb(jack_port_id_t /*port_id*/, int /*registered*/, void* /*jack_driver*/)
-{
- /* whatever. */
-}
-
-
-int
-JackDriver::jack_graph_order_cb(void* jack_driver)
-{
- JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
-
- assert(me);
- me->on_graph_order_changed();
-
- return 0;
-}
-
-
-int
-JackDriver::jack_xrun_cb(void* jack_driver)
-{
- JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
-
- assert(me);
-
- me->_xruns++;
- me->_xrun_delay = jack_get_xrun_delayed_usecs(me->_client);
- me->reset_delay();
-
- me->on_xrun();
-
- return 0;
-}
-
-
-int
-JackDriver::jack_buffer_size_cb(jack_nframes_t buffer_size, void* jack_driver)
-{
- JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
-
- assert(me);
- me->reset_xruns();
- me->reset_delay();
- me->on_buffer_size_changed(buffer_size);
- me->_buffer_size = buffer_size;
-
- return 0;
-}
-
-
-int
-JackDriver::jack_process_cb(jack_nframes_t nframes, void* jack_driver)
-{
- JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
-
- assert(me);
-
- me->on_process(nframes);
-
- return 0;
-}
-
-
-void
-JackDriver::jack_shutdown_cb(void* jack_driver)
-{
- JackDriver* me = reinterpret_cast<JackDriver*>(jack_driver);
- assert(me);
-
- me->reset_delay();
- me->reset_xruns();
-
- me->on_shutdown();
-
- me->_client = NULL;
-}
-
-
-void
-JackDriver::error_cb(const char* msg)
-{
- cerr << "JACK ERROR: " << msg << endl;
-}
-
-
-jack_nframes_t
-JackDriver::buffer_size()
-{
- if (_is_activated)
- return _buffer_size;
- else
- return jack_get_buffer_size(_client);
-}
-
-
-void
-JackDriver::reset_xruns()
-{
- _xruns = 0;
- _xrun_delay = 0;
-}
-
-
-bool
-JackDriver::set_buffer_size(jack_nframes_t size)
-{
- if (buffer_size() == size) {
- return true;
- }
-
- if (!_client) {
- _buffer_size = size;
- return true;
- }
-
- if (jack_set_buffer_size(_client, size)) {
- //_app->status_message("[JACK] ERROR: Unable to set buffer size");
- return false;
- } else {
- return true;
- }
-}
-
-
-} // namespace Raul
-
diff --git a/src/engine/RaulJackDriver.hpp b/src/engine/RaulJackDriver.hpp
deleted file mode 100644
index e3d6076..0000000
--- a/src/engine/RaulJackDriver.hpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/* This file is part of Raul.
- * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
- *
- * Raul 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.
- *
- * Raul 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 details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef RAUL_JACK_DRIVER_HPP
-#define RAUL_JACK_DRIVER_HPP
-
-#include <iostream>
-#include <string>
-#include <jack/jack.h>
-#include <jack/statistics.h>
-
-namespace Raul {
-
-
-/** Jack based driver for an audio context.
- *
- * Apps can override the on_* methods of this class to implement reactions
- * to Jack events (e.g. new port, process callback, etc).
- */
-class JackDriver
-{
-public:
- JackDriver();
- virtual ~JackDriver();
-
- void attach(const std::string& client_name, std::string server_name="");
- void detach();
-
- void activate();
- void deactivate();
-
- bool is_activated() const { return _is_activated; }
- bool is_attached() const { return (_client != NULL); }
- bool is_realtime() const { return _client && jack_is_realtime(_client); }
-
- void start_transport() { jack_transport_start(_client); }
- void stop_transport() { jack_transport_stop(_client); }
-
- void rewind_transport() {
- jack_position_t zero;
- zero.frame = 0;
- zero.valid = (jack_position_bits_t)0;
- jack_transport_reposition(_client, &zero);
- }
-
- jack_nframes_t buffer_size();
- bool set_buffer_size(jack_nframes_t size);
-
- inline jack_nframes_t sample_rate() { return jack_get_sample_rate(_client); }
-
- inline size_t xruns() { return _xruns; }
- void reset_xruns();
-
- inline float max_delay() { return jack_get_max_delayed_usecs(_client); }
- inline void reset_delay() { jack_reset_max_delayed_usecs(_client); }
-
- jack_client_t* jack_client() { return _client; }
-
-
-protected:
- /** Process callback. Derived classes should do all audio processing here. */
- virtual void on_process(jack_nframes_t /*nframes*/) {}
-
- /** Graph order change callback. */
- virtual void on_graph_order_changed() {}
-
- /** Buffer size changed callback.
- * At the time this is called, buffer_size() will still return the old
- * size. Immediately afterwards, it will be set to the new value.
- */
- virtual void on_buffer_size_changed(jack_nframes_t /*size*/) {}
-
- virtual void on_xrun() {}
- virtual void on_shutdown() {}
- virtual void on_error() {}
-
-protected:
- jack_client_t* _client;
-
-private:
-
- static void error_cb(const char* msg);
-
- void destroy_all_ports();
-
- void update_time();
-
- static void jack_port_registration_cb(jack_port_id_t port_id, int registered, void* me);
- static int jack_graph_order_cb(void* me);
- static int jack_xrun_cb(void* me);
- static int jack_buffer_size_cb(jack_nframes_t buffer_size, void* me);
- static int jack_process_cb(jack_nframes_t nframes, void* me);
-
- static void jack_shutdown_cb(void* me);
-
- bool _is_activated;
- jack_position_t _last_pos;
- jack_nframes_t _buffer_size;
- size_t _xruns;
- float _xrun_delay;
-};
-
-
-} // namespace Raul
-
-#endif // RAUL_JACK_DRIVER_HPP
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
index 8e13d08..0b2851b 100644
--- a/src/engine/machina/JackDriver.hpp
+++ b/src/engine/machina/JackDriver.hpp
@@ -19,15 +19,18 @@
#define MACHINA_JACKDRIVER_HPP
#include <boost/enable_shared_from_this.hpp>
+
+#include <jack/jack.h>
#include <jack/midiport.h>
-#include "raul/SharedPtr.hpp"
+
+#include "raul/Command.hpp"
#include "raul/DoubleBuffer.hpp"
#include "raul/EventRingBuffer.hpp"
#include "raul/Semaphore.hpp"
-#include "raul/Command.hpp"
-#include "RaulJackDriver.hpp"
-#include "Machine.hpp"
+#include "raul/SharedPtr.hpp"
+
#include "Driver.hpp"
+#include "Machine.hpp"
#include "Recorder.hpp"
namespace Machina {
@@ -41,8 +44,7 @@ class Node;
* "Ticks" are individual frames when running under this driver, and all code
* in the processing context must be realtime safe (non-blocking).
*/
-class JackDriver : public Raul::JackDriver,
- public Machina::Driver,
+class JackDriver : public Machina::Driver,
public boost::enable_shared_from_this<JackDriver> {
public:
JackDriver(SharedPtr<Machine> machine = SharedPtr<Machine>());
@@ -51,8 +53,8 @@ public:
void attach(const std::string& client_name);
void detach();
- void activate() { Raul::JackDriver::activate(); }
- void deactivate() { Raul::JackDriver::deactivate(); }
+ void activate();
+ void deactivate();
void set_machine(SharedPtr<Machine> machine);
@@ -69,11 +71,34 @@ public:
void start_record(bool step);
void finish_record();
+ void start_transport() { jack_transport_start(_client); }
+ void stop_transport() { jack_transport_stop(_client); }
+
+ void rewind_transport() {
+ jack_position_t zero;
+ zero.frame = 0;
+ zero.valid = (jack_position_bits_t)0;
+ jack_transport_reposition(_client, &zero);
+ }
+
+ bool is_activated() const { return _is_activated; }
+ bool is_attached() const { return (_client != NULL); }
+ bool is_realtime() const { return _client && jack_is_realtime(_client); }
+
+ jack_nframes_t sample_rate() const { return jack_get_sample_rate(_client); }
+ jack_client_t* jack_client() const { return _client; }
+
private:
void process_input(SharedPtr<Machine> machine,
const Raul::TimeSlice& time);
+
+ static void jack_error_cb(const char* msg);
+ static int jack_process_cb(jack_nframes_t nframes, void* me);
+ static void jack_shutdown_cb(void* me);
+
+ void on_process(jack_nframes_t nframes);
- virtual void on_process(jack_nframes_t nframes);
+ jack_client_t* _client;
Raul::Semaphore _machine_changed;
SharedPtr<Machine> _last_machine;
@@ -93,6 +118,7 @@ private:
Raul::TimeDuration _record_dur;
Raul::AtomicInt _recording;
SharedPtr<Recorder> _recorder;
+ bool _is_activated;
};
diff --git a/src/engine/wscript b/src/engine/wscript
index 513ed22..e420abb 100644
--- a/src/engine/wscript
+++ b/src/engine/wscript
@@ -15,7 +15,6 @@ def build(bld):
MidiAction.cpp
Mutation.cpp
Node.cpp
- RaulJackDriver.cpp
Recorder.cpp
SMFDriver.cpp
'''