From 138a87e915ad3aff184730415105f94c874174bf Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 20 Apr 2011 16:26:40 +0000 Subject: Rename Ingen::Engine to Ingen::Server (hopefully avoid odd name clases and fix #675). git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@3184 a436a847-0d15-0410-975c-d299462d15a1 --- src/server/Buffer.hpp | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/server/Buffer.hpp (limited to 'src/server/Buffer.hpp') diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp new file mode 100644 index 00000000..e44915b3 --- /dev/null +++ b/src/server/Buffer.hpp @@ -0,0 +1,97 @@ +/* This file is part of Ingen. + * Copyright 2007-2011 David 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 + */ + +#ifndef INGEN_ENGINE_BUFFER_HPP +#define INGEN_ENGINE_BUFFER_HPP + +#include +#include +#include +#include +#include "raul/Deletable.hpp" +#include "raul/SharedPtr.hpp" +#include "ingen/PortType.hpp" +#include "types.hpp" +#include "BufferFactory.hpp" + +namespace Ingen { +namespace Server { + +class Context; +class Engine; +class BufferFactory; + +class Buffer : public boost::noncopyable, public Raul::Deletable +{ +public: + Buffer(BufferFactory& bufs, PortType type, size_t size) + : _factory(bufs) + , _type(type) + , _size(size) + , _next(NULL) + , _refs(0) + {} + + /** Clear contents and reset state */ + virtual void clear() = 0; + + virtual void resize(size_t size) { _size = size; } + + virtual void* port_data(PortType port_type, SampleCount offset=0) = 0; + virtual const void* port_data(PortType port_type, SampleCount offset=0) const = 0; + + /** Rewind (ie reset read pointer), but leave contents unchanged */ + virtual void rewind() const {} + + virtual void copy(Context& context, const Buffer* src) = 0; + + virtual void prepare_read(Context& context) {} + virtual void prepare_write(Context& context) {} + + PortType type() const { return _type; } + size_t size() const { return _size; } + + inline void ref() { ++_refs; } + + inline void deref() { + assert(_refs > 0); + if ((--_refs) == 0) + _factory.recycle(this); + } + +protected: + BufferFactory& _factory; + PortType _type; + size_t _size; + + friend class BufferFactory; + virtual ~Buffer() {} + +private: + Buffer* _next; ///< Intrusive linked list for BufferFactory + size_t _refs; ///< Intrusive reference count for intrusive_ptr +}; + +} // 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 -- cgit v1.2.1