From 1429e4b2279566384ec09bfe3bfe7d7e0f0f79eb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 21 Feb 2007 02:30:09 +0000 Subject: 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 --- src/engine/machina/Action.hpp | 8 +++--- src/engine/machina/Engine.hpp | 51 ++++++++++++++++++++++++++++++++++ src/engine/machina/JackDriver.hpp | 20 ++++++------- src/engine/machina/JackNodeFactory.hpp | 43 ---------------------------- src/engine/machina/LearnRequest.hpp | 8 +++--- src/engine/machina/Loader.hpp | 5 +--- src/engine/machina/Machina.hpp | 28 ------------------- src/engine/machina/Machine.hpp | 16 +++++------ src/engine/machina/Makefile.am | 5 ++-- src/engine/machina/MidiAction.hpp | 3 +- src/engine/machina/MidiDriver.hpp | 6 ++-- src/engine/machina/Node.hpp | 28 ++++++++++--------- src/engine/machina/NodeFactory.hpp | 40 -------------------------- src/engine/machina/types.hpp | 4 +-- 14 files changed, 100 insertions(+), 165 deletions(-) create mode 100644 src/engine/machina/Engine.hpp delete mode 100644 src/engine/machina/JackNodeFactory.hpp delete mode 100644 src/engine/machina/Machina.hpp delete mode 100644 src/engine/machina/NodeFactory.hpp (limited to 'src/engine/machina') 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 #include #include +#include #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/Engine.hpp b/src/engine/machina/Engine.hpp new file mode 100644 index 0000000..fcb75d3 --- /dev/null +++ b/src/engine/machina/Engine.hpp @@ -0,0 +1,51 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave Robillard + * + * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef MACHINA_ENGINE_HPP +#define MACHINA_ENGINE_HPP + +#include + +namespace Machina { + +class Machine; +class JackDriver; + + +class Engine { +public: + Engine(SharedPtr driver, SharedPtr machine) + : _driver(driver) + , _machine(machine) + {} + + SharedPtr driver() { return _driver; } + SharedPtr machine() { return _machine; } + + void set_bpm(double bpm); + + void set_quantization(double beat_fraction); + +private: + SharedPtr _driver; + SharedPtr _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 #include +#include #include #include "Machine.hpp" #include "MidiDriver.hpp" @@ -46,19 +47,13 @@ public: void set_machine(SharedPtr 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 _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 - * - * 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 -#include "NodeFactory.hpp" - -namespace Machina { - -class JackDriver; - - -class JackNodeFactory : public NodeFactory { -public: - JackNodeFactory(WeakPtr driver) : _driver(driver) {} - - SharedPtr create_node(Node::ID id, - unsigned char note, - FrameCount duration); -private: - WeakPtr _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() { return _node; } const SharedPtr& enter_action() { return _enter_action; } @@ -69,7 +69,7 @@ private: } bool _started; - Timestamp _start_time; + BeatTime _start_time; SharedPtr _node; SharedPtr _enter_action; SharedPtr _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 node_factory, - SharedPtr = SharedPtr()); + Loader(SharedPtr = SharedPtr()); SharedPtr load(const Glib::ustring& filename); private: - SharedPtr _node_factory; SharedPtr _namespaces; }; diff --git a/src/engine/machina/Machina.hpp b/src/engine/machina/Machina.hpp deleted file mode 100644 index 6cefcc5..0000000 --- a/src/engine/machina/Machina.hpp +++ /dev/null @@ -1,28 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007 Dave Robillard - * - * 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 Street, Fifth Floor, Boston, MA 02110-1301, USA - */ - -#include - -namespace Machina { - -class Machina { -private: - std::list _nodes; -}; - - -} // namespace Machina 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 #include #include +#include #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 first_learn() { return *_pending_learns.begin(); } @@ -65,10 +65,10 @@ private: SharedPtr earliest_node() const; void exit_node(const SharedPtr); - bool _is_activated; - bool _is_finished; - FrameCount _time; - Nodes _nodes; + bool _is_activated; + bool _is_finished; + Raul::BeatTime _time; + Nodes _nodes; //Raul::List > _pending_learns; SharedPtr _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 #include #include +#include #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 #include #include -#include "types.hpp" +#include #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); void remove_enter_action(SharedPtr action); @@ -50,21 +52,21 @@ public: void add_exit_action(SharedPtr action); void remove_exit_action(SharedPtr action); - void enter(Timestamp time); - void exit(Timestamp time); + void enter(BeatTime time); + void exit(BeatTime time); void add_outgoing_edge(SharedPtr edge); void remove_outgoing_edge(SharedPtr 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 > 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 _enter_action; SharedPtr _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 - * - * 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 -#include "types.hpp" -#include "Node.hpp" - -namespace Machina { - - -class NodeFactory { -public: - virtual ~NodeFactory() {} - - virtual SharedPtr 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; -- cgit v1.2.1