aboutsummaryrefslogtreecommitdiffstats
path: root/src/gui/MachinaGUI.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/MachinaGUI.cpp')
-rw-r--r--src/gui/MachinaGUI.cpp74
1 files changed, 36 insertions, 38 deletions
diff --git a/src/gui/MachinaGUI.cpp b/src/gui/MachinaGUI.cpp
index 63cbb76..f95eec2 100644
--- a/src/gui/MachinaGUI.cpp
+++ b/src/gui/MachinaGUI.cpp
@@ -102,8 +102,8 @@ MachinaGUI::MachinaGUI(SPtr<machina::Engine> engine)
_record_button->signal_toggled().connect(
sigc::mem_fun(this, &MachinaGUI::record_toggled));
- _stop_button->signal_clicked().connect(
- sigc::mem_fun(this, &MachinaGUI::stop_clicked));
+ _stop_button->signal_toggled().connect(
+ sigc::mem_fun(this, &MachinaGUI::stop_toggled));
_play_button->signal_toggled().connect(
sigc::mem_fun(this, &MachinaGUI::play_toggled));
@@ -199,13 +199,12 @@ MachinaGUI::MachinaGUI(SPtr<machina::Engine> engine)
_evolve_toolbar->set_sensitive(false);
#endif
- _controller->announce(engine->machine());
- _canvas->arrange();
-
_client_model->signal_new_object.connect(
sigc::mem_fun(this, &MachinaGUI::on_new_object));
_client_model->signal_erase_object.connect(
sigc::mem_fun(this, &MachinaGUI::on_erase_object));
+
+ rebuild_canvas();
}
MachinaGUI::~MachinaGUI()
@@ -294,7 +293,7 @@ MachinaGUI::evolve_toggled()
_evolver = SPtr<Evolver>(
new Evolver(_unit, _target_filename, _engine->machine()));
_evolve = true;
- stop_clicked();
+ stop_toggled();
_engine->driver()->set_machine(SPtr<Machine>());
_evolver->start();
} else {
@@ -365,16 +364,24 @@ MachinaGUI::mutate(SPtr<Machine> machine, unsigned mutation)
void
MachinaGUI::update_toolbar()
{
- _record_button->set_active(_engine->driver()->recording());
- _play_button->set_active(_engine->machine()->is_activated());
+ const Driver::PlayState state = _engine->driver()->play_state();
+ _record_button->set_active(state == Driver::PlayState::RECORDING);
+ _play_button->set_active(state == Driver::PlayState::PLAYING);
_quantize_spinbutton->set_sensitive(_quantize_checkbutton->get_active());
}
void
+MachinaGUI::rebuild_canvas()
+{
+ _controller->announce(_engine->machine());
+ _canvas->arrange();
+}
+
+void
MachinaGUI::quantize_changed()
{
if (_quantize_checkbutton->get_active()) {
- _engine->set_quantization(1/(double)_quantize_spinbutton->get_value_as_int());
+ _engine->set_quantization(1.0 / _quantize_spinbutton->get_value());
} else {
_engine->set_quantization(0.0);
}
@@ -426,9 +433,7 @@ MachinaGUI::menu_file_open()
if (result == Gtk::RESPONSE_OK) {
SPtr<machina::Machine> new_machine = _engine->load_machine(dialog.get_uri());
if (new_machine) {
- _canvas->destroy();
- _controller->announce(new_machine);
- _canvas->arrange();
+ rebuild_canvas();
_save_uri = dialog.get_uri();
}
}
@@ -536,10 +541,9 @@ MachinaGUI::menu_import_midi()
if (machine) {
dialog.hide();
- machine->activate();
machine->reset(NULL, machine->time());
_engine->driver()->set_machine(machine);
- _controller->announce(machine);
+ rebuild_canvas();
} else {
Gtk::MessageDialog msg_dialog(dialog, "Error loading MIDI file",
false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
@@ -651,41 +655,35 @@ MachinaGUI::menu_help_help()
}
void
-MachinaGUI::record_toggled()
+MachinaGUI::stop_toggled()
{
- if (_record_button->get_active() && ! _engine->driver()->recording()) {
- _engine->driver()->start_record(_step_record_checkbutton->get_active());
- } else if (_engine->driver()->recording()) {
- _engine->driver()->finish_record();
- _controller->announce(_engine->machine());
- update_toolbar();
+ if (_stop_button->get_active()) {
+ const Driver::PlayState old_state = _engine->driver()->play_state();
+ _engine->driver()->set_play_state(Driver::PlayState::STOPPED);
+ if (old_state == Driver::PlayState::RECORDING) {
+ rebuild_canvas();
+ }
}
}
void
-MachinaGUI::stop_clicked()
+MachinaGUI::play_toggled()
{
- _play_button->set_active(false);
-
- if (_engine->driver()->recording()) {
- _engine->driver()->stop();
- _engine->machine()->deactivate();
- _controller->announce(_engine->machine());
- } else {
- _engine->driver()->stop();
- _engine->machine()->deactivate();
+ if (_play_button->get_active()) {
+ const Driver::PlayState old_state = _engine->driver()->play_state();
+ _engine->driver()->set_play_state(Driver::PlayState::PLAYING);
+ if (old_state == Driver::PlayState::RECORDING) {
+ rebuild_canvas();
+ }
}
-
- update_toolbar();
}
void
-MachinaGUI::play_toggled()
+MachinaGUI::record_toggled()
{
- if (_play_button->get_active())
- _engine->machine()->activate();
- else
- _engine->machine()->deactivate();
+ if (_record_button->get_active()) {
+ _engine->driver()->set_play_state(Driver::PlayState::RECORDING);
+ }
}
void