diff options
author | David Robillard <d@drobilla.net> | 2007-02-21 02:30:09 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-02-21 02:30:09 +0000 |
commit | 1429e4b2279566384ec09bfe3bfe7d7e0f0f79eb (patch) | |
tree | 9f0fb4eed56bacf52e738cd13029ec2683ee56e2 /src/engine/machina | |
parent | a865ddb5043c4dc094b8f64d2cae60e0df16b8ac (diff) | |
download | machina-1429e4b2279566384ec09bfe3bfe7d7e0f0f79eb.tar.gz machina-1429e4b2279566384ec09bfe3bfe7d7e0f0f79eb.tar.bz2 machina-1429e4b2279566384ec09bfe3bfe7d7e0f0f79eb.zip |
Tempo based time in Machina (and related utilities added to Raul).
git-svn-id: http://svn.drobilla.net/lad/machina@324 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine/machina')
-rw-r--r-- | src/engine/machina/Action.hpp | 8 | ||||
-rw-r--r-- | src/engine/machina/Engine.hpp (renamed from src/engine/machina/Machina.hpp) | 29 | ||||
-rw-r--r-- | src/engine/machina/JackDriver.hpp | 20 | ||||
-rw-r--r-- | src/engine/machina/JackNodeFactory.hpp | 43 | ||||
-rw-r--r-- | src/engine/machina/LearnRequest.hpp | 8 | ||||
-rw-r--r-- | src/engine/machina/Loader.hpp | 5 | ||||
-rw-r--r-- | src/engine/machina/Machine.hpp | 16 | ||||
-rw-r--r-- | src/engine/machina/Makefile.am | 5 | ||||
-rw-r--r-- | src/engine/machina/MidiAction.hpp | 3 | ||||
-rw-r--r-- | src/engine/machina/MidiDriver.hpp | 6 | ||||
-rw-r--r-- | src/engine/machina/Node.hpp | 28 | ||||
-rw-r--r-- | src/engine/machina/NodeFactory.hpp | 40 | ||||
-rw-r--r-- | src/engine/machina/types.hpp | 4 |
13 files changed, 75 insertions, 140 deletions
diff --git a/src/engine/machina/Action.hpp b/src/engine/machina/Action.hpp index 984a1a0..2bffaa3 100644 --- a/src/engine/machina/Action.hpp +++ b/src/engine/machina/Action.hpp @@ -21,17 +21,16 @@ #include <string> #include <iostream> #include <raul/Deletable.h> +#include <raul/TimeSlice.h> #include "types.hpp" namespace Machina { /** An Action, executed on entering or exiting of a state. - * - * Actions do not have time as a property. */ struct Action : public Raul::Deletable { - virtual void execute(Timestamp /*time*/) {} + virtual void execute(Raul::BeatTime /*time*/) {} }; @@ -39,7 +38,8 @@ class PrintAction : public Action { public: PrintAction(const std::string& msg) : _msg(msg) {} - void execute(Timestamp time) { std::cout << "t=" << time << ": " << _msg << std::endl; } + void execute(Raul::BeatTime time) + { std::cout << "t=" << time << ": " << _msg << std::endl; } private: std::string _msg; diff --git a/src/engine/machina/Machina.hpp b/src/engine/machina/Engine.hpp index 6cefcc5..fcb75d3 100644 --- a/src/engine/machina/Machina.hpp +++ b/src/engine/machina/Engine.hpp @@ -15,14 +15,37 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <list> +#ifndef MACHINA_ENGINE_HPP +#define MACHINA_ENGINE_HPP + +#include <raul/SharedPtr.h> namespace Machina { -class Machina { +class Machine; +class JackDriver; + + +class Engine { +public: + Engine(SharedPtr<JackDriver> driver, SharedPtr<Machine> machine) + : _driver(driver) + , _machine(machine) + {} + + SharedPtr<JackDriver> driver() { return _driver; } + SharedPtr<Machine> machine() { return _machine; } + + void set_bpm(double bpm); + + void set_quantization(double beat_fraction); + private: - std::list<Node> _nodes; + SharedPtr<JackDriver> _driver; + SharedPtr<Machine> _machine; }; } // namespace Machina + +#endif // MACHINA_ENGINE_HPP diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp index e1f809f..e52af88 100644 --- a/src/engine/machina/JackDriver.hpp +++ b/src/engine/machina/JackDriver.hpp @@ -20,6 +20,7 @@ #include <raul/JackDriver.h> #include <raul/SharedPtr.h> +#include <raul/DoubleBuffer.h> #include <jack/midiport.h> #include "Machine.hpp" #include "MidiDriver.hpp" @@ -46,19 +47,13 @@ public: void set_machine(SharedPtr<Machine> machine) { _machine = machine; } - // Audio context - Timestamp cycle_start() { return _current_cycle_start; } - FrameCount cycle_length() { return _current_cycle_nframes; } - - void write_event(Timestamp time, + void write_event(Raul::BeatTime time, size_t size, const unsigned char* event); -private: - // Audio context - Timestamp subcycle_offset() { return _current_cycle_offset; } - Timestamp stamp_to_offset(Timestamp stamp); + void set_bpm(double bpm) { _bpm.set(bpm); } +private: void process_input(jack_nframes_t nframes); virtual void on_process(jack_nframes_t nframes); @@ -66,9 +61,10 @@ private: jack_port_t* _input_port; jack_port_t* _output_port; - Timestamp _current_cycle_start; ///< in machine relative time - Timestamp _current_cycle_offset; ///< for split cycles - FrameCount _current_cycle_nframes; + + Raul::TimeSlice _cycle_time; + + Raul::DoubleBuffer<double> _bpm; }; diff --git a/src/engine/machina/JackNodeFactory.hpp b/src/engine/machina/JackNodeFactory.hpp deleted file mode 100644 index 017cc6d..0000000 --- a/src/engine/machina/JackNodeFactory.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * Machina is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Machina 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 General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef MACHINA_JACKNODEFACTORY_HPP -#define MACHINA_JACKNODEFACTORY_HPP - -#include <raul/WeakPtr.h> -#include "NodeFactory.hpp" - -namespace Machina { - -class JackDriver; - - -class JackNodeFactory : public NodeFactory { -public: - JackNodeFactory(WeakPtr<JackDriver> driver) : _driver(driver) {} - - SharedPtr<Node> create_node(Node::ID id, - unsigned char note, - FrameCount duration); -private: - WeakPtr<JackDriver> _driver; -}; - - -} // namespace Machina - -#endif // MACHINA_JACKNODEFACTORY_HPP diff --git a/src/engine/machina/LearnRequest.hpp b/src/engine/machina/LearnRequest.hpp index 60f1b27..f485560 100644 --- a/src/engine/machina/LearnRequest.hpp +++ b/src/engine/machina/LearnRequest.hpp @@ -44,7 +44,7 @@ public: } // Add the learned actions to the node - void finish(Timestamp time) + void finish(BeatTime time) { _node->add_enter_action(_enter_action); _node->add_exit_action(_exit_action); @@ -52,8 +52,8 @@ public: std::cerr << "LEARN DURATION: " << _node->duration() << std::endl; } - void start(Timestamp time) { _started = true; _start_time = time; } - bool started() { return _started; } + void start(BeatTime time) { _started = true; _start_time = time; } + bool started() { return _started; } const SharedPtr<Node>& node() { return _node; } const SharedPtr<MidiAction>& enter_action() { return _enter_action; } @@ -69,7 +69,7 @@ private: } bool _started; - Timestamp _start_time; + BeatTime _start_time; SharedPtr<Node> _node; SharedPtr<MidiAction> _enter_action; SharedPtr<MidiAction> _exit_action; diff --git a/src/engine/machina/Loader.hpp b/src/engine/machina/Loader.hpp index c3ce013..af35c56 100644 --- a/src/engine/machina/Loader.hpp +++ b/src/engine/machina/Loader.hpp @@ -28,18 +28,15 @@ using Raul::Namespaces; namespace Machina { class Machine; -class NodeFactory; class Loader { public: - Loader(SharedPtr<NodeFactory> node_factory, - SharedPtr<Namespaces> = SharedPtr<Namespaces>()); + Loader(SharedPtr<Namespaces> = SharedPtr<Namespaces>()); SharedPtr<Machine> load(const Glib::ustring& filename); private: - SharedPtr<NodeFactory> _node_factory; SharedPtr<Namespaces> _namespaces; }; diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index 3e63530..a7b92c8 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -21,6 +21,7 @@ #include <raul/SharedPtr.h> #include <raul/List.h> #include <raul/RDFWriter.h> +#include <raul/TimeSlice.h> #include "types.hpp" #include "LearnRequest.hpp" #include "Node.hpp" @@ -46,12 +47,11 @@ public: void write_state(Raul::RDFWriter& writer); // Audio context - void reset(); - FrameCount run(FrameCount nframes); + void reset(); + BeatCount run(const Raul::TimeSlice& time); // Any context - FrameCount time() { return _time; } - + Raul::BeatTime time() { return _time; } //LearnRequest pop_learn() { return _pending_learns.pop_front(); } //SharedPtr<LearnRequest> first_learn() { return *_pending_learns.begin(); } @@ -65,10 +65,10 @@ private: SharedPtr<Node> earliest_node() const; void exit_node(const SharedPtr<Node>); - bool _is_activated; - bool _is_finished; - FrameCount _time; - Nodes _nodes; + bool _is_activated; + bool _is_finished; + Raul::BeatTime _time; + Nodes _nodes; //Raul::List<SharedPtr<LearnRequest> > _pending_learns; SharedPtr<LearnRequest> _pending_learn; diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am index 7bdd1fd..1e8c6c3 100644 --- a/src/engine/machina/Makefile.am +++ b/src/engine/machina/Makefile.am @@ -7,8 +7,7 @@ libmachinainclude_HEADERS = \ Machine.hpp \ Loader.hpp \ JackDriver.hpp \ - NodeFactory.hpp \ - JackNodeFactory.hpp \ MidiAction.hpp \ MidiDriver.hpp \ - LearnRequest.hpp + LearnRequest.hpp \ + Engine.hpp diff --git a/src/engine/machina/MidiAction.hpp b/src/engine/machina/MidiAction.hpp index 7dff692..6467659 100644 --- a/src/engine/machina/MidiAction.hpp +++ b/src/engine/machina/MidiAction.hpp @@ -21,6 +21,7 @@ #include <raul/Maid.h> #include <raul/WeakPtr.h> #include <raul/AtomicPtr.h> +#include <raul/TimeSlice.h> #include "types.hpp" #include "Action.hpp" @@ -46,7 +47,7 @@ public: bool set_event(size_t size, const byte* event); - void execute(Timestamp time); + void execute(Raul::BeatTime time); private: MidiAction(size_t size, diff --git a/src/engine/machina/MidiDriver.hpp b/src/engine/machina/MidiDriver.hpp index 7f6dca1..a4d9f51 100644 --- a/src/engine/machina/MidiDriver.hpp +++ b/src/engine/machina/MidiDriver.hpp @@ -30,20 +30,20 @@ public: virtual ~MidiDriver() {} /** Emit a MIDI event at the given time */ - virtual void write_event(Timestamp time, + virtual void write_event(Raul::BeatTime time, size_t size, const unsigned char* event) = 0; /** Beginning of current cycle in absolute time. */ - virtual Timestamp cycle_start() = 0; + //virtual Raul::TickTime cycle_start() = 0; /** Length of current cycle in ticks. * * A "tick" is the smallest recognizable unit of (discrete) time. * Ticks could be single audio frames, MIDI clock at a certain ppqn, etc. */ - virtual FrameCount cycle_length() = 0; + //virtual Raul::TickCount cycle_length() = 0; }; diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp index 10d4ed4..c4d9dee 100644 --- a/src/engine/machina/Node.hpp +++ b/src/engine/machina/Node.hpp @@ -22,12 +22,14 @@ #include <raul/SharedPtr.h> #include <raul/List.h> #include <raul/Stateful.h> -#include "types.hpp" +#include <raul/TimeSlice.h> #include "Action.hpp" namespace Machina { class Edge; +using Raul::BeatCount; +using Raul::BeatTime; /** A node is a state (as in a FSM diagram), or "note". @@ -42,7 +44,7 @@ class Node : public Raul::Stateful, public boost::noncopyable { public: typedef std::string ID; - Node(FrameCount duration=0, bool initial=false); + Node(BeatCount duration=0, bool initial=false); void add_enter_action(SharedPtr<Action> action); void remove_enter_action(SharedPtr<Action> action); @@ -50,21 +52,21 @@ public: void add_exit_action(SharedPtr<Action> action); void remove_exit_action(SharedPtr<Action> action); - void enter(Timestamp time); - void exit(Timestamp time); + void enter(BeatTime time); + void exit(BeatTime time); void add_outgoing_edge(SharedPtr<Edge> edge); void remove_outgoing_edge(SharedPtr<Edge> edge); void write_state(Raul::RDFWriter& writer); - bool is_initial() const { return _is_initial; } - void set_initial(bool i) { _is_initial = i; } - bool is_active() const { return _is_active; } - Timestamp enter_time() const { return _enter_time; } - Timestamp exit_time() const { return _enter_time + _duration; } - FrameCount duration() { return _duration; } - void set_duration(FrameCount d) { _duration = d; } + bool is_initial() const { return _is_initial; } + void set_initial(bool i) { _is_initial = i; } + bool is_active() const { return _is_active; } + BeatTime enter_time() const { return _enter_time; } + BeatTime exit_time() const { return _enter_time + _duration; } + BeatCount duration() { return _duration; } + void set_duration(BeatCount d) { _duration = d; } typedef Raul::List<SharedPtr<Edge> > EdgeList; const EdgeList& outgoing_edges() const { return _outgoing_edges; } @@ -72,8 +74,8 @@ public: private: bool _is_initial; bool _is_active; - Timestamp _enter_time; ///< valid iff _is_active - FrameCount _duration; + BeatTime _enter_time; ///< valid iff _is_active + BeatCount _duration; SharedPtr<Action> _enter_action; SharedPtr<Action> _exit_action; EdgeList _outgoing_edges; diff --git a/src/engine/machina/NodeFactory.hpp b/src/engine/machina/NodeFactory.hpp deleted file mode 100644 index f38fd92..0000000 --- a/src/engine/machina/NodeFactory.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007 Dave Robillard <http://drobilla.net> - * - * Machina is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free Software - * Foundation; either version 2 of the License, or (at your option) any later - * version. - * - * Machina 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 General Public License for details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#ifndef MACHINA_NODEFACTORY_HPP -#define MACHINA_NODEFACTORY_HPP - -#include <raul/SharedPtr.h> -#include "types.hpp" -#include "Node.hpp" - -namespace Machina { - - -class NodeFactory { -public: - virtual ~NodeFactory() {} - - virtual SharedPtr<Node> create_node(Node::ID id, - unsigned char note, - FrameCount duration) = 0; -}; - - -} // namespace Machina - -#endif // MACHINA_NODEFACTORY_HPP diff --git a/src/engine/machina/types.hpp b/src/engine/machina/types.hpp index 1236f65..70eae7d 100644 --- a/src/engine/machina/types.hpp +++ b/src/engine/machina/types.hpp @@ -23,8 +23,8 @@ namespace Machina { -typedef jack_nframes_t FrameCount; -typedef jack_nframes_t Timestamp; +//typedef jack_nframes_t FrameCount; +//typedef jack_nframes_t Timestamp; typedef unsigned char byte; |