aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2007-03-02 00:05:18 +0000
committerDavid Robillard <d@drobilla.net>2007-03-02 00:05:18 +0000
commit19b537a142c127dd2c1d9a40a7999714f9d2175d (patch)
tree85d7da2a138e34ca5783dffbc6547fd4500ca7ca /util
parentde25ae35ccb0613290ba20bfcf0ea15476c26ed5 (diff)
downloadmachina-19b537a142c127dd2c1d9a40a7999714f9d2175d.tar.gz
machina-19b537a142c127dd2c1d9a40a7999714f9d2175d.tar.bz2
machina-19b537a142c127dd2c1d9a40a7999714f9d2175d.zip
Work towards Action serialization.
Made edge length in dot graphs (from machina2dot) correspond to node duration to make automaton diagram map closer to music notation. git-svn-id: http://svn.drobilla.net/lad/machina@341 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'util')
-rwxr-xr-xutil/machina2dot.py62
1 files changed, 33 insertions, 29 deletions
diff --git a/util/machina2dot.py b/util/machina2dot.py
index bbf9725..f4e67ec 100755
--- a/util/machina2dot.py
+++ b/util/machina2dot.py
@@ -16,56 +16,60 @@ parser.parse_into_model(model, "file:" + sys.argv[1])
print """
digraph finite_state_machine {
rankdir=LR;
- size="8,5"
- node [shape = doublecircle];
+ node [shape = doublecircle, width = 1.25 ];
""",
+node_durations = { }
-initial_nodes = RDF.SPARQLQuery("""
+initial_nodes_query = RDF.SPARQLQuery("""
PREFIX machina: <http://drobilla.net/ns/machina#>
-SELECT ?n ?dur WHERE {
+SELECT DISTINCT ?n ?dur WHERE {
?m machina:initialNode ?n .
?n a machina:Node ;
machina:duration ?dur .
}
-""").execute(model)
+""")
-for result in initial_nodes:
- print '\t', result['n'].blank_identifier, "[ label = \"",
- print float(result['dur'].literal_value['string']),
- print "\"]; "
+for result in initial_nodes_query.execute(model):
+ node_id = result['n'].blank_identifier
+ duration = float(result['dur'].literal_value['string'])
+ node_durations[node_id] = duration
+ print '\t', node_id, "[ label = \"d:", duration, "\"];"
-print "\tnode [shape = circle];"
+print "\tnode [shape = circle, width = 1.25 ];"
-nodes = RDF.SPARQLQuery("""
+
+nodes_query = RDF.SPARQLQuery("""
PREFIX machina: <http://drobilla.net/ns/machina#>
-SELECT ?n ?dur WHERE {
+SELECT DISTINCT ?n ?dur WHERE {
?m machina:node ?n .
?n a machina:Node ;
machina:duration ?dur .
}
-""").execute(model)
-
-for result in nodes:
- print '\t', result['n'].blank_identifier, "[ label = \"",
- print float(result['dur'].literal_value['string']),
- print "\"]; "
+""")
+for result in nodes_query.execute(model):
+ node_id = result['n'].blank_identifier
+ duration = float(result['dur'].literal_value['string'])
+ node_durations[node_id] = duration
+ print '\t', node_id, "[ label = \"d:", duration, "\"]; "
-edges = RDF.SPARQLQuery("""
+
+edge_query = RDF.SPARQLQuery("""
PREFIX machina: <http://drobilla.net/ns/machina#>
-SELECT ?tail ?head ?prob WHERE {
+SELECT DISTINCT ?tail ?head ?prob WHERE {
?e a machina:Edge ;
- machina:tail ?tail ;
+ machina:tail ?tail ;
machina:head ?head ;
machina:probability ?prob .
}
-""").execute(model);
-
-for result in edges:
- print '\t', result['tail'].blank_identifier, ' -> ',
- print result['head'].blank_identifier, ' ',
- print "[ label = \"", result['prob'].literal_value['string'], "\" ];"
-
-print "\n}"
+""")
+
+for edge in edge_query.execute(model):
+ print '\t', edge['tail'].blank_identifier, ' -> ',
+ print edge['head'].blank_identifier, ' ',
+ print "[ label = \"", edge['prob'].literal_value['string'], "\" ",
+ print "minlen = ", node_durations[edge['tail'].blank_identifier] * 7.5, " ];"
+
+print "}"