diff options
author | David Robillard <d@drobilla.net> | 2009-05-28 14:33:33 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2009-05-28 14:33:33 +0000 |
commit | 46b2e1598ed75319735893ed039ac669aca2d8a7 (patch) | |
tree | a36c8c2ba5e2c14c468c34396d0914be258edfda /src/engine | |
parent | f2c45c3f5b1f6c06d351ed91223343cd3a69ab4b (diff) | |
download | ingen-46b2e1598ed75319735893ed039ac669aca2d8a7.tar.gz ingen-46b2e1598ed75319735893ed039ac669aca2d8a7.tar.bz2 ingen-46b2e1598ed75319735893ed039ac669aca2d8a7.zip |
Make SetMetadataEvent do multiple properties at once.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@2019 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r-- | src/engine/ClientBroadcaster.cpp | 8 | ||||
-rw-r--r-- | src/engine/ClientBroadcaster.hpp | 4 | ||||
-rw-r--r-- | src/engine/QueuedEngineInterface.cpp | 3 | ||||
-rw-r--r-- | src/engine/events/SetMetadataEvent.cpp | 165 | ||||
-rw-r--r-- | src/engine/events/SetMetadataEvent.hpp | 44 |
5 files changed, 140 insertions, 84 deletions
diff --git a/src/engine/ClientBroadcaster.cpp b/src/engine/ClientBroadcaster.cpp index 8aaffe94..50a1112b 100644 --- a/src/engine/ClientBroadcaster.cpp +++ b/src/engine/ClientBroadcaster.cpp @@ -162,6 +162,14 @@ ClientBroadcaster::send_disconnection(const Path& src_port_path, const Path& dst } +void +ClientBroadcaster::send_put(const Raul::URI& subject, const Shared::Resource::Properties& properties) +{ + for (Clients::const_iterator i = _clients.begin(); i != _clients.end(); ++i) + (*i).second->put(subject, properties); +} + + /** Send notification of a property update. * * Like control changes, does not send update to client that set the property, if applicable. diff --git a/src/engine/ClientBroadcaster.hpp b/src/engine/ClientBroadcaster.hpp index 2aea8eb0..8d9d5c4d 100644 --- a/src/engine/ClientBroadcaster.hpp +++ b/src/engine/ClientBroadcaster.hpp @@ -69,8 +69,8 @@ public: void send_connection(const SharedPtr<const ConnectionImpl> connection); void send_disconnection(const Raul::Path& src_port_path, const Raul::Path& dst_port_path); void send_move(const Raul::Path& old_path, const Raul::Path& new_path); - void send_variable_change(const Raul::URI& node_path, const Raul::URI& key, const Raul::Atom& value); - void send_property_change(const Raul::URI& node_path, const Raul::URI& key, const Raul::Atom& value); + void send_put(const Raul::URI& subject, const Shared::Resource::Properties& properties); + void send_property_change(const Raul::URI& subject, const Raul::URI& key, const Raul::Atom& value); void send_port_value(const Raul::Path& port_path, const Raul::Atom& value); void send_activity(const Raul::Path& path); diff --git a/src/engine/QueuedEngineInterface.cpp b/src/engine/QueuedEngineInterface.cpp index 4b2926e7..7d9a8dcc 100644 --- a/src/engine/QueuedEngineInterface.cpp +++ b/src/engine/QueuedEngineInterface.cpp @@ -155,6 +155,7 @@ void QueuedEngineInterface::put(const URI& uri, const Resource::Properties& properties) { + cerr << "PUT " << uri << endl; size_t hash = uri.find("#"); bool meta = (hash != string::npos); Path path(meta ? (string("/") + uri.chop_start("#")) : uri.str()); @@ -169,6 +170,8 @@ QueuedEngineInterface::put(const URI& uri, DataType data_type(DataType::UNKNOWN); ResourceImpl::type(properties, is_patch, is_node, is_port, is_output, data_type); + // PutEvent + if (is_patch) { uint32_t poly = 1; iterator p = properties.find("ingen:polyphony"); diff --git a/src/engine/events/SetMetadataEvent.cpp b/src/engine/events/SetMetadataEvent.cpp index 00db9161..a88490d6 100644 --- a/src/engine/events/SetMetadataEvent.cpp +++ b/src/engine/events/SetMetadataEvent.cpp @@ -43,10 +43,7 @@ SetMetadataEvent::SetMetadataEvent( const Atom& value) : QueuedEvent(engine, responder, timestamp) , _error(NO_ERROR) - , _special_type(NONE) , _subject(subject) - , _key(key) - , _value(value) , _object(NULL) , _patch(NULL) , _compiled_patch(NULL) @@ -55,6 +52,27 @@ SetMetadataEvent::SetMetadataEvent( { cerr << "SET " << subject << " : " << key << " = " << value << endl; assert(value.type() != Atom::URI || strcmp(value.get_uri(), "lv2:ControlPort")); + _properties.insert(make_pair(key, value)); +} + + +SetMetadataEvent::SetMetadataEvent( + Engine& engine, + SharedPtr<Responder> responder, + SampleCount timestamp, + bool meta, + const URI& subject, + const Shared::Resource::Properties& properties) + : QueuedEvent(engine, responder, timestamp) + , _error(NO_ERROR) + , _subject(subject) + , _properties(properties) + , _object(NULL) + , _patch(NULL) + , _compiled_patch(NULL) + , _is_meta(meta) + , _success(false) +{ } @@ -75,43 +93,55 @@ SetMetadataEvent::pre_process() /*cerr << "SET " << _object->path() << (_property ? " PROP " : " VAR ") << _key << " :: " << _value.type() << endl;*/ - GraphObjectImpl* obj = dynamic_cast<GraphObjectImpl*>(_object); - if (obj) { - if (_is_meta) - obj->meta().set_property(_key, _value); - else - obj->set_property(_key, _value); - - _patch = dynamic_cast<PatchImpl*>(_object); - - if (_key.str() == "ingen:broadcast") { - _special_type = ENABLE_BROADCAST; - } else if (_patch) { - if (_key.str() == "ingen:enabled") { - if (_value.type() == Atom::BOOL) { - _special_type = ENABLE; - if (_value.get_bool() && !_patch->compiled_patch()) - _compiled_patch = _patch->compile(); + _types.reserve(_properties.size()); + typedef Shared::Resource::Properties Properties; + for (Properties::iterator p = _properties.begin(); p != _properties.end(); ++p) { + const Raul::URI& key = p->first; + const Raul::Atom& value = p->second; + GraphObjectImpl* obj = dynamic_cast<GraphObjectImpl*>(_object); + if (obj) { + if (_is_meta) + obj->meta().set_property(key, value); + else + obj->set_property(key, value); + + _patch = dynamic_cast<PatchImpl*>(_object); + + if (key.str() == "ingen:broadcast") { + _types.push_back(ENABLE_BROADCAST); + } else if (_patch) { + if (key.str() == "ingen:enabled") { + if (value.type() == Atom::BOOL) { + _types.push_back(ENABLE); + if (value.get_bool() && !_patch->compiled_patch()) + _compiled_patch = _patch->compile(); + } else { + _error = BAD_TYPE; + } + } else if (key.str() == "ingen:polyphonic") { + if (value.type() == Atom::BOOL) { + _types.push_back(POLYPHONIC); + } else { + _error = BAD_TYPE; + } + } else if (key.str() == "ingen:polyphony") { + if (value.type() == Atom::INT) { + _types.push_back(POLYPHONY); + _patch->prepare_internal_poly(value.get_int32()); + } else { + _error = BAD_TYPE; + } } else { - _error = BAD_TYPE; - } - } else if (_key.str() == "ingen:polyphonic") { - if (_value.type() == Atom::BOOL) { - _special_type = POLYPHONIC; - } else { - _error = BAD_TYPE; - } - } else if (_key.str() == "ingen:polyphony") { - if (_value.type() == Atom::INT) { - _special_type = POLYPHONY; - _patch->prepare_internal_poly(_value.get_int32()); - } else { - _error = BAD_TYPE; + _types.push_back(NONE); } + if (_error != NO_ERROR) + break; } + } else { + _types.push_back(NONE); } - } else { - _object->set_property(_key, _value); + + _object->set_property(key, value); } QueuedEvent::pre_process(); @@ -124,33 +154,38 @@ SetMetadataEvent::execute(ProcessContext& context) if (_error != NO_ERROR) return; - PortImpl* port = 0; - GraphObjectImpl* object = 0; - switch (_special_type) { - case ENABLE_BROADCAST: - if ((port = dynamic_cast<PortImpl*>(_object))) - port->broadcast(_value.get_bool()); - break; - case ENABLE: - if (_value.get_bool()) { - if (!_patch->compiled_patch()) - _patch->compiled_patch(_compiled_patch); - _patch->enable(); - } else { - _patch->disable(); + typedef Shared::Resource::Properties Properties; + std::vector<SpecialType>::const_iterator t = _types.begin(); + for (Properties::iterator p = _properties.begin(); p != _properties.end(); ++p, ++t) { + const Raul::Atom& value = p->second; + PortImpl* port = 0; + GraphObjectImpl* object = 0; + switch (*t) { + case ENABLE_BROADCAST: + if ((port = dynamic_cast<PortImpl*>(_object))) + port->broadcast(value.get_bool()); + break; + case ENABLE: + if (value.get_bool()) { + if (!_patch->compiled_patch()) + _patch->compiled_patch(_compiled_patch); + _patch->enable(); + } else { + _patch->disable(); + } + break; + case POLYPHONIC: + if ((object = dynamic_cast<GraphObjectImpl*>(_object))) + if (!object->set_polyphonic(*_engine.maid(), value.get_bool())) + _error = INTERNAL; + break; + case POLYPHONY: + if (!_patch->apply_internal_poly(*_engine.maid(), value.get_int32())) + _error = INTERNAL; + break; + default: + _success = true; } - break; - case POLYPHONIC: - if ((object = dynamic_cast<GraphObjectImpl*>(_object))) - if (!object->set_polyphonic(*_engine.maid(), _value.get_bool())) - _error = INTERNAL; - break; - case POLYPHONY: - if (!_patch->apply_internal_poly(*_engine.maid(), _value.get_int32())) - _error = INTERNAL; - break; - default: - _success = true; } QueuedEvent::execute(context); @@ -163,16 +198,16 @@ SetMetadataEvent::post_process() switch (_error) { case NO_ERROR: _responder->respond_ok(); - _engine.broadcaster()->send_property_change(_subject, _key, _value); + _engine.broadcaster()->send_put(_subject, _properties); break; case NOT_FOUND: _responder->respond_error((boost::format( - "Unable to find object '%1%' to set '%2%'") % _subject % _key).str()); + "Unable to find object '%1%'") % _subject).str()); case INTERNAL: _responder->respond_error("Internal error"); break; case BAD_TYPE: - _responder->respond_error((boost::format("Bad type for '%1%'") % _key).str()); + _responder->respond_error("Bad type for predicate"); break; } } diff --git a/src/engine/events/SetMetadataEvent.hpp b/src/engine/events/SetMetadataEvent.hpp index b33cc9ca..e43b1e9f 100644 --- a/src/engine/events/SetMetadataEvent.hpp +++ b/src/engine/events/SetMetadataEvent.hpp @@ -18,6 +18,7 @@ #ifndef SETMETADATAEVENT_H #define SETMETADATAEVENT_H +#include <vector> #include "raul/URI.hpp" #include "raul/Atom.hpp" #include "shared/ResourceImpl.hpp" @@ -37,13 +38,22 @@ class CompiledPatch; class SetMetadataEvent : public QueuedEvent { public: - SetMetadataEvent(Engine& engine, - SharedPtr<Responder> responder, - SampleCount timestamp, - bool meta, - const Raul::URI& subject, - const Raul::URI& key, - const Raul::Atom& value); + SetMetadataEvent( + Engine& engine, + SharedPtr<Responder> responder, + SampleCount timestamp, + bool meta, + const Raul::URI& subject, + const Raul::URI& key, + const Raul::Atom& value); + + SetMetadataEvent( + Engine& engine, + SharedPtr<Responder> responder, + SampleCount timestamp, + bool meta, + const Raul::URI& subject, + const Shared::Resource::Properties& properties); void pre_process(); void execute(ProcessContext& context); @@ -51,22 +61,22 @@ public: private: enum { NO_ERROR, NOT_FOUND, INTERNAL, BAD_TYPE } _error; - enum { + enum SpecialType { NONE, ENABLE, ENABLE_BROADCAST, POLYPHONY, POLYPHONIC - } _special_type; + }; - Raul::URI _subject; - Raul::URI _key; - Raul::Atom _value; - Shared::ResourceImpl* _object; - PatchImpl* _patch; - CompiledPatch* _compiled_patch; - bool _is_meta; - bool _success; + std::vector<SpecialType> _types; + Raul::URI _subject; + Shared::Resource::Properties _properties; + Shared::ResourceImpl* _object; + PatchImpl* _patch; + CompiledPatch* _compiled_patch; + bool _is_meta; + bool _success; }; |