diff options
-rw-r--r-- | src/Makefile.am | 9 | ||||
-rw-r--r-- | src/engine/SMFDriver.cpp | 8 | ||||
-rw-r--r-- | src/engine/machina/SMFDriver.hpp | 4 | ||||
-rw-r--r-- | src/gui/main.cpp | 2 | ||||
-rw-r--r-- | src/machina.cpp (renamed from src/main.cpp) | 0 | ||||
-rw-r--r-- | src/midi2machina.cpp | 83 | ||||
-rwxr-xr-x | util/machina2dot.py | 15 |
7 files changed, 102 insertions, 19 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index 23a14da..1928c51 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,9 +3,10 @@ SUBDIRS = engine gui -bin_PROGRAMS = machina +bin_PROGRAMS = machina midi2machina -machina_CXXFLAGS = @RAUL_CFLAGS@ @JACK_CFLAGS@ @GLIBMM_CFLAGS@ -I$(top_srcdir)/src/engine -machina_LDADD = @RAUL_LIBS@ @JACK_LIBS@ @GLIBMM_LIBS@ engine/libmachina.la +AM_CXXFLAGS = @RAUL_CFLAGS@ @JACK_CFLAGS@ @GLIBMM_CFLAGS@ -I$(top_srcdir)/src/engine +LDADD = @RAUL_LIBS@ @JACK_LIBS@ @GLIBMM_LIBS@ engine/libmachina.la -machina_SOURCES = main.cpp +machina_SOURCES = machina.cpp +midi2machina_SOURCES = midi2machina.cpp diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index 70756d1..cdf2ad7 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -38,10 +38,8 @@ namespace Machina { * @return the resulting machine. */ SharedPtr<Machine> -SMFDriver::learn(const Glib::ustring& uri, unsigned track, Raul::BeatTime max_duration) +SMFDriver::learn(const string& filename, unsigned track, Raul::BeatTime max_duration) { - const string filename = Glib::filename_from_uri(uri); - SharedPtr<Machine> m(new Machine()); Raul::SMFReader reader; @@ -64,10 +62,8 @@ SMFDriver::learn(const Glib::ustring& uri, unsigned track, Raul::BeatTime max_du * This will result in a disjoint subgraph in the machine, one for each track. */ SharedPtr<Machine> -SMFDriver::learn(const Glib::ustring& uri, Raul::BeatTime max_duration) +SMFDriver::learn(const string& filename, Raul::BeatTime max_duration) { - const string filename = Glib::filename_from_uri(uri); - SharedPtr<Machine> m(new Machine()); Raul::SMFReader reader; diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp index 17c196e..3e74726 100644 --- a/src/engine/machina/SMFDriver.hpp +++ b/src/engine/machina/SMFDriver.hpp @@ -35,8 +35,8 @@ class Machine; class SMFDriver : public Raul::SMFWriter, public boost::enable_shared_from_this<SMFDriver> { public: - SharedPtr<Machine> learn(const Glib::ustring& uri, Raul::BeatTime max_duration=0); - SharedPtr<Machine> learn(const Glib::ustring& uri, unsigned track, Raul::BeatTime max_duration=0); + SharedPtr<Machine> learn(const std::string& filename, Raul::BeatTime max_duration=0); + SharedPtr<Machine> learn(const std::string& filename, unsigned track, Raul::BeatTime max_duration=0); void run(SharedPtr<Machine> machine, Raul::BeatTime max_time); diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 20f75b9..b6dea9c 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -38,7 +38,7 @@ main(int argc, char** argv) string filename = argv[1]; cout << "Building machine from MIDI file " << filename << endl; SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver()); - machine = file_driver->learn(string("file://") + filename, 0.0); + machine = file_driver->learn(filename, 0.0); } // Build engine diff --git a/src/main.cpp b/src/machina.cpp index f04a646..f04a646 100644 --- a/src/main.cpp +++ b/src/machina.cpp diff --git a/src/midi2machina.cpp b/src/midi2machina.cpp new file mode 100644 index 0000000..fb5951f --- /dev/null +++ b/src/midi2machina.cpp @@ -0,0 +1,83 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave 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 Street, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include <iostream> +#include <signal.h> +#include <raul/RDFWriter.h> +#include "machina/Engine.hpp" +#include "machina/Machine.hpp" +#include "machina/Node.hpp" +#include "machina/Action.hpp" +#include "machina/Edge.hpp" +#include "machina/SMFDriver.hpp" +#include "machina/MidiAction.hpp" + +using namespace std; +using namespace Machina; + + +bool quit = false; + + +void +catch_int(int) +{ + signal(SIGINT, catch_int); + signal(SIGTERM, catch_int); + + std::cout << "Interrupted" << std::endl; + + quit = true; +} + + +int +main(int argc, char** argv) +{ + if (argc != 2) { + cout << "Usage: " << argv[0] << " FILE" << endl; + return -1; + } + + SharedPtr<SMFDriver> driver(new SMFDriver()); + + SharedPtr<Machine> machine = driver->learn(argv[1]); + + if (!machine) { + cout << "Failed to load MIDI file." << endl; + return -1; + } + + string out_filename = argv[1]; + if (out_filename.find_last_of("/") != string::npos) + out_filename = out_filename.substr(out_filename.find_last_of("/")+1); + + const string::size_type last_dot = out_filename.find_last_of("."); + if (last_dot != string::npos && last_dot != 0) + out_filename = out_filename.substr(0, last_dot); + out_filename += ".machina"; + + cout << "Writing output to " << out_filename << endl; + + Raul::RDFWriter writer; + writer.start_to_filename(out_filename); + machine->write_state(writer); + writer.finish(); + + return 0; +} + diff --git a/util/machina2dot.py b/util/machina2dot.py index eb89ec8..cb704ef 100755 --- a/util/machina2dot.py +++ b/util/machina2dot.py @@ -16,7 +16,7 @@ parser.parse_into_model(model, "file:" + sys.argv[1]) print """ digraph finite_state_machine { rankdir=LR; - node [shape = doublecircle ]; + node [ shape = circle ]; """, node_durations = { } @@ -30,14 +30,17 @@ SELECT DISTINCT ?n ?dur 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']) node_durations[node_id] = duration + print "\t{ node [ style = invis ] ", + print "invis%d" % invis_id, " }" print '\t', node_id, "[ label = \"d =", duration, "\"];" - - -print "\tnode [shape = circle ];" + print '\t', "invis%d" % invis_id, " -> ", node_id + invis_id += 1 nodes_query = RDF.SPARQLQuery(""" @@ -53,7 +56,7 @@ 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, "\"]; " + print '\t', node_id, "[ label = \"d =", "%.2f" % duration, "\"]; " edge_query = RDF.SPARQLQuery(""" @@ -69,7 +72,7 @@ SELECT DISTINCT ?tail ?head ?prob WHERE { 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 "[ label = \"", "%1.2f" % float(edge['prob'].literal_value['string']), "\" ", print "minlen = ", node_durations[edge['tail'].blank_identifier] * 2, " ];" print "}" |