summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-10-07 00:13:35 +0000
committerDavid Robillard <d@drobilla.net>2011-10-07 00:13:35 +0000
commit59d6a7095c79a84475b95cb4121d9e3845806d16 (patch)
tree0576aa01920cd100bb42ac8bb41b0cf36e61857f /src/server
parent43f3bebb6faf2e065bf8f61b66a04ceabb0dd5e5 (diff)
downloadingen-59d6a7095c79a84475b95cb4121d9e3845806d16.tar.gz
ingen-59d6a7095c79a84475b95cb4121d9e3845806d16.tar.bz2
ingen-59d6a7095c79a84475b95cb4121d9e3845806d16.zip
Tidy.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3537 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/server')
-rw-r--r--src/server/PatchImpl.cpp69
-rw-r--r--src/server/PatchImpl.hpp56
2 files changed, 81 insertions, 44 deletions
diff --git a/src/server/PatchImpl.cpp b/src/server/PatchImpl.cpp
index e253e7b3..4f26473f 100644
--- a/src/server/PatchImpl.cpp
+++ b/src/server/PatchImpl.cpp
@@ -71,7 +71,7 @@ PatchImpl::activate(BufferFactory& bufs)
{
NodeImpl::activate(bufs);
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
(*i)->activate(bufs);
assert(_activated);
@@ -83,7 +83,7 @@ PatchImpl::deactivate()
if (_activated) {
NodeImpl::deactivate();
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i) {
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i) {
if ((*i)->activated())
(*i)->deactivate();
assert(!(*i)->activated());
@@ -99,7 +99,7 @@ PatchImpl::disable()
_process = false;
- for (List<PortImpl*>::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i)
+ for (Ports::iterator i = _outputs.begin(); i != _outputs.end(); ++i)
if ((*i)->context() == Context::AUDIO)
(*i)->clear_buffers();
}
@@ -111,10 +111,10 @@ PatchImpl::prepare_internal_poly(BufferFactory& bufs, uint32_t poly)
// TODO: Subpatch dynamic polyphony (i.e. changing port polyphony)
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
(*i)->prepare_poly(bufs, poly);
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
for (uint32_t j = 0; j < (*i)->num_ports(); ++j)
(*i)->port_impl(j)->prepare_poly_buffers(bufs);
@@ -122,16 +122,19 @@ PatchImpl::prepare_internal_poly(BufferFactory& bufs, uint32_t poly)
}
bool
-PatchImpl::apply_internal_poly(ProcessContext& context, BufferFactory& bufs, Raul::Maid& maid, uint32_t poly)
+PatchImpl::apply_internal_poly(ProcessContext& context,
+ BufferFactory& bufs,
+ Raul::Maid& maid,
+ uint32_t poly)
{
ThreadManager::assert_thread(THREAD_PROCESS);
// TODO: Subpatch dynamic polyphony (i.e. changing port polyphony)
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
(*i)->apply_poly(maid, poly);
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i) {
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i) {
for (uint32_t j = 0; j < (*i)->num_ports(); ++j) {
PortImpl* const port = (*i)->port_impl(j);
if (port->is_input() && dynamic_cast<InputPort*>(port)->direct_connect())
@@ -141,7 +144,7 @@ PatchImpl::apply_internal_poly(ProcessContext& context, BufferFactory& bufs, Rau
}
const bool polyphonic = parent_patch() && (poly == parent_patch()->internal_poly());
- for (List<PortImpl*>::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i)
+ for (Ports::iterator i = _outputs.begin(); i != _outputs.end(); ++i)
(*i)->setup_buffers(bufs, polyphonic ? poly : 1);
_internal_poly = poly;
@@ -252,7 +255,10 @@ PatchImpl::process_single(ProcessContext& context)
}
void
-PatchImpl::set_buffer_size(Context& context, BufferFactory& bufs, PortType type, size_t size)
+PatchImpl::set_buffer_size(Context& context,
+ BufferFactory& bufs,
+ PortType type,
+ size_t size)
{
NodeImpl::set_buffer_size(context, bufs, type, size);
@@ -266,7 +272,7 @@ PatchImpl::set_buffer_size(Context& context, BufferFactory& bufs, PortType type,
* Preprocessing thread only.
*/
void
-PatchImpl::add_node(List<NodeImpl*>::Node* ln)
+PatchImpl::add_node(Nodes::Node* ln)
{
ThreadManager::assert_thread(THREAD_PRE_PROCESS);
assert(ln != NULL);
@@ -284,7 +290,7 @@ PatchImpl::Nodes::Node*
PatchImpl::remove_node(const Raul::Symbol& symbol)
{
ThreadManager::assert_thread(THREAD_PRE_PROCESS);
- for (List<NodeImpl*>::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
+ for (Nodes::iterator i = _nodes.begin(); i != _nodes.end(); ++i)
if ((*i)->symbol() == symbol)
return _nodes.erase(i);
@@ -330,21 +336,24 @@ PatchImpl::num_ports() const
if (ThreadManager::thread_is(THREAD_PROCESS))
return NodeImpl::num_ports();
else
- return _input_ports.size() + _output_ports.size();
+ return _inputs.size() + _outputs.size();
}
/** Create a port. Not realtime safe.
*/
PortImpl*
-PatchImpl::create_port(BufferFactory& bufs, const string& name, PortType type, size_t buffer_size, bool is_output, bool polyphonic)
+PatchImpl::create_port(BufferFactory& bufs,
+ const string& name,
+ PortType type,
+ size_t buffer_size,
+ bool is_output,
+ bool polyphonic)
{
if (type == PortType::UNKNOWN) {
error << "[PatchImpl::create_port] Unknown port type " << type.uri() << endl;
return NULL;
}
- assert( !(type == PortType::UNKNOWN) );
-
Raul::Atom value;
if (type == PortType::CONTROL)
value = 0.0f;
@@ -360,25 +369,25 @@ PatchImpl::create_port(BufferFactory& bufs, const string& name, PortType type, s
*
* Realtime safe. Preprocessing thread only.
*/
-List<PortImpl*>::Node*
+PatchImpl::Ports::Node*
PatchImpl::remove_port(const string& symbol)
{
ThreadManager::assert_thread(THREAD_PRE_PROCESS);
bool found = false;
- List<PortImpl*>::Node* ret = NULL;
- for (List<PortImpl*>::iterator i = _input_ports.begin(); i != _input_ports.end(); ++i) {
+ Ports::Node* ret = NULL;
+ for (Ports::iterator i = _inputs.begin(); i != _inputs.end(); ++i) {
if ((*i)->symbol() == symbol) {
- ret = _input_ports.erase(i);
+ ret = _inputs.erase(i);
found = true;
break;
}
}
if (!found)
- for (List<PortImpl*>::iterator i = _output_ports.begin(); i != _output_ports.end(); ++i) {
+ for (Ports::iterator i = _outputs.begin(); i != _outputs.end(); ++i) {
if ((*i)->symbol() == symbol) {
- ret = _output_ports.erase(i);
+ ret = _outputs.erase(i);
found = true;
break;
}
@@ -402,8 +411,8 @@ PatchImpl::clear_ports()
{
ThreadManager::assert_thread(THREAD_PRE_PROCESS);
- _input_ports.clear();
- _output_ports.clear();
+ _inputs.clear();
+ _outputs.clear();
}
Raul::Array<PortImpl*>*
@@ -411,16 +420,19 @@ PatchImpl::build_ports_array() const
{
ThreadManager::assert_thread(THREAD_PRE_PROCESS);
- Raul::Array<PortImpl*>* const result = new Raul::Array<PortImpl*>(_input_ports.size() + _output_ports.size());
+ const size_t n = _inputs.size() + _outputs.size();
+ Raul::Array<PortImpl*>* const result = new Raul::Array<PortImpl*>(n);
size_t i = 0;
- for (List<PortImpl*>::const_iterator p = _input_ports.begin(); p != _input_ports.end(); ++p,++i)
+ for (Ports::const_iterator p = _inputs.begin(); p != _inputs.end(); ++p,++i)
result->at(i) = *p;
- for (List<PortImpl*>::const_iterator p = _output_ports.begin(); p != _output_ports.end(); ++p,++i)
+ for (Ports::const_iterator p = _outputs.begin(); p != _outputs.end(); ++p,++i)
result->at(i) = *p;
+ assert(i == n - 1);
+
return result;
}
@@ -459,7 +471,8 @@ PatchImpl::compile() const
}
// Add any queued connections that must be run after a cycle
- for (Connections::const_iterator i = _connections.begin(); i != _connections.end(); ++i) {
+ for (Connections::const_iterator i = _connections.begin();
+ i != _connections.end(); ++i) {
SharedPtr<ConnectionImpl> c = PtrCast<ConnectionImpl>(i->second);
if (c->src_port()->context() == Context::AUDIO &&
c->dst_port()->context() == Context::MESSAGE) {
diff --git a/src/server/PatchImpl.hpp b/src/server/PatchImpl.hpp
index 095a04b7..4dfdba61 100644
--- a/src/server/PatchImpl.hpp
+++ b/src/server/PatchImpl.hpp
@@ -28,6 +28,7 @@
#include "NodeImpl.hpp"
#include "PluginImpl.hpp"
#include "PortType.hpp"
+#include "ThreadManager.hpp"
namespace Ingen {
@@ -66,7 +67,10 @@ public:
void process(ProcessContext& context);
- void set_buffer_size(Context& context, BufferFactory& bufs, PortType type, size_t size);
+ void set_buffer_size(Context& context,
+ BufferFactory& bufs,
+ PortType type,
+ size_t size);
/** Prepare for a new (internal) polyphony value.
*
@@ -84,7 +88,10 @@ public:
* \param poly Must be < the most recent value passed to prepare_internal_poly.
* \param maid Any objects no longer needed will be pushed to this
*/
- bool apply_internal_poly(ProcessContext& context, BufferFactory& bufs, Raul::Maid& maid, uint32_t poly);
+ bool apply_internal_poly(ProcessContext& context,
+ BufferFactory& bufs,
+ Raul::Maid& maid,
+ uint32_t poly);
// Patch specific stuff not inherited from Node
@@ -101,15 +108,32 @@ public:
uint32_t num_ports() const;
- PortImpl* create_port(BufferFactory& bufs, const std::string& name, PortType type, size_t buffer_size, bool is_output, bool polyphonic);
- void add_input(Raul::List<PortImpl*>::Node* port) { _input_ports.push_back(port); } ///< Preprocesser thread
- void add_output(Raul::List<PortImpl*>::Node* port) { _output_ports.push_back(port); } ///< Preprocessor thread
- Raul::List<PortImpl*>::Node* remove_port(const std::string& name);
- void clear_ports();
+ PortImpl* create_port(BufferFactory& bufs,
+ const std::string& name,
+ PortType type,
+ size_t buffer_size,
+ bool is_output,
+ bool polyphonic);
+
+ typedef Raul::List<PortImpl*> Ports;
+
+ void add_input(Ports::Node* port) {
+ ThreadManager::assert_thread(THREAD_PRE_PROCESS);
+ _inputs.push_back(port);
+ }
+
+ void add_output(Ports::Node* port) {
+ ThreadManager::assert_thread(THREAD_PRE_PROCESS);
+ _outputs.push_back(port);
+ }
+
+ Ports::Node* remove_port(const std::string& name);
+ void clear_ports();
void add_connection(SharedPtr<ConnectionImpl> c);
- SharedPtr<ConnectionImpl> remove_connection(const PortImpl* src_port, const PortImpl* dst_port);
+ SharedPtr<ConnectionImpl> remove_connection(const PortImpl* src_port,
+ const PortImpl* dst_port);
bool has_connection(const PortImpl* src_port, const PortImpl* dst_port) const;
@@ -134,14 +158,14 @@ private:
void process_parallel(ProcessContext& context);
void process_single(ProcessContext& context);
- Engine& _engine;
- uint32_t _internal_poly;
- CompiledPatch* _compiled_patch; ///< Accessed in audio thread only
- Connections _connections; ///< Accessed in preprocessing thread only
- Raul::List<PortImpl*> _input_ports; ///< Accessed in preprocessing thread only
- Raul::List<PortImpl*> _output_ports; ///< Accessed in preprocessing thread only
- Nodes _nodes; ///< Accessed in preprocessing thread only
- bool _process;
+ Engine& _engine;
+ uint32_t _internal_poly;
+ CompiledPatch* _compiled_patch; ///< Process thread only
+ Connections _connections; ///< Pre-process thread only
+ Ports _inputs; ///< Pre-process thread only
+ Ports _outputs; ///< Pre-process thread only
+ Nodes _nodes; ///< Pre-process thread only
+ bool _process;
};
/** Private helper for compile */