diff options
Diffstat (limited to 'src/engine/machina')
-rw-r--r-- | src/engine/machina/Driver.hpp | 24 | ||||
-rw-r--r-- | src/engine/machina/Machine.hpp | 39 |
2 files changed, 41 insertions, 22 deletions
diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp index 3e65c9d..84a6cfd 100644 --- a/src/engine/machina/Driver.hpp +++ b/src/engine/machina/Driver.hpp @@ -18,6 +18,8 @@ #ifndef MACHINA_DRIVER_HPP #define MACHINA_DRIVER_HPP +#include <atomic> + #include "raul/RingBuffer.hpp" #include "machina/types.hpp" @@ -28,15 +30,21 @@ namespace machina { class Machine; -class Driver - : public MIDISink +class Driver : public MIDISink { public: Driver(Raul::Forge& forge, SPtr<Machine> machine) : _forge(forge) , _machine(machine) + , _play_state(PlayState::STOPPED) {} + enum class PlayState { + STOPPED, + PLAYING, + RECORDING + }; + virtual ~Driver() {} SPtr<Machine> machine() { return _machine; } @@ -51,23 +59,21 @@ public: _updates = b; } - virtual void set_bpm(double bpm) = 0; - virtual void set_quantization(double q) = 0; + virtual void set_bpm(double bpm) = 0; + virtual void set_quantization(double q) = 0; + virtual void set_play_state(PlayState state) = 0; virtual bool is_activated() const { return false; } virtual void activate() {} virtual void deactivate() {} - virtual void stop() {} - - virtual bool recording() { return false; } - virtual void start_record(bool step) {} - virtual void finish_record() {} + PlayState play_state() const { return _play_state.load(); } protected: Raul::Forge& _forge; SPtr<Machine> _machine; SPtr<Raul::RingBuffer> _updates; + std::atomic<PlayState> _play_state; }; } // namespace machina diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index e82f992..8a98e4c 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -43,20 +43,18 @@ class Machine { public: Machine(TimeUnit unit); + + /** Copy a Machine. + * + * Creates a deep copy which is the 'same' machine, but with fresh state, + * i.e. all nodes are inactive and time is at zero. + */ Machine(const Machine& copy); Machine& operator=(const Machine& other); - // Kluge to appease Eugene - bool operator==(const Machine& other) { return false; } - - // Main context - void activate() { _is_activated = true; } - void deactivate() { _is_activated = false; } - - bool is_empty() { return _nodes.empty(); } - bool is_finished() { return _is_finished; } - bool is_activated() { return _is_activated; } + bool is_empty() { return _nodes.empty(); } + bool is_finished() { return _is_finished; } void add_node(SPtr<Node> node); void remove_node(SPtr<Node> node); @@ -64,8 +62,19 @@ public: void write_state(Sord::Model& model); - // Audio context - void reset(MIDISink* sink, Raul::TimeStamp time); + /** Exit all active nodes and reset time to 0. + */ + void reset(MIDISink* sink, Raul::TimeStamp time); + + /** Run the machine for a (real) time slice. + * + * Returns the duration of time the machine actually ran in frames. + * + * Caller can check is_finished() to determine if the machine still has any + * active nodes. If not, time() will return the exact time stamp the + * machine actually finished on (so it can be restarted immediately + * with sample accuracy if necessary). + */ uint32_t run(Context& context, SPtr<Raul::RingBuffer> updates); // Any context @@ -78,6 +87,8 @@ public: Nodes& nodes() { return _nodes; } const Nodes& nodes() const { return _nodes; } + SPtr<Node> initial_node() const { return _initial_node; } + SPtr<Node> random_node(); SPtr<Edge> random_edge(); @@ -85,6 +96,8 @@ private: // Audio context SPtr<Node> earliest_node() const; + void assign(const Machine& other); + bool enter_node(Context& context, SPtr<Node> node, SPtr<Raul::RingBuffer> updates); @@ -95,12 +108,12 @@ private: static const size_t MAX_ACTIVE_NODES = 128; + SPtr<Node> _initial_node; std::vector< SPtr<Node> > _active_nodes; SPtr<LearnRequest> _pending_learn; Nodes _nodes; Raul::TimeStamp _time; - bool _is_activated; bool _is_finished; }; |