From 2fd41e8d03877f454bff4943901d5c1638aac9bb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 28 Jul 2008 22:14:12 +0000 Subject: Remove near duplicate SetPortValueEvent and SetPortValueQueuedEvent classes. git-svn-id: http://svn.drobilla.net/lad/ingen@1294 a436a847-0d15-0410-975c-d299462d15a1 --- src/libs/engine/Makefile.am | 2 - src/libs/engine/QueuedEngineInterface.cpp | 8 +- src/libs/engine/events.hpp | 1 - src/libs/engine/events/Makefile.am | 2 - src/libs/engine/events/SetPortValueEvent.cpp | 31 +++- src/libs/engine/events/SetPortValueEvent.hpp | 13 +- src/libs/engine/events/SetPortValueQueuedEvent.cpp | 174 --------------------- src/libs/engine/events/SetPortValueQueuedEvent.hpp | 75 --------- 8 files changed, 43 insertions(+), 263 deletions(-) delete mode 100644 src/libs/engine/events/SetPortValueQueuedEvent.cpp delete mode 100644 src/libs/engine/events/SetPortValueQueuedEvent.hpp (limited to 'src/libs') diff --git a/src/libs/engine/Makefile.am b/src/libs/engine/Makefile.am index 9ddfe88a..f04d3f3d 100644 --- a/src/libs/engine/Makefile.am +++ b/src/libs/engine/Makefile.am @@ -178,8 +178,6 @@ libingen_engine_la_SOURCES = \ events/SetPolyphonyEvent.hpp \ events/SetPortValueEvent.cpp \ events/SetPortValueEvent.hpp \ - events/SetPortValueQueuedEvent.cpp \ - events/SetPortValueQueuedEvent.hpp \ events/UnregisterClientEvent.cpp \ events/UnregisterClientEvent.hpp \ jack_compat.h \ diff --git a/src/libs/engine/QueuedEngineInterface.cpp b/src/libs/engine/QueuedEngineInterface.cpp index 08ab781a..d6792b09 100644 --- a/src/libs/engine/QueuedEngineInterface.cpp +++ b/src/libs/engine/QueuedEngineInterface.cpp @@ -255,7 +255,7 @@ QueuedEngineInterface::set_port_value(const string& port_path, uint32_t data_size, const void* data) { - push_queued(new SetPortValueQueuedEvent(_engine, _responder, now(), port_path, type_uri, data_size, data)); + push_queued(new SetPortValueEvent(_engine, _responder, true, now(), port_path, type_uri, data_size, data)); } @@ -266,7 +266,7 @@ QueuedEngineInterface::set_port_value(const string& port_path, uint32_t data_size, const void* data) { - push_queued(new SetPortValueQueuedEvent(_engine, _responder, now(), voice, port_path, type_uri, data_size, data)); + push_queued(new SetPortValueEvent(_engine, _responder, true, now(), voice, port_path, type_uri, data_size, data)); } @@ -276,7 +276,7 @@ QueuedEngineInterface::set_port_value_immediate(const string& port_path, uint32_t data_size, const void* data) { - push_stamped(new SetPortValueEvent(_engine, _responder, now(), port_path, type_uri, data_size, data)); + push_stamped(new SetPortValueEvent(_engine, _responder, false, now(), port_path, type_uri, data_size, data)); } @@ -287,7 +287,7 @@ QueuedEngineInterface::set_port_value_immediate(const string& port_path, uint32_t data_size, const void* data) { - push_stamped(new SetPortValueEvent(_engine, _responder, now(), voice, port_path, type_uri, data_size, data)); + push_stamped(new SetPortValueEvent(_engine, _responder, false, now(), voice, port_path, type_uri, data_size, data)); } diff --git a/src/libs/engine/events.hpp b/src/libs/engine/events.hpp index a2ea50a5..608bbeaa 100644 --- a/src/libs/engine/events.hpp +++ b/src/libs/engine/events.hpp @@ -48,7 +48,6 @@ #include "SetPolyphonicEvent.hpp" #include "SetPolyphonyEvent.hpp" #include "SetPortValueEvent.hpp" -#include "SetPortValueQueuedEvent.hpp" #include "UnregisterClientEvent.hpp" #endif // EVENTS_H diff --git a/src/libs/engine/events/Makefile.am b/src/libs/engine/events/Makefile.am index 18b02d8c..ccb9e6db 100644 --- a/src/libs/engine/events/Makefile.am +++ b/src/libs/engine/events/Makefile.am @@ -60,8 +60,6 @@ EXTRA_DIST = \ SetPolyphonyEvent.hpp \ SetPortValueEvent.cpp \ SetPortValueEvent.hpp \ - SetPortValueQueuedEvent.cpp \ - SetPortValueQueuedEvent.hpp \ UnregisterClientEvent.cpp \ UnregisterClientEvent.hpp diff --git a/src/libs/engine/events/SetPortValueEvent.cpp b/src/libs/engine/events/SetPortValueEvent.cpp index cf9e60c3..29f3f6c7 100644 --- a/src/libs/engine/events/SetPortValueEvent.cpp +++ b/src/libs/engine/events/SetPortValueEvent.cpp @@ -36,12 +36,14 @@ namespace Ingen { /** Omni (all voices) control setting */ SetPortValueEvent::SetPortValueEvent(Engine& engine, SharedPtr responder, + bool queued, SampleCount timestamp, const string& port_path, const string& data_type, uint32_t data_size, const void* data) - : Event(engine, responder, timestamp) + : QueuedEvent(engine, responder, timestamp) + , _queued(queued) , _omni(true) , _voice_num(0) , _port_path(port_path) @@ -51,6 +53,9 @@ SetPortValueEvent::SetPortValueEvent(Engine& engine, , _port(NULL) , _error(NO_ERROR) { + if (_queued) + pre_process(); + memcpy(_data, data, data_size); } @@ -58,13 +63,15 @@ SetPortValueEvent::SetPortValueEvent(Engine& engine, /** Voice-specific control setting */ SetPortValueEvent::SetPortValueEvent(Engine& engine, SharedPtr responder, + bool queued, SampleCount timestamp, uint32_t voice_num, const string& port_path, const string& data_type, uint32_t data_size, const void* data) - : Event(engine, responder, timestamp) + : QueuedEvent(engine, responder, timestamp) + , _queued(queued) , _omni(false) , _voice_num(voice_num) , _data_type(data_type) @@ -73,6 +80,9 @@ SetPortValueEvent::SetPortValueEvent(Engine& engine, , _port(NULL) , _error(NO_ERROR) { + if (_queued) + pre_process(); + memcpy(_data, data, data_size); } @@ -82,6 +92,21 @@ SetPortValueEvent::~SetPortValueEvent() free(_data); } + +void +SetPortValueEvent::pre_process() +{ + if (_queued) { + if (_port == NULL) + _port = _engine.object_store()->find_port(_port_path); + + if (_port == NULL) + _error = PORT_NOT_FOUND; + } + + QueuedEvent::pre_process(); +} + void SetPortValueEvent::execute(ProcessContext& context) @@ -94,7 +119,7 @@ SetPortValueEvent::execute(ProcessContext& context) if (_port == NULL) { _error = PORT_NOT_FOUND; -/* } else if (_port->buffer(0)->size() < _data_size) { + /*} else if (_port->buffer(0)->capacity() < _data_size) { _error = NO_SPACE;*/ } else { Buffer* const buf = _port->buffer(0); diff --git a/src/libs/engine/events/SetPortValueEvent.hpp b/src/libs/engine/events/SetPortValueEvent.hpp index d814a55b..6f89fc20 100644 --- a/src/libs/engine/events/SetPortValueEvent.hpp +++ b/src/libs/engine/events/SetPortValueEvent.hpp @@ -19,7 +19,7 @@ #define SETPORTVALUEEVENT_H #include -#include "Event.hpp" +#include "QueuedEvent.hpp" #include "types.hpp" using std::string; @@ -29,14 +29,20 @@ class PortImpl; /** An event to change the value of a port. + * + * This event can either be queued or immediate, depending on the queued + * parameter passed to the constructor. It must be passed to the appropriate + * place (ie queued event passed to the event queue and non-queued event + * processed in the audio thread) or nasty things will happen. * * \ingroup engine */ -class SetPortValueEvent : public Event +class SetPortValueEvent : public QueuedEvent { public: SetPortValueEvent(Engine& engine, SharedPtr responder, + bool queued, SampleCount timestamp, const string& port_path, const string& data_type, @@ -45,6 +51,7 @@ public: SetPortValueEvent(Engine& engine, SharedPtr responder, + bool queued, SampleCount timestamp, uint32_t voice_num, const string& port_path, @@ -54,12 +61,14 @@ public: ~SetPortValueEvent(); + void pre_process(); void execute(ProcessContext& context); void post_process(); private: enum ErrorType { NO_ERROR, PORT_NOT_FOUND, NO_SPACE }; + bool _queued; bool _omni; uint32_t _voice_num; const string _port_path; diff --git a/src/libs/engine/events/SetPortValueQueuedEvent.cpp b/src/libs/engine/events/SetPortValueQueuedEvent.cpp deleted file mode 100644 index 14060134..00000000 --- a/src/libs/engine/events/SetPortValueQueuedEvent.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard - * - * 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 -#include -#include "SetPortValueQueuedEvent.hpp" -#include "Responder.hpp" -#include "Engine.hpp" -#include "PortImpl.hpp" -#include "ClientBroadcaster.hpp" -#include "PluginImpl.hpp" -#include "NodeImpl.hpp" -#include "ObjectStore.hpp" -#include "AudioBuffer.hpp" -#include "EventBuffer.hpp" -#include "ProcessContext.hpp" - -using namespace std; - -namespace Ingen { - - -/** Omni (all voices) control setting */ -SetPortValueQueuedEvent::SetPortValueQueuedEvent(Engine& engine, - SharedPtr responder, - SampleCount timestamp, - const string& port_path, - const string& data_type, - uint32_t data_size, - const void* data) - : QueuedEvent(engine, responder, timestamp) - , _omni(true) - , _voice_num(0) - , _port_path(port_path) - , _data_type(data_type) - , _data_size(data_size) - , _data(malloc(data_size)) - , _port(NULL) - , _error(NO_ERROR) -{ - memcpy(_data, data, data_size); -} - - -/** Voice-specific control setting */ -SetPortValueQueuedEvent::SetPortValueQueuedEvent(Engine& engine, - SharedPtr responder, - SampleCount timestamp, - uint32_t voice_num, - const string& port_path, - const string& data_type, - uint32_t data_size, - const void* data) - : QueuedEvent(engine, responder, timestamp) - , _omni(false) - , _voice_num(voice_num) - , _port_path(port_path) - , _data_type(data_type) - , _data_size(data_size) - , _data(malloc(data_size)) - , _port(NULL) - , _error(NO_ERROR) -{ - memcpy(_data, data, data_size); -} - - -void -SetPortValueQueuedEvent::pre_process() -{ - if (_port == NULL) - _port = _engine.object_store()->find_port(_port_path); - - if (_port == NULL) { - _error = PORT_NOT_FOUND; -/* } else if (_port->buffer_size() < _data_size) { - _error = NO_SPACE;*/ - } - - QueuedEvent::pre_process(); -} - - -void -SetPortValueQueuedEvent::execute(ProcessContext& context) -{ - QueuedEvent::execute(context); - assert(_time >= context.start() && _time <= context.end()); - - if (_error == NO_ERROR) { - assert(_port); - - Buffer* const buf = _port->buffer(0); - AudioBuffer* const abuf = dynamic_cast(buf); - if (abuf) { - const uint32_t offset = (buf->size() == 1) ? 0 : _time - context.start(); - - if (_omni) - for (uint32_t i=0; i < _port->poly(); ++i) - ((AudioBuffer*)_port->buffer(i))->set(*(float*)_data, offset); - else - ((AudioBuffer*)_port->buffer(_voice_num))->set(*(float*)_data, offset); - - return; - } - - EventBuffer* const ebuf = dynamic_cast(buf); - // FIXME: eliminate string comparisons - if (ebuf && _data_type == "lv2_midi:MidiEvent") { - const LV2Features::Feature* f = _engine.world()->lv2_features->feature(LV2_URI_MAP_URI); - LV2URIMap* map = (LV2URIMap*)f->controller; - const uint32_t type_id = map->uri_to_id(NULL, "http://lv2plug.in/ns/ext/midi#MidiEvent"); - const uint32_t frames = std::max((uint32_t)(_time - context.start()), ebuf->latest_frames()); - ebuf->prepare_write(context.nframes()); - // FIXME: how should this work? binary over OSC, ick - // Message is an event: - ebuf->append(frames, 0, type_id, _data_size, (const unsigned char*)_data); - // Message is an event buffer: - //ebuf->append((LV2_Event_Buffer*)_data); - _port->raise_set_by_user_flag(); - return; - } - - cerr << "WARNING: Unknown value type " << _data_type << ", ignoring" << endl; - } -} - - -void -SetPortValueQueuedEvent::post_process() -{ - if (_error == NO_ERROR) { - assert(_port != NULL); - - _responder->respond_ok(); - _engine.broadcaster()->send_control_change(_port_path, *(float*)_data); - - // Send patch port control change, if this is a bridge port - /*Port* parent_port = _port->parent_node()->as_port(); - if (parent_port != NULL) { - assert(parent_port->type() == DataType::FLOAT); - _engine.broadcaster()->send_control_change(parent_port->path(), _val); - }*/ - - } else if (_error == PORT_NOT_FOUND) { - string msg = "Unable to find port "; - msg.append(_port_path).append(" for set_port_value_slow"); - _responder->respond_error(msg); - - } else if (_error == NO_SPACE) { - std::ostringstream msg("Attempt to write "); - msg << _data_size << " bytes to " << _port_path << ", with capacity " - << _port->buffer_size() << std::endl; - _responder->respond_error(msg.str()); - } -} - - -} // namespace Ingen - diff --git a/src/libs/engine/events/SetPortValueQueuedEvent.hpp b/src/libs/engine/events/SetPortValueQueuedEvent.hpp deleted file mode 100644 index 937a3ad8..00000000 --- a/src/libs/engine/events/SetPortValueQueuedEvent.hpp +++ /dev/null @@ -1,75 +0,0 @@ -/* This file is part of Ingen. - * Copyright (C) 2007 Dave Robillard - * - * 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 SETPORTVALUEQUEUEDEVENT_H -#define SETPORTVALUEQUEUEDEVENT_H - -#include "QueuedEvent.hpp" -#include "types.hpp" -#include -using std::string; - -namespace Ingen { - -class PortImpl; - - -/** An event to change the value of a port. - * - * \ingroup engine - */ -class SetPortValueQueuedEvent : public QueuedEvent -{ -public: - SetPortValueQueuedEvent(Engine& engine, - SharedPtr responder, - SampleCount timestamp, - const string& port_path, - const string& data_type, - uint32_t data_size, - const void* data); - - SetPortValueQueuedEvent(Engine& engine, - SharedPtr responder, - SampleCount timestamp, - uint32_t voice_num, - const string& port_path, - const string& data_type, - uint32_t data_size, - const void* data); - - void pre_process(); - void execute(ProcessContext& context); - void post_process(); - -private: - enum ErrorType { NO_ERROR, PORT_NOT_FOUND, NO_SPACE }; - - bool _omni; - uint32_t _voice_num; - string _port_path; - const string _data_type; - uint32_t _data_size; - void* _data; - PortImpl* _port; - ErrorType _error; -}; - - -} // namespace Ingen - -#endif // SETPORTVALUEQUEUEDEVENT_H -- cgit v1.2.1