aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/MachinaGUI.cpp156
-rw-r--r--src/gui/MachinaGUI.hpp14
-rw-r--r--src/gui/machina.glade22
3 files changed, 112 insertions, 80 deletions
diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp
index 8e0b68a..42cb4ce 100644
--- a/src/gui/MachinaGUI.cpp
+++ b/src/gui/MachinaGUI.cpp
@@ -36,9 +36,10 @@ using namespace Machina;
MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine)
-: _refresh(false),
- _engine(engine),
- _maid(new Raul::Maid(32))
+ : _refresh(false)
+ , _evolve(false)
+ , _engine(engine)
+ , _maid(new Raul::Maid(32))
{
_canvas = boost::shared_ptr<MachinaCanvas>(new MachinaCanvas(this, 1600*2, 1200*2));
@@ -71,6 +72,7 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine)
xml->get_widget("zoom_normal_but", _zoom_normal_button);
xml->get_widget("zoom_full_but", _zoom_full_button);
xml->get_widget("arrange_but", _arrange_button);
+ xml->get_widget("evolve_but", _evolve_button);
xml->get_widget("mutate_but", _mutate_button);
xml->get_widget("compress_but", _compress_button);
xml->get_widget("add_node_but", _add_node_button);
@@ -128,22 +130,24 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine)
_quantize_spinbutton->signal_changed().connect(
sigc::mem_fun(this, &MachinaGUI::quantize_changed));
- _mutate_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::mutate));
- _compress_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::compress));
- _add_node_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::add_node));
- _remove_node_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::remove_node));
- _adjust_node_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::adjust_node));
- _add_edge_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::add_edge));
- _remove_edge_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::remove_edge));
- _adjust_edge_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::adjust_edge));
+ _evolve_button->signal_clicked().connect(
+ sigc::mem_fun(this, &MachinaGUI::evolve));
+ _mutate_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::random_mutation), SharedPtr<Machine>()));
+ _compress_button->signal_clicked().connect(sigc::hide_return(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 0)));
+ _add_node_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 1));
+ _remove_node_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 2));
+ _adjust_node_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 3));
+ _add_edge_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 4));
+ _remove_edge_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 5));
+ _adjust_edge_button->signal_clicked().connect(sigc::bind(
+ sigc::mem_fun(this, &MachinaGUI::mutate), SharedPtr<Machine>(), 6));
connect_widgets();
@@ -165,6 +169,9 @@ MachinaGUI::MachinaGUI(SharedPtr<Machina::Engine> engine)
// Idle callback to update node states
Glib::signal_timeout().connect(sigc::mem_fun(this, &MachinaGUI::idle_callback), 100);
+ // Periodic mutation callback (FIXME: temporary kludge, thread this)
+ Glib::signal_timeout().connect(sigc::mem_fun(this, &MachinaGUI::evolve_callback), 1000);
+
_canvas->build(engine->machine());
}
@@ -175,6 +182,20 @@ MachinaGUI::~MachinaGUI()
bool
+MachinaGUI::evolve_callback()
+{
+ if (_evolve) {
+ // Single greedy mutation
+ SharedPtr<Machine> copy(new Machine(*_engine->machine().get()));
+ random_mutation(copy);
+ _canvas->build(copy);
+ }
+
+ return true;
+}
+
+
+bool
MachinaGUI::idle_callback()
{
const bool show_labels = _menu_view_labels->get_active();
@@ -223,73 +244,64 @@ MachinaGUI::arrange()
void
-MachinaGUI::mutate()
+MachinaGUI::evolve()
{
- switch (rand() % 7) {
- case 0: compress(); break;
- case 1: add_node(); break;
- case 2: remove_node(); break;
- case 3: adjust_node(); break;
- case 4: add_edge(); break;
- case 5: remove_edge(); break;
- case 6: adjust_edge(); default: break;
- }
+ if (_evolve_button->get_active())
+ _evolve = true;
+ else
+ _evolve = false;
}
void
-MachinaGUI::compress()
+MachinaGUI::random_mutation(SharedPtr<Machine> machine)
{
- Mutation::Compress::mutate(*_engine->machine().get());
- _canvas->build(_engine->machine());
-}
-
+ if (!machine)
+ machine = _engine->machine();
-void
-MachinaGUI::add_node()
-{
- Mutation::AddNode::mutate(*_engine->machine().get());
- _canvas->build(_engine->machine());
+ mutate(machine, rand() % 7);
}
void
-MachinaGUI::remove_node()
+MachinaGUI::mutate(SharedPtr<Machine> machine, unsigned mutation)
{
- Mutation::RemoveNode::mutate(*_engine->machine().get());
- _canvas->build(_engine->machine());
-}
+ if (!machine)
+ machine = _engine->machine();
-
-void
-MachinaGUI::adjust_node()
-{
- Mutation::AdjustNode::mutate(*_engine->machine().get());
- idle_callback(); // update nodes
-}
+ using namespace Mutation;
-
-void
-MachinaGUI::add_edge()
-{
- Mutation::AddEdge::mutate(*_engine->machine().get());
- _canvas->build(_engine->machine());
-}
-
-
-void
-MachinaGUI::remove_edge()
-{
- Mutation::RemoveEdge::mutate(*_engine->machine().get());
- _canvas->build(_engine->machine());
-}
-
-
-void
-MachinaGUI::adjust_edge()
-{
- Mutation::AdjustEdge::mutate(*_engine->machine().get());
- _canvas->update_edges();
+ switch (mutation) {
+ case 0:
+ Compress::mutate(*machine.get());
+ _canvas->build(machine);
+ break;
+ case 1:
+ AddNode::mutate(*machine.get());
+ _canvas->build(machine);
+ break;
+ case 2:
+ RemoveNode::mutate(*machine.get());
+ _canvas->build(machine);
+ break;
+ case 3:
+ AdjustNode::mutate(*machine.get());
+ idle_callback(); // update nodes
+ break;
+ case 4:
+ AddEdge::mutate(*machine.get());
+ _canvas->build(machine);
+ break;
+ case 5:
+ RemoveEdge::mutate(*machine.get());
+ _canvas->build(machine);
+ break;
+ case 6:
+ AdjustEdge::mutate(*machine.get());
+ _canvas->update_edges();
+ break;
+ default: throw;
+ }
}
diff --git a/src/gui/MachinaGUI.hpp b/src/gui/MachinaGUI.hpp
index c82cd01..bbba67f 100644
--- a/src/gui/MachinaGUI.hpp
+++ b/src/gui/MachinaGUI.hpp
@@ -63,16 +63,12 @@ protected:
void menu_help_about();
void menu_help_help();
void arrange();
- void mutate();
- void compress();
- void add_node();
- void remove_node();
- void adjust_node();
- void add_edge();
- void remove_edge();
- void adjust_edge();
+ void evolve();
+ void random_mutation(SharedPtr<Machina::Machine> machine);
+ void mutate(SharedPtr<Machina::Machine> machine, unsigned mutation);
void zoom(double z);
void update_toolbar();
+ bool evolve_callback();
bool idle_callback();
bool scrolled_window_event(GdkEvent* ev);
@@ -84,6 +80,7 @@ protected:
void tempo_changed();
bool _refresh;
+ bool _evolve;
string _save_uri;
@@ -123,6 +120,7 @@ protected:
Gtk::ToolButton* _zoom_normal_button;
Gtk::ToolButton* _zoom_full_button;
Gtk::ToolButton* _arrange_button;
+ Gtk::ToggleToolButton* _evolve_button;
Gtk::ToolButton* _mutate_button;
Gtk::ToolButton* _compress_button;
Gtk::ToolButton* _add_node_button;
diff --git a/src/gui/machina.glade b/src/gui/machina.glade
index 2153908..e91553d 100644
--- a/src/gui/machina.glade
+++ b/src/gui/machina.glade
@@ -404,6 +404,27 @@
<property name="icon_size">GTK_ICON_SIZE_SMALL_TOOLBAR</property>
<property name="icon_size_set">True</property>
<child>
+ <widget class="GtkSeparatorToolItem" id="toolbutton5">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ <property name="homogeneous">False</property>
+ </packing>
+ </child>
+ <child>
+ <widget class="GtkToggleToolButton" id="evolve_but">
+ <property name="visible">True</property>
+ <property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
+ <property name="label" translatable="yes">Evolve machine (towards target MIDI)</property>
+ <property name="stock_id">gtk-execute</property>
+ </widget>
+ <packing>
+ <property name="expand">False</property>
+ </packing>
+ </child>
+ <child>
<widget class="GtkSeparatorToolItem" id="toolbutton4">
<property name="visible">True</property>
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
@@ -432,6 +453,7 @@
</widget>
<packing>
<property name="expand">False</property>
+ <property name="homogeneous">False</property>
</packing>
</child>
<child>