From cee33ba4c0859b117be94df6ccbf3eb756a850af Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 10 Feb 2007 07:30:56 +0000 Subject: Finished MIDI genericification. Work on MIDI learn. git-svn-id: http://svn.drobilla.net/lad/machina@299 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/machina/Action.hpp | 4 ++++ src/engine/machina/JackDriver.hpp | 34 ++++++++++++++++++++++++++-------- src/engine/machina/Machine.hpp | 5 +++-- src/engine/machina/MidiAction.hpp | 18 ++++++++++++------ src/engine/machina/types.hpp | 1 + 5 files changed, 46 insertions(+), 16 deletions(-) (limited to 'src/engine/machina') diff --git a/src/engine/machina/Action.hpp b/src/engine/machina/Action.hpp index ffee5b1..feb0e0b 100644 --- a/src/engine/machina/Action.hpp +++ b/src/engine/machina/Action.hpp @@ -25,6 +25,10 @@ namespace Machina { +/** An Action, executed on entering or exiting of a state. + * + * Actions do not have time as a property. + */ struct Action { virtual ~Action() {} diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp index bae3ab2..9a72a62 100644 --- a/src/engine/machina/JackDriver.hpp +++ b/src/engine/machina/JackDriver.hpp @@ -23,16 +23,21 @@ #include #include "Machine.hpp" #include "MidiDriver.hpp" +#include namespace Machina { +class MidiAction; +class Node; + /** Realtime JACK Driver. * * "Ticks" are individual frames when running under this driver, and all code * in the processing context must be realtime safe (non-blocking). */ -class JackDriver : public Raul::JackDriver, public Machina::MidiDriver { +class JackDriver : public Raul::JackDriver, public Machina::MidiDriver, + public boost::enable_shared_from_this { public: JackDriver(); @@ -45,18 +50,31 @@ public: Timestamp cycle_start() { return _current_cycle_start; } FrameCount cycle_length() { return _current_cycle_nframes; } + void learn(SharedPtr node); + + void write_event(Timestamp time, + size_t size, + const unsigned char* event); + private: // Audio context - Timestamp subcycle_offset() { return _current_cycle_offset; } - jack_port_t* output_port() { return _output_port; } - virtual void on_process(jack_nframes_t nframes); + Timestamp subcycle_offset() { return _current_cycle_offset; } Timestamp stamp_to_offset(Timestamp stamp); + + void process_input(jack_nframes_t nframes); + virtual void on_process(jack_nframes_t nframes); + SharedPtr _machine; - jack_port_t* _output_port; - Timestamp _current_cycle_start; - Timestamp _current_cycle_offset; ///< for split cycles - FrameCount _current_cycle_nframes; + SharedPtr _learn_node; + SharedPtr _learn_enter_action; + SharedPtr _learn_exit_action; + + jack_port_t* _input_port; + jack_port_t* _output_port; + Timestamp _current_cycle_start; + Timestamp _current_cycle_offset; ///< for split cycles + FrameCount _current_cycle_nframes; }; diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index 5d16a4e..4036ef3 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -20,7 +20,8 @@ #include #include -#include "raul/SharedPtr.h" +#include +#include #include "types.hpp" #include "Node.hpp" @@ -48,7 +49,7 @@ public: FrameCount time() { return _time; } private: - typedef std::vector > Nodes; + typedef Raul::List > Nodes; // Audio context SharedPtr earliest_node() const; diff --git a/src/engine/machina/MidiAction.hpp b/src/engine/machina/MidiAction.hpp index 2e1d1fc..d362a63 100644 --- a/src/engine/machina/MidiAction.hpp +++ b/src/engine/machina/MidiAction.hpp @@ -19,6 +19,7 @@ #define MACHINA_MIDIACTION_HPP #include +#include #include "types.hpp" #include "Action.hpp" @@ -29,16 +30,21 @@ class MidiDriver; class MidiAction : public Action { public: - JackNoteOnAction(WeakPtr driver, - size_t size, - unsigned char* event); + MidiAction(WeakPtr driver, + size_t size, + const unsigned char* event); + + ~MidiAction(); + + bool set_event(size_t size, const byte* event); void execute(Timestamp time); private: - WeakPtr _driver; - size_t _size; - unsigned char* _event; + WeakPtr _driver; + size_t _size; + const size_t _max_size; + Raul::AtomicPtr _event; }; diff --git a/src/engine/machina/types.hpp b/src/engine/machina/types.hpp index db36901..1236f65 100644 --- a/src/engine/machina/types.hpp +++ b/src/engine/machina/types.hpp @@ -26,6 +26,7 @@ namespace Machina { typedef jack_nframes_t FrameCount; typedef jack_nframes_t Timestamp; +typedef unsigned char byte; } // namespace Machina -- cgit v1.2.1