From 8d1e92ab0655d4ede8ea17358d678b3a5aabc1bc Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 23 Apr 2012 02:32:33 +0000 Subject: Localise buffer reference stuff. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4252 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/Buffer.hpp | 7 ------- src/server/BufferFactory.cpp | 12 ++++++------ src/server/BufferFactory.hpp | 11 +++++------ src/server/BufferRef.hpp | 39 ++++++++++++++++++++++++++++++++++++++ src/server/ConnectionImpl.cpp | 2 +- src/server/ConnectionImpl.hpp | 2 +- src/server/ControlBindings.hpp | 2 +- src/server/DuplexPort.cpp | 6 +++--- src/server/DuplexPort.hpp | 6 +++--- src/server/InputPort.cpp | 6 +++--- src/server/InputPort.hpp | 6 +++--- src/server/NodeImpl.cpp | 8 ++++---- src/server/OutputPort.cpp | 6 +++--- src/server/OutputPort.hpp | 6 +++--- src/server/PortImpl.cpp | 10 +++++----- src/server/PortImpl.hpp | 41 ++++++++++++++++++++-------------------- src/server/events/Connect.cpp | 2 +- src/server/events/Connect.hpp | 2 +- src/server/events/Disconnect.cpp | 2 +- src/server/events/Disconnect.hpp | 12 ++++++------ 20 files changed, 110 insertions(+), 78 deletions(-) create mode 100644 src/server/BufferRef.hpp diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp index 11436d9c..fcd6fe65 100644 --- a/src/server/Buffer.hpp +++ b/src/server/Buffer.hpp @@ -44,8 +44,6 @@ class Buffer : public boost::noncopyable, public Raul::Deletable public: Buffer(BufferFactory& bufs, LV2_URID type, uint32_t capacity); - typedef boost::intrusive_ptr Ref; - virtual void clear(); virtual void resize(uint32_t size); virtual void copy(Context& context, const Buffer* src); @@ -94,9 +92,4 @@ private: } // namespace Server } // namespace Ingen -namespace boost { -inline void intrusive_ptr_add_ref(Ingen::Server::Buffer* b) { b->ref(); } -inline void intrusive_ptr_release(Ingen::Server::Buffer* b) { b->deref(); } -} - #endif // INGEN_ENGINE_BUFFER_HPP diff --git a/src/server/BufferFactory.cpp b/src/server/BufferFactory.cpp index d5b268b7..73b6558d 100644 --- a/src/server/BufferFactory.cpp +++ b/src/server/BufferFactory.cpp @@ -92,7 +92,7 @@ BufferFactory::default_buffer_size(LV2_URID type) } } -BufferFactory::Ref +BufferRef BufferFactory::get(LV2_URID type, uint32_t capacity, bool force_create) { Raul::AtomicPtr& head_ptr = free_list(type); @@ -114,21 +114,21 @@ BufferFactory::get(LV2_URID type, uint32_t capacity, bool force_create) } else { assert(false); error << "Failed to obtain buffer" << endl; - return Ref(); + return BufferRef(); } } try_head->_next = NULL; - return Ref(try_head); + return BufferRef(try_head); } -BufferFactory::Ref +BufferRef BufferFactory::silent_buffer() { return _silent_buffer; } -BufferFactory::Ref +BufferRef BufferFactory::create(LV2_URID type, uint32_t capacity) { ThreadManager::assert_not_thread(THREAD_PROCESS); @@ -152,7 +152,7 @@ BufferFactory::create(LV2_URID type, uint32_t capacity) buffer->atom()->type = type; assert(buffer); - return Ref(buffer); + return BufferRef(buffer); } void diff --git a/src/server/BufferFactory.hpp b/src/server/BufferFactory.hpp index e04cf1e9..08f7680b 100644 --- a/src/server/BufferFactory.hpp +++ b/src/server/BufferFactory.hpp @@ -32,6 +32,7 @@ #include "ingen/shared/URIs.hpp" #include "Buffer.hpp" +#include "BufferRef.hpp" #include "PortType.hpp" #include "types.hpp" @@ -50,14 +51,12 @@ public: ~BufferFactory(); - typedef boost::intrusive_ptr Ref; - static uint32_t audio_buffer_size(SampleCount nframes); uint32_t default_buffer_size(LV2_URID type); - Ref get(LV2_URID type, uint32_t capacity, bool force_create=false); + BufferRef get(LV2_URID type, uint32_t capacity, bool force_create=false); - Ref silent_buffer(); + BufferRef silent_buffer(); void set_block_length(SampleCount block_length); @@ -69,7 +68,7 @@ private: friend class Buffer; void recycle(Buffer* buf); - Ref create(LV2_URID type, uint32_t capacity=0); + BufferRef create(LV2_URID type, uint32_t capacity=0); inline Raul::AtomicPtr& free_list(LV2_URID type) { if (type == _uris->atom_Float) { @@ -91,7 +90,7 @@ private: Engine& _engine; SharedPtr _uris; - Ref _silent_buffer; + BufferRef _silent_buffer; }; } // namespace Server diff --git a/src/server/BufferRef.hpp b/src/server/BufferRef.hpp new file mode 100644 index 00000000..12a62930 --- /dev/null +++ b/src/server/BufferRef.hpp @@ -0,0 +1,39 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard + + Ingen is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or 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 Affero General Public License for details. + + You should have received a copy of the GNU Affero General Public License + along with Ingen. If not, see . +*/ + +#ifndef INGEN_ENGINE_BUFFERREF_HPP +#define INGEN_ENGINE_BUFFERREF_HPP + +#include + +namespace Ingen { +namespace Server { + +class Buffer; + +typedef boost::intrusive_ptr BufferRef; + +} // namespace Server +} // namespace Ingen + +namespace boost { + +inline void intrusive_ptr_add_ref(Ingen::Server::Buffer* b) { b->ref(); } +inline void intrusive_ptr_release(Ingen::Server::Buffer* b) { b->deref(); } + +} + +#endif // INGEN_ENGINE_BUFFERREF_HPP diff --git a/src/server/ConnectionImpl.cpp b/src/server/ConnectionImpl.cpp index 6c17618e..2b6a0255 100644 --- a/src/server/ConnectionImpl.cpp +++ b/src/server/ConnectionImpl.cpp @@ -128,7 +128,7 @@ ConnectionImpl::queue(Context& context) } } -BufferFactory::Ref +BufferRef ConnectionImpl::buffer(uint32_t voice) const { assert(!must_mix()); diff --git a/src/server/ConnectionImpl.hpp b/src/server/ConnectionImpl.hpp index 20f5586f..4d915606 100644 --- a/src/server/ConnectionImpl.hpp +++ b/src/server/ConnectionImpl.hpp @@ -83,7 +83,7 @@ public: * buffer, and will return accordingly (e.g. the same buffer for every * voice in a mono->poly connection). */ - BufferFactory::Ref buffer(uint32_t voice) const; + BufferRef buffer(uint32_t voice) const; /** Returns true if this connection must mix down voices into a local buffer */ bool must_mix() const; diff --git a/src/server/ControlBindings.hpp b/src/server/ControlBindings.hpp index 1a42961c..0a3a92c0 100644 --- a/src/server/ControlBindings.hpp +++ b/src/server/ControlBindings.hpp @@ -111,7 +111,7 @@ private: PortImpl* _learn_port; SharedPtr _bindings; - BufferFactory::Ref _feedback; + BufferRef _feedback; }; } // namespace Server diff --git a/src/server/DuplexPort.cpp b/src/server/DuplexPort.cpp index 749eaf84..6050e669 100644 --- a/src/server/DuplexPort.cpp +++ b/src/server/DuplexPort.cpp @@ -57,9 +57,9 @@ DuplexPort::DuplexPort( } bool -DuplexPort::get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const +DuplexPort::get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const { if (_is_output) return InputPort::get_buffers(bufs, buffers, poly); diff --git a/src/server/DuplexPort.hpp b/src/server/DuplexPort.hpp index a928f27c..5b8f30e0 100644 --- a/src/server/DuplexPort.hpp +++ b/src/server/DuplexPort.hpp @@ -52,9 +52,9 @@ public: virtual ~DuplexPort() {} - bool get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const; + bool get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const; void pre_process(Context& context); void post_process(Context& context); diff --git a/src/server/InputPort.cpp b/src/server/InputPort.cpp index f50a3d55..3fadd312 100644 --- a/src/server/InputPort.cpp +++ b/src/server/InputPort.cpp @@ -78,9 +78,9 @@ InputPort::apply_poly(Maid& maid, uint32_t poly) * @return true iff buffers are locally owned by the port */ bool -InputPort::get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const +InputPort::get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const { size_t num_connections = (ThreadManager::thread_is(THREAD_PROCESS)) ? _connections.size() : _num_connections; diff --git a/src/server/InputPort.hpp b/src/server/InputPort.hpp index d4af9a2c..89f3949a 100644 --- a/src/server/InputPort.hpp +++ b/src/server/InputPort.hpp @@ -73,9 +73,9 @@ public: bool apply_poly(Raul::Maid& maid, uint32_t poly); - bool get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const; + bool get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const; void pre_process(Context& context); void post_process(Context& context); diff --git a/src/server/NodeImpl.cpp b/src/server/NodeImpl.cpp index 0d930a5f..36074649 100644 --- a/src/server/NodeImpl.cpp +++ b/src/server/NodeImpl.cpp @@ -232,10 +232,10 @@ NodeImpl::post_process(Context& context) } void -NodeImpl::set_port_buffer(uint32_t voice, - uint32_t port_num, - BufferFactory::Ref buf, - SampleCount offset) +NodeImpl::set_port_buffer(uint32_t voice, + uint32_t port_num, + BufferRef buf, + SampleCount offset) { /*std::cout << path() << " set port " << port_num << " voice " << voice << " buffer " << buf << " offset " << offset << std::endl;*/ diff --git a/src/server/OutputPort.cpp b/src/server/OutputPort.cpp index f7d6de95..b8ad0169 100644 --- a/src/server/OutputPort.cpp +++ b/src/server/OutputPort.cpp @@ -49,9 +49,9 @@ OutputPort::OutputPort(BufferFactory& bufs, } bool -OutputPort::get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const +OutputPort::get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const { for (uint32_t v = 0; v < poly; ++v) buffers->at(v) = bufs.get(buffer_type(), _buffer_size); diff --git a/src/server/OutputPort.hpp b/src/server/OutputPort.hpp index 9fb3ab58..2338f5cf 100644 --- a/src/server/OutputPort.hpp +++ b/src/server/OutputPort.hpp @@ -51,9 +51,9 @@ public: virtual ~OutputPort() {} - bool get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const; + bool get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const; void pre_process(Context& context); void post_process(Context& context); diff --git a/src/server/PortImpl.cpp b/src/server/PortImpl.cpp index 4ca87cf8..c4d186d7 100644 --- a/src/server/PortImpl.cpp +++ b/src/server/PortImpl.cpp @@ -55,7 +55,7 @@ PortImpl::PortImpl(BufferFactory& bufs, , _min(bufs.forge().make(0.0f)) , _max(bufs.forge().make(1.0f)) , _last_broadcasted_value(value) - , _buffers(new Array(static_cast(poly))) + , _buffers(new Array(static_cast(poly))) , _prepared_buffers(NULL) , _broadcast(false) , _set_by_user(false) @@ -99,12 +99,12 @@ PortImpl::supports(const Raul::URI& value_type) const _bufs.forge().alloc_uri(value_type.str())); } -Raul::Array* -PortImpl::set_buffers(Raul::Array* buffers) +Raul::Array* +PortImpl::set_buffers(Raul::Array* buffers) { ThreadManager::assert_thread(THREAD_PROCESS); - Raul::Array* ret = NULL; + Raul::Array* ret = NULL; if (buffers != _buffers) { ret = _buffers; _buffers = buffers; @@ -135,7 +135,7 @@ PortImpl::prepare_poly(BufferFactory& bufs, uint32_t poly) } if (!_prepared_buffers) - _prepared_buffers = new Array(poly, *_buffers, NULL); + _prepared_buffers = new Array(poly, *_buffers, NULL); return true; } diff --git a/src/server/PortImpl.hpp b/src/server/PortImpl.hpp index 2c106f32..ddbaa087 100644 --- a/src/server/PortImpl.hpp +++ b/src/server/PortImpl.hpp @@ -26,6 +26,7 @@ #include "ingen/Port.hpp" #include "Buffer.hpp" +#include "BufferRef.hpp" #include "Context.hpp" #include "GraphObjectImpl.hpp" #include "PortType.hpp" @@ -60,7 +61,7 @@ public: * Audio thread. Returned value must be freed by caller. * \a buffers must be poly() long */ - Raul::Array* set_buffers(Raul::Array* buffers); + Raul::Array* set_buffers(Raul::Array* buffers); /** Prepare for a new (external) polyphony value. * @@ -90,10 +91,10 @@ public: void set_minimum(const Raul::Atom& min) { _min = min; } void set_maximum(const Raul::Atom& max) { _max = max; } - inline Buffer::Ref buffer(uint32_t voice) const { + inline BufferRef buffer(uint32_t voice) const { return _buffers->at((_poly == 1) ? 0 : voice); } - inline Buffer::Ref prepared_buffer(uint32_t voice) const { + inline BufferRef prepared_buffer(uint32_t voice) const { return _prepared_buffers->at(voice); } @@ -104,9 +105,9 @@ public: /** Empty buffer contents completely (ie silence) */ virtual void clear_buffers(); - virtual bool get_buffers(BufferFactory& bufs, - Raul::Array* buffers, - uint32_t poly) const = 0; + virtual bool get_buffers(BufferFactory& bufs, + Raul::Array* buffers, + uint32_t poly) const = 0; void setup_buffers(BufferFactory& bufs, uint32_t poly) { get_buffers(bufs, _buffers, poly); @@ -158,20 +159,20 @@ protected: const Raul::Atom& value, size_t buffer_size); - BufferFactory& _bufs; - uint32_t _index; - uint32_t _poly; - uint32_t _buffer_size; - PortType _type; - LV2_URID _buffer_type; - Raul::Atom _value; - Raul::Atom _min; - Raul::Atom _max; - Raul::Atom _last_broadcasted_value; - Raul::Array* _buffers; - Raul::Array* _prepared_buffers; - bool _broadcast; - bool _set_by_user; + BufferFactory& _bufs; + uint32_t _index; + uint32_t _poly; + uint32_t _buffer_size; + PortType _type; + LV2_URID _buffer_type; + Raul::Atom _value; + Raul::Atom _min; + Raul::Atom _max; + Raul::Atom _last_broadcasted_value; + Raul::Array* _buffers; + Raul::Array* _prepared_buffers; + bool _broadcast; + bool _set_by_user; }; } // namespace Server diff --git a/src/server/events/Connect.cpp b/src/server/events/Connect.cpp index bda3fc4c..f61a5cd1 100644 --- a/src/server/events/Connect.cpp +++ b/src/server/events/Connect.cpp @@ -145,7 +145,7 @@ Connect::pre_process() _dst_input_port->increment_num_connections(); } - _buffers = new Raul::Array(_dst_input_port->poly()); + _buffers = new Raul::Array(_dst_input_port->poly()); _dst_input_port->get_buffers(*_engine.buffer_factory(), _buffers, _dst_input_port->poly()); diff --git a/src/server/events/Connect.hpp b/src/server/events/Connect.hpp index afc4f5fe..f4544272 100644 --- a/src/server/events/Connect.hpp +++ b/src/server/events/Connect.hpp @@ -71,7 +71,7 @@ private: SharedPtr _connection; - Raul::Array* _buffers; + Raul::Array* _buffers; }; } // namespace Events diff --git a/src/server/events/Disconnect.cpp b/src/server/events/Disconnect.cpp index 5fcc12b4..ddf3bb1c 100644 --- a/src/server/events/Disconnect.cpp +++ b/src/server/events/Disconnect.cpp @@ -93,7 +93,7 @@ Disconnect::Impl::Impl(Engine& e, _dst_input_port->decrement_num_connections(); if (_dst_input_port->num_connections() == 0) { - _buffers = new Raul::Array(_dst_input_port->poly()); + _buffers = new Raul::Array(_dst_input_port->poly()); _dst_input_port->get_buffers(*_engine.buffer_factory(), _buffers, _dst_input_port->poly()); diff --git a/src/server/events/Disconnect.hpp b/src/server/events/Disconnect.hpp index c855207c..05ac2aa7 100644 --- a/src/server/events/Disconnect.hpp +++ b/src/server/events/Disconnect.hpp @@ -68,12 +68,12 @@ public: InputPort* dst_port() { return _dst_input_port; } private: - Engine& _engine; - OutputPort* _src_output_port; - InputPort* _dst_input_port; - PatchImpl* _patch; - SharedPtr _connection; - Raul::Array* _buffers; + Engine& _engine; + OutputPort* _src_output_port; + InputPort* _dst_input_port; + PatchImpl* _patch; + SharedPtr _connection; + Raul::Array* _buffers; }; private: -- cgit v1.2.1