diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/MachinaCanvas.cpp | 4 | ||||
-rw-r--r-- | src/gui/MachinaGUI.cpp | 27 | ||||
-rw-r--r-- | src/gui/Makefile.am | 5 | ||||
-rw-r--r-- | src/gui/NodePropertiesWindow.cpp | 99 | ||||
-rw-r--r-- | src/gui/NodePropertiesWindow.hpp | 51 | ||||
-rw-r--r-- | src/gui/NodeView.cpp | 22 | ||||
-rw-r--r-- | src/gui/NodeView.hpp | 5 | ||||
-rw-r--r-- | src/gui/machina.glade | 181 | ||||
-rw-r--r-- | src/gui/main.cpp | 14 |
9 files changed, 371 insertions, 37 deletions
diff --git a/src/gui/MachinaCanvas.cpp b/src/gui/MachinaCanvas.cpp index 6fdbc86..e11532e 100644 --- a/src/gui/MachinaCanvas.cpp +++ b/src/gui/MachinaCanvas.cpp @@ -98,7 +98,7 @@ MachinaCanvas::canvas_event(GdkEvent* event) SharedPtr<Machina::Node> node(new Machina::Node(1.0, false)); //node->add_enter_action(SharedPtr<Machina::Action>(new Machina::PrintAction(name))); - SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), + SharedPtr<NodeView> view(new NodeView(_app->window(), shared_from_this(), node, name, x, y)); view->signal_clicked.connect(sigc::bind<0>(sigc::mem_fun(this, @@ -173,7 +173,7 @@ MachinaCanvas::disconnect_node(boost::shared_ptr<NodeView> src, SharedPtr<NodeView> MachinaCanvas::create_node_view(SharedPtr<Machina::Node> node) { - SharedPtr<NodeView> view(new NodeView(node, shared_from_this(), + SharedPtr<NodeView> view(new NodeView(_app->window(), shared_from_this(), node, "", 10, 10)); if ( ! node->enter_action() && ! node->exit_action() ) diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp index fdd75c6..381d8f4 100644 --- a/src/gui/MachinaGUI.cpp +++ b/src/gui/MachinaGUI.cpp @@ -24,6 +24,7 @@ #include <raul/RDFWriter.h> #include <machina/Machine.hpp> #include <machina/SMFDriver.hpp> +#include "GladeXml.hpp" #include "MachinaGUI.hpp" #include "MachinaCanvas.hpp" #include "NodeView.hpp" @@ -42,31 +43,7 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine) _canvas = boost::shared_ptr<MachinaCanvas>(new MachinaCanvas(this, 1600*2, 1200*2)); - Glib::RefPtr<Gnome::Glade::Xml> xml; - - // Check for the .glade file in current directory - string glade_filename = "./machina.glade"; - ifstream fs(glade_filename.c_str()); - if (fs.fail()) { // didn't find it, check PKGDATADIR - fs.clear(); - glade_filename = PKGDATADIR; - glade_filename += "/machina.glade"; - - fs.open(glade_filename.c_str()); - if (fs.fail()) { - cerr << "Unable to find machina.glade in current directory or " - << PKGDATADIR << "." << endl; - exit(EXIT_FAILURE); - } - fs.close(); - } - - try { - xml = Gnome::Glade::Xml::create(glade_filename); - } catch(const Gnome::Glade::XmlError& ex) { - std::cerr << ex.what() << std::endl; - throw; - } + Glib::RefPtr<Gnome::Glade::Xml> xml = GladeXml::create(); xml->get_widget("machina_win", _main_window); xml->get_widget("about_win", _about_window); diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index 1d6390d..3a204f2 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -15,6 +15,7 @@ machina_gui_LDADD = @FLOWCANVAS_LIBS@ @LIBGLADEMM_LIBS@ @GNOMECANVASMM_LIBS@ @JA bin_PROGRAMS = machina_gui machina_gui_SOURCES = \ main.cpp \ + GladeXml.hpp \ MachinaGUI.hpp \ MachinaGUI.cpp \ MachinaCanvas.hpp \ @@ -22,6 +23,8 @@ machina_gui_SOURCES = \ NodeView.hpp \ NodeView.cpp \ EdgeView.hpp \ - EdgeView.cpp + EdgeView.cpp \ + NodePropertiesWindow.hpp \ + NodePropertiesWindow.cpp endif diff --git a/src/gui/NodePropertiesWindow.cpp b/src/gui/NodePropertiesWindow.cpp new file mode 100644 index 0000000..151c602 --- /dev/null +++ b/src/gui/NodePropertiesWindow.cpp @@ -0,0 +1,99 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave Robillard <http://drobilla.net> + * + * Machina is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Machina is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include <string> +#include "machina/MidiAction.hpp" +#include "NodePropertiesWindow.hpp" +#include "GladeXml.hpp" + +using namespace std; +using namespace Machina; + + +NodePropertiesWindow* NodePropertiesWindow::_instance = NULL; + + +NodePropertiesWindow::NodePropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& xml) + : Gtk::Dialog(cobject) +{ + property_visible() = false; + + xml->get_widget("node_properties_note_spinbutton", _note_spinbutton); + xml->get_widget("node_properties_duration_spinbutton", _duration_spinbutton); + 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)); + _cancel_button->signal_clicked().connect(sigc::mem_fun(this, &NodePropertiesWindow::cancel_clicked)); +} + + +NodePropertiesWindow::~NodePropertiesWindow() +{ +} + + +void +NodePropertiesWindow::ok_clicked() +{ + assert(this == _instance); + delete _instance; + _instance = NULL; +} + + +void +NodePropertiesWindow::cancel_clicked() +{ + assert(this == _instance); + delete _instance; + _instance = NULL; +} + + +void +NodePropertiesWindow::set_node(SharedPtr<Machina::Node> node) +{ + _node = node; + SharedPtr<MidiAction> enter_action = PtrCast<MidiAction>(node->enter_action()); + if (enter_action && enter_action->event_size() > 1 + && (enter_action->event()[0] & 0xF0) == 0x90) { + _note_spinbutton->set_value(enter_action->event()[1]); + _note_spinbutton->show(); + } else { + _note_spinbutton->hide(); + } + _duration_spinbutton->set_value(node->duration()); +} + + +void +NodePropertiesWindow::present(Gtk::Window* parent, SharedPtr<Machina::Node> node) +{ + if (!_instance) { + Glib::RefPtr<Gnome::Glade::Xml> xml = GladeXml::create(); + + xml->get_widget_derived("node_properties_dialog", _instance); + + if (parent) + _instance->set_transient_for(*parent); + } + + _instance->set_node(node); + _instance->show(); +} + diff --git a/src/gui/NodePropertiesWindow.hpp b/src/gui/NodePropertiesWindow.hpp new file mode 100644 index 0000000..461b51b --- /dev/null +++ b/src/gui/NodePropertiesWindow.hpp @@ -0,0 +1,51 @@ +/* This file is part of Machina. + * Copyright (C) 2007 Dave Robillard <http://drobilla.net> + * + * Machina is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) any later + * version. + * + * Machina is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef NODEPROPERTIESWINDOW_H +#define NODEPROPERTIESWINDOW_H + +#include <gtkmm.h> +#include <libglademm/xml.h> +#include "machina/Node.hpp" + +class NodePropertiesWindow : public Gtk::Dialog +{ +public: + static void present(Gtk::Window* parent, SharedPtr<Machina::Node> node); + +private: + friend class Gnome::Glade::Xml; + NodePropertiesWindow(BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& glade_xml); + ~NodePropertiesWindow(); + + void set_node(SharedPtr<Machina::Node> node); + + void ok_clicked(); + void cancel_clicked(); + + static NodePropertiesWindow* _instance; + + SharedPtr<Machina::Node> _node; + + Gtk::SpinButton* _note_spinbutton; + Gtk::SpinButton* _duration_spinbutton; + Gtk::Button* _cancel_button; + Gtk::Button* _ok_button; +}; + + +#endif // NODEPROPERTIESWINDOW_H diff --git a/src/gui/NodeView.cpp b/src/gui/NodeView.cpp index d675f1d..be40047 100644 --- a/src/gui/NodeView.cpp +++ b/src/gui/NodeView.cpp @@ -16,14 +16,17 @@ */ #include "NodeView.hpp" -#include <iostream> +#include "NodePropertiesWindow.hpp" -NodeView::NodeView(SharedPtr<Machina::Node> node, + +NodeView::NodeView(Gtk::Window* window, SharedPtr<LibFlowCanvas::FlowCanvas> canvas, + SharedPtr<Machina::Node> node, const std::string& name, double x, double y) : LibFlowCanvas::Ellipse(canvas, name, x, y, 20, 20, false) + , _window(window) , _node(node) { //signal_double_clicked.connect(sigc::mem_fun(this, &NodeView::on_double_click)); @@ -33,9 +36,18 @@ NodeView::NodeView(SharedPtr<Machina::Node> node, void NodeView::on_double_click(GdkEventButton*) { - bool is_initial = _node->is_initial(); - _node->set_initial( ! is_initial ); - set_border_width(is_initial ? 1.0 : 2.0); + NodePropertiesWindow::present(_window, _node); +} + + +void +NodeView::on_click(GdkEventButton* event) +{ + if (event->button == 3) { + bool is_initial = _node->is_initial(); + _node->set_initial( ! is_initial ); + set_border_width(is_initial ? 1.0 : 2.0); + } } diff --git a/src/gui/NodeView.hpp b/src/gui/NodeView.hpp index ae5c34e..4641787 100644 --- a/src/gui/NodeView.hpp +++ b/src/gui/NodeView.hpp @@ -24,8 +24,9 @@ class NodeView : public LibFlowCanvas::Ellipse { public: - NodeView(SharedPtr<Machina::Node> node, + NodeView(Gtk::Window* window, SharedPtr<LibFlowCanvas::FlowCanvas> canvas, + SharedPtr<Machina::Node> node, const std::string& name, double x, double y); @@ -35,8 +36,10 @@ public: void update_state(); private: + void on_click(GdkEventButton* ev); void on_double_click(GdkEventButton* ev); + Gtk::Window* _window; SharedPtr<Machina::Node> _node; uint32_t _old_color; }; diff --git a/src/gui/machina.glade b/src/gui/machina.glade index 8536e8f..df73a85 100644 --- a/src/gui/machina.glade +++ b/src/gui/machina.glade @@ -672,4 +672,185 @@ Connect some nodes up and double click one. You'll get it.</property> </child> </widget> +<widget class="GtkDialog" id="node_properties_dialog"> + <property name="border_width">8</property> + <property name="title" translatable="yes">Node Properties</property> + <property name="type">GTK_WINDOW_TOPLEVEL</property> + <property name="window_position">GTK_WIN_POS_NONE</property> + <property name="modal">False</property> + <property name="resizable">False</property> + <property name="destroy_with_parent">True</property> + <property name="decorated">True</property> + <property name="skip_taskbar_hint">True</property> + <property name="skip_pager_hint">True</property> + <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property> + <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> + <property name="focus_on_map">True</property> + <property name="urgency_hint">False</property> + <property name="has_separator">True</property> + + <child internal-child="vbox"> + <widget class="GtkVBox" id="dialog-vbox2"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">8</property> + + <child internal-child="action_area"> + <widget class="GtkHButtonBox" id="dialog-action_area2"> + <property name="visible">True</property> + <property name="layout_style">GTK_BUTTONBOX_END</property> + + <child> + <widget class="GtkButton" id="node_properties_cancel_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-cancel</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="response_id">-6</property> + </widget> + </child> + + <child> + <widget class="GtkButton" id="node_properties_ok_button"> + <property name="visible">True</property> + <property name="can_default">True</property> + <property name="can_focus">True</property> + <property name="label">gtk-ok</property> + <property name="use_stock">True</property> + <property name="relief">GTK_RELIEF_NORMAL</property> + <property name="focus_on_click">True</property> + <property name="response_id">-5</property> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="pack_type">GTK_PACK_END</property> + </packing> + </child> + + <child> + <widget class="GtkTable" id="table1"> + <property name="visible">True</property> + <property name="n_rows">2</property> + <property name="n_columns">2</property> + <property name="homogeneous">False</property> + <property name="row_spacing">8</property> + <property name="column_spacing">4</property> + + <child> + <widget class="GtkSpinButton" id="node_properties_note_spinbutton"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_focus">True</property> + <property name="climb_rate">1</property> + <property name="digits">0</property> + <property name="numeric">True</property> + <property name="update_policy">GTK_UPDATE_ALWAYS</property> + <property name="snap_to_ticks">False</property> + <property name="wrap">False</property> + <property name="adjustment">60 0 127 1 10 10</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label6"> + <property name="visible">True</property> + <property name="label" translatable="yes">Note: </property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">0</property> + <property name="bottom_attach">1</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label7"> + <property name="visible">True</property> + <property name="label" translatable="yes">Duration: </property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + + <child> + <widget class="GtkSpinButton" id="node_properties_duration_spinbutton"> + <property name="visible">True</property> + <property name="sensitive">False</property> + <property name="can_focus">True</property> + <property name="climb_rate">1</property> + <property name="digits">2</property> + <property name="numeric">True</property> + <property name="update_policy">GTK_UPDATE_ALWAYS</property> + <property name="snap_to_ticks">False</property> + <property name="wrap">False</property> + <property name="adjustment">1 0 999999 1 10 10</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> + <property name="y_options"></property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + </child> +</widget> + </glade-interface> diff --git a/src/gui/main.cpp b/src/gui/main.cpp index 6f1fc4d..741c801 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -38,11 +38,19 @@ main(int argc, char** argv) SharedPtr<Machina::Machine> machine; // Load machine, if given - if (argc == 2) { - string filename = argv[1]; + if (argc >= 2) { + const string filename = argv[1]; cout << "Building machine from MIDI file " << filename << endl; SharedPtr<Machina::SMFDriver> file_driver(new Machina::SMFDriver()); - machine = file_driver->learn(filename); + + 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); + } } if (!machine) |