/* 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 "ClearPatchEvent.hpp" #include "Responder.hpp" #include "Engine.hpp" #include "PatchImpl.hpp" #include "ClientBroadcaster.hpp" #include "util.hpp" #include "ObjectStore.hpp" #include "PortImpl.hpp" #include "NodeImpl.hpp" #include "ConnectionImpl.hpp" #include "QueuedEventSource.hpp" namespace Ingen { ClearPatchEvent::ClearPatchEvent(Engine& engine, SharedPtr responder, FrameTime time, QueuedEventSource* source, const string& patch_path) : QueuedEvent(engine, responder, time, true, source), _patch_path(patch_path), _patch(NULL), _process(false) { } void ClearPatchEvent::pre_process() { cerr << "FIXME: CLEAR PATCH\n"; #if 0 _patch = _engine.object_store()->find_patch(_patch_path); if (_patch != NULL) { _process = _patch->enabled(); for (List::const_iterator i = _patch->nodes().begin(); i != _patch->nodes().end(); ++i) (*i)->remove_from_store(); } #endif QueuedEvent::pre_process(); } void ClearPatchEvent::execute(ProcessContext& context) { QueuedEvent::execute(context); if (_patch != NULL) { _patch->disable(); cerr << "FIXME: CLEAR PATCH\n"; //for (List::const_iterator i = _patch->nodes().begin(); i != _patch->nodes().end(); ++i) // (*i)->remove_from_patch(); if (_patch->compiled_patch() != NULL) { _engine.maid()->push(_patch->compiled_patch()); _patch->compiled_patch(NULL); } } } void ClearPatchEvent::post_process() { if (_patch != NULL) { // Delete all nodes for (List::iterator i = _patch->nodes().begin(); i != _patch->nodes().end(); ++i) { (*i)->deactivate(); delete *i; } _patch->nodes().clear(); // Delete all connections for (PatchImpl::Connections::iterator i = _patch->connections().begin(); i != _patch->connections().end(); ++i) (*i).reset(); _patch->connections().clear(); // Restore patch's run state if (_process) _patch->enable(); else _patch->disable(); // Make sure everything's sane assert(_patch->nodes().size() == 0); assert(_patch->connections().size() == 0); // Reply _responder->respond_ok(); _engine.broadcaster()->send_patch_cleared(_patch_path); } else { _responder->respond_error(string("Patch ") + _patch_path + " not found"); } _source->unblock(); // FIXME: can be done earlier in execute? } } // namespace Ingen