diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/engine/SMFDriver.cpp | 6 | ||||
-rw-r--r-- | src/engine/machina/SMFDriver.hpp | 2 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 28 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/engine/SMFDriver.cpp b/src/engine/SMFDriver.cpp index 181da52..3481222 100644 --- a/src/engine/SMFDriver.cpp +++ b/src/engine/SMFDriver.cpp @@ -36,7 +36,7 @@ namespace Machina { * @return the resulting machine. */ SharedPtr<Machine> -SMFDriver::learn(const Glib::ustring& uri) +SMFDriver::learn(const Glib::ustring& uri, unsigned track) { const string filename = Glib::filename_from_uri(uri); @@ -51,6 +51,10 @@ SMFDriver::learn(const Glib::ustring& uri) Raul::SMFReader reader; reader.open(filename); + + if ( ! reader.seek_to_track(track) ) + return SharedPtr<Machine>(); + Raul::BeatTime t = 0; unsigned char buf[4]; uint32_t ev_size; diff --git a/src/engine/machina/SMFDriver.hpp b/src/engine/machina/SMFDriver.hpp index e702534..f5d1229 100644 --- a/src/engine/machina/SMFDriver.hpp +++ b/src/engine/machina/SMFDriver.hpp @@ -34,7 +34,7 @@ class Machine; class SMFDriver : public Raul::SMFWriter, public boost::enable_shared_from_this<SMFDriver> { public: - SharedPtr<Machine> learn(const Glib::ustring& uri); + SharedPtr<Machine> learn(const Glib::ustring& uri, unsigned track=1); void run(SharedPtr<Machine> machine, Raul::BeatTime max_time); }; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 1266147..8f8e607 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -445,15 +445,33 @@ MachinaGUI::menu_import_midi() dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK); + Gtk::HBox* extra_widget = Gtk::manage(new Gtk::HBox()); + Gtk::SpinButton* track_sb = Gtk::manage(new Gtk::SpinButton()); + track_sb->set_increments(1, 10); + track_sb->set_range(1, 256); + extra_widget->pack_start(*Gtk::manage(new Gtk::Label("")), true, true); + extra_widget->pack_start(*Gtk::manage(new Gtk::Label("Track: ")), false, false); + extra_widget->pack_start(*track_sb, false, false); + dialog.set_extra_widget(*extra_widget); + extra_widget->show_all(); + const int result = dialog.run(); if (result == Gtk::RESPONSE_OK) { SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver()); - SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri()); - machine->activate(); - machine->reset(); - _engine->driver()->set_machine(machine); - _canvas->build(machine); + SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri(), + track_sb->get_value_as_int()); + + if (machine) { + machine->activate(); + machine->reset(); + _engine->driver()->set_machine(machine); + _canvas->build(machine); + } else { + Gtk::MessageDialog msg_dialog(*_main_window, "Error loading MIDI file", + false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true); + msg_dialog.run(); + } } } |