diff options
-rw-r--r-- | src/libs/engine/AlsaMidiDriver.cpp | 14 | ||||
-rw-r--r-- | src/libs/engine/AlsaMidiDriver.h | 2 | ||||
-rw-r--r-- | src/libs/engine/AudioDriver.h | 4 | ||||
-rw-r--r-- | src/libs/engine/Driver.h | 6 | ||||
-rw-r--r-- | src/libs/engine/JackAudioDriver.cpp | 39 | ||||
-rw-r--r-- | src/libs/engine/JackAudioDriver.h | 11 | ||||
-rw-r--r-- | src/libs/engine/JackMidiDriver.cpp | 14 | ||||
-rw-r--r-- | src/libs/engine/JackMidiDriver.h | 2 | ||||
-rw-r--r-- | src/libs/engine/events/AddPortEvent.cpp | 3 | ||||
-rw-r--r-- | src/libs/engine/events/DestroyEvent.cpp | 11 | ||||
-rw-r--r-- | src/libs/engine/events/DestroyEvent.h | 2 |
11 files changed, 44 insertions, 64 deletions
diff --git a/src/libs/engine/AlsaMidiDriver.cpp b/src/libs/engine/AlsaMidiDriver.cpp index 3f6b060d..c8b2b906 100644 --- a/src/libs/engine/AlsaMidiDriver.cpp +++ b/src/libs/engine/AlsaMidiDriver.cpp @@ -89,20 +89,6 @@ AlsaMidiPort::~AlsaMidiPort() void -AlsaMidiPort::add_to_driver() -{ - _driver->add_port(this); -} - - -void -AlsaMidiPort::remove_from_driver() -{ - _driver->remove_port(this); -} - - -void AlsaMidiPort::set_name(const string& name) { snd_seq_port_info_t* info = NULL; diff --git a/src/libs/engine/AlsaMidiDriver.h b/src/libs/engine/AlsaMidiDriver.h index 6f1c76d9..9309a05b 100644 --- a/src/libs/engine/AlsaMidiDriver.h +++ b/src/libs/engine/AlsaMidiDriver.h @@ -49,8 +49,6 @@ public: void prepare_block(const SampleCount block_start, const SampleCount block_end); - void add_to_driver(); - void remove_from_driver(); void set_name(const std::string& name); int port_id() const { return _port_id; } diff --git a/src/libs/engine/AudioDriver.h b/src/libs/engine/AudioDriver.h index f72c43ea..a2f4ac50 100644 --- a/src/libs/engine/AudioDriver.h +++ b/src/libs/engine/AudioDriver.h @@ -20,6 +20,7 @@ #include "Driver.h" #include "types.h" #include "List.h" +#include "raul/Path.h" namespace Ingen { @@ -39,6 +40,9 @@ public: virtual void set_root_patch(Patch* patch) = 0; virtual Patch* root_patch() = 0; + virtual void add_port(DriverPort* port) = 0; + virtual DriverPort* remove_port(const Path& path) = 0; + virtual SampleCount buffer_size() const = 0; virtual SampleCount sample_rate() const = 0; virtual SampleCount frame_time() const = 0; diff --git a/src/libs/engine/Driver.h b/src/libs/engine/Driver.h index 61d2b830..103c4fe6 100644 --- a/src/libs/engine/Driver.h +++ b/src/libs/engine/Driver.h @@ -37,12 +37,6 @@ class DriverPort : boost::noncopyable { public: virtual ~DriverPort() {} - /** Add this port to driver at the beginning of a process cycle (realtime safe) */ - virtual void add_to_driver() = 0; - - /** Remove this port at the beginning of a process cycle (realtime safe) */ - virtual void remove_from_driver() = 0; - /** Set the name of the system port */ virtual void set_name(const std::string& name) = 0; diff --git a/src/libs/engine/JackAudioDriver.cpp b/src/libs/engine/JackAudioDriver.cpp index 58834139..87728e93 100644 --- a/src/libs/engine/JackAudioDriver.cpp +++ b/src/libs/engine/JackAudioDriver.cpp @@ -73,19 +73,6 @@ JackAudioPort::~JackAudioPort() void -JackAudioPort::add_to_driver() -{ - _driver->add_port(this); -} - - -void -JackAudioPort::remove_from_driver() -{ - _driver->remove_port(this); -} - -void JackAudioPort::prepare_buffer(jack_nframes_t nframes) { // FIXME: Technically this doesn't need to be done every time for output ports @@ -227,9 +214,12 @@ JackAudioDriver::deactivate() * See create_port() and remove_port(). */ void -JackAudioDriver::add_port(JackAudioPort* port) +JackAudioDriver::add_port(DriverPort* port) { - _ports.push_back(port); + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); + + assert(dynamic_cast<JackAudioPort*>(port)); + _ports.push_back((JackAudioPort*)port); } @@ -241,11 +231,13 @@ JackAudioDriver::add_port(JackAudioPort* port) * * It is the callers responsibility to delete the returned port. */ -JackAudioPort* -JackAudioDriver::remove_port(JackAudioPort* port) +DriverPort* +JackAudioDriver::remove_port(const Path& path) { + assert(ThreadManager::current_thread_id() == THREAD_PROCESS); + for (List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) - if ((*i) == port) + if ((*i)->patch_port()->path() == path) return _ports.remove(i)->elem(); cerr << "[JackAudioDriver::remove_port] WARNING: Failed to find Jack port to remove!" << endl; @@ -254,6 +246,17 @@ JackAudioDriver::remove_port(JackAudioPort* port) DriverPort* +JackAudioDriver::port(const Path& path) +{ + for (List<JackAudioPort*>::iterator i = _ports.begin(); i != _ports.end(); ++i) + if ((*i)->patch_port()->path() == path) + return (*i); + + return NULL; +} + + +DriverPort* JackAudioDriver::create_port(DuplexPort<Sample>* patch_port) { if (patch_port->buffer_size() == _buffer_size) diff --git a/src/libs/engine/JackAudioDriver.h b/src/libs/engine/JackAudioDriver.h index 53f48035..38c908a6 100644 --- a/src/libs/engine/JackAudioDriver.h +++ b/src/libs/engine/JackAudioDriver.h @@ -20,6 +20,7 @@ #include <jack/jack.h> #include <jack/transport.h> #include "raul/Thread.h" +#include "raul/Path.h" #include "List.h" #include "AudioDriver.h" #include "Buffer.h" @@ -44,8 +45,6 @@ public: JackAudioPort(JackAudioDriver* driver, DuplexPort<Sample>* patch_port); ~JackAudioPort(); - void add_to_driver(); - void remove_from_driver(); void set_name(const std::string& name) { jack_port_set_name(_jack_port, name.c_str()); }; void prepare_buffer(jack_nframes_t nframes); @@ -84,8 +83,12 @@ public: void enable(); void disable(); + DriverPort* port(const Path& path); DriverPort* create_port(DuplexPort<Sample>* patch_port); + void add_port(DriverPort* port); + DriverPort* remove_port(const Path& path); + Patch* root_patch() { return _root_patch; } void set_root_patch(Patch* patch) { _root_patch = patch; } @@ -105,10 +108,6 @@ public: private: friend class JackAudioPort; - - // Functions for JackAudioPort - void add_port(JackAudioPort* port); - JackAudioPort* remove_port(JackAudioPort* port); // These are the static versions of the callbacks, they call // the non-static ones below diff --git a/src/libs/engine/JackMidiDriver.cpp b/src/libs/engine/JackMidiDriver.cpp index 016889d7..55ba3522 100644 --- a/src/libs/engine/JackMidiDriver.cpp +++ b/src/libs/engine/JackMidiDriver.cpp @@ -59,20 +59,6 @@ JackMidiPort::~JackMidiPort() } -void -JackMidiPort::add_to_driver() -{ - m_driver->add_port(this); -} - - -void -JackMidiPort::remove_from_driver() -{ - m_driver->remove_port(this); -} - - /** Prepare events for a block. * * This is basically trivial (as opposed to AlsaMidiPort) since Jack MIDI diff --git a/src/libs/engine/JackMidiDriver.h b/src/libs/engine/JackMidiDriver.h index 3c5fe558..e870b3c2 100644 --- a/src/libs/engine/JackMidiDriver.h +++ b/src/libs/engine/JackMidiDriver.h @@ -44,8 +44,6 @@ public: void prepare_block(const SampleCount block_start, const SampleCount block_end); - void add_to_driver(); - void remove_from_driver(); void set_name(const std::string& name) { jack_port_set_name(m_jack_port, name.c_str()); }; DuplexPort<MidiMessage>* patch_port() const { return m_patch_port; } diff --git a/src/libs/engine/events/AddPortEvent.cpp b/src/libs/engine/events/AddPortEvent.cpp index bdce9267..4173ced2 100644 --- a/src/libs/engine/events/AddPortEvent.cpp +++ b/src/libs/engine/events/AddPortEvent.cpp @@ -120,7 +120,6 @@ AddPortEvent::pre_process() assert(_ports_array->size() == _patch->num_ports()); - } } QueuedEvent::pre_process(); @@ -141,7 +140,7 @@ AddPortEvent::execute(SampleCount nframes, FrameTime start, FrameTime end) } if (_driver_port) - _driver_port->add_to_driver(); + _engine.audio_driver()->add_port(_driver_port); } diff --git a/src/libs/engine/events/DestroyEvent.cpp b/src/libs/engine/events/DestroyEvent.cpp index 26902697..9866fe95 100644 --- a/src/libs/engine/events/DestroyEvent.cpp +++ b/src/libs/engine/events/DestroyEvent.cpp @@ -21,6 +21,7 @@ #include "Tree.h" #include "Node.h" #include "Plugin.h" +#include "AudioDriver.h" #include "InternalNode.h" #include "DisconnectNodeEvent.h" #include "DisconnectPortEvent.h" @@ -40,6 +41,7 @@ DestroyEvent::DestroyEvent(Engine& engine, SharedPtr<Responder> responder, Frame _object(NULL), _node(NULL), _port(NULL), + _driver_port(NULL), _patch_node_listnode(NULL), _patch_port_listnode(NULL), _store_treenode(NULL), @@ -58,6 +60,7 @@ DestroyEvent::DestroyEvent(Engine& engine, SharedPtr<Responder> responder, Frame _object(node), _node(node), _port(NULL), + _driver_port(NULL), _patch_node_listnode(NULL), _patch_port_listnode(NULL), _store_treenode(NULL), @@ -174,6 +177,10 @@ DestroyEvent::execute(SampleCount nframes, FrameTime start, FrameTime end) _engine.maid()->push(_port->parent_patch()->external_ports()); _port->parent_patch()->external_ports(_ports_array); + + if (!_port->parent_patch()->parent()) + _driver_port = _engine.audio_driver()->remove_port(_port->path()); + } } @@ -209,6 +216,10 @@ DestroyEvent::post_process() } else { _responder->respond_error("Unable to destroy object"); } + + if (_driver_port) + delete _driver_port; + //_engine.maid()->push(_driver_port); } diff --git a/src/libs/engine/events/DestroyEvent.h b/src/libs/engine/events/DestroyEvent.h index 6dfebbf7..1249eceb 100644 --- a/src/libs/engine/events/DestroyEvent.h +++ b/src/libs/engine/events/DestroyEvent.h @@ -33,6 +33,7 @@ class GraphObject; class Patch; class Node; class Port; +class DriverPort; class Plugin; class DisconnectNodeEvent; class DisconnectPortEvent; @@ -58,6 +59,7 @@ private: GraphObject* _object; Node* _node; ///< Same as _object if it is a Node, otherwise NULL Port* _port; ///< Same as _object if it is a Port, otherwise NULL + DriverPort* _driver_port; ListNode<Node*>* _patch_node_listnode; ListNode<Port*>* _patch_port_listnode; TreeNode<GraphObject*>* _store_treenode; |