diff options
Diffstat (limited to 'src/engine/events/SetMetadataEvent.cpp')
-rw-r--r-- | src/engine/events/SetMetadataEvent.cpp | 93 |
1 files changed, 81 insertions, 12 deletions
diff --git a/src/engine/events/SetMetadataEvent.cpp b/src/engine/events/SetMetadataEvent.cpp index 8caede6e..e0b51f2b 100644 --- a/src/engine/events/SetMetadataEvent.cpp +++ b/src/engine/events/SetMetadataEvent.cpp @@ -23,6 +23,7 @@ #include "PortImpl.hpp" #include "ClientBroadcaster.hpp" #include "GraphObjectImpl.hpp" +#include "PatchImpl.hpp" #include "EngineStore.hpp" using std::string; @@ -46,6 +47,8 @@ SetMetadataEvent::SetMetadataEvent( , _key(key) , _value(value) , _object(NULL) + , _patch(NULL) + , _compiled_patch(NULL) { } @@ -61,17 +64,47 @@ SetMetadataEvent::pre_process() _object = _engine.engine_store()->find_object(_path); if (_object == NULL) { + _error = NOT_FOUND; QueuedEvent::pre_process(); return; } + /*cerr << "SET " << _object->path() << (_property ? " PROP " : " VAR ") + << _key << " :: " << _value.type() << endl;*/ + if (_property) _object->set_property(_key, _value); else _object->set_variable(_key, _value); - if (_key == "ingen:broadcast") + _patch = dynamic_cast<PatchImpl*>(_object); + + if (_key == "ingen:broadcast") { _special_type = ENABLE_BROADCAST; + } else if (_patch) { + if (!_property && _key == "ingen:enabled") { + if (_value.type() == Atom::BOOL) { + _special_type = ENABLE; + if (_value.get_bool() && !_patch->compiled_patch()) + _compiled_patch = _patch->compile(); + } else { + _error = BAD_TYPE; + } + } else if (!_property && _key == "ingen:polyphonic") { + if (_value.type() == Atom::BOOL) { + _special_type = POLYPHONIC; + } else { + _error = BAD_TYPE; + } + } else if (_property && _key == "ingen:polyphony") { + if (_value.type() == Atom::INT) { + _special_type = POLYPHONY; + _patch->prepare_internal_poly(_value.get_int32()); + } else { + _error = BAD_TYPE; + } + } + } QueuedEvent::pre_process(); } @@ -80,33 +113,69 @@ SetMetadataEvent::pre_process() void SetMetadataEvent::execute(ProcessContext& context) { - if (_special_type == ENABLE_BROADCAST) { - PortImpl* port = dynamic_cast<PortImpl*>(_object); - if (port) + if (_error != NO_ERROR) + return; + + PortImpl* port = 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(); + } + break; + case POLYPHONIC: + 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); - // Do nothing } void SetMetadataEvent::post_process() { - if (_error == INVALID_PATH) { - _responder->respond_error((boost::format("Invalid path '%1%' setting '%2%'") % _path % _key).str()); - } else if (_object == NULL) { - string msg = (boost::format("Unable to find object '%1%' to set '%2%'") % _path % _key).str(); - _responder->respond_error(msg); - } else { + switch (_error) { + case NO_ERROR: _responder->respond_ok(); if (_property) _engine.broadcaster()->send_property_change(_path, _key, _value); else _engine.broadcaster()->send_variable_change(_path, _key, _value); + break; + case NOT_FOUND: + _responder->respond_error((boost::format( + "Unable to find object '%1%' to set '%2%'") + % _path % _key).str()); + case INTERNAL: + _responder->respond_error("Internal error"); + break; + case INVALID_PATH: + _responder->respond_error((boost::format( + "Invalid path '%1%' setting '%2%'") + % _path % _key).str()); + break; + case BAD_TYPE: + _responder->respond_error((boost::format("Bad type for '%1%'") % _key).str()); + break; } } } // namespace Ingen + |