Added AddPortEvent

git-svn-id: http://svn.drobilla.net/lad@65 a436a847-0d15-0410-975c-d299462d15a1
This commit is contained in:
dave 2006-06-19 18:25:21 +00:00
parent 5da27f13a8
commit 9455eb5206
2 changed files with 192 additions and 0 deletions

View File

@ -0,0 +1,119 @@
/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
*
* Om 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.
*
* Om 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "AddPortEvent.h"
#include "Responder.h"
#include "Patch.h"
#include "Tree.h"
#include "Plugin.h"
#include "Om.h"
#include "OmApp.h"
#include "Patch.h"
#include "Maid.h"
#include "util/Path.h"
#include "ObjectStore.h"
#include "ClientBroadcaster.h"
#include "util/Path.h"
#include "Port.h"
#include "AudioDriver.h"
#include "List.h"
namespace Om {
AddPortEvent::AddPortEvent(CountedPtr<Responder> responder, const string& path, const string& type, bool is_output)
: QueuedEvent(responder),
_path(path),
_type(type),
_is_output(is_output),
_data_type(DataType::UNKNOWN),
_patch(NULL),
_port(NULL),
_succeeded(true)
{
string type_str;
if (type == "CONTROL" || type == "AUDIO")
_data_type = DataType::FLOAT;
else if (type == "MIDI")
_data_type = DataType::MIDI;
}
AddPortEvent::~AddPortEvent()
{
}
void
AddPortEvent::pre_process()
{
if (om->object_store()->find(_path) != NULL) {
QueuedEvent::pre_process();
return;
}
_patch = om->object_store()->find_patch(_path.parent());
if (_patch != NULL) {
assert(_patch->path() == _path.parent());
size_t buffer_size = 1;
if (_type == "AUDIO" || _type == "MIDI")
buffer_size = om->audio_driver()->buffer_size();
_port = _patch->create_port(_path.name(), _data_type, buffer_size, _is_output);
if (_port) {
if (_is_output)
_patch->add_output(new ListNode<Port*>(_port));
else
_patch->add_input(new ListNode<Port*>(_port));
_ports_array = new Array<Port*>(_patch->num_ports() + 1, _patch->external_ports());
_ports_array->at(_patch->num_ports()) = _port;
om->object_store()->add(_port);
}
}
QueuedEvent::pre_process();
}
void
AddPortEvent::execute(samplecount offset)
{
QueuedEvent::execute(offset);
if (_port) {
om->maid()->push(_patch->external_ports());
//_patch->add_port(_port);
_patch->external_ports(_ports_array);
}
}
void
AddPortEvent::post_process()
{
if (!_succeeded) {
const string msg = string("Could not create port - ").append(_path);// + " already exists.";
m_responder->respond_error(msg);
} else {
m_responder->respond_ok();
om->client_broadcaster()->send_port(_port);
}
}
} // namespace Om

View File

@ -0,0 +1,73 @@
/* This file is part of Om. Copyright (C) 2006 Dave Robillard.
*
* Om 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.
*
* Om 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.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef ADDPORTEVENT_H
#define ADDPORTEVENT_H
#include "QueuedEvent.h"
#include "util/Path.h"
#include "DataType.h"
#include "Array.h"
#include <string>
using std::string;
template <typename T> class Array;
namespace Om {
class Patch;
class Port;
class Plugin;
/** An event to add a Port to a Patch.
*
* \ingroup engine
*/
class AddPortEvent : public QueuedEvent
{
public:
AddPortEvent(CountedPtr<Responder> responder, const string& path, const string& type, bool is_output);
~AddPortEvent();
void pre_process();
void execute(samplecount offset);
void post_process();
private:
Path _path;
string _type;
bool _is_output;
DataType _data_type;
Patch* _patch;
Port* _port;
Array<Port*>* _ports_array; // New (external) ports array for Patch
bool _succeeded;
/*
string m_patch_name;
Path m_path;
Plugin* m_plugin;
bool m_poly;
Patch* m_patch;
Node* m_node;
Array<Node*>* m_process_order; // Patch's new process order
bool m_node_already_exists;*/
};
} // namespace Om
#endif // ADDPORTEVENT_H