aboutsummaryrefslogtreecommitdiffstats
path: root/src/engine
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-12-07 17:27:06 +0000
committerDavid Robillard <d@drobilla.net>2007-12-07 17:27:06 +0000
commitaa11564fef8ed9330d42081288e8f310072c67d6 (patch)
tree3d092d0117fd8a309d4ec16e158893744a777362 /src/engine
parent885af895243b43220b1e99f1d3b2bebcc2ec6398 (diff)
downloadmachina-aa11564fef8ed9330d42081288e8f310072c67d6.tar.gz
machina-aa11564fef8ed9330d42081288e8f310072c67d6.tar.bz2
machina-aa11564fef8ed9330d42081288e8f310072c67d6.zip
Fix loading selector nodes.
Choosing evolution target MIDI from GUI. git-svn-id: http://svn.drobilla.net/lad/machina@963 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/engine')
-rw-r--r--src/engine/Loader.cpp20
-rw-r--r--src/engine/MachineBuilder.cpp6
-rw-r--r--src/engine/Mutation.cpp6
-rw-r--r--src/engine/Problem.cpp4
-rw-r--r--src/engine/machina/Node.hpp2
-rw-r--r--src/engine/machina/Problem.hpp2
6 files changed, 31 insertions, 9 deletions
diff --git a/src/engine/Loader.cpp b/src/engine/Loader.cpp
index 3b60223..cf41bd1 100644
--- a/src/engine/Loader.cpp
+++ b/src/engine/Loader.cpp
@@ -119,6 +119,26 @@ Loader::load(const Glib::ustring& uri)
}
+ /* Find out which nodes are selectors */
+
+ query = Query(_rdf_world, ustring(
+ "SELECT DISTINCT ?node WHERE {\n") +
+ machine_uri + " :node ?node .\n"
+ "?node a :SelectorNode .\n"
+ "}\n");
+
+ results = query.run(_rdf_world, model);
+
+ for (Query::Results::iterator i = results.begin(); i != results.end(); ++i) {
+ const char* node_id = (*i)["node"];
+ Created::iterator n = created.find(node_id);
+ if (n != created.end())
+ n->second->set_selector(true);
+ else
+ cerr << "WARNING: Selector node " << node_id << " not found" << endl;
+ }
+
+
/* Get note actions */
query = Query(_rdf_world, ustring(
diff --git a/src/engine/MachineBuilder.cpp b/src/engine/MachineBuilder.cpp
index 7f0da03..34e45b8 100644
--- a/src/engine/MachineBuilder.cpp
+++ b/src/engine/MachineBuilder.cpp
@@ -44,7 +44,7 @@ MachineBuilder::MachineBuilder(SharedPtr<Machine> machine, Raul::BeatTime q)
void
MachineBuilder::reset()
{
- _initial_node = SharedPtr<Node>(new Node());
+ _initial_node = SharedPtr<Node>(new Node(0.0));
_initial_node->set_initial(true);
_connect_node = _initial_node;
_connect_node_end_time = 0;
@@ -123,7 +123,7 @@ MachineBuilder::event(Raul::BeatTime time_offset,
if ((buf[0] & 0xF0) == MIDI_CMD_NOTE_ON) {
- SharedPtr<Node> node(new Node());
+ SharedPtr<Node> node(new Node(0.0));
node->set_enter_action(SharedPtr<Action>(new MidiAction(ev_size, buf)));
SharedPtr<Node> this_connect_node;
@@ -187,7 +187,7 @@ MachineBuilder::event(Raul::BeatTime time_offset,
// Finish a polyphonic section
if (_poly_nodes.size() > 0) {
- _connect_node = SharedPtr<Node>(new Node());
+ _connect_node = SharedPtr<Node>(new Node(0.0));
_machine->add_node(_connect_node);
connect_nodes(_machine, resolved, t, _connect_node, t);
diff --git a/src/engine/Mutation.cpp b/src/engine/Mutation.cpp
index d60ef34..a307ce5 100644
--- a/src/engine/Mutation.cpp
+++ b/src/engine/Mutation.cpp
@@ -52,10 +52,12 @@ AddNode::mutate(Machine& machine)
//cout << "ADD NODE" << endl;
// Create random node
- SharedPtr<Node> node(new Node(1.0));
+ SharedPtr<Node> node(new Node());
node->set_selector(true);
SharedPtr<Node> note_node = machine.random_node();
+ if (!note_node)
+ return;
uint8_t note = PtrCast<MidiAction>(note_node->enter_action())->event()[1];
node->set_enter_action(ActionFactory::note_on(note));
@@ -154,7 +156,7 @@ RemoveEdge::mutate(Machine& machine)
//cout << "REMOVE EDGE" << endl;
SharedPtr<Node> tail = machine.random_node();
- if (tail)
+ if (tail && !(tail->is_initial() && tail->edges().size() == 1))
tail->remove_edge(tail->random_edge());
}
diff --git a/src/engine/Problem.cpp b/src/engine/Problem.cpp
index 3fa793f..0db588c 100644
--- a/src/engine/Problem.cpp
+++ b/src/engine/Problem.cpp
@@ -42,7 +42,7 @@ Problem::Problem(const std::string& target_midi, SharedPtr<Machine> seed)
const bool opened = smf.open(target_midi);
assert(opened);
- smf.seek_to_track(2); // FIXME: kluge
+ smf.seek_to_track(2); // FIXME: ?
uint8_t buf[4];
uint32_t ev_size;
@@ -221,7 +221,7 @@ Problem::initial_population(size_t gene_size, size_t pop_size) const
for (uint8_t i=0; i < 128; ++i) {
if (_target._counts[i] > 0) {
//cout << "Initial note: " << (int)i << endl;
- SharedPtr<Node> node(new Node(1.0));
+ SharedPtr<Node> node(new Node(1/4.0));
node->set_enter_action(ActionFactory::note_on(i));
node->set_exit_action(ActionFactory::note_off(i));
node->set_selector(true);
diff --git a/src/engine/machina/Node.hpp b/src/engine/machina/Node.hpp
index 87e14af..04e7c07 100644
--- a/src/engine/machina/Node.hpp
+++ b/src/engine/machina/Node.hpp
@@ -44,7 +44,7 @@ class Node : public Raul::Stateful {
public:
typedef std::string ID;
- Node(BeatCount duration=1.0, bool initial=false);
+ Node(BeatCount duration=1/4.0, bool initial=false);
Node(const Node& copy);
void set_enter_action(SharedPtr<Action> action);
diff --git a/src/engine/machina/Problem.hpp b/src/engine/machina/Problem.hpp
index 7605e88..067be51 100644
--- a/src/engine/machina/Problem.hpp
+++ b/src/engine/machina/Problem.hpp
@@ -81,7 +81,7 @@ private:
};*/
struct Evaluator : public Raul::MIDISink {
- Evaluator(const Problem& problem) : _problem(problem), _order(8), _n_notes(0), _first_note(0) {
+ Evaluator(const Problem& problem) : _problem(problem), _order(4), _n_notes(0), _first_note(0) {
for (uint8_t i=0; i < 128; ++i)
_counts[i] = 0;
}