From 0bf73b59335d917400c18ae9d664226c1a4da4c2 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 28 Nov 2008 01:26:54 +0000 Subject: MIDI learn for note trigger node. git-svn-id: http://svn.drobilla.net/lad/trunk/ingen@1812 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/MidiTriggerNode.cpp | 9 +++++++++ src/engine/MidiTriggerNode.hpp | 4 ++++ src/engine/NodeBase.hpp | 2 ++ src/engine/events/MidiLearnEvent.cpp | 6 ++---- src/gui/NodeMenu.cpp | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/engine/MidiTriggerNode.cpp b/src/engine/MidiTriggerNode.cpp index c68a0b96..0212154a 100644 --- a/src/engine/MidiTriggerNode.cpp +++ b/src/engine/MidiTriggerNode.cpp @@ -34,6 +34,7 @@ namespace Ingen { MidiTriggerNode::MidiTriggerNode(const string& path, bool polyphonic, PatchImpl* parent, SampleRate srate, size_t buffer_size) : NodeBase(new InternalPlugin(NS_INGEN "trigger_node", "trigger", "Trigger"), path, false, parent, srate, buffer_size) + , _learning(false) { _ports = new Raul::Array(5); @@ -106,6 +107,14 @@ MidiTriggerNode::note_on(ProcessContext& context, uchar note_num, uchar velocity { assert(time >= context.start() && time <= context.end()); assert(time - context.start() < _buffer_size); + + if (_learning) { + _note_port->set_value(note_num); + ((AudioBuffer*)_note_port->buffer(0))->set_value( + (float)note_num, context.start(), context.end()); + _note_port->broadcast_value(context, true); + _learning = false; + } /*cerr << "[MidiTriggerNode] " << path() << " Note " << (int)note_num << " on @ " << time << endl;*/ diff --git a/src/engine/MidiTriggerNode.hpp b/src/engine/MidiTriggerNode.hpp index ba96589b..413b8102 100644 --- a/src/engine/MidiTriggerNode.hpp +++ b/src/engine/MidiTriggerNode.hpp @@ -46,8 +46,12 @@ public: void note_on(ProcessContext& context, uchar note_num, uchar velocity, FrameTime time); void note_off(ProcessContext& context, uchar note_num, FrameTime time); + + void learn() { _learning = true; } private: + bool _learning; + InputPort* _midi_in_port; InputPort* _note_port; OutputPort* _gate_port; diff --git a/src/engine/NodeBase.hpp b/src/engine/NodeBase.hpp index 3626f6b9..790e6b72 100644 --- a/src/engine/NodeBase.hpp +++ b/src/engine/NodeBase.hpp @@ -69,6 +69,8 @@ public: virtual void process_unlock(); virtual void wait_for_input(size_t num_providers); virtual unsigned n_inputs_ready() const { return _n_inputs_ready.get(); } + + virtual void learn() {} virtual void message_process(MessageContext& context, uint32_t* output) {} diff --git a/src/engine/events/MidiLearnEvent.cpp b/src/engine/events/MidiLearnEvent.cpp index b542eccd..8c2439a2 100644 --- a/src/engine/events/MidiLearnEvent.cpp +++ b/src/engine/events/MidiLearnEvent.cpp @@ -51,11 +51,9 @@ MidiLearnEvent::execute(ProcessContext& context) QueuedEvent::execute(context); if (_node != NULL) { - if (_node->plugin_impl()->type() == Plugin::Internal - && _node->plugin_impl()->uri() == "http://drobilla.net/ns/ingen#control_node") { - ((MidiControlNode*)_node)->learn(); + if (_node->plugin_impl()->type() == Plugin::Internal) { + ((NodeBase*)_node)->learn(); } else { - std::cout << "NOT CAPABLE: " << _node->plugin_impl()->uri() << std::endl; _error = INVALID_NODE_TYPE; } } diff --git a/src/gui/NodeMenu.cpp b/src/gui/NodeMenu.cpp index accf8ef1..e4273330 100644 --- a/src/gui/NodeMenu.cpp +++ b/src/gui/NodeMenu.cpp @@ -90,7 +90,8 @@ NodeMenu::init(SharedPtr node) else _randomize_menuitem->hide(); - if (plugin->uri() == "http://drobilla.net/ns/ingen#control_node") + if (plugin->uri() == "http://drobilla.net/ns/ingen#control_node" + || plugin->uri() == "http://drobilla.net/ns/ingen#trigger_node") _learn_menuitem->show(); else _learn_menuitem->hide(); -- cgit v1.2.1