diff options
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | data/test.ttl | 31 | ||||
-rw-r--r-- | src/Machina.hpp | 3 | ||||
-rw-r--r-- | src/Machine.cpp | 16 | ||||
-rw-r--r-- | src/Machine.hpp | 18 | ||||
-rw-r--r-- | src/Node.hpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 30 |
7 files changed, 70 insertions, 31 deletions
diff --git a/configure.ac b/configure.ac index 1665508..575d881 100644 --- a/configure.ac +++ b/configure.ac @@ -12,6 +12,7 @@ AC_TYPE_SIZE_T PKG_CHECK_MODULES(JACK, jack >= 0.102.20) PKG_CHECK_MODULES(RAUL, raul >= 0.0.0) +PKG_CHECK_MODULES(GLIBMM, glibmm-2.4) # Check for debugging flag debug="no" diff --git a/data/test.ttl b/data/test.ttl index 1a334b1..741d9cb 100644 --- a/data/test.ttl +++ b/data/test.ttl @@ -1,9 +1,24 @@ -@prefix : <http://codeson.net/ns/machina#> . - -<#test> - a Machine; - node [ - a Node; - midiNote 60; - duration 100; +@prefix : <http://drobilla.net/ns/machina#> . + +<> + a :Machine; + + :initialNode <#n1> ; + :node <#n2> ; + + :edge [ + :tail <#n1> ; + :head <#n2> ; ] . + + +<#n1> + a :Node ; + :midiNote 60 ; + :duration 600 . + +<#n2> + a :Node ; + :midiNote 70 ; + :duration 700 . + diff --git a/src/Machina.hpp b/src/Machina.hpp index ba02239..4387978 100644 --- a/src/Machina.hpp +++ b/src/Machina.hpp @@ -16,9 +16,12 @@ #include <list> +namespace Machina { class Machina { private: std::list<Node> _nodes; }; + +} // namespace Machina diff --git a/src/Machine.cpp b/src/Machine.cpp index 91335c7..246db73 100644 --- a/src/Machine.cpp +++ b/src/Machine.cpp @@ -23,7 +23,8 @@ namespace Machina { Machine::Machine(size_t poly) - : _initial_node(new Node()) + : _activated(false) + , _initial_node(new Node()) , _voices(poly, NULL)//_initial_node) , _time(0) { @@ -35,13 +36,14 @@ Machine::Machine(size_t poly) Machine::~Machine() { - delete _initial_node; } void Machine::reset() { + assert(!_activated); + for (std::vector<Node*>::iterator i = _voices.begin(); i != _voices.end(); ++i) { *i = NULL; @@ -50,11 +52,21 @@ Machine::reset() void +Machine::add_node(const Node::ID& id, SharedPtr<Node> node) +{ + assert(!_activated); + _nodes[id] = node; +} + + +void Machine::process(FrameCount nframes) { const FrameCount cycle_end = _time + nframes; bool done = false; + assert(_activated); + FrameCount latest_event = _time; std::cerr << "--------- " << _time << " - " << _time + nframes << std::endl; diff --git a/src/Machine.hpp b/src/Machine.hpp index aefd041..a2360bb 100644 --- a/src/Machine.hpp +++ b/src/Machine.hpp @@ -18,26 +18,36 @@ #define MACHINA_MACHINE_HPP #include <vector> +#include <map> +#include "raul/SharedPtr.h" #include "types.hpp" +#include "Node.hpp" namespace Machina { -class Node; - class Machine { public: Machine(size_t poly); ~Machine(); - Node* initial_node() { return _initial_node; } + // Main context + void activate() { _activated = true; } + void deactivate() { _activated = false; } + void add_node(const Node::ID& id, SharedPtr<Node> node); + // Audio context void reset(); void process(FrameCount nframes); + + SharedPtr<Node> initial_node() { return _initial_node; } private: - Node* _initial_node; + bool _activated; + SharedPtr<Node> _initial_node; std::vector<Node*> _voices; + + std::map<Node::ID, SharedPtr<Node> > _nodes; FrameCount _time; }; diff --git a/src/Node.hpp b/src/Node.hpp index 353cbc2..40fc6f3 100644 --- a/src/Node.hpp +++ b/src/Node.hpp @@ -34,6 +34,8 @@ class Edge; */ class Node : public boost::noncopyable { public: + typedef std::string ID; + Node(FrameCount duration=0); void add_enter_action(Action* action); diff --git a/src/main.cpp b/src/main.cpp index 9b4511b..79809e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,29 +19,24 @@ #include "Node.hpp" #include "Action.hpp" #include "Edge.hpp" +#include "Loader.hpp" using namespace std; using namespace Machina; -Node* create_debug_node(const string& name, FrameCount duration) +int +main(int argc, char** argv) { - // leaks like a sieve, obviously - - Node* n = new Node(duration); - PrintAction* a_enter = new PrintAction(string("> ") + name); - PrintAction* a_exit = new PrintAction(string("< ")/* + name*/); + if (argc != 2) + return -1; - n->add_enter_action(a_enter); - n->add_exit_action(a_exit); + Loader l; + SharedPtr<Machine> m = l.load(argv[1]); - return n; -} + m->activate(); - -int -main()//int argc, char** argv) -{ + /* Machine m(1); Node* n1 = create_debug_node("1", 1); @@ -50,12 +45,13 @@ main()//int argc, char** argv) m.initial_node()->add_outgoing_edge(new Edge(n1)); n1->add_outgoing_edge(new Edge(n2)); n2->add_outgoing_edge(new Edge(m.initial_node())); + */ Timestamp t = 0; - while (t < 80) { - m.process(10); - t += 10; + while (t < 4000) { + m->process(1000); + t += 1000; } return 0; |