summaryrefslogtreecommitdiffstats
path: root/src/server/Buffer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/Buffer.hpp')
-rw-r--r--src/server/Buffer.hpp113
1 files changed, 60 insertions, 53 deletions
diff --git a/src/server/Buffer.hpp b/src/server/Buffer.hpp
index c67f9fd7..2c32076b 100644
--- a/src/server/Buffer.hpp
+++ b/src/server/Buffer.hpp
@@ -19,14 +19,12 @@
#include "BufferFactory.hpp"
#include "BufferRef.hpp"
-#include "PortType.hpp"
+#include "server.h"
#include "types.hpp"
-#include "ingen/URIs.hpp"
-#include "ingen/ingen.h"
-#include "ingen/types.hpp"
-#include "lv2/atom/atom.h"
-#include "lv2/urid/urid.h"
+#include <ingen/URIs.hpp>
+#include <lv2/atom/atom.h>
+#include <lv2/urid/urid.h>
#include <atomic>
#include <cassert>
@@ -35,13 +33,15 @@
namespace ingen {
+enum class PortType;
+
class Atom;
namespace server {
class RunContext;
-class INGEN_API Buffer
+class INGEN_SERVER_API Buffer
{
public:
Buffer(BufferFactory& bufs,
@@ -56,74 +56,83 @@ public:
void clear();
void resize(uint32_t capacity);
- void copy(const RunContext& context, const Buffer* src);
- void prepare_write(RunContext& context);
+ void copy(const RunContext& ctx, const Buffer* src);
+ void prepare_write(RunContext& ctx);
void* port_data(PortType port_type, SampleCount offset);
const void* port_data(PortType port_type, SampleCount offset) const;
- inline LV2_URID type() const { return _type; }
- inline LV2_URID value_type() const { return _value_type; }
- inline uint32_t capacity() const { return _capacity; }
- inline uint32_t size() const {
+ LV2_URID type() const { return _type; }
+ LV2_URID value_type() const { return _value_type; }
+ uint32_t capacity() const { return _capacity; }
+ uint32_t size() const {
return is_audio() ? _capacity : sizeof(LV2_Atom) + get<LV2_Atom>()->size;
}
- typedef BufferRef (BufferFactory::*GetFn)(LV2_URID, LV2_URID, uint32_t);
+ using GetFn = BufferRef (BufferFactory::*)(LV2_URID, LV2_URID, uint32_t);
/** Set the buffer type and optional value type for this buffer.
*
- * @param get Called to get auxiliary buffers if necessary.
+ * @param get_func Called to get auxiliary buffers if necessary.
* @param type Type of buffer.
* @param value_type Type of values in buffer if applicable (for sequences).
*/
- void set_type(GetFn get, LV2_URID type, LV2_URID value_type);
+ void set_type(GetFn get_func, LV2_URID type, LV2_URID value_type);
- inline bool is_audio() const {
+ bool is_audio() const {
return _type == _factory.uris().atom_Sound;
}
- inline bool is_control() const {
+ bool is_control() const {
return _type == _factory.uris().atom_Float;
}
- inline bool is_sequence() const {
+ bool is_sequence() const {
return _type == _factory.uris().atom_Sequence;
}
/// Audio or float buffers only
- inline const Sample* samples() const {
+ const Sample* samples() const {
if (is_control()) {
- return (const Sample*)LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>());
- } else if (is_audio()) {
- return (const Sample*)_buf;
+ return static_cast<const Sample*>(
+ LV2_ATOM_BODY_CONST(get<LV2_Atom_Float>()));
+ }
+
+ if (is_audio()) {
+ return static_cast<const Sample*>(_buf);
}
+
return nullptr;
}
/// Audio buffers only
- inline Sample* samples() {
+ Sample* samples() {
if (is_control()) {
- return (Sample*)LV2_ATOM_BODY(get<LV2_Atom_Float>());
- } else if (is_audio()) {
- return (Sample*)_buf;
+ return static_cast<Sample*>(LV2_ATOM_BODY(get<LV2_Atom_Float>()));
}
+
+ if (is_audio()) {
+ return static_cast<Sample*>(_buf);
+ }
+
return nullptr;
}
/// Numeric buffers only
- inline Sample value_at(SampleCount offset) const {
+ Sample value_at(SampleCount offset) const {
if (is_audio() || is_control()) {
return samples()[offset];
- } else if (_value_buffer) {
- return ((LV2_Atom_Float*)value())->body;
}
+
+ if (_value_buffer) {
+ return reinterpret_cast<const LV2_Atom_Float*>(value())->body;
+ }
+
return 0.0f;
}
- inline void set_block(const Sample val,
- const SampleCount start,
- const SampleCount end)
+ void
+ set_block(const Sample val, const SampleCount start, const SampleCount end)
{
if (is_sequence()) {
append_event(start, sizeof(val), _factory.uris().atom_Float,
@@ -142,9 +151,8 @@ public:
}
}
- inline void add_block(const Sample val,
- const SampleCount start,
- const SampleCount end)
+ void
+ add_block(const Sample val, const SampleCount start, const SampleCount end)
{
assert(is_audio() || is_control());
assert(end <= _capacity / sizeof(Sample));
@@ -155,10 +163,10 @@ public:
}
}
- inline void write_block(const Sample val,
- const SampleCount start,
- const SampleCount end,
- const bool add)
+ void write_block(const Sample val,
+ const SampleCount start,
+ const SampleCount end,
+ const bool add)
{
if (add) {
add_block(val, start, end);
@@ -168,10 +176,10 @@ public:
}
/// Audio buffers only
- float peak(const RunContext& context) const;
+ float peak(const RunContext& ctx) const;
/// Sequence buffers only
- void prepare_output_write(RunContext& context);
+ void prepare_output_write(RunContext& ctx);
/// Sequence buffers only
bool append_event(int64_t frames,
@@ -201,11 +209,7 @@ public:
void update_value_buffer(SampleCount offset);
/// Set/add to audio buffer from the Sequence of Float in `src`
- void render_sequence(const RunContext& context, const Buffer* src, bool add);
-
-#ifndef NDEBUG
- void dump_cv(const RunContext& context) const;
-#endif
+ void render_sequence(const RunContext& ctx, const Buffer* src, bool add);
void set_capacity(uint32_t capacity) { _capacity = capacity; }
@@ -216,9 +220,9 @@ public:
template<typename T> const T* get() const { return reinterpret_cast<const T*>(_buf); }
template<typename T> T* get() { return reinterpret_cast<T*>(_buf); }
- inline void ref() { ++_refs; }
+ void ref() { ++_refs; }
- inline void deref() {
+ void deref() {
if ((--_refs) == 0) {
recycle();
}
@@ -230,15 +234,18 @@ private:
void recycle();
- BufferFactory& _factory;
- Buffer* _next; ///< Intrusive linked list for BufferFactory
+ BufferFactory& _factory;
+
+ // NOLINTNEXTLINE(clang-analyzer-webkit.NoUncountedMemberChecker)
+ Buffer* _next{nullptr}; ///< Intrusive linked list for BufferFactory
+
void* _buf; ///< Actual buffer memory
BufferRef _value_buffer; ///< Value buffer for numeric sequences
- int64_t _latest_event;
+ int64_t _latest_event{0};
LV2_URID _type;
LV2_URID _value_type;
uint32_t _capacity;
- std::atomic<unsigned> _refs; ///< Intrusive reference count
+ std::atomic<unsigned> _refs{0}; ///< Intrusive reference count
bool _external; ///< Buffer is externally allocated
};