diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 8 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 61 | ||||
-rw-r--r-- | src/gui/MachinaGUI.hpp | 2 | ||||
-rw-r--r-- | src/gui/machina.glade | 32 | ||||
-rw-r--r-- | src/gui/main.cpp | 38 |
5 files changed, 82 insertions, 59 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 3c2c1e8..c7d9843 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -176,6 +176,9 @@ MachinaCanvas::create_node_view(SharedPtr<Machina::Node> node) SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), "", 10, 10)); + if ( ! node->enter_action() && ! node->exit_action() ) + view->set_base_color(0x101010FF); + view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, &MachinaCanvas::node_clicked), WeakPtr<NodeView>(view))); @@ -209,7 +212,10 @@ MachinaCanvas::build(SharedPtr<Machina::Machine> machine) e != view->node()->outgoing_edges().end(); ++e) { SharedPtr<NodeView> dst_view = views[(*e)->dst()]; - assert(dst_view); + if (!dst_view) { + cerr << "WARNING: Edge to node with no view" << endl; + continue; + } boost::shared_ptr<Connection> c(new EdgeView(shared_from_this(), view, dst_view, (*e))); diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 592001f..0848f8b 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -28,46 +28,6 @@ #include "MachinaCanvas.hpp" #include "NodeView.hpp" -//#include "config.h" - -// FIXME: include to avoid undefined reference to boost SP debug hooks stuff -#include <raul/SharedPtr.h> - - - -/* Gtk helpers (resize combo boxes) */ - -#if 0 -static void -gtkmm_get_ink_pixel_size (Glib::RefPtr<Pango::Layout> layout, - int& width, - int& height) -{ - Pango::Rectangle ink_rect = layout->get_ink_extents (); - - width = (ink_rect.get_width() + PANGO_SCALE / 2) / PANGO_SCALE; - height = (ink_rect.get_height() + PANGO_SCALE / 2) / PANGO_SCALE; -} - - -static void -gtkmm_set_width_for_given_text (Gtk::Widget &w, const gchar *text, - gint hpadding/*, gint vpadding*/) - -{ - int old_width, old_height; - w.get_size_request(old_width, old_height); - - int width, height; - w.ensure_style (); - - gtkmm_get_ink_pixel_size (w.create_pango_layout (text), width, height); - w.set_size_request(width + hpadding, old_height);//height + vpadding); -} -#endif -/* end Gtk helpers */ - - MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) : _pane_closed(false), @@ -117,6 +77,7 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) xml->get_widget("quit_menuitem", _menu_file_quit); xml->get_widget("import_midi_menuitem", _menu_import_midi); xml->get_widget("export_midi_menuitem", _menu_export_midi); + xml->get_widget("export_graphviz_menuitem", _menu_export_graphviz); xml->get_widget("view_toolbar_menuitem", _menu_view_toolbar); //xml->get_widget("view_refresh_menuitem", _menu_view_refresh); //xml->get_widget("view_messages_menuitem", _menu_view_messages); @@ -160,6 +121,8 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) sigc::mem_fun(this, &MachinaGUI::menu_import_midi)); _menu_export_midi->signal_activate().connect( sigc::mem_fun(this, &MachinaGUI::menu_export_midi)); + _menu_export_graphviz->signal_activate().connect( + sigc::mem_fun(this, &MachinaGUI::menu_export_graphviz)); //_menu_view_refresh->signal_activate().connect( // sigc::mem_fun(this, &MachinaGUI::menu_view_refresh)); _menu_view_toolbar->signal_toggled().connect( @@ -216,6 +179,8 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) // Faster idle callback to update DSP load progress bar //Glib::signal_timeout().connect(sigc::mem_fun(this, &MachinaGUI::update_load), 50); + + _canvas->build(engine->machine()); } @@ -462,7 +427,7 @@ MachinaGUI::menu_import_midi() SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver()); //SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri(), // track_sb->get_value_as_int()); - SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri()); + SharedPtr<Machina::Machine> machine = file_driver->learn(dialog.get_uri(), 16.0); if (machine) { dialog.hide(); @@ -503,6 +468,20 @@ MachinaGUI::menu_export_midi() void +MachinaGUI::menu_export_graphviz() +{ + Gtk::FileChooserDialog dialog(*_main_window, "Export to a GraphViz DOT file", Gtk::FILE_CHOOSER_ACTION_SAVE); + dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL); + dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK); + + const int result = dialog.run(); + + if (result == Gtk::RESPONSE_OK) + _canvas->render_to_dot(dialog.get_filename()); +} + + +void MachinaGUI::on_pane_position_changed() { // avoid infinite recursion... diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 7774ff6..6677d24 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -61,6 +61,7 @@ protected: void menu_file_save_as(); void menu_import_midi(); void menu_export_midi(); + void menu_export_graphviz(); //void show_messages_toggled(); void show_toolbar_toggled(); //void menu_view_refresh(); @@ -102,6 +103,7 @@ protected: Gtk::MenuItem* _menu_file_quit; Gtk::MenuItem* _menu_import_midi; Gtk::MenuItem* _menu_export_midi; + Gtk::MenuItem* _menu_export_graphviz; Gtk::MenuItem* _menu_help_about; Gtk::CheckMenuItem* _menu_view_toolbar; //Gtk::CheckMenuItem* _menu_view_messages; diff --git a/src/gui/machina.glade b/src/gui/machina.glade index 216dfeb..b53398b 100644 --- a/src/gui/machina.glade +++ b/src/gui/machina.glade @@ -85,7 +85,7 @@ <accelerator key="I" modifiers="GDK_CONTROL_MASK" signal="activate"/> <child internal-child="image"> - <widget class="GtkImage" id="image9"> + <widget class="GtkImage" id="image16"> <property name="visible">True</property> <property name="stock">gtk-media-record</property> <property name="icon_size">1</property> @@ -107,7 +107,35 @@ <accelerator key="E" modifiers="GDK_CONTROL_MASK" signal="activate"/> <child internal-child="image"> - <widget class="GtkImage" id="image10"> + <widget class="GtkImage" id="image17"> + <property name="visible">True</property> + <property name="stock">gtk-convert</property> + <property name="icon_size">1</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + </child> + </widget> + </child> + + <child> + <widget class="GtkSeparatorMenuItem" id="separator7"> + <property name="visible">True</property> + </widget> + </child> + + <child> + <widget class="GtkImageMenuItem" id="export_graphviz_menuitem"> + <property name="visible">True</property> + <property name="label" translatable="yes">Export _Graphviz...</property> + <property name="use_underline">True</property> + <signal name="activate" handler="on_export_graphviz_menuitem_activate" last_modification_time="Mon, 12 Mar 2007 19:47:58 GMT"/> + <accelerator key="G" modifiers="GDK_CONTROL_MASK" signal="activate"/> + + <child internal-child="image"> + <widget class="GtkImage" id="image18"> <property name="visible">True</property> <property name="stock">gtk-convert</property> <property name="icon_size">1</property> diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 3e7f737..cb9b7e9 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -17,40 +17,48 @@ #include <signal.h> #include <iostream> +#include <string> #include <libgnomecanvasmm.h> - #include "machina/Loader.hpp" #include "machina/JackDriver.hpp" - +#include "machina/SMFDriver.hpp" #include "MachinaGUI.hpp" +using namespace std; using namespace Machina; int main(int argc, char** argv) { - // Build engine + SharedPtr<Machina::Machine> machine; - SharedPtr<JackDriver> driver(new JackDriver()); + // Load machine, if given + if (argc == 2) { + 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, 16.0); + } + // Build engine + SharedPtr<JackDriver> driver(new JackDriver(machine)); driver->attach("machina"); - SharedPtr<Engine> engine(new Engine(driver)); // Launch GUI try { - - Gnome::Canvas::init(); - Gtk::Main app(argc, argv); - - driver->activate(); - MachinaGUI gui(engine); - app.run(*gui.window()); - - } catch (std::string msg) { - std::cerr << "Caught exception, aborting. Error message was: " << msg << std::endl; + Gnome::Canvas::init(); + Gtk::Main app(argc, argv); + + driver->activate(); + MachinaGUI gui(engine); + + app.run(*gui.window()); + + } catch (string msg) { + cerr << "Caught exception, aborting. Error message was: " << msg << endl; return 1; } |