From db6f6e87dc4ff620f399597913f14a3b4eda277f Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 2 Apr 2007 01:52:53 +0000 Subject: Edge label toggling. Made state properties dialog actually work. Other things... git-svn-id: http://svn.drobilla.net/lad/machina@390 a436a847-0d15-0410-975c-d299462d15a1 --- src/gui/EdgeView.cpp | 21 ++++++++++++++++++--- src/gui/EdgeView.hpp | 3 ++- src/gui/MachinaGUI.cpp | 24 ++++++++++++++++++++++-- src/gui/MachinaGUI.hpp | 4 +++- src/gui/NodePropertiesWindow.cpp | 19 ++++++++++++++----- src/gui/NodePropertiesWindow.hpp | 4 +++- src/gui/machina.glade | 33 ++++++++++++++++++++++++++------- src/gui/main.cpp | 5 +++++ 8 files changed, 93 insertions(+), 20 deletions(-) (limited to 'src/gui') diff --git a/src/gui/EdgeView.cpp b/src/gui/EdgeView.cpp index fccf8d5..d8e11a9 100644 --- a/src/gui/EdgeView.cpp +++ b/src/gui/EdgeView.cpp @@ -41,12 +41,27 @@ EdgeView::length_hint() const } +void +EdgeView::show_label(bool show) +{ + if (show) { + char label[4]; + snprintf(label, 4, "%3f", _edge->probability()); + set_label(label); + } else { + set_label(""); + } +} + + void EdgeView::update_label() { - char label[4]; - snprintf(label, 4, "%3f", _edge->probability()); - set_label(label); + if (_label) { + char label[4]; + snprintf(label, 4, "%3f", _edge->probability()); + set_label(label); + } } diff --git a/src/gui/EdgeView.hpp b/src/gui/EdgeView.hpp index c394d49..61de52f 100644 --- a/src/gui/EdgeView.hpp +++ b/src/gui/EdgeView.hpp @@ -33,11 +33,12 @@ public: SharedPtr edge() { return _edge; } - void update_label(); + void show_label(bool show); virtual double length_hint() const; private: + void update_label(); bool on_event(GdkEvent* ev); SharedPtr _edge; diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index 3ddb13f..4098ff8 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -29,6 +29,7 @@ #include "MachinaGUI.hpp" #include "MachinaCanvas.hpp" #include "NodeView.hpp" +#include "EdgeView.hpp" MachinaGUI::MachinaGUI(SharedPtr engine) @@ -58,6 +59,7 @@ MachinaGUI::MachinaGUI(SharedPtr engine) 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_labels_menuitem", _menu_view_labels); //xml->get_widget("view_refresh_menuitem", _menu_view_refresh); //xml->get_widget("view_messages_menuitem", _menu_view_messages); xml->get_widget("help_about_menuitem", _menu_help_about); @@ -115,6 +117,8 @@ MachinaGUI::MachinaGUI(SharedPtr engine) // sigc::mem_fun(this, &MachinaGUI::menu_view_refresh)); _menu_view_toolbar->signal_toggled().connect( sigc::mem_fun(this, &MachinaGUI::show_toolbar_toggled)); + _menu_view_labels->signal_toggled().connect( + sigc::mem_fun(this, &MachinaGUI::show_labels_toggled)); //_menu_view_messages->signal_toggled().connect( // sigc::mem_fun(this, &MachinaGUI::show_messages_toggled)); _menu_help_about->signal_activate().connect( @@ -346,7 +350,8 @@ MachinaGUI::menu_file_open() const int result = dialog.run(); if (result == Gtk::RESPONSE_OK) { - SharedPtr new_machine = _engine->load_machine(dialog.get_uri()); + //SharedPtr new_machine = _engine->load_machine(dialog.get_uri()); + SharedPtr new_machine = _engine->import_machine(dialog.get_uri()); if (new_machine) { _canvas->destroy(); _canvas->build(new_machine); @@ -596,6 +601,21 @@ MachinaGUI::show_toolbar_toggled() _toolbar->hide(); } + +void +MachinaGUI::show_labels_toggled() +{ + const bool show = _menu_view_labels->get_active(); + + for (ConnectionList::iterator c = _canvas->connections().begin(); + c != _canvas->connections().end(); ++c) { + const SharedPtr ev = PtrCast(*c); + if (ev) + ev->show_label(show); + } +} + + /* void MachinaGUI::menu_view_refresh() @@ -643,7 +663,7 @@ MachinaGUI::stop_clicked() _engine->driver()->finish_record(); } else { _engine->machine()->deactivate(); - _engine->machine()->reset(); + _engine->driver()->reset(); } update_toolbar(); diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp index 96fb772..eba8a93 100644 --- a/src/gui/MachinaGUI.hpp +++ b/src/gui/MachinaGUI.hpp @@ -64,6 +64,7 @@ protected: void menu_export_graphviz(); //void show_messages_toggled(); void show_toolbar_toggled(); + void show_labels_toggled(); //void menu_view_refresh(); void menu_help_about(); void menu_help_help(); @@ -110,9 +111,10 @@ protected: Gtk::MenuItem* _menu_export_midi; Gtk::MenuItem* _menu_export_graphviz; Gtk::MenuItem* _menu_help_about; + Gtk::CheckMenuItem* _menu_view_labels; Gtk::CheckMenuItem* _menu_view_toolbar; //Gtk::CheckMenuItem* _menu_view_messages; - Gtk::MenuItem* _menu_view_refresh; + //Gtk::MenuItem* _menu_view_refresh; Gtk::MenuItem* _menu_help_help; Gtk::ScrolledWindow* _canvas_scrolledwindow; Gtk::TextView* _status_text; diff --git a/src/gui/NodePropertiesWindow.cpp b/src/gui/NodePropertiesWindow.cpp index 151c602..6ba3e47 100644 --- a/src/gui/NodePropertiesWindow.cpp +++ b/src/gui/NodePropertiesWindow.cpp @@ -34,11 +34,13 @@ NodePropertiesWindow::NodePropertiesWindow(BaseObjectType* cobject, const Glib:: xml->get_widget("node_properties_note_spinbutton", _note_spinbutton); xml->get_widget("node_properties_duration_spinbutton", _duration_spinbutton); + xml->get_widget("node_properties_apply_button", _apply_button); xml->get_widget("node_properties_cancel_button", _cancel_button); xml->get_widget("node_properties_ok_button", _ok_button); - _ok_button->signal_clicked().connect(sigc::mem_fun(this, &NodePropertiesWindow::ok_clicked)); + _apply_button->signal_clicked().connect(sigc::mem_fun(this, &NodePropertiesWindow::apply_clicked)); _cancel_button->signal_clicked().connect(sigc::mem_fun(this, &NodePropertiesWindow::cancel_clicked)); + _ok_button->signal_clicked().connect(sigc::mem_fun(this, &NodePropertiesWindow::ok_clicked)); } @@ -48,11 +50,10 @@ NodePropertiesWindow::~NodePropertiesWindow() void -NodePropertiesWindow::ok_clicked() +NodePropertiesWindow::apply_clicked() { - assert(this == _instance); - delete _instance; - _instance = NULL; + double duration = _duration_spinbutton->get_value(); + _node->set_duration(duration); } @@ -64,6 +65,14 @@ NodePropertiesWindow::cancel_clicked() _instance = NULL; } + +void +NodePropertiesWindow::ok_clicked() +{ + apply_clicked(); + cancel_clicked(); +} + void NodePropertiesWindow::set_node(SharedPtr node) diff --git a/src/gui/NodePropertiesWindow.hpp b/src/gui/NodePropertiesWindow.hpp index 461b51b..51ab42b 100644 --- a/src/gui/NodePropertiesWindow.hpp +++ b/src/gui/NodePropertiesWindow.hpp @@ -34,8 +34,9 @@ private: void set_node(SharedPtr node); - void ok_clicked(); + void apply_clicked(); void cancel_clicked(); + void ok_clicked(); static NodePropertiesWindow* _instance; @@ -43,6 +44,7 @@ private: Gtk::SpinButton* _note_spinbutton; Gtk::SpinButton* _duration_spinbutton; + Gtk::Button* _apply_button; Gtk::Button* _cancel_button; Gtk::Button* _ok_button; }; diff --git a/src/gui/machina.glade b/src/gui/machina.glade index fb61bd8..b5349be 100644 --- a/src/gui/machina.glade +++ b/src/gui/machina.glade @@ -46,6 +46,7 @@ True + Open a saved machine gtk-open True @@ -55,6 +56,7 @@ True + Save machine gtk-save True @@ -64,6 +66,7 @@ True + Save machine to file gtk-save-as True @@ -79,6 +82,7 @@ True + Import a MIDI file _Import MIDI... True @@ -101,6 +105,7 @@ True + Export a MIDI file _Export MIDI... True @@ -129,7 +134,7 @@ True - Export a DOT file for rendering diagram with the GraphViz suite of tools + Export a DOT file for rendering with GraphViz Export _GraphViz... True @@ -158,6 +163,7 @@ True + Exit Machina gtk-quit True @@ -836,12 +842,12 @@ Connect some nodes up and double click one. You'll get it. 8 - Node Properties + dialog1 GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False False - True + False True True True @@ -852,16 +858,29 @@ Connect some nodes up and double click one. You'll get it. True - + True False 8 - + True GTK_BUTTONBOX_END + + + True + True + True + gtk-apply + True + GTK_RELIEF_NORMAL + True + -10 + + + True @@ -879,6 +898,7 @@ Connect some nodes up and double click one. You'll get it. True True + True True gtk-ok True @@ -908,7 +928,6 @@ Connect some nodes up and double click one. You'll get it. True - False True 1 0 @@ -986,8 +1005,8 @@ Connect some nodes up and double click one. You'll get it. True - False True + True 1 2 True diff --git a/src/gui/main.cpp b/src/gui/main.cpp index c522898..e1e86ea 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -51,6 +51,11 @@ main(int argc, char** argv) cout << "No quantization." << endl; machine = file_driver->learn(filename); } + + if (!machine) { + cout << "Not a MIDI file. Attempting to load as Machina file." << endl; + machine = Loader().load(filename); + } } if (!machine) -- cgit v1.2.1