13
0

Execute plugin worker tasks immediately in the audio thread if freewheeling.

git-svn-id: svn://localhost/ardour2/branches/3.0@11803 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
David Robillard 2012-04-06 02:42:19 +00:00
parent 164db566b0
commit 9e2dc2e50c
2 changed files with 28 additions and 12 deletions

View File

@ -130,6 +130,8 @@ class LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
void enable_ui_emmission(); void enable_ui_emmission();
void emit_to_ui(void* controller, UIMessageSink sink); void emit_to_ui(void* controller, UIMessageSink sink);
Worker* worker() { return _worker; }
void work(uint32_t size, const void* data); void work(uint32_t size, const void* data);
void work_response(uint32_t size, const void* data); void work_response(uint32_t size, const void* data);
@ -147,6 +149,7 @@ class LV2Plugin : public ARDOUR::Plugin, public ARDOUR::Workee
Impl* _impl; Impl* _impl;
void* _module; void* _module;
LV2_Feature** _features; LV2_Feature** _features;
Worker* _worker;
framecnt_t _sample_rate; framecnt_t _sample_rate;
float* _control_data; float* _control_data;
float* _shadow_data; float* _shadow_data;

View File

@ -121,9 +121,15 @@ work_schedule(LV2_Worker_Schedule_Handle handle,
uint32_t size, uint32_t size,
const void* data) const void* data)
{ {
Worker* worker = (Worker*)handle; LV2Plugin* plugin = (LV2Plugin*)handle;
return worker->schedule(size, data) ? if (plugin->session().engine().freewheeling()) {
LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN; // Freewheeling, do the work immediately in this (audio) thread
plugin->work(size, data);
} else {
// Enqueue message for the worker thread
return plugin->worker()->schedule(size, data) ?
LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN;
}
} }
/** Called by the plugin to respond to non-RT work. */ /** Called by the plugin to respond to non-RT work. */
@ -132,14 +138,20 @@ work_respond(LV2_Worker_Respond_Handle handle,
uint32_t size, uint32_t size,
const void* data) const void* data)
{ {
Worker* worker = (Worker*)handle; LV2Plugin* plugin = (LV2Plugin*)handle;
return worker->respond(size, data) ? if (plugin->session().engine().freewheeling()) {
LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN; // Freewheeling, respond immediately in this (audio) thread
plugin->work_response(size, data);
} else {
// Enqueue response for the worker
return plugin->worker()->respond(size, data) ?
LV2_WORKER_SUCCESS : LV2_WORKER_ERR_UNKNOWN;
}
} }
struct LV2Plugin::Impl { struct LV2Plugin::Impl {
Impl() : plugin(0), ui(0), ui_type(0), name(0), author(0), instance(0) Impl() : plugin(0), ui(0), ui_type(0), name(0), author(0), instance(0)
, worker(0), work_iface(0) , work_iface(0)
#ifdef HAVE_NEW_LILV #ifdef HAVE_NEW_LILV
, state(0) , state(0)
#endif #endif
@ -150,7 +162,6 @@ struct LV2Plugin::Impl {
LilvNode* name; LilvNode* name;
LilvNode* author; LilvNode* author;
LilvInstance* instance; LilvInstance* instance;
Worker* worker;
LV2_Worker_Interface* work_iface; LV2_Worker_Interface* work_iface;
#ifdef HAVE_NEW_LILV #ifdef HAVE_NEW_LILV
LilvState* state; LilvState* state;
@ -164,6 +175,7 @@ LV2Plugin::LV2Plugin (AudioEngine& engine,
: Plugin(engine, session) : Plugin(engine, session)
, _impl(new Impl()) , _impl(new Impl())
, _features(NULL) , _features(NULL)
, _worker(NULL)
, _insert_id("0") , _insert_id("0")
{ {
init(c_plugin, rate); init(c_plugin, rate);
@ -173,6 +185,7 @@ LV2Plugin::LV2Plugin (const LV2Plugin& other)
: Plugin(other) : Plugin(other)
, _impl(new Impl()) , _impl(new Impl())
, _features(NULL) , _features(NULL)
, _worker(NULL)
, _insert_id(other._insert_id) , _insert_id(other._insert_id)
{ {
init(other._impl->plugin, other._sample_rate); init(other._impl->plugin, other._sample_rate);
@ -240,8 +253,8 @@ LV2Plugin::init(void* c_plugin, framecnt_t rate)
if (lilv_plugin_has_feature(plugin, worker_schedule)) { if (lilv_plugin_has_feature(plugin, worker_schedule)) {
LV2_Worker_Schedule* schedule = (LV2_Worker_Schedule*)malloc( LV2_Worker_Schedule* schedule = (LV2_Worker_Schedule*)malloc(
sizeof(LV2_Worker_Schedule)); sizeof(LV2_Worker_Schedule));
_impl->worker = new Worker(this, 4096); _worker = new Worker(this, 4096);
schedule->handle = _impl->worker; schedule->handle = this;
schedule->schedule_work = work_schedule; schedule->schedule_work = work_schedule;
_work_schedule_feature.data = schedule; _work_schedule_feature.data = schedule;
_features[6] = &_work_schedule_feature; _features[6] = &_work_schedule_feature;
@ -939,7 +952,7 @@ void
LV2Plugin::work(uint32_t size, const void* data) LV2Plugin::work(uint32_t size, const void* data)
{ {
_impl->work_iface->work( _impl->work_iface->work(
_impl->instance->lv2_handle, work_respond, _impl->worker, size, data); _impl->instance->lv2_handle, work_respond, this, size, data);
} }
void void
@ -1360,7 +1373,7 @@ LV2Plugin::run(pframes_t nframes)
lilv_instance_run(_impl->instance, nframes); lilv_instance_run(_impl->instance, nframes);
if (_impl->work_iface) { if (_impl->work_iface) {
_impl->worker->emit_responses(); _worker->emit_responses();
if (_impl->work_iface->end_run) { if (_impl->work_iface->end_run) {
_impl->work_iface->end_run(_impl->instance->lv2_handle); _impl->work_iface->end_run(_impl->instance->lv2_handle);
} }