From 0a02e807beea6104248cb6cf00ef6689c9231912 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 14 Jan 2013 07:39:55 +0000 Subject: Fix saving and loading machines. git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4984 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/main.cpp | 60 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 35 insertions(+), 25 deletions(-) (limited to 'src/gui') diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 46cb21c..04d9e6d 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -14,15 +14,19 @@ along with Machina. If not, see . */ -#include "machina_config.h" #include + #include #include -#include "sord/sordmm.hpp" + +#include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "machina/Engine.hpp" #include "machina/Loader.hpp" #include "machina/Machine.hpp" #include "machina/URIs.hpp" +#include "machina_config.h" +#include "sord/sordmm.hpp" + #include "MachinaGUI.hpp" using namespace std; @@ -31,49 +35,55 @@ using namespace machina; int main(int argc, char** argv) { - if (!Glib::thread_supported()) { - Glib::thread_init(); - } + Glib::thread_init(); + machina::URIs::init(); Sord::World rdf_world; + rdf_world.add_prefix("", MACHINA_NS); + rdf_world.add_prefix("midi", LV2_MIDI_PREFIX); - machina::URIs::init(); - + Raul::Forge forge; SPtr machine; + Raul::TimeUnit beats(TimeUnit::BEATS, MACHINA_PPQN); + // Load machine, if given -#if 0 if (argc >= 2) { const string filename = argv[1]; - cout << "Building machine from MIDI file " << filename << endl; - SPtr file_driver(new machina::SMFDriver()); - - if (argc >= 3) { - float q = strtof(argv[2], NULL); - cout << "Quantization: " << q << endl; - machine = file_driver->learn(filename, q); - } else { - cout << "No quantization." << endl; - machine = file_driver->learn(filename); + const string ext = filename.substr(filename.length() - 4); + + if (ext == ".ttl") { + cout << "Loading machine from " << filename << endl; + machine = Loader(forge, rdf_world).load(filename); + + } else if (ext == ".mid") { + cout << "Building machine from MIDI file " << filename << endl; + + double q = 0.0; + if (argc >= 3) { + q = strtod(argv[2], NULL); + cout << "Quantization: " << q << endl; + } + + machine = Loader(forge, rdf_world).load_midi( + filename, q, Raul::TimeDuration(beats, 0, 0)); } if (!machine) { - cout << "Not MIDI, attempting to load machine" << endl; - machine = Loader(rdf_world).load(filename); + cerr << "Failed to load machine, exiting" << std::endl; + return 1; } } -#endif - Raul::Forge forge; if (!machine) { - machine = SPtr(new Machine(TimeUnit(TimeUnit::BEATS, 19200))); + machine = SPtr(new Machine(beats)); } std::string driver_name = "smf"; - #ifdef HAVE_JACK +#ifdef HAVE_JACK driver_name = "jack"; - #endif +#endif // Build engine SPtr driver(Engine::new_driver(forge, driver_name, machine)); -- cgit v1.2.1