diff options
Diffstat (limited to 'src/server/BlockImpl.cpp')
-rw-r--r-- | src/server/BlockImpl.cpp | 83 |
1 files changed, 40 insertions, 43 deletions
diff --git a/src/server/BlockImpl.cpp b/src/server/BlockImpl.cpp index ba0bdc77..b4f407c3 100644 --- a/src/server/BlockImpl.cpp +++ b/src/server/BlockImpl.cpp @@ -20,33 +20,31 @@ #include "GraphImpl.hpp" #include "PluginImpl.hpp" #include "PortImpl.hpp" +#include "PortType.hpp" #include "RunContext.hpp" #include "ThreadManager.hpp" -#include "raul/Array.hpp" -#include "raul/Maid.hpp" -#include "raul/Symbol.hpp" +#include <lv2/urid/urid.h> +#include <raul/Array.hpp> +#include <raul/Symbol.hpp> +#include <algorithm> #include <cassert> #include <cstdint> #include <initializer_list> #include <string> -namespace ingen { -namespace server { +namespace ingen::server { BlockImpl::BlockImpl(PluginImpl* plugin, - const Raul::Symbol& symbol, + const raul::Symbol& symbol, bool polyphonic, GraphImpl* parent, SampleRate) : NodeImpl(plugin->uris(), parent, symbol) , _plugin(plugin) , _polyphony((polyphonic && parent) ? parent->internal_poly() : 1) - , _mark(Mark::UNVISITED) , _polyphonic(polyphonic) - , _activated(false) - , _enabled(true) { assert(_plugin); assert(_polyphony > 0); @@ -57,7 +55,7 @@ BlockImpl::~BlockImpl() assert(!_activated); if (is_linked()) { - ((GraphImpl*)_parent)->remove_block(*this); + reinterpret_cast<GraphImpl*>(_parent)->remove_block(*this); } } @@ -120,7 +118,7 @@ BlockImpl::prepare_poly(BufferFactory& bufs, uint32_t poly) } bool -BlockImpl::apply_poly(RunContext& context, uint32_t poly) +BlockImpl::apply_poly(RunContext& ctx, uint32_t poly) { if (!_polyphonic) { poly = 1; @@ -130,7 +128,7 @@ BlockImpl::apply_poly(RunContext& context, uint32_t poly) if (_ports) { for (uint32_t i = 0; i < num_ports(); ++i) { - _ports->at(i)->apply_poly(context, poly); + _ports->at(i)->apply_poly(ctx, poly); } } @@ -138,7 +136,7 @@ BlockImpl::apply_poly(RunContext& context, uint32_t poly) } void -BlockImpl::set_buffer_size(RunContext& context, +BlockImpl::set_buffer_size(RunContext& ctx, BufferFactory& bufs, LV2_URID type, uint32_t size) @@ -147,7 +145,7 @@ BlockImpl::set_buffer_size(RunContext& context, for (uint32_t i = 0; i < _ports->size(); ++i) { PortImpl* const p = _ports->at(i); if (p->buffer_type() == type) { - p->set_buffer_size(context, bufs, size); + p->set_buffer_size(ctx, bufs, size); } } } @@ -180,18 +178,18 @@ BlockImpl::port_by_symbol(const char* symbol) } void -BlockImpl::pre_process(RunContext& context) +BlockImpl::pre_process(RunContext& ctx) { // Mix down input ports for (uint32_t i = 0; i < num_ports(); ++i) { PortImpl* const port = _ports->at(i); - port->pre_process(context); + port->pre_process(ctx); port->connect_buffers(); } } void -BlockImpl::bypass(RunContext& context) +BlockImpl::bypass(RunContext& ctx) { if (!_ports) { return; @@ -200,20 +198,22 @@ BlockImpl::bypass(RunContext& context) // Prepare port buffers for reading, converting/mixing if necessary for (uint32_t i = 0; i < _ports->size(); ++i) { _ports->at(i)->connect_buffers(); - _ports->at(i)->pre_run(context); + _ports->at(i)->pre_run(ctx); } // Dumb bypass - for (PortType t : { PortType::AUDIO, PortType::CV, PortType::ATOM }) { + for (const PortType t : { PortType::AUDIO, PortType::CV, PortType::ATOM }) { for (uint32_t i = 0;; ++i) { - PortImpl* in = nth_port_by_type(i, true, t); - PortImpl* out = nth_port_by_type(i, false, t); + const PortImpl* in = nth_port_by_type(i, true, t); + const PortImpl* out = nth_port_by_type(i, false, t); if (!out) { - break; // Finished writing all outputs - } else if (in) { + break; // Finished writing all outputs + } + + if (in) { // Copy corresponding input to output for (uint32_t v = 0; v < _polyphony; ++v) { - out->buffer(v)->copy(context, in->buffer(v).get()); + out->buffer(v)->copy(ctx, in->buffer(v).get()); } } else { // Output but no corresponding input, clear @@ -223,32 +223,30 @@ BlockImpl::bypass(RunContext& context) } } } - post_process(context); + post_process(ctx); } void -BlockImpl::process(RunContext& context) +BlockImpl::process(RunContext& ctx) { - pre_process(context); + pre_process(ctx); if (!_enabled) { - bypass(context); - post_process(context); + bypass(ctx); + post_process(ctx); return; } - RunContext subcontext(context); - for (SampleCount offset = 0; offset < context.nframes();) { + RunContext subcontext(ctx); + for (SampleCount offset = 0; offset < ctx.nframes();) { // Find earliest offset of a value change - SampleCount chunk_end = context.nframes(); + SampleCount chunk_end = ctx.nframes(); for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - PortImpl* const port = _ports->at(i); + const PortImpl* const port = _ports->at(i); if (port->type() == PortType::CONTROL && port->is_input()) { const SampleCount o = port->next_value_offset( - offset, context.nframes()); - if (o < chunk_end) { - chunk_end = o; - } + offset, ctx.nframes()); + chunk_end = std::min(o, chunk_end); } } @@ -266,7 +264,7 @@ BlockImpl::process(RunContext& context) // Emit control port outputs as events for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - PortImpl* const port = _ports->at(i); + const PortImpl* const port = _ports->at(i); if (port->type() == PortType::CONTROL && port->is_output()) { // TODO: Only emit events when value has actually changed? for (uint32_t v = 0; v < _polyphony; ++v) { @@ -279,15 +277,15 @@ BlockImpl::process(RunContext& context) subcontext.slice(offset, chunk_end - offset); } - post_process(context); + post_process(ctx); } void -BlockImpl::post_process(RunContext& context) +BlockImpl::post_process(RunContext& ctx) { // Write output ports for (uint32_t i = 0; _ports && i < _ports->size(); ++i) { - _ports->at(i)->post_process(context); + _ports->at(i)->post_process(ctx); } } @@ -298,5 +296,4 @@ BlockImpl::set_port_buffer(uint32_t, uint32_t, const BufferRef&, SampleCount) << " buffer " << buf << " offset " << offset << std::endl;*/ } -} // namespace server -} // namespace ingen +} // namespace ingen::server |