diff options
Diffstat (limited to 'src/engine/machina')
-rw-r--r-- | src/engine/machina/Action.hpp | 57 | ||||
-rw-r--r-- | src/engine/machina/ActionFactory.hpp | 37 | ||||
-rw-r--r-- | src/engine/machina/Driver.hpp | 11 | ||||
-rw-r--r-- | src/engine/machina/Edge.hpp | 66 | ||||
-rw-r--r-- | src/engine/machina/Engine.hpp | 17 | ||||
-rw-r--r-- | src/engine/machina/Machine.hpp | 8 | ||||
-rw-r--r-- | src/engine/machina/MidiAction.hpp | 57 | ||||
-rw-r--r-- | src/engine/machina/Node.hpp | 105 | ||||
-rw-r--r-- | src/engine/machina/SMFDriver.hpp | 79 | ||||
-rw-r--r-- | src/engine/machina/Stateful.hpp | 48 | ||||
-rw-r--r-- | src/engine/machina/types.hpp | 6 |
11 files changed, 29 insertions, 462 deletions
diff --git a/src/engine/machina/Action.hpp b/src/engine/machina/Action.hpp deleted file mode 100644 index 84181a3..0000000 --- a/src/engine/machina/Action.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_ACTION_HPP -#define MACHINA_ACTION_HPP - -#include <string> -#include <iostream> - -#include "raul/MIDISink.hpp" -#include "raul/SharedPtr.hpp" -#include "raul/TimeSlice.hpp" - -#include "Stateful.hpp" -#include "types.hpp" - -namespace Machina { - - -/** An Action, executed on entering or exiting of a state. - */ -struct Action : public Raul::Deletable, public Stateful { - virtual void execute(SharedPtr<Raul::MIDISink> sink, Raul::TimeStamp time) = 0; - - virtual void write_state(Redland::Model& model); -}; - - -class PrintAction : public Action { -public: - PrintAction(const std::string& msg) : _msg(msg) {} - - void execute(SharedPtr<Raul::MIDISink>, Raul::TimeStamp time) - { std::cout << "t=" << time << ": " << _msg << std::endl; } - -private: - std::string _msg; -}; - - -} // namespace Machina - -#endif // MACHINA_ACTION_HPP diff --git a/src/engine/machina/ActionFactory.hpp b/src/engine/machina/ActionFactory.hpp deleted file mode 100644 index 04b0c74..0000000 --- a/src/engine/machina/ActionFactory.hpp +++ /dev/null @@ -1,37 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_ACTIONFACTORY_HPP -#define MACHINA_ACTIONFACTORY_HPP - -#include "raul/SharedPtr.hpp" - -namespace Machina { - -class Action; - - -namespace ActionFactory { - SharedPtr<Action> copy(SharedPtr<Action> copy); - SharedPtr<Action> note_on(unsigned char note); - SharedPtr<Action> note_off(unsigned char note); -} - - -} // namespace Machina - -#endif // MACHINA_ACTIONFACTORY_HPP diff --git a/src/engine/machina/Driver.hpp b/src/engine/machina/Driver.hpp index f850d3d..814f041 100644 --- a/src/engine/machina/Driver.hpp +++ b/src/engine/machina/Driver.hpp @@ -19,12 +19,14 @@ #define MACHINA_DRIVER_HPP #include "raul/MIDISink.hpp" +#include "raul/RingBuffer.hpp" + +#include "machina/types.hpp" namespace Machina { class Machine; - class Driver : public Raul::MIDISink { public: Driver(SharedPtr<Machine> machine) : _machine(machine) {} @@ -33,9 +35,13 @@ public: SharedPtr<Machine> machine() { return _machine; } virtual void set_machine(SharedPtr<Machine> machine) { _machine = machine; } + SharedPtr<UpdateBuffer> update_sink() { return _updates; } + void set_update_sink(SharedPtr<UpdateBuffer> b) { _updates = b; } + virtual void set_bpm(double bpm) = 0; virtual void set_quantization(double q) = 0; + virtual bool is_activated() const { return false; } virtual void activate() {} virtual void deactivate() {} @@ -46,7 +52,8 @@ public: virtual void finish_record() {} protected: - SharedPtr<Machine> _machine; + SharedPtr<Machine> _machine; + SharedPtr<UpdateBuffer> _updates; }; diff --git a/src/engine/machina/Edge.hpp b/src/engine/machina/Edge.hpp deleted file mode 100644 index 8a2d1c2..0000000 --- a/src/engine/machina/Edge.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_EDGE_HPP -#define MACHINA_EDGE_HPP - -#include <list> -#include <boost/utility.hpp> - -#include "raul/DoubleBuffer.hpp" -#include "raul/SharedPtr.hpp" -#include "raul/WeakPtr.hpp" - -#include "Action.hpp" -#include "Stateful.hpp" -#include "types.hpp" - -namespace Machina { - -class Node; - -class Edge : public Stateful { -public: - - Edge(WeakPtr<Node> tail, SharedPtr<Node> head) - : _probability(1.0f) - , _tail(tail) - , _head(head) - {} - - void write_state(Redland::Model& model); - - WeakPtr<Node> tail() { return _tail; } - SharedPtr<Node> head() { return _head; } - - void set_tail(WeakPtr<Node> tail) { _tail = tail; } - void set_head(SharedPtr<Node> head) { _head = head; } - - inline float probability() { return _probability.get(); } - inline void set_probability(float p) { _probability.set(p); } - -private: - Raul::DoubleBuffer<float> _probability; - - WeakPtr<Node> _tail; - SharedPtr<Node> _head; -}; - - -} // namespace Machina - -#endif // MACHINA_EDGE_HPP diff --git a/src/engine/machina/Engine.hpp b/src/engine/machina/Engine.hpp index 17d555d..022a2ca 100644 --- a/src/engine/machina/Engine.hpp +++ b/src/engine/machina/Engine.hpp @@ -34,12 +34,7 @@ class Machine; class Engine { public: - Engine(SharedPtr<Driver> driver, Redland::World& rdf_world) - : _driver(driver) - , _rdf_world(rdf_world) - , _loader(_rdf_world) - { - } + Engine(SharedPtr<Driver> driver, Redland::World& rdf_world); Redland::World& rdf_world() { return _rdf_world; } @@ -50,8 +45,14 @@ public: SharedPtr<Machine> machine() { return _driver->machine(); } SharedPtr<Machine> load_machine(const Glib::ustring& uri); - SharedPtr<Machine> import_machine(const Glib::ustring& uri); - SharedPtr<Machine> import_midi(const Glib::ustring& uri, double q, Raul::TimeDuration d); + SharedPtr<Machine> load_machine_midi(const Glib::ustring& uri, + double q, + Raul::TimeDuration dur); + + void import_machine(SharedPtr<Machine> machine); + + void export_midi(const Glib::ustring& filename, + Raul::TimeDuration dur); void set_bpm(double bpm); void set_quantization(double beat_fraction); diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp index e1a0f25..f3469c7 100644 --- a/src/engine/machina/Machine.hpp +++ b/src/engine/machina/Machine.hpp @@ -23,6 +23,7 @@ #include "raul/List.hpp" #include "raul/Maid.hpp" +#include "raul/RingBuffer.hpp" #include "raul/SharedPtr.hpp" #include "raul/TimeSlice.hpp" #include "raul/WeakPtr.hpp" @@ -33,6 +34,7 @@ namespace Machina { +class Controller; class LearnRequest; /** A (Finite State) Machine. @@ -63,7 +65,7 @@ public: // Audio context void reset(Raul::TimeStamp time); - uint32_t run(const Raul::TimeSlice& time); + uint32_t run(const Raul::TimeSlice& time, SharedPtr<UpdateBuffer> updates); // Any context inline Raul::TimeStamp time() const { return _time; } @@ -84,8 +86,8 @@ private: // Audio context SharedPtr<Node> earliest_node() const; - bool enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node); - void exit_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node>); + bool enter_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node> node, SharedPtr<UpdateBuffer> updates); + void exit_node(SharedPtr<Raul::MIDISink> sink, SharedPtr<Node>, SharedPtr<UpdateBuffer> updates); static const size_t MAX_ACTIVE_NODES = 128; std::vector< SharedPtr<Node> > _active_nodes; diff --git a/src/engine/machina/MidiAction.hpp b/src/engine/machina/MidiAction.hpp deleted file mode 100644 index 73aed7b..0000000 --- a/src/engine/machina/MidiAction.hpp +++ /dev/null @@ -1,57 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_MIDIACTION_HPP -#define MACHINA_MIDIACTION_HPP - -#include "raul/AtomicPtr.hpp" -#include "raul/TimeSlice.hpp" -#include "types.hpp" -#include "Action.hpp" - -namespace Raul { class MIDISink; } - -namespace Machina { - - -class MidiAction : public Action { -public: - ~MidiAction(); - - MidiAction(size_t size, - const unsigned char* event); - - size_t event_size() { return _size; } - byte* event() { return _event.get(); } - - bool set_event(size_t size, const byte* event); - - void execute(SharedPtr<Raul::MIDISink> driver, Raul::TimeStamp time); - - virtual void write_state(Redland::Model& model); - -private: - - size_t _size; - const size_t _max_size; - Raul::AtomicPtr<byte> _event; -}; - - -} // namespace Machina - -#endif // MACHINA_MIDIACTION_HPP diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp deleted file mode 100644 index 57f62f1..0000000 --- a/src/engine/machina/Node.hpp +++ /dev/null @@ -1,105 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_NODE_HPP -#define MACHINA_NODE_HPP - -#include "raul/List.hpp" -#include "raul/MIDISink.hpp" -#include "raul/SharedPtr.hpp" - -#include "Action.hpp" -#include "Schrodinbit.hpp" -#include "Stateful.hpp" - -namespace Machina { - -class Edge; -using Raul::TimeDuration; -using Raul::TimeStamp; -using Raul::TimeUnit; - - -/** A node is a state (as in a FSM diagram), or "note". - * - * It contains a action, as well as a duration and pointers to it's - * successors (states/nodes that (may) follow it). - * - * Initial nodes do not have enter actions (since they are entered at - * an undefined point in time <= 0). - */ -class Node : public Stateful { -public: - typedef std::string ID; - - Node(TimeDuration duration, bool initial=false); - Node(const Node& copy); - - void set_enter_action(SharedPtr<Action> action); - void set_exit_action(SharedPtr<Action> action); - - SharedPtr<Action> enter_action() { return _enter_action; } - SharedPtr<Action> exit_action() { return _exit_action; } - - void enter(SharedPtr<Raul::MIDISink> driver, TimeStamp time); - void exit(SharedPtr<Raul::MIDISink> driver, TimeStamp time); - - void edges_changed(); - - void add_edge(SharedPtr<Edge> edge); - void remove_edge(SharedPtr<Edge> edge); - void remove_edges_to(SharedPtr<Node> node); - bool connected_to(SharedPtr<Node> node); - - void write_state(Redland::Model& model); - - 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 { assert(_is_active); return _enter_time; } - TimeStamp exit_time() const { assert(_is_active); return _enter_time + _duration; } - TimeDuration duration() { return _duration; } - void set_duration(TimeDuration d) { _duration = d; } - bool is_selector() const { return _is_selector; } - void set_selector(bool i); - - inline bool changed() { return _changed; } - inline void set_changed() { _changed = true; } - - typedef Raul::List<SharedPtr<Edge> > Edges; - Edges& edges() { return _edges; } - - SharedPtr<Edge> random_edge(); - -private: - Node& operator=(const Node& other); // undefined - - Schrodinbit _changed; - bool _is_initial; - bool _is_selector; - bool _is_active; - TimeStamp _enter_time; ///< valid iff _is_active - TimeDuration _duration; - SharedPtr<Action> _enter_action; - SharedPtr<Action> _exit_action; - Edges _edges; -}; - - -} // namespace Machina - -#endif // MACHINA_NODE_HPP diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp deleted file mode 100644 index a10442d..0000000 --- a/src/engine/machina/SMFDriver.hpp +++ /dev/null @@ -1,79 +0,0 @@ -/* This file is part of Machina. - * Copyright (C) 2007-2009 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_SMFDRIVER_HPP -#define MACHINA_SMFDRIVER_HPP - -#include <boost/enable_shared_from_this.hpp> -#include <glibmm/ustring.h> - -#include "raul/SMFReader.hpp" -#include "raul/SMFWriter.hpp" -#include "raul/SharedPtr.hpp" - -#include "machina/Driver.hpp" -#include "machina/types.hpp" - -#include "MachineBuilder.hpp" - -namespace Machina { - -class Node; -class Machine; - - -class SMFDriver : public Driver, - public boost::enable_shared_from_this<SMFDriver> { -public: - SMFDriver(SharedPtr<Machine> machine = SharedPtr<Machine>()); - - SharedPtr<Machine> learn(const std::string& filename, - double q, - Raul::TimeDuration max_duration); - - SharedPtr<Machine> learn(const std::string& filename, - unsigned track, - double q, - Raul::TimeDuration max_duration); - - void run(SharedPtr<Machine> machine, Raul::TimeStamp max_time); - - void write_event(Raul::TimeStamp time, - size_t ev_size, - const unsigned char* ev) throw (std::logic_error) - { _writer->write_event(time, ev_size, ev); } - - void set_bpm(double /*bpm*/) { } - void set_quantization(double /*quantization*/) { } - - SharedPtr<Raul::SMFWriter> writer() { return _writer; } - -private: - SharedPtr<Raul::SMFWriter> _writer; - - void learn_track(SharedPtr<MachineBuilder> builder, - Raul::SMFReader& reader, - unsigned track, - double q, - Raul::TimeDuration max_duration); -}; - - -} // namespace Machina - -#endif // MACHINA_SMFDRIVER_HPP - diff --git a/src/engine/machina/Stateful.hpp b/src/engine/machina/Stateful.hpp deleted file mode 100644 index f35c00a..0000000 --- a/src/engine/machina/Stateful.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* This file is part of Machina - * Copyright (C) 2007-2010 David 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 3 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 more details. - * - * You should have received a copy of the GNU General Public License - * along with Machina. If not, see <http://www.gnu.org/licenses/>. - */ - -#ifndef MACHINA_STATEFUL_HPP -#define MACHINA_STATEFUL_HPP - -#include <stdint.h> - -#include "redlandmm/World.hpp" -#include "redlandmm/Model.hpp" - -namespace Machina { - -class Stateful { -public: - Stateful(); - - virtual ~Stateful() {} - - virtual void write_state(Redland::Model& model) = 0; - - uint64_t id() const { return _id; } - const Redland::Node& rdf_id(Redland::World& world) const; - -private: - static uint64_t _next_id; - - uint64_t _id; - mutable Redland::Node _rdf_id; -}; - -} // namespace Machina - -#endif // MACHINA_STATEFUL_HPP diff --git a/src/engine/machina/types.hpp b/src/engine/machina/types.hpp index c39b682..74410d9 100644 --- a/src/engine/machina/types.hpp +++ b/src/engine/machina/types.hpp @@ -18,10 +18,16 @@ #ifndef MACHINA_TYPES_HPP #define MACHINA_TYPES_HPP +#include "raul/RingBuffer.hpp" + namespace Machina { typedef unsigned char byte; +typedef Raul::RingBuffer UpdateBuffer; + +typedef uint32_t URIInt; + } // namespace Machina #endif // MACHINA_TYPES_HPP |