summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-10-01 03:23:30 +0000
committerDavid Robillard <d@drobilla.net>2007-10-01 03:23:30 +0000
commit344cdcbd4f2bc7a9203b4e98da2ac349581e521a (patch)
tree1d91bb47256094b8af4b3afe8a0e5514f0032d75 /src
parent8ebd59309b153e7337f2e6668b7e2cb4301cc34a (diff)
downloadingen-344cdcbd4f2bc7a9203b4e98da2ac349581e521a.tar.gz
ingen-344cdcbd4f2bc7a9203b4e98da2ac349581e521a.tar.bz2
ingen-344cdcbd4f2bc7a9203b4e98da2ac349581e521a.zip
Generic audio thread generated Event sending system.
git-svn-id: http://svn.drobilla.net/lad/ingen@793 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/libs/engine/EventSink.cpp38
-rw-r--r--src/libs/engine/EventSink.hpp4
-rw-r--r--src/libs/engine/InputPort.cpp4
-rw-r--r--src/libs/engine/OutputPort.cpp5
-rw-r--r--src/libs/engine/PostProcessor.cpp18
-rw-r--r--src/libs/engine/PostProcessor.hpp3
-rw-r--r--src/libs/engine/ProcessContext.hpp7
7 files changed, 62 insertions, 17 deletions
diff --git a/src/libs/engine/EventSink.cpp b/src/libs/engine/EventSink.cpp
index 441e7aac..7fc7b157 100644
--- a/src/libs/engine/EventSink.cpp
+++ b/src/libs/engine/EventSink.cpp
@@ -24,7 +24,7 @@ using namespace std;
namespace Ingen {
-
+#if 0
void
EventSink::control_change(Port* port, FrameTime time, float val)
{
@@ -32,12 +32,42 @@ EventSink::control_change(Port* port, FrameTime time, float val)
SendPortValueEvent ev(_engine, time, port, false, 0, val);
_events.write(sizeof(ev), (uchar*)&ev);
}
-
+#endif
+
+/** \a size is not size_t because an event will never be even remotely close
+ * to UINT32_MAX in size, so uint32_t saves wasted space on 64-bit.
+ */
+bool
+EventSink::write(uint32_t size, const Event* ev)
+{
+ if (size > _events.write_space())
+ return false;
+ _events.write(sizeof(uint32_t), (uint8_t*)&size);
+ _events.write(size, (uint8_t*)ev);
+
+ return true;
+}
+
+
+/** Read the next event into event_buffer.
+ *
+ * \a event_buffer can be casted to Event* and virtual methods called.
+ */
bool
-EventSink::read_control_change(SendPortValueEvent& ev)
+EventSink::read(uint32_t event_buffer_size, uint8_t* event_buffer)
{
- return _events.full_read(sizeof(SendPortValueEvent), (uchar*)&ev);
+ uint32_t read_size;
+ bool success = _events.full_read(sizeof(uint32_t), (uint8_t*)&read_size);
+ if (!success)
+ return false;
+
+ assert(read_size <= event_buffer_size);
+
+ if (read_size > 0)
+ return _events.full_read(read_size, event_buffer);
+ else
+ return false;
}
diff --git a/src/libs/engine/EventSink.hpp b/src/libs/engine/EventSink.hpp
index b7753a79..4816a069 100644
--- a/src/libs/engine/EventSink.hpp
+++ b/src/libs/engine/EventSink.hpp
@@ -47,9 +47,9 @@ public:
/* FIXME: Figure out variable sized event queues and make this a generic
* interface (ie don't add a method for every event type, crap..) */
- void control_change(Port* port, FrameTime time, float val);
+ bool write(uint32_t size, const Event* ev);
- bool read_control_change(SendPortValueEvent& ev);
+ bool read(uint32_t event_buffer_size, uint8_t* event_buffer);
private:
Engine& _engine;
diff --git a/src/libs/engine/InputPort.cpp b/src/libs/engine/InputPort.cpp
index 6cc7beb4..16a1c86a 100644
--- a/src/libs/engine/InputPort.cpp
+++ b/src/libs/engine/InputPort.cpp
@@ -223,8 +223,8 @@ InputPort::post_process(ProcessContext& context)
if (_monitor && _type == DataType::FLOAT && _buffer_size == 1) {
const Sample value = ((AudioBuffer*)(*_buffers)[0])->value_at(0);
if (value != _last_reported_value) {
- context.event_sink().control_change(this, context.start(),
- ((AudioBuffer*)(*_buffers)[0])->value_at(0));
+ const SendPortValueEvent ev(context.engine(), context.start(), this, false, 0, value);
+ context.event_sink().write(sizeof(ev), &ev);
_last_reported_value = value;
}
}
diff --git a/src/libs/engine/OutputPort.cpp b/src/libs/engine/OutputPort.cpp
index 260f3038..6d49a1d1 100644
--- a/src/libs/engine/OutputPort.cpp
+++ b/src/libs/engine/OutputPort.cpp
@@ -34,8 +34,9 @@ void
OutputPort::post_process(ProcessContext& context)
{
if (_monitor && _type == DataType::FLOAT && _buffer_size == 1) {
- context.event_sink().control_change(this, context.start(),
- ((AudioBuffer*)(*_buffers)[0])->value_at(0));
+ const Sample value = ((AudioBuffer*)(*_buffers)[0])->value_at(0);
+ const SendPortValueEvent ev(context.engine(), context.start(), this, false, 0, value);
+ context.event_sink().write(sizeof(ev), &ev);
}
for (uint32_t i=0; i < _poly; ++i)
diff --git a/src/libs/engine/PostProcessor.cpp b/src/libs/engine/PostProcessor.cpp
index d1b09271..96aee3b1 100644
--- a/src/libs/engine/PostProcessor.cpp
+++ b/src/libs/engine/PostProcessor.cpp
@@ -36,6 +36,8 @@ PostProcessor::PostProcessor(Engine& engine, size_t queue_size)
: _engine(engine)
, _max_time(0)
, _events(queue_size)
+ , _event_buffer_size(sizeof(SendPortValueEvent)) // FIXME: make generic
+ , _event_buffer((uint8_t*)malloc(_event_buffer_size))
{
}
@@ -43,15 +45,19 @@ PostProcessor::PostProcessor(Engine& engine, size_t queue_size)
void
PostProcessor::process()
{
+ const FrameTime end_time = _max_time.get();
+
/* Process any audio thread generated events */
- /* FIXME: process events from all thread if parallel */
- /* TODO: obviously this needs work to be generic */
- SendPortValueEvent ev(_engine, 0, NULL, false, 0, 0.0f);
- while (_engine.audio_driver()->context().event_sink().read_control_change(ev)) {
- ev.post_process();
+ /* FIXME: process events from all threads if parallel */
+
+ while (_engine.audio_driver()->context().event_sink().read(
+ _event_buffer_size, _event_buffer)) {
+ if (((Event*)_event_buffer)->time() > end_time)
+ break;
+ ((Event*)_event_buffer)->post_process();
}
- FrameTime end_time = _max_time.get();
+
/* Process normal events */
while ( ! _events.empty()) {
diff --git a/src/libs/engine/PostProcessor.hpp b/src/libs/engine/PostProcessor.hpp
index cc19cdbe..3d51136d 100644
--- a/src/libs/engine/PostProcessor.hpp
+++ b/src/libs/engine/PostProcessor.hpp
@@ -61,6 +61,9 @@ private:
Raul::AtomicInt _max_time;
//Raul::Maid& _maid;
Raul::SRSWQueue<Event*> _events;
+ uint32_t _event_buffer_size;
+ uint8_t* _event_buffer;
+
//virtual void _whipped();
};
diff --git a/src/libs/engine/ProcessContext.hpp b/src/libs/engine/ProcessContext.hpp
index c85c9ff6..0f090b3b 100644
--- a/src/libs/engine/ProcessContext.hpp
+++ b/src/libs/engine/ProcessContext.hpp
@@ -38,7 +38,10 @@ namespace Ingen {
class ProcessContext
{
public:
- ProcessContext(Engine& engine) : _event_sink(engine, 1024) {} // FIXME: size?
+ ProcessContext(Engine& engine)
+ : _engine(engine)
+ , _event_sink(engine, 1024) // FIXME: size?
+ {}
void set_time_slice(SampleCount nframes, FrameTime start, FrameTime end) {
_nframes = nframes;
@@ -46,6 +49,7 @@ public:
_end = end;
}
+ inline Engine& engine() const { return _engine; }
inline SampleCount nframes() const { return _nframes; }
inline FrameTime start() const { return _start; }
inline FrameTime end() const { return _end; }
@@ -53,6 +57,7 @@ public:
inline EventSink& event_sink() { return _event_sink; }
private:
+ Engine& _engine; ///< Engine we're running in
SampleCount _nframes; ///< Number of actual time (Jack) frames this cycle
FrameTime _start; ///< Start frame of this cycle, timeline relative
FrameTime _end; ///< End frame of this cycle, timeline relative