aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2010-12-22 02:16:39 +0000
committerDavid Robillard <d@drobilla.net>2010-12-22 02:16:39 +0000
commit731274226c322192ccec35fb893f594e9bd69a88 (patch)
tree044e35fd4897fd6a0f7987a71c9fbe3adc3bc00e /src
parent3d68bae339ee6f1285fc66d8192ea704708847f7 (diff)
downloadmachina-731274226c322192ccec35fb893f594e9bd69a88.tar.gz
machina-731274226c322192ccec35fb893f594e9bd69a88.tar.bz2
machina-731274226c322192ccec35fb893f594e9bd69a88.zip
Assign all objects a numeric ID at creation time.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@2778 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src')
-rw-r--r--src/engine/Action.cpp5
-rw-r--r--src/engine/Edge.cpp33
-rw-r--r--src/engine/Machine.cpp6
-rw-r--r--src/engine/MidiAction.cpp4
-rw-r--r--src/engine/Node.cpp36
-rw-r--r--src/engine/Stateful.cpp42
-rw-r--r--src/engine/machina/Stateful.hpp15
-rw-r--r--src/engine/wscript1
-rw-r--r--src/gui/EdgeView.cpp6
9 files changed, 99 insertions, 49 deletions
diff --git a/src/engine/Action.cpp b/src/engine/Action.cpp
index 6cd419d..abea09f 100644
--- a/src/engine/Action.cpp
+++ b/src/engine/Action.cpp
@@ -26,10 +26,7 @@ Action::write_state(Redland::Model& model)
{
using namespace Raul;
- if (!_id.is_valid())
- set_id(Redland::Node::blank_id(model.world()));
-
- model.add_statement(_id,
+ model.add_statement(id(model.world()),
Redland::Node(model.world(), Redland::Node::RESOURCE, "rdf:type"),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:Action"));
}
diff --git a/src/engine/Edge.cpp b/src/engine/Edge.cpp
index d8f64d6..d2c628f 100644
--- a/src/engine/Edge.cpp
+++ b/src/engine/Edge.cpp
@@ -30,12 +30,12 @@ Edge::write_state(Redland::Model& model)
{
using namespace Raul;
- if (!_id.is_valid())
- set_id(Redland::Node::blank_id(model.world()));
-
- model.add_statement(_id,
- "rdf:type",
- Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:Edge"));
+ const Redland::Node& rdf_id = id(model.world());
+
+ model.add_statement(
+ rdf_id,
+ "rdf:type",
+ Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:Edge"));
SharedPtr<Node> tail = _tail.lock();
SharedPtr<Node> head = _head;
@@ -43,19 +43,20 @@ Edge::write_state(Redland::Model& model)
if (!tail || !head)
return;
- assert(tail->id() && head->id());
+ assert(tail->id(model.world()) && head->id(model.world()));
- model.add_statement(_id,
- "machina:tail",
- tail->id());
+ model.add_statement(rdf_id,
+ "machina:tail",
+ tail->id(model.world()));
- model.add_statement(_id,
- "machina:head",
- head->id());
+ model.add_statement(rdf_id,
+ "machina:head",
+ head->id(model.world()));
- model.add_statement(_id,
- "machina:probability",
- AtomRDF::atom_to_node(model, Atom(_probability.get())));
+ model.add_statement(
+ rdf_id,
+ "machina:probability",
+ AtomRDF::atom_to_node(model, Atom(_probability.get())));
}
diff --git a/src/engine/Machine.cpp b/src/engine/Machine.cpp
index 2afedbc..611ecc5 100644
--- a/src/engine/Machine.cpp
+++ b/src/engine/Machine.cpp
@@ -397,11 +397,11 @@ Machine::write_state(Redland::Model& model)
if ((*n)->is_initial()) {
model.add_statement(model.base_uri(),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:initialNode"),
- (*n)->id());
+ (*n)->id(model.world()));
} else {
model.add_statement(model.base_uri(),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:node"),
- (*n)->id());
+ (*n)->id(model.world()));
}
}
@@ -416,7 +416,7 @@ Machine::write_state(Redland::Model& model)
model.add_statement(model.base_uri(),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:edge"),
- (*e)->id());
+ (*e)->id(model.world()));
}
}
diff --git a/src/engine/MidiAction.cpp b/src/engine/MidiAction.cpp
index 6cc7583..bcdf7e2 100644
--- a/src/engine/MidiAction.cpp
+++ b/src/engine/MidiAction.cpp
@@ -98,12 +98,12 @@ MidiAction::write_state(Redland::Model& model)
Action::write_state(model);
- model.add_statement(_id,
+ model.add_statement(id(model.world()),
Redland::Node(model.world(), Redland::Node::RESOURCE, "rdf:type"),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:MidiAction"));
// FIXME: Assumes note on/note off
- model.add_statement(_id,
+ model.add_statement(id(model.world()),
Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:midiNote"),
AtomRDF::atom_to_node(model, Atom((int)(_event.get()[1]))));
}
diff --git a/src/engine/Node.cpp b/src/engine/Node.cpp
index f9a7e11..e4f70d1 100644
--- a/src/engine/Node.cpp
+++ b/src/engine/Node.cpp
@@ -209,36 +209,38 @@ Node::write_state(Redland::Model& model)
{
using namespace Raul;
- if (!_id.is_valid())
- set_id(Redland::Node::blank_id(model.world()));
+ const Redland::Node& rdf_id = id(model.world());
if (_is_selector)
- model.add_statement(_id,
- "rdf:type",
- Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:SelectorNode"));
+ model.add_statement(
+ rdf_id,
+ "rdf:type",
+ Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:SelectorNode"));
else
- model.add_statement(_id,
- "rdf:type",
- Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:Node"));
+ model.add_statement(
+ rdf_id,
+ "rdf:type",
+ Redland::Node(model.world(), Redland::Node::RESOURCE, "machina:Node"));
- model.add_statement(_id,
- "machina:duration",
- AtomRDF::atom_to_node(model, Atom((float)_duration.to_double())));
+ model.add_statement(
+ rdf_id,
+ "machina:duration",
+ AtomRDF::atom_to_node(model, Atom((float)_duration.to_double())));
if (_enter_action) {
_enter_action->write_state(model);
- model.add_statement(_id,
- "machina:enterAction",
- _enter_action->id());
+ model.add_statement(rdf_id,
+ "machina:enterAction",
+ _enter_action->id(model.world()));
}
if (_exit_action) {
_exit_action->write_state(model);
- model.add_statement(_id,
- "machina:exitAction",
- _exit_action->id());
+ model.add_statement(rdf_id,
+ "machina:exitAction",
+ _exit_action->id(model.world()));
}
}
diff --git a/src/engine/Stateful.cpp b/src/engine/Stateful.cpp
new file mode 100644
index 0000000..7ddf1c1
--- /dev/null
+++ b/src/engine/Stateful.cpp
@@ -0,0 +1,42 @@
+/* This file is part of Machina.
+ * Copyright (C) 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 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
+ */
+
+#include "machina/Stateful.hpp"
+
+namespace Machina {
+
+uint64_t Stateful::_next_id = 1;
+
+Stateful::Stateful()
+ : _id(_next_id++)
+{
+}
+
+
+Redland::Node
+Stateful::id(Redland::World& world) const
+{
+ if (!_rdf_id.is_valid()) {
+ std::ostringstream ss;
+ ss << "b" << _id;
+ _rdf_id = Redland::Node(world, Redland::Node::BLANK, ss.str());
+ }
+
+ return _rdf_id;
+}
+
+} // namespace Machina
diff --git a/src/engine/machina/Stateful.hpp b/src/engine/machina/Stateful.hpp
index 1a72db5..8dbf23d 100644
--- a/src/engine/machina/Stateful.hpp
+++ b/src/engine/machina/Stateful.hpp
@@ -18,21 +18,28 @@
#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;
- Redland::Node id() const { return _id; }
- void set_id(const Redland::Node& id) { _id = id; }
+ Redland::Node id(Redland::World& world) const;
+
+private:
+ static uint64_t _next_id;
-protected:
- Redland::Node _id;
+ uint64_t _id;
+ mutable Redland::Node _rdf_id;
};
} // namespace Machina
diff --git a/src/engine/wscript b/src/engine/wscript
index e420abb..35f1303 100644
--- a/src/engine/wscript
+++ b/src/engine/wscript
@@ -17,6 +17,7 @@ def build(bld):
Node.cpp
Recorder.cpp
SMFDriver.cpp
+ Stateful.cpp
'''
if bld.env['HAVE_EUGENE']:
core_source += '''
diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp
index c72fc3f..eff796c 100644
--- a/src/gui/EdgeView.cpp
+++ b/src/gui/EdgeView.cpp
@@ -44,9 +44,9 @@
inline static uint32_t edge_color(float prob)
{
- static uint32_t min = 0xFF4444C0;
- static uint32_t mid = 0xFFFF44C0;
- static uint32_t max = 0x44FF44C0;
+ static const uint32_t min = 0xFF4444C0;
+ static const uint32_t mid = 0xFFFF44C0;
+ static const uint32_t max = 0x44FF44C0;
if (prob <= 0.5)
return UINT_INTERPOLATE(min, mid, prob*2.0);