aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine/machina
diff options
context:
space:
mode:
Diffstat (limited to 'src/engine/machina')
-rw-r--r--src/engine/machina/Action.hpp48
-rw-r--r--src/engine/machina/Driver.hpp42
-rw-r--r--src/engine/machina/Edge.hpp51
-rw-r--r--src/engine/machina/JackActions.hpp57
-rw-r--r--src/engine/machina/JackDriver.hpp60
-rw-r--r--src/engine/machina/JackNodeFactory.hpp43
-rw-r--r--src/engine/machina/Loader.hpp49
-rw-r--r--src/engine/machina/Machina.hpp28
-rw-r--r--src/engine/machina/Machine.hpp64
-rw-r--r--src/engine/machina/Makefile.am12
-rw-r--r--src/engine/machina/Node.hpp82
-rw-r--r--src/engine/machina/NodeFactory.hpp40
-rw-r--r--src/engine/machina/types.hpp31
13 files changed, 607 insertions, 0 deletions
diff --git a/src/engine/machina/Action.hpp b/src/engine/machina/Action.hpp
new file mode 100644
index 0000000..ffee5b1
--- /dev/null
+++ b/src/engine/machina/Action.hpp
@@ -0,0 +1,48 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_ACTION_HPP
+#define MACHINA_ACTION_HPP
+
+#include <string>
+#include <iostream>
+#include "types.hpp"
+
+namespace Machina {
+
+
+struct Action {
+ virtual ~Action() {}
+
+ virtual void execute(Timestamp /*time*/) {}
+};
+
+
+class PrintAction : public Action {
+public:
+ PrintAction(const std::string& msg) : _msg(msg) {}
+
+ void execute(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/Driver.hpp b/src/engine/machina/Driver.hpp
new file mode 100644
index 0000000..f2816ba
--- /dev/null
+++ b/src/engine/machina/Driver.hpp
@@ -0,0 +1,42 @@
+/* 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_JACKDRIVER_HPP
+#define MACHINA_JACKDRIVER_HPP
+
+#include <raul/JackDriver.h>
+
+namespace Machine {
+
+
+class JackDriver : public Raul::JackDriver {
+public:
+ JackDriver(SharedPtr<Machine> machine);
+
+ virtual void set_machine(SharedPtr<Machine> machine);
+
+protected:
+ virtual void on_process(jack_nframes_t nframes);
+
+private:
+ SharedPtr<Machine> _machine;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_JACKDRIVER_HPP
diff --git a/src/engine/machina/Edge.hpp b/src/engine/machina/Edge.hpp
new file mode 100644
index 0000000..f20e5db
--- /dev/null
+++ b/src/engine/machina/Edge.hpp
@@ -0,0 +1,51 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_EDGE_HPP
+#define MACHINA_EDGE_HPP
+
+#include <list>
+#include <boost/utility.hpp>
+#include <raul/WeakPtr.h>
+#include <raul/SharedPtr.h>
+#include "types.hpp"
+#include "Action.hpp"
+
+namespace Machina {
+
+class Node;
+
+class Edge : boost::noncopyable {
+public:
+
+ Edge(WeakPtr<Node> src, SharedPtr<Node> dst) : _src(src) , _dst(dst) {}
+
+ WeakPtr<Node> src() { return _src; }
+ SharedPtr<Node> dst() { return _dst; }
+
+ void set_src(WeakPtr<Node> src) { _src = src; }
+ void set_dst(SharedPtr<Node> dst) { _dst = dst; }
+
+private:
+ WeakPtr<Node> _src;
+ SharedPtr<Node> _dst;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_EDGE_HPP
diff --git a/src/engine/machina/JackActions.hpp b/src/engine/machina/JackActions.hpp
new file mode 100644
index 0000000..0eb50b8
--- /dev/null
+++ b/src/engine/machina/JackActions.hpp
@@ -0,0 +1,57 @@
+/* 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_JACKACTIONS_HPP
+#define MACHINA_JACKACTIONS_HPP
+
+#include <raul/WeakPtr.h>
+#include "types.hpp"
+#include "Action.hpp"
+
+namespace Machina {
+
+class Node;
+class JackDriver;
+
+
+class JackNoteOnAction : public Action {
+public:
+ JackNoteOnAction(WeakPtr<JackDriver> driver, unsigned char note_num);
+
+ void execute(Timestamp time);
+
+private:
+ WeakPtr<JackDriver> _driver;
+ unsigned char _note_num;
+};
+
+
+class JackNoteOffAction : public Action {
+public:
+ JackNoteOffAction(WeakPtr<JackDriver> driver, unsigned char note_num);
+
+ void execute(Timestamp time);
+
+private:
+ WeakPtr<JackDriver> _driver;
+ unsigned char _note_num;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_JACKACTIONS_HPP
diff --git a/src/engine/machina/JackDriver.hpp b/src/engine/machina/JackDriver.hpp
new file mode 100644
index 0000000..84c9223
--- /dev/null
+++ b/src/engine/machina/JackDriver.hpp
@@ -0,0 +1,60 @@
+/* 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_JACKDRIVER_HPP
+#define MACHINA_JACKDRIVER_HPP
+
+#include <raul/JackDriver.h>
+#include <raul/SharedPtr.h>
+#include <jack/midiport.h>
+#include "Machine.hpp"
+
+namespace Machina {
+
+
+class JackDriver : public Raul::JackDriver {
+public:
+ JackDriver();
+
+ void attach(const std::string& client_name);
+ void detach();
+
+ void set_machine(SharedPtr<Machine> machine) { _machine = machine; }
+
+ // Audio context
+ Timestamp stamp_to_offset(Timestamp stamp);
+ jack_port_t* output_port() { return _output_port; }
+ //Timestamp current_cycle_start() { return _current_cycle_start; }
+ //Timestamp current_cycle_offset() { return _current_cycle_offset; }
+ FrameCount current_cycle_nframes() { return _current_cycle_nframes; }
+
+
+protected:
+ virtual void on_process(jack_nframes_t nframes);
+
+private:
+ SharedPtr<Machine> _machine;
+ jack_port_t* _output_port;
+ Timestamp _current_cycle_start;
+ Timestamp _current_cycle_offset; ///< for split cycles
+ FrameCount _current_cycle_nframes;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_JACKDRIVER_HPP
diff --git a/src/engine/machina/JackNodeFactory.hpp b/src/engine/machina/JackNodeFactory.hpp
new file mode 100644
index 0000000..017cc6d
--- /dev/null
+++ b/src/engine/machina/JackNodeFactory.hpp
@@ -0,0 +1,43 @@
+/* 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/Loader.hpp b/src/engine/machina/Loader.hpp
new file mode 100644
index 0000000..c3ce013
--- /dev/null
+++ b/src/engine/machina/Loader.hpp
@@ -0,0 +1,49 @@
+/* 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_LOADER_HPP
+#define MACHINA_LOADER_HPP
+
+#include <glibmm/ustring.h>
+#include "raul/SharedPtr.h"
+#include "raul/Path.h"
+#include "raul/Namespaces.h"
+
+using Raul::Namespaces;
+
+namespace Machina {
+
+class Machine;
+class NodeFactory;
+
+
+class Loader {
+public:
+ Loader(SharedPtr<NodeFactory> node_factory,
+ SharedPtr<Namespaces> = SharedPtr<Namespaces>());
+
+ SharedPtr<Machine> load(const Glib::ustring& filename);
+
+private:
+ SharedPtr<NodeFactory> _node_factory;
+ SharedPtr<Namespaces> _namespaces;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_LOADER_HPP
diff --git a/src/engine/machina/Machina.hpp b/src/engine/machina/Machina.hpp
new file mode 100644
index 0000000..6cefcc5
--- /dev/null
+++ b/src/engine/machina/Machina.hpp
@@ -0,0 +1,28 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include <list>
+
+namespace Machina {
+
+class Machina {
+private:
+ std::list<Node> _nodes;
+};
+
+
+} // namespace Machina
diff --git a/src/engine/machina/Machine.hpp b/src/engine/machina/Machine.hpp
new file mode 100644
index 0000000..2ac739e
--- /dev/null
+++ b/src/engine/machina/Machine.hpp
@@ -0,0 +1,64 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_MACHINE_HPP
+#define MACHINA_MACHINE_HPP
+
+#include <vector>
+#include <map>
+#include "raul/SharedPtr.h"
+#include "types.hpp"
+#include "Node.hpp"
+
+namespace Machina {
+
+
+class Machine {
+public:
+ Machine();
+ ~Machine();
+
+ // Main context
+ void activate() { _is_activated = true; }
+ void deactivate() { _is_activated = false; }
+
+ void add_node(SharedPtr<Node> node);
+
+ // Audio context
+ void reset();
+ bool run(FrameCount nframes);
+
+ // Any context
+ FrameCount time() { return _time; }
+
+private:
+ typedef std::vector<SharedPtr<Node> > Nodes;
+
+ // Audio context
+ SharedPtr<Node> earliest_node() const;
+ void exit_node(const SharedPtr<Node>);
+
+ bool _is_activated;
+ bool _is_finished;
+ FrameCount _time;
+ Nodes _nodes;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_MACHINE_HPP
diff --git a/src/engine/machina/Makefile.am b/src/engine/machina/Makefile.am
new file mode 100644
index 0000000..eca6f9b
--- /dev/null
+++ b/src/engine/machina/Makefile.am
@@ -0,0 +1,12 @@
+libmachinaincludedir = $(includedir)/machina
+
+libmachinainclude_HEADERS = \
+ types.hpp \
+ Node.hpp \
+ Edge.hpp \
+ Machine.hpp \
+ Loader.hpp \
+ JackDriver.hpp \
+ JackActions.hpp \
+ NodeFactory.hpp \
+ JackNodeFactory.hpp
diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp
new file mode 100644
index 0000000..d0e19db
--- /dev/null
+++ b/src/engine/machina/Node.hpp
@@ -0,0 +1,82 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_NODE_HPP
+#define MACHINA_NODE_HPP
+
+#include <boost/utility.hpp>
+#include <raul/SharedPtr.h>
+#include <raul/List.h>
+#include "types.hpp"
+#include "Action.hpp"
+
+namespace Machina {
+
+class Edge;
+
+
+/** 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 boost::noncopyable {
+public:
+ typedef std::string ID;
+
+ Node(FrameCount duration=0, bool initial=false);
+
+ void add_enter_action(Action* action);
+ void remove_enter_action(Action* action);
+
+ void add_exit_action(Action* action);
+ void remove_exit_action(Action* action);
+
+ void enter(Timestamp time);
+ void exit(Timestamp time);
+
+ void add_outgoing_edge(SharedPtr<Edge> edge);
+ void remove_outgoing_edge(SharedPtr<Edge> edge);
+
+ 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; }
+
+ typedef Raul::List<SharedPtr<Edge> > EdgeList;
+ const EdgeList& outgoing_edges() const { return _outgoing_edges; }
+
+private:
+ bool _is_initial;
+ bool _is_active;
+ Timestamp _enter_time; ///< valid iff _is_active
+ FrameCount _duration;
+ Action* _enter_action;
+ Action* _exit_action;
+ EdgeList _outgoing_edges;
+};
+
+
+} // namespace Machina
+
+#endif // MACHINA_NODE_HPP
diff --git a/src/engine/machina/NodeFactory.hpp b/src/engine/machina/NodeFactory.hpp
new file mode 100644
index 0000000..f38fd92
--- /dev/null
+++ b/src/engine/machina/NodeFactory.hpp
@@ -0,0 +1,40 @@
+/* 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
new file mode 100644
index 0000000..8793fb1
--- /dev/null
+++ b/src/engine/machina/types.hpp
@@ -0,0 +1,31 @@
+/* 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 Street, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#ifndef MACHINA_TYPES_HPP
+#define MACHINA_TYPES_HPP
+
+#include <jack/types.h>
+
+namespace Machina {
+
+
+typedef jack_nframes_t FrameCount;
+typedef jack_nframes_t Timestamp;
+
+} // namespace Machina
+
+#endif // MACHINA_TYPES_HPP