diff options
author | David Robillard <d@drobilla.net> | 2007-04-02 01:52:53 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2007-04-02 01:52:53 +0000 |
commit | db6f6e87dc4ff620f399597913f14a3b4eda277f (patch) | |
tree | 4258f8cc7f2a841fd41ce9dac222919f0ee98eeb /util/machina2dot | |
parent | 69ad86f21555d28f5065923eea06ccc3cc4f4ce5 (diff) | |
download | machina-db6f6e87dc4ff620f399597913f14a3b4eda277f.tar.gz machina-db6f6e87dc4ff620f399597913f14a3b4eda277f.tar.bz2 machina-db6f6e87dc4ff620f399597913f14a3b4eda277f.zip |
Edge label toggling.
Made state properties dialog actually work.
Other things...
git-svn-id: http://svn.drobilla.net/lad/machina@390 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'util/machina2dot')
-rwxr-xr-x | util/machina2dot | 107 |
1 files changed, 100 insertions, 7 deletions
diff --git a/util/machina2dot b/util/machina2dot index 726f98a..22cfbf0 100755 --- a/util/machina2dot +++ b/util/machina2dot @@ -15,10 +15,50 @@ parser.parse_into_model(model, "file:" + sys.argv[1]) print """ digraph finite_state_machine { rankdir=LR; - node [ shape = circle ]; + { + node [ shape = doublecircle ]; """, -node_durations = { } +written_nodes = {} +node_durations = {} +invis_id = 0; + + +# Initial selectors + +initial_selectors_query = RDF.SPARQLQuery(""" +PREFIX machina: <http://drobilla.net/ns/machina#> +SELECT DISTINCT ?n ?dur ?note WHERE { + ?m machina:initialNode ?n . + ?n a machina:SelectorNode ; + machina:duration ?dur . + OPTIONAL { ?n machina:enterAction ?a . + ?a machina:midiNote ?note } +} +""") + +for result in initial_selectors_query.execute(model): + node_id = result['n'].blank_identifier + duration = float(result['dur'].literal_value['string']) + written_nodes[node_id] = True; + node_durations[node_id] = duration + print "\t{ node [ style = invis ] ", + print "invis%d" % invis_id, " }" + + label = "d=%.1f" % duration + if result['note']: + label += "\\nn=%s" % result['note'].literal_value['string'] + + print '\t', node_id, "[ label=\"%s\" ]" % label + print '\t', "invis%d" % invis_id, " -> ", node_id + invis_id += 1 + +print """ } { + node [ shape = circle ]; +""" + + +# Initial non-selectors initial_nodes_query = RDF.SPARQLQuery(""" PREFIX machina: <http://drobilla.net/ns/machina#> @@ -31,11 +71,14 @@ SELECT DISTINCT ?n ?dur ?note WHERE { } """) -invis_id = 0; - for result in initial_nodes_query.execute(model): node_id = result['n'].blank_identifier duration = float(result['dur'].literal_value['string']) + + if written_nodes.has_key(node_id): + continue + + written_nodes[node_id] = True; node_durations[node_id] = duration print "\t{ node [ style = invis ] ", print "invis%d" % invis_id, " }" @@ -49,6 +92,47 @@ for result in initial_nodes_query.execute(model): invis_id += 1 +# Non-initial selectors + +print """ } { + node [ shape = doublecircle ]; +""" + +selectors_query = RDF.SPARQLQuery(""" +PREFIX machina: <http://drobilla.net/ns/machina#> +SELECT DISTINCT ?n ?dur ?note WHERE { + ?m machina:node ?n . + ?n a machina:SelectorNode ; + machina:duration ?dur . + OPTIONAL { ?n machina:enterAction ?a . + ?a machina:midiNote ?note } +} +""") + + +for result in selectors_query.execute(model): + node_id = result['n'].blank_identifier + duration = float(result['dur'].literal_value['string']) + + if written_nodes.has_key(node_id): + continue + + node_durations[node_id] = duration + + label = "d=%.1f" % duration + if result['note']: + label += "\\nn=%s" % result['note'].literal_value['string'] + + print '\t', node_id, "[ label=\"%s\" ]" % label + + + +# Non-initial non-selectors + +print """ } { + node [ shape = circle ]; +""" + nodes_query = RDF.SPARQLQuery(""" PREFIX machina: <http://drobilla.net/ns/machina#> SELECT DISTINCT ?n ?dur ?note WHERE { @@ -60,9 +144,14 @@ SELECT DISTINCT ?n ?dur ?note WHERE { } """) + for result in nodes_query.execute(model): node_id = result['n'].blank_identifier duration = float(result['dur'].literal_value['string']) + + if written_nodes.has_key(node_id): + continue + node_durations[node_id] = duration label = "d=%.1f" % duration @@ -71,7 +160,9 @@ for result in nodes_query.execute(model): print '\t', node_id, "[ label=\"%s\" ]" % label - + +# Edges + edge_query = RDF.SPARQLQuery(""" PREFIX machina: <http://drobilla.net/ns/machina#> SELECT DISTINCT ?tail ?head ?prob WHERE { @@ -86,6 +177,8 @@ for edge in edge_query.execute(model): print '\t', edge['tail'].blank_identifier, ' -> ', print edge['head'].blank_identifier, ' ', print "[ label = \"%1.2f\"" % float(edge['prob'].literal_value['string']), - print "minlen = ", node_durations[edge['tail'].blank_identifier], " ];" + print "minlen = ", node_durations[edge['tail'].blank_identifier]+0.1, " ];" -print "}" +print """ + } +}""" |