From ee76743c774f64759daef42d416d3fb7bbc4a473 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 12 Mar 2007 01:33:51 +0000 Subject: Flowcanvas resizing, auto-arrange resizes if necessary. Per-track SMF reading (raul and machina) git-svn-id: http://svn.drobilla.net/lad/machina@354 a436a847-0d15-0410-975c-d299462d15a1 --- src/engine/SMFDriver.cpp | 6 +++++- src/engine/machina/SMFDriver.hpp | 2 +- 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 -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(); + 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 { public: - SharedPtr learn(const Glib::ustring& uri); + SharedPtr learn(const Glib::ustring& uri, unsigned track=1); void run(SharedPtr 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 file_driver(new Machina::SMFDriver()); - SharedPtr machine = file_driver->learn(dialog.get_uri()); - machine->activate(); - machine->reset(); - _engine->driver()->set_machine(machine); - _canvas->build(machine); + SharedPtr 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(); + } } } -- cgit v1.2.1