diff options
author | David Robillard <d@drobilla.net> | 2013-01-14 07:39:55 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2013-01-14 07:39:55 +0000 |
commit | 0a02e807beea6104248cb6cf00ef6689c9231912 (patch) | |
tree | cb279fb1a1b801c48fa83a59fb56dde486b6dbfd /src/gui | |
parent | 035a94ce6c9a32025f88441ef8aedaf887a40318 (diff) | |
download | machina-0a02e807beea6104248cb6cf00ef6689c9231912.tar.gz machina-0a02e807beea6104248cb6cf00ef6689c9231912.tar.bz2 machina-0a02e807beea6104248cb6cf00ef6689c9231912.zip |
Fix saving and loading machines.
git-svn-id: http://svn.drobilla.net/lad/trunk/machina@4984 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/main.cpp | 60 |
1 files changed, 35 insertions, 25 deletions
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 <http://www.gnu.org/licenses/>. */ -#include "machina_config.h" #include <signal.h> + #include <iostream> #include <string> -#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<machina::Machine> 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<machina::SMFDriver> 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<Machine>(new Machine(TimeUnit(TimeUnit::BEATS, 19200))); + machine = SPtr<Machine>(new Machine(beats)); } std::string driver_name = "smf"; - #ifdef HAVE_JACK +#ifdef HAVE_JACK driver_name = "jack"; - #endif +#endif // Build engine SPtr<Driver> driver(Engine::new_driver(forge, driver_name, machine)); |