From e435554efa3f7a6b9dba2320b6c10f49a027dec8 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 31 Aug 2012 18:07:47 +0000 Subject: Implement host side of buf-size via options. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4763 a436a847-0d15-0410-975c-d299462d15a1 --- src/URIs.cpp | 4 +++ src/server/Engine.cpp | 6 +++- src/server/Engine.hpp | 26 ++++++++------- src/server/LV2Options.hpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 src/server/LV2Options.hpp (limited to 'src') diff --git a/src/URIs.cpp b/src/URIs.cpp index 78f57f58..df02099d 100644 --- a/src/URIs.cpp +++ b/src/URIs.cpp @@ -17,6 +17,7 @@ #include "ingen/URIMap.hpp" #include "ingen/URIs.hpp" #include "lv2/lv2plug.in/ns/ext/atom/atom.h" +#include "lv2/lv2plug.in/ns/ext/buf-size/buf-size.h" #include "lv2/lv2plug.in/ns/ext/log/log.h" #include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "lv2/lv2plug.in/ns/ext/patch/patch.h" @@ -54,6 +55,9 @@ URIs::URIs(Forge& f, URIMap* map) , atom_bufferType (forge, map, LV2_ATOM__bufferType) , atom_eventTransfer (forge, map, LV2_ATOM__eventTransfer) , atom_supports (forge, map, LV2_ATOM__supports) + , bufsz_maxBlockLength (forge, map, LV2_BUF_SIZE__maxBlockLength) + , bufsz_minBlockLength (forge, map, LV2_BUF_SIZE__minBlockLength) + , bufsz_sequenceSize (forge, map, LV2_BUF_SIZE__sequenceSize) , doap_name (forge, map, "http://usefulinc.com/ns/doap#name") , ingen_Block (forge, map, NS_INGEN "Block") , ingen_Edge (forge, map, NS_INGEN "Edge") diff --git a/src/server/Engine.cpp b/src/server/Engine.cpp index deb1ff50..4a1afb86 100644 --- a/src/server/Engine.cpp +++ b/src/server/Engine.cpp @@ -35,6 +35,7 @@ #include "Event.hpp" #include "EventWriter.hpp" #include "GraphImpl.hpp" +#include "LV2Options.hpp" #include "PostProcessor.hpp" #include "PreProcessor.hpp" #include "ProcessContext.hpp" @@ -55,10 +56,11 @@ Engine::Engine(Ingen::World* world) , _broadcaster(new Broadcaster()) , _buffer_factory(new BufferFactory(*this, world->uris())) , _control_bindings(NULL) + , _event_writer(new EventWriter(*this)) , _maid(new Raul::Maid()) + , _options(new LV2Options(*this)) , _pre_processor(new PreProcessor()) , _post_processor(new PostProcessor(*this)) - , _event_writer(new EventWriter(*this)) , _root_graph(NULL) , _worker(new Worker(world->log(), event_queue_size())) , _process_context(*this) @@ -72,6 +74,7 @@ Engine::Engine(Ingen::World* world) _control_bindings = new ControlBindings(*this); _world->lv2_features().add_feature(_worker->schedule_feature()); + _world->lv2_features().add_feature(_options); } Engine::~Engine() @@ -179,6 +182,7 @@ Engine::activate() ThreadManager::single_threaded = true; _buffer_factory->set_block_length(_driver->block_length()); + _options->set(*this); _pre_processor->start(); diff --git a/src/server/Engine.hpp b/src/server/Engine.hpp index 2d49bde0..692fbee8 100644 --- a/src/server/Engine.hpp +++ b/src/server/Engine.hpp @@ -42,6 +42,7 @@ class Driver; class Event; class EventWriter; class GraphImpl; +class LV2Options; class PostProcessor; class PreProcessor; class ProcessContext; @@ -92,7 +93,7 @@ public: Ingen::World* world() const { return _world; } EventWriter* interface() const { return _event_writer; } - BlockFactory* block_factory() const { return _block_factory; } + BlockFactory* block_factory() const { return _block_factory; } Broadcaster* broadcaster() const { return _broadcaster; } BufferFactory* buffer_factory() const { return _buffer_factory; } ControlBindings* control_bindings() const { return _control_bindings; } @@ -112,17 +113,18 @@ public: private: Ingen::World* _world; - BlockFactory* _block_factory; - Broadcaster* _broadcaster; - BufferFactory* _buffer_factory; - ControlBindings* _control_bindings; - SharedPtr _driver; - Raul::Maid* _maid; - PreProcessor* _pre_processor; - PostProcessor* _post_processor; - EventWriter* _event_writer; - GraphImpl* _root_graph; - Worker* _worker; + BlockFactory* _block_factory; + Broadcaster* _broadcaster; + BufferFactory* _buffer_factory; + ControlBindings* _control_bindings; + SharedPtr _driver; + EventWriter* _event_writer; + Raul::Maid* _maid; + SharedPtr _options; + PreProcessor* _pre_processor; + PostProcessor* _post_processor; + GraphImpl* _root_graph; + Worker* _worker; ProcessContext _process_context; diff --git a/src/server/LV2Options.hpp b/src/server/LV2Options.hpp new file mode 100644 index 00000000..fd3801f1 --- /dev/null +++ b/src/server/LV2Options.hpp @@ -0,0 +1,84 @@ +/* + 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_LV2OPTIONS_HPP +#define INGEN_ENGINE_LV2OPTIONS_HPP + +#include "ingen/LV2Features.hpp" +#include "lv2/lv2plug.in/ns/ext/options/options.h" + +#include "BlockImpl.hpp" +#include "BufferFactory.hpp" +#include "Driver.hpp" +#include "Engine.hpp" + +namespace Ingen { +namespace Server { + +struct LV2Options : public Ingen::LV2Features::Feature { + LV2Options(Engine& engine) + : _block_length(0) + , _seq_size(0) + { + set(engine); + } + + static void delete_feature(LV2_Feature* feature) { + free(feature->data); + free(feature); + } + + void set(Engine& engine) { + if (engine.driver()) { + _block_length = engine.driver()->block_length(); + _seq_size = engine.buffer_factory()->default_size( + engine.world()->uris().atom_Sequence); + } + } + + SharedPtr feature(World* w, Node* n) { + BlockImpl* block = dynamic_cast(n); + if (!block) { + return SharedPtr(); + } + Engine& engine = block->parent_graph()->engine(); + URIs& uris = engine.world()->uris(); + const LV2_Options_Option options[] = { + { uris.bufsz_minBlockLength, sizeof(int32_t), uris.atom_Int, + &_block_length }, + { uris.bufsz_maxBlockLength, sizeof(int32_t), uris.atom_Int, + &_block_length }, + { uris.bufsz_sequenceSize, sizeof(int32_t), uris.atom_Int, + &_seq_size }, + { 0, 0, 0, NULL } + }; + + LV2_Feature* f = (LV2_Feature*)malloc(sizeof(LV2_Feature)); + f->URI = LV2_OPTIONS__options; + f->data = malloc(sizeof(options)); + memcpy(f->data, options, sizeof(options)); + return SharedPtr(f, &delete_feature); + } + +private: + int32_t _block_length; + int32_t _seq_size; +}; + +} // namespace Server +} // namespace Ingen + +#endif // INGEN_ENGINE_LV2OPTIONS_HPP -- cgit v1.2.1