diff options
author | David Robillard <d@drobilla.net> | 2012-11-16 04:26:45 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-11-16 04:26:45 +0000 |
commit | e5943aa05fd46771f1ff7009c8971f1294c9d791 (patch) | |
tree | 828fb9156f373149883a81dd0638991b0b9ba851 | |
parent | efd2fb1315413bb456cf5a7dc9a61513e15c8035 (diff) | |
download | ingen-e5943aa05fd46771f1ff7009c8971f1294c9d791.tar.gz ingen-e5943aa05fd46771f1ff7009c8971f1294c9d791.tar.bz2 ingen-e5943aa05fd46771f1ff7009c8971f1294c9d791.zip |
Add time internal that sends Jack transport updates as LV2 time positions.
git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@4819 a436a847-0d15-0410-975c-d299462d15a1
-rw-r--r-- | ingen/URIs.hpp | 8 | ||||
-rw-r--r-- | src/URIs.cpp | 9 | ||||
-rw-r--r-- | src/server/BlockFactory.cpp | 4 | ||||
-rw-r--r-- | src/server/DirectDriver.hpp | 3 | ||||
-rw-r--r-- | src/server/Driver.hpp | 4 | ||||
-rw-r--r-- | src/server/InternalPlugin.cpp | 3 | ||||
-rw-r--r-- | src/server/JackDriver.cpp | 62 | ||||
-rw-r--r-- | src/server/JackDriver.hpp | 9 | ||||
-rw-r--r-- | src/server/ingen_lv2.cpp | 4 | ||||
-rw-r--r-- | src/server/internals/Time.cpp | 82 | ||||
-rw-r--r-- | src/server/internals/Time.hpp | 59 | ||||
-rw-r--r-- | src/server/wscript | 1 |
12 files changed, 248 insertions, 0 deletions
diff --git a/ingen/URIs.hpp b/ingen/URIs.hpp index 6b11d0dc..9cea37a8 100644 --- a/ingen/URIs.hpp +++ b/ingen/URIs.hpp @@ -146,6 +146,14 @@ public: const Quark pprops_logarithmic; const Quark rdf_type; const Quark rdfs_seeAlso; + const Quark time_Position; + const Quark time_bar; + const Quark time_barBeat; + const Quark time_beatUnit; + const Quark time_beatsPerBar; + const Quark time_beatsPerMinute; + const Quark time_frame; + const Quark time_speed; const Quark wildcard; }; diff --git a/src/URIs.cpp b/src/URIs.cpp index 796f45e9..0fd39849 100644 --- a/src/URIs.cpp +++ b/src/URIs.cpp @@ -23,6 +23,7 @@ #include "lv2/lv2plug.in/ns/ext/morph/morph.h" #include "lv2/lv2plug.in/ns/ext/patch/patch.h" #include "lv2/lv2plug.in/ns/ext/port-props/port-props.h" +#include "lv2/lv2plug.in/ns/ext/time/time.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" namespace Ingen { @@ -133,6 +134,14 @@ URIs::URIs(Forge& f, URIMap* map) , pprops_logarithmic (forge, map, LV2_PORT_PROPS__logarithmic) , rdf_type (forge, map, NS_RDF "type") , rdfs_seeAlso (forge, map, NS_RDFS "seeAlso") + , time_Position (forge, map, LV2_TIME__Position) + , time_bar (forge, map, LV2_TIME__bar) + , time_barBeat (forge, map, LV2_TIME__barBeat) + , time_beatUnit (forge, map, LV2_TIME__beatUnit) + , time_beatsPerBar (forge, map, LV2_TIME__beatsPerBar) + , time_beatsPerMinute (forge, map, LV2_TIME__beatsPerMinute) + , time_frame (forge, map, LV2_TIME__frame) + , time_speed (forge, map, LV2_TIME__speed) , wildcard (forge, map, NS_INGEN "wildcard") { } diff --git a/src/server/BlockFactory.cpp b/src/server/BlockFactory.cpp index 3e08aa7f..9ae1fddb 100644 --- a/src/server/BlockFactory.cpp +++ b/src/server/BlockFactory.cpp @@ -22,6 +22,7 @@ #include "internals/Controller.hpp" #include "internals/Delay.hpp" #include "internals/Note.hpp" +#include "internals/Time.hpp" #include "internals/Trigger.hpp" #include "InternalPlugin.hpp" @@ -86,6 +87,9 @@ BlockFactory::load_internal_plugins() InternalPlugin* note_plug = NoteNode::internal_plugin(uris); _plugins.insert(make_pair(note_plug->uri(), note_plug)); + InternalPlugin* time_plug = TimeNode::internal_plugin(uris); + _plugins.insert(make_pair(time_plug->uri(), time_plug)); + InternalPlugin* trigger_plug = TriggerNode::internal_plugin(uris); _plugins.insert(make_pair(trigger_plug->uri(), trigger_plug)); } diff --git a/src/server/DirectDriver.hpp b/src/server/DirectDriver.hpp index 5fde93d9..87192599 100644 --- a/src/server/DirectDriver.hpp +++ b/src/server/DirectDriver.hpp @@ -65,6 +65,9 @@ public: return false; } + virtual void append_time_events(ProcessContext& context, + Buffer& buffer) {} + private: SampleCount _sample_rate; SampleCount _block_length; diff --git a/src/server/Driver.hpp b/src/server/Driver.hpp index a34fc6f5..52adbdc9 100644 --- a/src/server/Driver.hpp +++ b/src/server/Driver.hpp @@ -89,6 +89,10 @@ public: /** Return true iff the driver is running in real-time mode */ virtual bool is_realtime() const = 0; + + /** Append time events for this cycle to @p buffer. */ + virtual void append_time_events(ProcessContext& context, + Buffer& buffer) = 0; }; } // namespace Server diff --git a/src/server/InternalPlugin.cpp b/src/server/InternalPlugin.cpp index 60d3d1a7..dc64fb73 100644 --- a/src/server/InternalPlugin.cpp +++ b/src/server/InternalPlugin.cpp @@ -18,6 +18,7 @@ #include "internals/Controller.hpp" #include "internals/Delay.hpp" #include "internals/Note.hpp" +#include "internals/Time.hpp" #include "internals/Trigger.hpp" #include "Driver.hpp" @@ -55,6 +56,8 @@ InternalPlugin::instantiate(BufferFactory& bufs, return new DelayNode(this, bufs, symbol, polyphonic, parent, srate); } else if (uri() == NS_INTERNALS "Note") { return new NoteNode(this, bufs, symbol, polyphonic, parent, srate); + } else if (uri() == NS_INTERNALS "Time") { + return new TimeNode(this, bufs, symbol, polyphonic, parent, srate); } else if (uri() == NS_INTERNALS "Trigger") { return new TriggerNode(this, bufs, symbol, polyphonic, parent, srate); } else { diff --git a/src/server/JackDriver.cpp b/src/server/JackDriver.cpp index 6da4e279..c266861e 100644 --- a/src/server/JackDriver.cpp +++ b/src/server/JackDriver.cpp @@ -29,6 +29,7 @@ #include "ingen/Configuration.hpp" #include "ingen/LV2Features.hpp" #include "ingen/Log.hpp" +#include "ingen/URIMap.hpp" #include "ingen/World.hpp" #include "lv2/lv2plug.in/ns/ext/atom/util.h" @@ -56,8 +57,13 @@ JackDriver::JackDriver(Engine& engine) , _block_length(0) , _sample_rate(0) , _is_activated(false) + , _old_bpm(120.0f) + , _old_frame(0) + , _old_rolling(false) { _midi_event_type = _engine.world()->uris().midi_MidiEvent; + lv2_atom_forge_init( + &_forge, &engine.world()->uri_map().urid_map_feature()->urid_map); } JackDriver::~JackDriver() @@ -331,6 +337,57 @@ JackDriver::post_process_port(ProcessContext& context, EnginePort* port) } } +void +JackDriver::append_time_events(ProcessContext& context, + Buffer& buffer) +{ + const URIs& uris = context.engine().world()->uris(); + const jack_position_t* pos = &_position; + const bool rolling = (_transport_state == JackTransportRolling); + + // Do nothing if there is no unexpected time change (other than rolling) + if (rolling == _old_rolling && + pos->frame == _old_frame && + pos->beats_per_minute == _old_bpm) { + return; + } + + // Update old time information to detect change next cycle + _old_frame = pos->frame; + _old_rolling = rolling; + _old_bpm = pos->beats_per_minute; + + std::cerr << "POS CHANGED" << endl; + + // Build an LV2 position object to append to the buffer + uint8_t pos_buf[256]; + LV2_Atom_Forge_Frame frame; + lv2_atom_forge_set_buffer(&_forge, pos_buf, sizeof(pos_buf)); + lv2_atom_forge_blank(&_forge, &frame, 1, uris.time_Position); + lv2_atom_forge_property_head(&_forge, uris.time_frame, 0); + lv2_atom_forge_long(&_forge, pos->frame); + lv2_atom_forge_property_head(&_forge, uris.time_speed, 0); + lv2_atom_forge_float(&_forge, rolling ? 1.0 : 0.0); + if (pos->valid & JackPositionBBT) { + lv2_atom_forge_property_head(&_forge, uris.time_barBeat, 0); + lv2_atom_forge_float( + &_forge, pos->beat - 1 + (pos->tick / pos->ticks_per_beat)); + lv2_atom_forge_property_head(&_forge, uris.time_bar, 0); + lv2_atom_forge_float(&_forge, pos->bar - 1); + lv2_atom_forge_property_head(&_forge, uris.time_beatUnit, 0); + lv2_atom_forge_float(&_forge, pos->beat_type); + lv2_atom_forge_property_head(&_forge, uris.time_beatsPerBar, 0); + lv2_atom_forge_float(&_forge, pos->beats_per_bar); + lv2_atom_forge_property_head(&_forge, uris.time_beatsPerMinute, 0); + lv2_atom_forge_float(&_forge, pos->beats_per_minute); + } + + // Append position to buffer at offset 0 (start of this cycle) + LV2_Atom* lpos = (LV2_Atom*)pos_buf; + buffer.append_event( + 0, lpos->size, lpos->type, (const uint8_t*)LV2_ATOM_BODY_CONST(lpos)); +} + /**** Jack Callbacks ****/ /** Jack process callback, drives entire audio thread. @@ -367,6 +424,11 @@ JackDriver::_process_cb(jack_nframes_t nframes) post_process_port(_engine.process_context(), &*i); } + // Update expected transport frame for next cycle to detect changes + if (_transport_state == JackTransportRolling) { + _old_frame += nframes; + } + return 0; } diff --git a/src/server/JackDriver.hpp b/src/server/JackDriver.hpp index 8ea84fd6..0369be05 100644 --- a/src/server/JackDriver.hpp +++ b/src/server/JackDriver.hpp @@ -30,6 +30,8 @@ #include "raul/AtomicInt.hpp" #include "raul/Semaphore.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/forge.h" + #include "Driver.hpp" #include "EnginePort.hpp" @@ -81,6 +83,9 @@ public: inline const jack_position_t* position() { return &_position; } inline jack_transport_state_t transport_state() { return _transport_state; } + void append_time_events(ProcessContext& context, + Buffer& buffer); + bool is_realtime() const { return jack_is_realtime(_client); } jack_client_t* jack_client() const { return _client; } @@ -130,6 +135,7 @@ protected: Engine& _engine; Ports _ports; + LV2_Atom_Forge _forge; Raul::Semaphore _sem; Raul::AtomicInt _flag; jack_client_t* _client; @@ -139,6 +145,9 @@ protected: bool _is_activated; jack_position_t _position; jack_transport_state_t _transport_state; + float _old_bpm; + jack_nframes_t _old_frame; + bool _old_rolling; }; } // namespace Server diff --git a/src/server/ingen_lv2.cpp b/src/server/ingen_lv2.cpp index 6239bb01..aaa0bcb2 100644 --- a/src/server/ingen_lv2.cpp +++ b/src/server/ingen_lv2.cpp @@ -246,6 +246,10 @@ public: return new EnginePort(graph_port); } + virtual void append_time_events(ProcessContext& context, + Buffer& buffer) + {} + /** Called in run thread for events received at control input port. */ void enqueue_message(const LV2_Atom* atom) { if (_from_ui.write(lv2_atom_total_size(atom), atom) == 0) { diff --git a/src/server/internals/Time.cpp b/src/server/internals/Time.cpp new file mode 100644 index 00000000..73a0c89c --- /dev/null +++ b/src/server/internals/Time.cpp @@ -0,0 +1,82 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard <http://drobilla.net/> + + 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 <http://www.gnu.org/licenses/>. +*/ + +#include "ingen/URIs.hpp" +#include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "lv2/lv2plug.in/ns/ext/midi/midi.h" + +#include "Buffer.hpp" +#include "Driver.hpp" +#include "Engine.hpp" +#include "InternalPlugin.hpp" +#include "OutputPort.hpp" +#include "PostProcessor.hpp" +#include "ProcessContext.hpp" +#include "internals/Time.hpp" +#include "util.hpp" + +namespace Ingen { +namespace Server { +namespace Internals { + +InternalPlugin* TimeNode::internal_plugin(URIs& uris) { + return new InternalPlugin( + uris, Raul::URI(NS_INTERNALS "Time"), Raul::Symbol("time")); +} + +TimeNode::TimeNode(InternalPlugin* plugin, + BufferFactory& bufs, + const Raul::Symbol& symbol, + bool polyphonic, + GraphImpl* parent, + SampleRate srate) + : BlockImpl(plugin, symbol, false, parent, srate) +{ + const Ingen::URIs& uris = bufs.uris(); + _ports = new Raul::Array<PortImpl*>(1); + + _notify_port = new OutputPort( + bufs, this, Raul::Symbol("notify"), 0, 1, + PortType::ATOM, uris.atom_Sequence, Raul::Atom(), 1024); + _notify_port->set_property(uris.lv2_name, bufs.forge().alloc("Notify")); + _notify_port->set_property(uris.atom_supports, + bufs.forge().make_urid(uris.time_Position)); + _ports->at(0) = _notify_port; +} + +void +TimeNode::process(ProcessContext& context) +{ + BlockImpl::pre_process(context); + + BufferRef buf = _notify_port->buffer(0); + LV2_Atom_Sequence* seq = (LV2_Atom_Sequence*)buf->atom(); + + // Initialise output to the empty sequence + seq->atom.type = _notify_port->bufs().uris().atom_Sequence; + seq->atom.size = sizeof(LV2_Atom_Sequence_Body); + + // Ask the driver to append any time events for this cycle + context.engine().driver()->append_time_events( + context, *_notify_port->buffer(0)); + + BlockImpl::post_process(context); +} + +} // namespace Internals +} // namespace Server +} // namespace Ingen + diff --git a/src/server/internals/Time.hpp b/src/server/internals/Time.hpp new file mode 100644 index 00000000..7efe5d6a --- /dev/null +++ b/src/server/internals/Time.hpp @@ -0,0 +1,59 @@ +/* + This file is part of Ingen. + Copyright 2007-2012 David Robillard <http://drobilla.net/> + + 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 <http://www.gnu.org/licenses/>. +*/ + +#ifndef INGEN_INTERNALS_TIME_HPP +#define INGEN_INTERNALS_TIME_HPP + +#include "BlockImpl.hpp" + +namespace Ingen { +namespace Server { + +class InputPort; +class OutputPort; +class InternalPlugin; + +namespace Internals { + +/** Time information block. + * + * This sends messages whenever the transport speed or tempo changes. + * + * \ingroup engine + */ +class TimeNode : public BlockImpl +{ +public: + TimeNode(InternalPlugin* plugin, + BufferFactory& bufs, + const Raul::Symbol& symbol, + bool polyphonic, + GraphImpl* parent, + SampleRate srate); + + void process(ProcessContext& context); + + static InternalPlugin* internal_plugin(URIs& uris); + +private: + OutputPort* _notify_port; +}; + +} // namespace Server +} // namespace Ingen +} // namespace Internals + +#endif // INGEN_INTERNALS_TIME_HPP diff --git a/src/server/wscript b/src/server/wscript index d548a77c..b739017e 100644 --- a/src/server/wscript +++ b/src/server/wscript @@ -41,6 +41,7 @@ def build(bld): internals/Controller.cpp internals/Delay.cpp internals/Note.cpp + internals/Time.cpp internals/Trigger.cpp mix.cpp ''' |