diff options
author | David Robillard <d@drobilla.net> | 2010-01-05 21:32:55 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2010-01-05 21:32:55 +0000 |
commit | 534b3d2248884d5a8352c2239c668e632ab16b41 (patch) | |
tree | 1307d53d6c62d3ab51b1ad0f3056d387fba9a682 /src | |
parent | f4800095303dbcdec079d9c96b921f169696903c (diff) | |
download | ingen-534b3d2248884d5a8352c2239c668e632ab16b41.tar.gz ingen-534b3d2248884d5a8352c2239c668e632ab16b41.tar.bz2 ingen-534b3d2248884d5a8352c2239c668e632ab16b41.zip |
Merge JackMidiDriver and JackAudioDriver.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2343 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
29 files changed, 200 insertions, 830 deletions
diff --git a/src/engine/BufferFactory.cpp b/src/engine/BufferFactory.cpp index 8a5617fa..02104b92 100644 --- a/src/engine/BufferFactory.cpp +++ b/src/engine/BufferFactory.cpp @@ -23,7 +23,7 @@ #include "ObjectBuffer.hpp" #include "BufferFactory.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "ThreadManager.hpp" namespace Ingen { @@ -92,13 +92,13 @@ BufferFactory::create(Shared::PortType type, size_t size) } else if (type.is_audio()) { if (size == 0) size = sizeof(LV2_Object) + sizeof(LV2_Vector_Body) - + _engine.audio_driver()->buffer_size() * sizeof(float); + + _engine.driver()->buffer_size() * sizeof(float); AudioBuffer* ret = new AudioBuffer(*this, type, size); ret->object()->type = _map->object_class_float32; buffer = ret; } else if (type.is_events()) { if (size == 0) - size = _engine.audio_driver()->buffer_size() * 4; // FIXME + size = _engine.driver()->buffer_size() * 4; // FIXME buffer = new EventBuffer(*this, size); } else if (type.is_value() || type.is_message()) { if (size == 0) diff --git a/src/engine/ConnectionImpl.cpp b/src/engine/ConnectionImpl.cpp index 6317c632..c80b8000 100644 --- a/src/engine/ConnectionImpl.cpp +++ b/src/engine/ConnectionImpl.cpp @@ -58,7 +58,7 @@ ConnectionImpl::ConnectionImpl(BufferFactory& bufs, PortImpl* src_port, PortImpl if (must_queue()) _queue = new Raul::RingBuffer<LV2_Object>(src_port->buffer_size() * 2); - dump(); + //dump(); } diff --git a/src/engine/Driver.hpp b/src/engine/Driver.hpp index 7a268e3c..cc1bec6c 100644 --- a/src/engine/Driver.hpp +++ b/src/engine/Driver.hpp @@ -22,6 +22,7 @@ #include <boost/utility.hpp> #include "raul/Deletable.hpp" #include "interface/PortType.hpp" +#include "interface/EventType.hpp" #include "DuplexPort.hpp" namespace Raul { class Path; } @@ -29,6 +30,7 @@ namespace Raul { class Path; } namespace Ingen { class DuplexPort; +class ProcessContext; /** Representation of a "system" (eg outside Ingen) port. @@ -43,17 +45,19 @@ class DriverPort : boost::noncopyable, public Raul::Deletable { public: virtual ~DriverPort() {} - /** Set the name of the system port */ + /** Set the name of the system port according to new path */ virtual void move(const Raul::Path& path) = 0; + /** Create system port */ virtual void create() = 0; + + /** Destroy system port */ virtual void destroy() = 0; bool is_input() const { return _patch_port->is_input(); } DuplexPort* patch_port() const { return _patch_port; } protected: - /** is_input from the perspective outside of ingen */ DriverPort(DuplexPort* port) : _patch_port(port) {} DuplexPort* _patch_port; @@ -68,34 +72,51 @@ protected: * * \ingroup engine */ -class Driver : boost::noncopyable -{ +class Driver : boost::noncopyable { public: - Driver(Shared::PortType type) - : _type(type) - {} - virtual ~Driver() {} + /** Activate driver (begin processing graph and events). */ virtual void activate() = 0; + + /** Deactivate driver (stop processing graph and events). */ virtual void deactivate() = 0; + /** Return true iff driver is activated (processing graph and events). */ virtual bool is_activated() const = 0; /** Create a port ready to be inserted with add_input (non realtime). - * - * May return NULL if the Driver can not drive the port for some reason. + * May return NULL if the Driver can not create the port for some reason. */ virtual DriverPort* create_port(DuplexPort* patch_port) = 0; + /** Return the DriverPort for a particular path, iff one exists. */ virtual DriverPort* driver_port(const Raul::Path& path) = 0; + /** Add a system visible port (e.g. a port on the root patch). */ virtual void add_port(DriverPort* port) = 0; + /** Remove a system visible port. */ virtual Raul::List<DriverPort*>::Node* remove_port(const Raul::Path& path) = 0; -protected: - Shared::PortType _type; + /** Return true iff this driver supports the given type of I/O */ + virtual bool supports(Shared::PortType port_type, Shared::EventType event_type) = 0; + + virtual void set_root_patch(PatchImpl* patch) = 0; + virtual PatchImpl* root_patch() = 0; + + /** Return the buffer size in frames (i.e. the maximum length of a process cycle) */ + virtual SampleCount buffer_size() const = 0; + + /** Return the sample rate in Hz */ + virtual SampleCount sample_rate() const = 0; + + /** Return the current frame time (running counter) */ + virtual SampleCount frame_time() const = 0; + + virtual bool is_realtime() const = 0; + + virtual ProcessContext& context() = 0; }; diff --git a/src/engine/Engine.cpp b/src/engine/Engine.cpp index ab7861b0..9a8bd182 100644 --- a/src/engine/Engine.cpp +++ b/src/engine/Engine.cpp @@ -29,16 +29,14 @@ #include "shared/LV2Features.hpp" #include "shared/LV2URIMap.hpp" #include "shared/Store.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "BufferFactory.hpp" #include "ClientBroadcaster.hpp" #include "Engine.hpp" #include "EngineStore.hpp" #include "Event.hpp" #include "MessageContext.hpp" -#include "MidiDriver.hpp" #include "NodeFactory.hpp" -#include "OSCDriver.hpp" #include "PatchImpl.hpp" #include "PostProcessor.hpp" #include "PostProcessor.hpp" @@ -58,8 +56,6 @@ using namespace Shared; Engine::Engine(Ingen::Shared::World* world) : _world(world) - , _midi_driver(NULL) - , _osc_driver(NULL) , _maid(new Raul::Maid(maid_queue_size)) , _post_processor(new PostProcessor(*this, post_processor_queue_size)) , _broadcaster(new ClientBroadcaster()) @@ -90,7 +86,6 @@ Engine::~Engine() delete _broadcaster; delete _node_factory; - delete _osc_driver; delete _post_processor; delete _maid; @@ -106,34 +101,6 @@ Engine::engine_store() const } -Driver* -Engine::driver(PortType type, EventType event_type) -{ - if (type == PortType::AUDIO) { - return _audio_driver.get(); - } else if (type == PortType::EVENTS) { - if (event_type == EventType::MIDI) { - return _midi_driver; - } else if (event_type == EventType::OSC) { - return _osc_driver; - } - } - - return NULL; -} - - -void -Engine::set_driver(PortType type, SharedPtr<Driver> driver) -{ - if (type == PortType::AUDIO) { - _audio_driver = PtrCast<AudioDriver>(driver); - } else { - cerr << "WARNING: Unable to set driver for type " << type.uri() << endl; - } -} - - int Engine::main() { @@ -180,49 +147,38 @@ Engine::add_event_source(SharedPtr<EventSource> source) } -void -Engine::set_midi_driver(MidiDriver* driver) -{ - _midi_driver = driver; -} - - bool Engine::activate() { - assert(_audio_driver); + assert(_driver); _message_context->Thread::start(); uint32_t parallelism = _world->conf->option("parallelism").get_int32(); - if (!_midi_driver) - _midi_driver = new DummyMidiDriver(); - for (EventSources::iterator i = _event_sources.begin(); i != _event_sources.end(); ++i) (*i)->activate_source(); // Create root patch - PatchImpl* root_patch = _audio_driver->root_patch(); + PatchImpl* root_patch = _driver->root_patch(); if (!root_patch) { root_patch = new PatchImpl(*this, "", 1, NULL, - _audio_driver->sample_rate(), _audio_driver->buffer_size(), 1); + _driver->sample_rate(), _driver->buffer_size(), 1); root_patch->meta().set_property("rdf:type", Raul::Atom(Raul::Atom::URI, "ingen:Patch")); root_patch->meta().set_property("ingen:polyphony", Raul::Atom(int32_t(1))); root_patch->set_property("rdf:type", Raul::Atom(Raul::Atom::URI, "ingen:Node")); root_patch->activate(); _world->store->add(root_patch); root_patch->compiled_patch(root_patch->compile()); - _audio_driver->set_root_patch(root_patch); + _driver->set_root_patch(root_patch); } - _audio_driver->activate(); - _midi_driver->attach(*_audio_driver.get()); + _driver->activate(); _process_slaves.clear(); _process_slaves.reserve(parallelism); for (size_t i=0; i < parallelism - 1; ++i) - _process_slaves.push_back(new ProcessSlave(*this, _audio_driver->is_realtime())); + _process_slaves.push_back(new ProcessSlave(*this, _driver->is_realtime())); root_patch->enable(); @@ -251,9 +207,9 @@ Engine::deactivate() if (_midi_driver) _midi_driver->deactivate(); - _audio_driver->deactivate(); + _driver->deactivate(); - _audio_driver->root_patch()->deactivate(); + _driver->root_patch()->deactivate(); /*for (size_t i=0; i < _process_slaves.size(); ++i) { delete _process_slaves[i]; @@ -264,7 +220,7 @@ Engine::deactivate() // Finalize any lingering events (unlikely) //_post_processor->process(); - //_audio_driver.reset(); + //_driver.reset(); //_event_sources.clear(); _activated = false; diff --git a/src/engine/Engine.hpp b/src/engine/Engine.hpp index a8674c12..beb505cf 100644 --- a/src/engine/Engine.hpp +++ b/src/engine/Engine.hpp @@ -33,7 +33,7 @@ namespace Raul { class Maid; } namespace Ingen { -class AudioDriver; +class Driver; class BufferFactory; class ClientBroadcaster; class Driver; @@ -41,9 +41,7 @@ class EngineStore; class Event; class EventSource; class MessageContext; -class MidiDriver; class NodeFactory; -class OSCDriver; class PostProcessor; class ProcessContext; class ProcessSlave; @@ -83,9 +81,7 @@ public: virtual bool activated() { return _activated; } Raul::Maid* maid() const { return _maid; } - AudioDriver* audio_driver() const { return _audio_driver.get(); } - MidiDriver* midi_driver() const { return _midi_driver; } - OSCDriver* osc_driver() const { return _osc_driver; } + Driver* driver() const { return _driver.get(); } PostProcessor* post_processor() const { return _post_processor; } ClientBroadcaster* broadcaster() const { return _broadcaster; } NodeFactory* node_factory() const { return _node_factory; } @@ -94,12 +90,7 @@ public: SharedPtr<EngineStore> engine_store() const; - /** Return the active driver for the given type */ - Driver* driver(Shared::PortType type, Shared::EventType event_type); - - /** Set the driver for the given data type (replacing the old) */ - virtual void set_driver(Shared::PortType type, SharedPtr<Driver> driver); - virtual void set_midi_driver(MidiDriver* driver); + virtual void set_driver(SharedPtr<Driver> driver) { _driver = driver; } virtual void add_event_source(SharedPtr<EventSource> source); @@ -117,9 +108,8 @@ private: ProcessSlaves _process_slaves; Ingen::Shared::World* _world; - SharedPtr<AudioDriver> _audio_driver; - MidiDriver* _midi_driver; - OSCDriver* _osc_driver; + SharedPtr<Driver> _driver; + SharedPtr<Driver> _midi_driver; Raul::Maid* _maid; PostProcessor* _post_processor; ClientBroadcaster* _broadcaster; diff --git a/src/engine/EventSource.hpp b/src/engine/EventSource.hpp index 39666254..0db5c879 100644 --- a/src/engine/EventSource.hpp +++ b/src/engine/EventSource.hpp @@ -28,7 +28,7 @@ class ProcessContext; /** Source for events to run in the audio thread. * - * The AudioDriver gets events from an EventSource in the process callback + * The Driver gets events from an EventSource in the process callback * (realtime audio thread) and executes them, then they are sent to the * PostProcessor and finalised (post-processing thread). * diff --git a/src/engine/InternalPlugin.cpp b/src/engine/InternalPlugin.cpp index a3d22e10..0c848feb 100644 --- a/src/engine/InternalPlugin.cpp +++ b/src/engine/InternalPlugin.cpp @@ -21,7 +21,7 @@ #include "internals/Trigger.hpp" #include "internals/Controller.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; @@ -47,8 +47,8 @@ InternalPlugin::instantiate(BufferFactory& bufs, { assert(_type == Internal); - SampleCount srate = engine.audio_driver()->sample_rate(); - SampleCount buffer_size = engine.audio_driver()->buffer_size(); + SampleCount srate = engine.driver()->sample_rate(); + SampleCount buffer_size = engine.driver()->buffer_size(); const string uri_str = uri().str(); if (uri_str == NS_INTERNALS "Note") { diff --git a/src/engine/JackAudioDriver.cpp b/src/engine/JackAudioDriver.cpp index d4c4da25..44951f27 100644 --- a/src/engine/JackAudioDriver.cpp +++ b/src/engine/JackAudioDriver.cpp @@ -15,27 +15,29 @@ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "JackAudioDriver.hpp" -#include "ingen-config.h" -#include "tuning.hpp" #include <iostream> #include <cstdlib> +#include <jack/midiport.h> #include "raul/List.hpp" +#include "shared/LV2Features.hpp" +#include "shared/LV2URIMap.hpp" #include "AudioBuffer.hpp" #include "DuplexPort.hpp" #include "Engine.hpp" #include "Event.hpp" +#include "EventBuffer.hpp" #include "EventSource.hpp" #include "EventSource.hpp" -#include "JackMidiDriver.hpp" +#include "JackAudioDriver.hpp" #include "MessageContext.hpp" -#include "MidiDriver.hpp" #include "PatchImpl.hpp" #include "PortImpl.hpp" #include "PostProcessor.hpp" #include "ProcessSlave.hpp" #include "QueuedEvent.hpp" #include "ThreadManager.hpp" +#include "ingen-config.h" +#include "tuning.hpp" #include "util.hpp" using namespace std; @@ -69,11 +71,14 @@ JackAudioPort::~JackAudioPort() void JackAudioPort::create() { - _jack_port = jack_port_register(_driver->jack_client(), - ingen_jack_port_name(_patch_port->path()).c_str(), - JACK_DEFAULT_AUDIO_TYPE, - (_patch_port->is_input()) ? JackPortIsInput : JackPortIsOutput, - 0); + _jack_port = jack_port_register( + _driver->jack_client(), + ingen_jack_port_name(_patch_port->path()).c_str(), + (_patch_port->type() == PortType::AUDIO) + ? JACK_DEFAULT_AUDIO_TYPE : JACK_DEFAULT_MIDI_TYPE, + (_patch_port->is_input()) + ? JackPortIsInput : JackPortIsOutput, + 0); if (_jack_port == NULL) { cerr << "[JackAudioPort] ERROR: Failed to register port " << _patch_port->path() << endl; @@ -100,28 +105,72 @@ JackAudioPort::move(const Raul::Path& path) void -JackAudioPort::pre_process(jack_nframes_t nframes) +JackAudioPort::pre_process(ProcessContext& context) { if (!is_input()) return; - jack_sample_t* jack_buf = (jack_sample_t*)jack_port_get_buffer(_jack_port, nframes); - AudioBuffer* patch_buf = (AudioBuffer*)_patch_port->buffer(0).get(); + const SampleCount nframes = context.nframes(); + + if (_patch_port->type() == PortType::AUDIO) { + jack_sample_t* jack_buf = (jack_sample_t*)jack_port_get_buffer(_jack_port, nframes); + AudioBuffer* patch_buf = (AudioBuffer*)_patch_port->buffer(0).get(); + + patch_buf->copy(jack_buf, 0, nframes - 1); + + } else if (_patch_port->type() == PortType::EVENTS) { + void* jack_buf = jack_port_get_buffer(_jack_port, nframes); + EventBuffer* patch_buf = (EventBuffer*)_patch_port->buffer(0).get(); - patch_buf->copy(jack_buf, 0, nframes - 1); + const jack_nframes_t event_count = jack_midi_get_event_count(jack_buf); + + patch_buf->prepare_write(context); + + // Copy events from Jack port buffer into patch port buffer + for (jack_nframes_t i = 0; i < event_count; ++i) { + jack_midi_event_t ev; + jack_midi_event_get(&ev, jack_buf, i); + + if (!patch_buf->append(ev.time, 0, _driver->_midi_event_type, ev.size, ev.buffer)) + cerr << "WARNING: Failed to write MIDI to port buffer, event(s) lost!" << endl; + } + } } void -JackAudioPort::post_process(jack_nframes_t nframes) +JackAudioPort::post_process(ProcessContext& context) { if (is_input()) return; - jack_sample_t* jack_buf = (jack_sample_t*)jack_port_get_buffer(_jack_port, nframes); - AudioBuffer* patch_buf = (AudioBuffer*)_patch_port->buffer(0).get(); + const SampleCount nframes = context.nframes(); + + if (_patch_port->type() == PortType::AUDIO) { + jack_sample_t* jack_buf = (jack_sample_t*)jack_port_get_buffer(_jack_port, nframes); + AudioBuffer* patch_buf = (AudioBuffer*)_patch_port->buffer(0).get(); + + memcpy(jack_buf, patch_buf->data(), nframes * sizeof(Sample)); + + } else if (_patch_port->type() == PortType::EVENTS) { + void* jack_buf = jack_port_get_buffer(_jack_port, context.nframes()); + EventBuffer* patch_buf = (EventBuffer*)_patch_port->buffer(0).get(); - memcpy(jack_buf, patch_buf->data(), nframes * sizeof(Sample)); + patch_buf->prepare_read(context); + jack_midi_clear_buffer(jack_buf); + + uint32_t frames = 0; + uint32_t subframes = 0; + uint16_t type = 0; + uint16_t size = 0; + uint8_t* data = NULL; + + // Copy events from Jack port buffer into patch port buffer + for (patch_buf->rewind(); patch_buf->is_valid(); patch_buf->increment()) { + patch_buf->get_event(&frames, &subframes, &type, &size, &data); + jack_midi_event_write(jack_buf, frames, data, size); + } + } } @@ -140,6 +189,9 @@ JackAudioDriver::JackAudioDriver(Engine& engine) , _process_context(engine) , _root_patch(NULL) { + SharedPtr<Shared::LV2URIMap> map = PtrCast<Shared::LV2URIMap>( + _engine.world()->lv2_features->feature(LV2_URI_MAP_URI)); + _midi_event_type = map->uri_to_id(NULL, "http://lv2plug.in/ns/ext/midi#MidiEvent"); } @@ -153,6 +205,14 @@ JackAudioDriver::~JackAudioDriver() bool +JackAudioDriver::supports(Shared::PortType port_type, Shared::EventType event_type) +{ + return (port_type == PortType::AUDIO + || (port_type == PortType::EVENTS && event_type == EventType::MIDI)); +} + + +bool JackAudioDriver::attach(const std::string& server_name, const std::string& client_name, void* jack_client) @@ -226,12 +286,6 @@ JackAudioDriver::activate() } else { cout << "[JackAudioDriver] Activated Jack client." << endl; } - - if (!_engine.midi_driver() || dynamic_cast<DummyMidiDriver*>(_engine.midi_driver())) { - JackMidiDriver* midi_driver = new JackMidiDriver(_engine); - midi_driver->attach(*this); - _engine.set_midi_driver(midi_driver); - } } @@ -242,13 +296,17 @@ JackAudioDriver::deactivate() _flag = 1; _is_activated = false; _sem.wait(); + for (Raul::List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) (*i)->destroy(); + jack_deactivate(_client); + if (_local_client) { jack_client_close(_client); _client = NULL; } + _jack_thread->stop(); cout << "[JackAudioDriver] Deactivated Jack client." << endl; } @@ -372,10 +430,7 @@ JackAudioDriver::_process_cb(jack_nframes_t nframes) // Read input for (Raul::List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - (*i)->pre_process(nframes); - - if (_engine.midi_driver()) - _engine.midi_driver()->pre_process(_process_context); + (*i)->pre_process(_process_context); // Run root patch if (_root_patch) @@ -385,12 +440,9 @@ JackAudioDriver::_process_cb(jack_nframes_t nframes) if (_engine.message_context()->has_requests()) _engine.message_context()->signal(_process_context); - if (_engine.midi_driver()) - _engine.midi_driver()->post_process(_process_context); - // Write output for (Raul::List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - (*i)->post_process(nframes); + (*i)->post_process(_process_context); _engine.post_processor()->set_end_time(_process_context.end()); diff --git a/src/engine/JackAudioDriver.hpp b/src/engine/JackAudioDriver.hpp index 02a60601..5ff6bf64 100644 --- a/src/engine/JackAudioDriver.hpp +++ b/src/engine/JackAudioDriver.hpp @@ -24,7 +24,7 @@ #include "raul/List.hpp" #include "raul/Semaphore.hpp" #include "raul/Thread.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "Buffer.hpp" #include "ProcessContext.hpp" @@ -55,8 +55,8 @@ public: void move(const Raul::Path& path); - void pre_process(jack_nframes_t nframes); - void post_process(jack_nframes_t nframes); + void pre_process(ProcessContext& context); + void post_process(ProcessContext& context); jack_port_t* jack_port() const { return _jack_port; } @@ -67,7 +67,7 @@ private: -/** The Jack AudioDriver. +/** The Jack Driver. * * The process callback here drives the entire audio thread by "pulling" * events from queues, processing them, running the patches, and passing @@ -75,12 +75,14 @@ private: * * \ingroup engine */ -class JackAudioDriver : public AudioDriver +class JackAudioDriver : public Driver { public: JackAudioDriver(Engine& engine); ~JackAudioDriver(); + bool supports(Shared::PortType port_type, Shared::EventType event_type); + bool attach(const std::string& server_name, const std::string& client_name, void* jack_client); @@ -122,15 +124,24 @@ public: private: friend class JackAudioPort; - // These are the static versions of the callbacks, they call - // the non-static ones below - inline static void thread_init_cb(void* const jack_driver); - inline static void shutdown_cb(void* const jack_driver); - inline static int process_cb(jack_nframes_t nframes, void* const jack_driver); - inline static int buffer_size_cb(jack_nframes_t nframes, void* const jack_driver); - inline static int sample_rate_cb(jack_nframes_t nframes, void* const jack_driver); - - // Non static callbacks + // Static JACK callbacks which call the non-static callbacks (methods) + inline static void thread_init_cb(void* const jack_driver) { + return ((JackAudioDriver*)jack_driver)->_thread_init_cb(); + } + inline static void shutdown_cb(void* const jack_driver) { + return ((JackAudioDriver*)jack_driver)->_shutdown_cb(); + } + inline static int process_cb(jack_nframes_t nframes, void* const jack_driver) { + return ((JackAudioDriver*)jack_driver)->_process_cb(nframes); + } + inline static int buffer_size_cb(jack_nframes_t nframes, void* const jack_driver) { + return ((JackAudioDriver*)jack_driver)->_buffer_size_cb(nframes); + } + inline static int sample_rate_cb(jack_nframes_t nframes, void* const jack_driver) { + return ((JackAudioDriver*)jack_driver)->_sample_rate_cb(nframes); + } + + // Non static callbacks (methods) void _thread_init_cb(); void _shutdown_cb(); int _process_cb(jack_nframes_t nframes); @@ -144,6 +155,7 @@ private: jack_client_t* _client; jack_nframes_t _buffer_size; jack_nframes_t _sample_rate; + uint32_t _midi_event_type; bool _is_activated; bool _local_client; ///< Whether _client should be closed on destruction jack_position_t _position; @@ -156,39 +168,6 @@ private: }; -inline int JackAudioDriver::process_cb(jack_nframes_t nframes, void* jack_driver) -{ - assert(jack_driver); - return ((JackAudioDriver*)jack_driver)->_process_cb(nframes); -} - -inline void JackAudioDriver::thread_init_cb(void* jack_driver) -{ - assert(jack_driver); - return ((JackAudioDriver*)jack_driver)->_thread_init_cb(); -} - -inline void JackAudioDriver::shutdown_cb(void* jack_driver) -{ - assert(jack_driver); - return ((JackAudioDriver*)jack_driver)->_shutdown_cb(); -} - - -inline int JackAudioDriver::buffer_size_cb(jack_nframes_t nframes, void* jack_driver) -{ - assert(jack_driver); - return ((JackAudioDriver*)jack_driver)->_buffer_size_cb(nframes); -} - - -inline int JackAudioDriver::sample_rate_cb(jack_nframes_t nframes, void* jack_driver) -{ - assert(jack_driver); - return ((JackAudioDriver*)jack_driver)->_sample_rate_cb(nframes); -} - - } // namespace Ingen #endif // JACKAUDIODRIVER_H diff --git a/src/engine/JackMidiDriver.cpp b/src/engine/JackMidiDriver.cpp deleted file mode 100644 index 7074d9ef..00000000 --- a/src/engine/JackMidiDriver.cpp +++ /dev/null @@ -1,301 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net> - * - * Ingen 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. - * - * Ingen 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 <iostream> -#include <cstdlib> -#include <pthread.h> -#include "raul/Maid.hpp" -#include "raul/midi_events.h" -#include "module/World.hpp" -#include "shared/LV2Features.hpp" -#include "event.lv2/event-helpers.h" -#include "shared/LV2URIMap.hpp" -#include "JackMidiDriver.hpp" -#include "JackAudioDriver.hpp" -#include "ThreadManager.hpp" -#include "AudioDriver.hpp" -#include "EventBuffer.hpp" -#include "DuplexPort.hpp" -#include "ProcessContext.hpp" -#include "Engine.hpp" -#include "util.hpp" - -using namespace std; -using namespace Raul; - -namespace Ingen { - - -//// JackMidiPort //// - -JackMidiPort::JackMidiPort(JackMidiDriver* driver, DuplexPort* patch_port) - : DriverPort(patch_port) - , Raul::List<JackMidiPort*>::Node(this) - , _driver(driver) - , _jack_port(NULL) -{ - assert(patch_port->poly() == 1); - - create(); - - patch_port->buffer(0)->clear(); -} - - -JackMidiPort::~JackMidiPort() -{ - assert(_jack_port == NULL); -} - - -void -JackMidiPort::create() -{ - _jack_port = jack_port_register(_driver->jack_client(), - ingen_jack_port_name(_patch_port->path()).c_str(), - JACK_DEFAULT_MIDI_TYPE, - (_patch_port->is_input()) ? JackPortIsInput : JackPortIsOutput, - 0); - - if (_jack_port == NULL) { - cerr << "[JackMidiPort] ERROR: Failed to register port " << _patch_port->path() << endl; - throw JackAudioDriver::PortRegistrationFailedException(); - } -} - - -void -JackMidiPort::destroy() -{ - assert(_jack_port); - if (jack_port_unregister(_driver->jack_client(), _jack_port)) - cerr << "[JackMidiPort] ERROR: Unable to unregister port" << endl; - - _jack_port = NULL; -} - - -void -JackMidiPort::move(const Raul::Path& path) -{ - jack_port_set_name(_jack_port, ingen_jack_port_name(path).c_str()); -} - - -/** Prepare input for a block before a cycle is run, in the audio thread. - * - * This is simple since Jack MIDI is in-band with audio. - */ -void -JackMidiPort::pre_process(ProcessContext& context) -{ - if ( ! is_input() ) - return; - - assert(_patch_port->poly() == 1); - - EventBuffer* patch_buf = dynamic_cast<EventBuffer*>(_patch_port->buffer(0).get()); - assert(patch_buf); - - void* jack_buffer = jack_port_get_buffer(_jack_port, context.nframes()); - const jack_nframes_t event_count = jack_midi_get_event_count(jack_buffer); - - patch_buf->prepare_write(context); - - // Copy events from Jack port buffer into patch port buffer - for (jack_nframes_t i=0; i < event_count; ++i) { - jack_midi_event_t ev; - jack_midi_event_get(&ev, jack_buffer, i); - - const bool success = patch_buf->append(ev.time, 0, _driver->_midi_event_type, - ev.size, ev.buffer); - if (!success) - cerr << "WARNING: Failed to write MIDI to port buffer, event(s) lost!" << endl; - } - - //if (event_count) - // cerr << "Jack MIDI got " << event_count << " events." << endl; -} - - -/** Prepare output for a block after a cycle is run, in the audio thread. - * - * This is simple since Jack MIDI is in-band with audio. - */ -void -JackMidiPort::post_process(ProcessContext& context) -{ - if (is_input()) - return; - - EventBuffer* patch_buf = dynamic_cast<EventBuffer*>(_patch_port->buffer(0).get()); - void* jack_buf = jack_port_get_buffer(_jack_port, context.nframes()); - - assert(_patch_port->poly() == 1); - assert(patch_buf); - - patch_buf->prepare_read(context); - jack_midi_clear_buffer(jack_buf); - - uint32_t frames = 0; - uint32_t subframes = 0; - uint16_t type = 0; - uint16_t size = 0; - uint8_t* data = NULL; - - // Copy events from Jack port buffer into patch port buffer - for (patch_buf->rewind(); patch_buf->is_valid(); patch_buf->increment()) { - patch_buf->get_event(&frames, &subframes, &type, &size, &data); - jack_midi_event_write(jack_buf, frames, data, size); - } - - //if (event_count) - // cerr << "Jack MIDI wrote " << event_count << " events." << endl; -} - - - -//// JackMidiDriver //// - - -bool JackMidiDriver::_midi_thread_exit_flag = true; - - -JackMidiDriver::JackMidiDriver(Engine& engine) - : _engine(engine) - , _client(NULL) - , _is_activated(false) - , _is_enabled(false) -{ - SharedPtr<Shared::LV2URIMap> map = PtrCast<Shared::LV2URIMap>( - _engine.world()->lv2_features->feature(LV2_URI_MAP_URI)); - _midi_event_type = map->uri_to_id(NULL, "http://lv2plug.in/ns/ext/midi#MidiEvent"); -} - - -JackMidiDriver::~JackMidiDriver() -{ - deactivate(); -} - - -void -JackMidiDriver::attach(AudioDriver& driver) -{ - JackAudioDriver* jad = dynamic_cast<JackAudioDriver*>(&driver); - assert(jad); - _client = jad->jack_client(); - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - (*i)->create(); -} - - -/** Launch and start the MIDI thread. - */ -void -JackMidiDriver::activate() -{ - _is_activated = true; -} - - -/** Terminate the MIDI thread. - */ -void -JackMidiDriver::deactivate() -{ - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - (*i)->destroy(); - _is_activated = false; -} - - -/** Build flat arrays of events to be used as input for the given cycle. - */ -void -JackMidiDriver::pre_process(ProcessContext& context) -{ - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - if ((*i)->is_input()) - (*i)->pre_process(context); -} - - -/** Write the output from any (top-level, exported) MIDI output ports to Jack ports. - */ -void -JackMidiDriver::post_process(ProcessContext& context) -{ - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - if (!(*i)->is_input()) - (*i)->post_process(context); -} - - -/** Add an Jack MIDI port. - * - * Realtime safe, this is to be called at the beginning of a process cycle to - * insert (and actually begin using) a new port. - * - * See new_port() and remove_port(). - */ -void -JackMidiDriver::add_port(DriverPort* port) -{ - assert(ThreadManager::current_thread_id() == THREAD_PROCESS); - assert(dynamic_cast<JackMidiPort*>(port)); - _ports.push_back((JackMidiPort*)port); -} - - -/** Remove a Jack MIDI port. - * - * Realtime safe. This is to be called at the beginning of a process cycle to - * remove the port from the lists read by the audio thread, so the port - * will no longer be used and can be removed afterwards. - * - * It is the callers responsibility to delete the returned port. - */ -Raul::List<DriverPort*>::Node* -JackMidiDriver::remove_port(const Path& path) -{ - assert(ThreadManager::current_thread_id() == THREAD_PROCESS); - - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - if ((*i)->patch_port()->path() == path) - return (Raul::List<DriverPort*>::Node*)_ports.erase(i); - - cerr << "[JackMidiDriver::remove_port] WARNING: Unable to find port " << path << endl; - return NULL; -} - - -DriverPort* -JackMidiDriver::driver_port(const Path& path) -{ - assert(ThreadManager::current_thread_id() == THREAD_PROCESS); - - for (Raul::List<JackMidiPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - if ((*i)->patch_port()->path() == path) - return (*i); - - return NULL; -} - - -} // namespace Ingen - diff --git a/src/engine/JackMidiDriver.hpp b/src/engine/JackMidiDriver.hpp deleted file mode 100644 index 68c8182a..00000000 --- a/src/engine/JackMidiDriver.hpp +++ /dev/null @@ -1,119 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net> - * - * Ingen 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. - * - * Ingen 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 JACKMIDIDRIVER_H -#define JACKMIDIDRIVER_H - -#include <jack/jack.h> -#include <jack/midiport.h> -#include "raul/List.hpp" -#include "MidiDriver.hpp" - -namespace Ingen { - -class NodeImpl; -class SetPortValueEvent; -class JackMidiDriver; -class DuplexPort; - - -/** Representation of an JACK MIDI port. - * - * \ingroup engine - */ -class JackMidiPort : public DriverPort, public Raul::List<JackMidiPort*>::Node -{ -public: - JackMidiPort(JackMidiDriver* driver, DuplexPort* port); - virtual ~JackMidiPort(); - - void create(); - void destroy(); - - void pre_process(ProcessContext& context); - void post_process(ProcessContext& context); - - void move(const Raul::Path& path); - -private: - JackMidiDriver* _driver; - jack_port_t* _jack_port; -}; - - -/** Jack MIDI driver. - * - * This driver reads Jack MIDI events and dispatches them to the appropriate - * JackMidiPort for processing. - * - * \ingroup engine - */ -class JackMidiDriver : public MidiDriver -{ -public: - JackMidiDriver(Engine& engine); - ~JackMidiDriver(); - - void attach(AudioDriver& driver); - - void activate(); - void deactivate(); - void enable() { _is_enabled = true; } - void disable() { _is_enabled = false; } - - bool is_activated() const { return _is_activated; } - bool is_enabled() const { return _is_enabled; } - - void pre_process(ProcessContext& context); - void post_process(ProcessContext& context); - - JackMidiPort* create_port(DuplexPort* patch_port) - { return new JackMidiPort(this, patch_port); } - - void add_port(DriverPort* port); - DriverPort* driver_port(const Raul::Path& path); - - Raul::List<DriverPort*>::Node* remove_port(const Raul::Path& path); - - jack_client_t* jack_client() { return _client; } - -private: - Engine& _engine; - uint32_t _midi_event_type; - - Raul::List<JackMidiPort*> _ports; - - friend class JackMidiPort; - - void add_output(Raul::List<JackMidiPort*>::Node* port); - Raul::List<JackMidiPort*>::Node* remove_output(JackMidiPort* port); - - // MIDI thread - static void* process_midi_in(void* me); - - jack_client_t* _client; - pthread_t _process_thread; - bool _is_activated; - bool _is_enabled; - static bool _midi_thread_exit_flag; -}; - - -} // namespace Ingen - - -#endif // JACKMIDIDRIVER_H diff --git a/src/engine/LADSPAPlugin.cpp b/src/engine/LADSPAPlugin.cpp index dd95bfbe..30b0eae2 100644 --- a/src/engine/LADSPAPlugin.cpp +++ b/src/engine/LADSPAPlugin.cpp @@ -22,7 +22,7 @@ #include "LADSPAPlugin.hpp" #include "LADSPANode.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; @@ -66,8 +66,8 @@ LADSPAPlugin::instantiate(BufferFactory& bufs, { assert(_id != 0); - SampleCount srate = engine.audio_driver()->sample_rate(); - SampleCount buffer_size = engine.audio_driver()->buffer_size(); + SampleCount srate = engine.driver()->sample_rate(); + SampleCount buffer_size = engine.driver()->buffer_size(); union { void* dp; diff --git a/src/engine/LV2Plugin.cpp b/src/engine/LV2Plugin.cpp index 3f3e25c2..b8b159e3 100644 --- a/src/engine/LV2Plugin.cpp +++ b/src/engine/LV2Plugin.cpp @@ -22,7 +22,7 @@ #include "LV2Node.hpp" #include "NodeImpl.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; @@ -66,8 +66,8 @@ LV2Plugin::instantiate(BufferFactory& bufs, Ingen::PatchImpl* parent, Engine& engine) { - SampleCount srate = engine.audio_driver()->sample_rate(); - SampleCount buffer_size = engine.audio_driver()->buffer_size(); + SampleCount srate = engine.driver()->sample_rate(); + SampleCount buffer_size = engine.driver()->buffer_size(); load(); // FIXME: unload at some point diff --git a/src/engine/MidiDriver.hpp b/src/engine/MidiDriver.hpp deleted file mode 100644 index 6bafb0fc..00000000 --- a/src/engine/MidiDriver.hpp +++ /dev/null @@ -1,103 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net> - * - * Ingen 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. - * - * Ingen 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 MIDIDRIVER_H -#define MIDIDRIVER_H - -#include <iostream> -#include "Driver.hpp" -#include "EventBuffer.hpp" -#include "ProcessContext.hpp" - -namespace Ingen { - -class ProcessContext; -class AudioDriver; - - -/** Midi driver abstract base class. - * - * \ingroup engine - */ -class MidiDriver : public Driver -{ -public: - MidiDriver() : Driver(Shared::PortType::EVENTS) {} - - virtual void attach(AudioDriver& master) {} - - /** Prepare input for the specified (upcoming) cycle. - * - * Realtime safe, run in audio thread before executing the graph for a cycle. - */ - virtual void pre_process(ProcessContext& context) = 0; - - /** Prepare output for the specified (just completed) cycle. - * - * Realtime safe, run in audio thread after executing the graph for a cycle. - */ - virtual void post_process(ProcessContext& context) = 0; -}; - - - -/** Dummy MIDIDriver. - * - * Not abstract, all functions are dummies. One of these will be allocated and - * "used" if no working MIDI driver is loaded. (Doing it this way as opposed to - * just making MidiDriver have dummy functions makes sure any existing MidiDriver - * derived class actually implements the required functions). - * - * \ingroup engine - */ -class DummyMidiDriver : public MidiDriver -{ -public: - DummyMidiDriver() { - std::cout << "[DummyMidiDriver] Started Dummy MIDI driver." << std::endl; - } - - ~DummyMidiDriver() {} - - void activate() {} - void deactivate() {} - - bool is_activated() const { return false; } - bool is_enabled() const { return false; } - - void enable() {} - void disable() {} - - DriverPort* create_port(DuplexPort* patch_port) { return NULL; } - - DriverPort* driver_port(const Raul::Path& path) { return NULL; } - - DriverPort* new_port(DuplexPort* patch_port) { return NULL; } - - void add_port(DriverPort* port) {} - - Raul::List<DriverPort*>::Node* remove_port(const Raul::Path& path) { return NULL; } - - void pre_process(ProcessContext& context) {} - void post_process(ProcessContext& context) {} -}; - - - -} // namespace Ingen - -#endif // MIDIDRIVER_H diff --git a/src/engine/OSCDriver.hpp b/src/engine/OSCDriver.hpp deleted file mode 100644 index e207d483..00000000 --- a/src/engine/OSCDriver.hpp +++ /dev/null @@ -1,83 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007-2009 Dave Robillard <http://drobilla.net> - * - * Ingen 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. - * - * Ingen 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 OSCDRIVER_H -#define OSCDRIVER_H - -#include "types.hpp" -#include "Driver.hpp" -#include <iostream> - -namespace Ingen { - - -/** OSC driver abstract base class. - * - * \ingroup engine - */ -class OSCDriver : public Driver -{ -public: - OSCDriver() : Driver(Shared::PortType::EVENTS) {} - - /** Prepare events (however neccessary) for the specified block (realtime safe) */ - virtual void prepare_block(const SampleCount block_start, const SampleCount block_end) = 0; -}; - - - -/** Dummy OSCDriver. - * - * Not abstract, all functions are dummies. One of these will be allocated and - * "used" if no working OSC driver is loaded. (Doing it this way as opposed to - * just making OSCDriver have dummy functions makes sure any existing OSCDriver - * derived class actually implements the required functions). - * - * \ingroup engine - */ -class DummyOSCDriver : public OSCDriver -{ -public: - DummyOSCDriver() { - std::cout << "[DummyOSCDriver] Started Dummy OSC driver." << std::endl; - } - - ~DummyOSCDriver() {} - - void activate() {} - void deactivate() {} - - bool is_activated() const { return false; } - bool is_enabled() const { return false; } - - void enable() {} - void disable() {} - - DriverPort* create_port(DuplexPort* patch_port) { return NULL; } - - void add_port(DriverPort* port) {} - - Raul::List<DriverPort*>::Node* remove_port(const Raul::Path& path) { return NULL; } - - void prepare_block(const SampleCount block_start, const SampleCount block_end) {} -}; - - - -} // namespace Ingen - -#endif // OSCDRIVER_H diff --git a/src/engine/PostProcessor.cpp b/src/engine/PostProcessor.cpp index 015df096..513274d5 100644 --- a/src/engine/PostProcessor.cpp +++ b/src/engine/PostProcessor.cpp @@ -23,7 +23,7 @@ #include "Event.hpp" #include "PostProcessor.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "ProcessContext.hpp" using namespace std; @@ -56,7 +56,7 @@ PostProcessor::process() /* Process audio thread generated events */ while (true) { - AudioDriver* driver = _engine.audio_driver(); + Driver* driver = _engine.driver(); if (driver && driver->context().event_sink().read(_event_buffer_size, _event_buffer)) { if (((Event*)_event_buffer)->time() > end_time) { cerr << "WARNING: Lost event with time " diff --git a/src/engine/QueuedEngineInterface.cpp b/src/engine/QueuedEngineInterface.cpp index 8adf2325..5532b732 100644 --- a/src/engine/QueuedEngineInterface.cpp +++ b/src/engine/QueuedEngineInterface.cpp @@ -21,7 +21,7 @@ #include "QueuedEventSource.hpp" #include "events.hpp" #include "Engine.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; @@ -44,8 +44,8 @@ QueuedEngineInterface::now() const { // Exactly one cycle latency (some could run ASAP if we get lucky, but not always, and a slight // constant latency is far better than jittery lower (average) latency - if (_engine.audio_driver()) - return _engine.audio_driver()->frame_time() + _engine.audio_driver()->buffer_size(); + if (_engine.driver()) + return _engine.driver()->frame_time() + _engine.driver()->buffer_size(); else return 0; } diff --git a/src/engine/QueuedEngineInterface.hpp b/src/engine/QueuedEngineInterface.hpp index 9552f0e7..9197a27b 100644 --- a/src/engine/QueuedEngineInterface.hpp +++ b/src/engine/QueuedEngineInterface.hpp @@ -38,7 +38,7 @@ class Engine; /** A queued (preprocessed) event source / interface. * * This is the bridge between the EngineInterface presented to the client, and - * the EventSource that needs to be presented to the AudioDriver. + * the EventSource that needs to be presented to the Driver. * * Responses occur through the event mechanism (which notified clients in * event post_process methods) and are related to an event by an integer ID. diff --git a/src/engine/events/CreateNode.cpp b/src/engine/events/CreateNode.cpp index 9a9e0826..bc43620d 100644 --- a/src/engine/events/CreateNode.cpp +++ b/src/engine/events/CreateNode.cpp @@ -31,7 +31,7 @@ #include "ClientBroadcaster.hpp" #include "EngineStore.hpp" #include "PortImpl.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; diff --git a/src/engine/events/CreatePatch.cpp b/src/engine/events/CreatePatch.cpp index aab2e6f6..b76efcdc 100644 --- a/src/engine/events/CreatePatch.cpp +++ b/src/engine/events/CreatePatch.cpp @@ -24,7 +24,7 @@ #include "PluginImpl.hpp" #include "Engine.hpp" #include "ClientBroadcaster.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "EngineStore.hpp" using namespace std; @@ -83,7 +83,8 @@ CreatePatch::pre_process() if (_parent != NULL && _poly > 1 && _poly == static_cast<int>(_parent->internal_polyphony())) poly = _poly; - _patch = new PatchImpl(_engine, path.name(), poly, _parent, _engine.audio_driver()->sample_rate(), _engine.audio_driver()->buffer_size(), _poly); + _patch = new PatchImpl(_engine, path.name(), poly, _parent, + _engine.driver()->sample_rate(), _engine.driver()->buffer_size(), _poly); _patch->meta().properties().insert(_properties.begin(), _properties.end()); _patch->meta().set_property("rdf:type", Atom(Atom::URI, "ingen:Patch")); _patch->set_property("rdf:type", Atom(Atom::URI, "ingen:Node")); @@ -114,7 +115,7 @@ CreatePatch::execute(ProcessContext& context) if (_parent == NULL) { assert(_path.is_root()); assert(_patch->parent_patch() == NULL); - _engine.audio_driver()->set_root_patch(_patch); + _engine.driver()->set_root_patch(_patch); } else { assert(_parent != NULL); assert(!_path.is_root()); diff --git a/src/engine/events/CreatePort.cpp b/src/engine/events/CreatePort.cpp index 60fd7cf9..ea2b3efa 100644 --- a/src/engine/events/CreatePort.cpp +++ b/src/engine/events/CreatePort.cpp @@ -30,9 +30,7 @@ #include "EngineStore.hpp" #include "ClientBroadcaster.hpp" #include "PortImpl.hpp" -#include "AudioDriver.hpp" -#include "MidiDriver.hpp" -#include "OSCDriver.hpp" +#include "Driver.hpp" #include "DuplexPort.hpp" using namespace std; @@ -94,7 +92,7 @@ CreatePort::pre_process() size_t buffer_size = 1; if (_type.str() != "ingen:Float") - buffer_size = _engine.audio_driver()->buffer_size(); + buffer_size = _engine.driver()->buffer_size(); const uint32_t old_num_ports = _patch->num_ports(); @@ -120,15 +118,9 @@ CreatePort::pre_process() _ports_array->at(_patch->num_ports()-1) = _patch_port; _engine.engine_store()->add(_patch_port); - if (!_patch->parent()) { - if (_type.str() == "lv2:AudioPort") { - _driver_port = _engine.audio_driver()->create_port( - dynamic_cast<DuplexPort*>(_patch_port)); - } else if (_type.str() == "lv2ev:EventPort") { - _driver_port = _engine.midi_driver()->create_port( - dynamic_cast<DuplexPort*>(_patch_port)); - } - } + if (!_patch->parent()) + _driver_port = _engine.driver()->create_port( + dynamic_cast<DuplexPort*>(_patch_port)); assert(_ports_array->size() == _patch->num_ports()); @@ -151,11 +143,7 @@ CreatePort::execute(ProcessContext& context) } if (_driver_port) { - if (_type.str() == "lv2:AudioPort") { - _engine.audio_driver()->add_port(_driver_port); - } else if (_type.str() == "lv2ev:EventPort") { - _engine.midi_driver()->add_port(_driver_port); - } + _engine.driver()->add_port(_driver_port); } } diff --git a/src/engine/events/Delete.cpp b/src/engine/events/Delete.cpp index 3c27ea94..62ddedf1 100644 --- a/src/engine/events/Delete.cpp +++ b/src/engine/events/Delete.cpp @@ -23,8 +23,7 @@ #include "PatchImpl.hpp" #include "NodeBase.hpp" #include "PluginImpl.hpp" -#include "AudioDriver.hpp" -#include "MidiDriver.hpp" +#include "Driver.hpp" #include "DisconnectAll.hpp" #include "ClientBroadcaster.hpp" #include "EngineStore.hpp" @@ -153,10 +152,7 @@ Delete::execute(ProcessContext& context) _port->parent_patch()->external_ports(_ports_array); if ( ! _port->parent_patch()->parent()) { - if (_port->type() == PortType::AUDIO) - _driver_port = _engine.audio_driver()->remove_port(_port->path()); - else if (_port->type() == PortType::EVENTS) - _driver_port = _engine.midi_driver()->remove_port(_port->path()); + _driver_port = _engine.driver()->remove_port(_port->path()); // Apparently this needs to be called in post_process?? //if (_driver_port) diff --git a/src/engine/events/Move.cpp b/src/engine/events/Move.cpp index d386ce44..d8e119f5 100644 --- a/src/engine/events/Move.cpp +++ b/src/engine/events/Move.cpp @@ -23,8 +23,7 @@ #include "EngineStore.hpp" #include "PatchImpl.hpp" #include "Responder.hpp" -#include "AudioDriver.hpp" -#include "MidiDriver.hpp" +#include "Driver.hpp" using namespace std; using namespace Raul; @@ -104,13 +103,7 @@ Move::execute(ProcessContext& context) SharedPtr<PortImpl> port = PtrCast<PortImpl>(_store_iterator->second); if (port && port->parent()->parent() == NULL) { - DriverPort* driver_port = NULL; - - if (port->type() == PortType::AUDIO) - driver_port = _engine.audio_driver()->driver_port(_new_path); - else if (port->type() == PortType::EVENTS) - driver_port = _engine.midi_driver()->driver_port(_new_path); - + DriverPort* driver_port = _engine.driver()->driver_port(_new_path); if (driver_port) driver_port->move(_new_path); } diff --git a/src/engine/events/SetPortValue.cpp b/src/engine/events/SetPortValue.cpp index 7fe6377d..5efc35ae 100644 --- a/src/engine/events/SetPortValue.cpp +++ b/src/engine/events/SetPortValue.cpp @@ -22,7 +22,7 @@ #include "shared/LV2Object.hpp" #include "module/World.hpp" #include "AudioBuffer.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "ClientBroadcaster.hpp" #include "Engine.hpp" #include "EngineStore.hpp" @@ -120,7 +120,7 @@ SetPortValue::pre_process() apply(*_engine.message_context()); _port->parent_node()->set_port_valid(_port->index()); _engine.message_context()->run(_port, - _engine.audio_driver()->frame_time() + _engine.audio_driver()->buffer_size()); + _engine.driver()->frame_time() + _engine.driver()->buffer_size()); } if (_port) { diff --git a/src/engine/ingen.lv2/ingen_lv2.cpp b/src/engine/ingen.lv2/ingen_lv2.cpp index 9be7c30a..8eea78ed 100644 --- a/src/engine/ingen.lv2/ingen_lv2.cpp +++ b/src/engine/ingen.lv2/ingen_lv2.cpp @@ -136,7 +136,7 @@ static void ingen_run(LV2_Handle instance, uint32_t sample_count) { IngenPlugin* plugin = (IngenPlugin*)instance; - ((IngenLV2Driver*)plugin->engine->audio_driver())->run(sample_count); + ((IngenLV2Driver*)plugin->engine->driver())->run(sample_count); } diff --git a/src/engine/ingen_jack.cpp b/src/engine/ingen_jack.cpp index a721383d..d9020ec8 100644 --- a/src/engine/ingen_jack.cpp +++ b/src/engine/ingen_jack.cpp @@ -29,7 +29,7 @@ struct IngenJackModule : public Ingen::Shared::Module { Ingen::JackAudioDriver* driver = new Ingen::JackAudioDriver(*world->local_engine.get()); driver->attach(world->conf->option("jack-server").get_string(), world->conf->option("jack-client").get_string(), NULL); - world->local_engine->set_driver(Shared::PortType::AUDIO, SharedPtr<Driver>(driver)); + world->local_engine->set_driver(SharedPtr<Driver>(driver)); } }; diff --git a/src/engine/internals/Note.cpp b/src/engine/internals/Note.cpp index 3e4eaa4e..cfaab3ed 100644 --- a/src/engine/internals/Note.cpp +++ b/src/engine/internals/Note.cpp @@ -22,7 +22,7 @@ #include <iostream> #include "internals/Note.hpp" #include "AudioBuffer.hpp" -#include "AudioDriver.hpp" +#include "Driver.hpp" #include "EventBuffer.hpp" #include "InputPort.hpp" #include "InternalPlugin.hpp" diff --git a/src/engine/wscript b/src/engine/wscript index 004b40da..752fd316 100644 --- a/src/engine/wscript +++ b/src/engine/wscript @@ -109,7 +109,7 @@ def build(bld): if bld.env['HAVE_JACK'] == 1: obj = bld.new_task_gen('cxx', 'shlib') - obj.source = 'JackAudioDriver.cpp JackMidiDriver.cpp ingen_jack.cpp' + obj.source = 'JackAudioDriver.cpp ingen_jack.cpp' obj.export_incdirs = ['.'] obj.includes = ['.', '..', '../..', '../common', '../engine'] obj.name = 'libingen_jack' diff --git a/src/gui/ConnectWindow.cpp b/src/gui/ConnectWindow.cpp index 1416bf2c..9643f693 100644 --- a/src/gui/ConnectWindow.cpp +++ b/src/gui/ConnectWindow.cpp @@ -250,7 +250,7 @@ ConnectWindow::connect(bool existing) SharedPtr<SigClientInterface> client(new SigClientInterface()); - if (!world->local_engine->audio_driver()) + if (!world->local_engine->driver()) world->load("ingen_jack"); world->local_engine->activate(); |