diff options
author | David Robillard <d@drobilla.net> | 2007-02-01 05:07:13 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-02-01 05:07:13 +0000 |
commit | ed85b5c7d96e40ada730614cb69776672738c87b (patch) | |
tree | 9aee0a533ae8f815e48e3fdf6a48013fe31f1f3c /src | |
parent | 822c1f64098b5d81aaa8b4c7d6f75901d9f431f2 (diff) | |
download | machina-ed85b5c7d96e40ada730614cb69776672738c87b.tar.gz machina-ed85b5c7d96e40ada730614cb69776672738c87b.tar.bz2 machina-ed85b5c7d96e40ada730614cb69776672738c87b.zip |
Partially implemented loading (from RDF files).
git-svn-id: http://svn.drobilla.net/lad/machina@272 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-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 |
5 files changed, 46 insertions, 23 deletions
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; |