GLUI: fix show/hide inst edit param window behaviour master
authorStefan Westerfeld <stefan@space.twc.de>
Fri, 15 Mar 2019 16:14:18 +0000 (17:14 +0100)
committerStefan Westerfeld <stefan@space.twc.de>
Fri, 15 Mar 2019 16:14:18 +0000 (17:14 +0100)
Signed-off-by: Stefan Westerfeld <stefan@space.twc.de>
glui/sminsteditparams.hh
glui/sminsteditwindow.hh

index 207ac18..aa1db42 100644 (file)
@@ -45,7 +45,10 @@ public:
     instrument (instrument)
   {
     window->add_child_window (this);
-    set_close_callback ([this,window]() { window->remove_child_window (this); });
+    set_close_callback ([this,window]() {
+      signal_closed();
+      window->remove_child_window (this);
+     });
 
     Shortcut *play_shortcut = new Shortcut (this, ' ');
     connect (play_shortcut->signal_activated, [this]() { signal_toggle_play(); });
@@ -371,6 +374,7 @@ public:
     instrument->set_encoder_config (enc_cfg);
   }
   Signal<> signal_toggle_play;
+  Signal<> signal_closed;
 };
 
 }
index 7a0eb25..ae44a3a 100644 (file)
@@ -248,6 +248,9 @@ class InstEditWindow : public Window
   Button   *play_button = nullptr;
   bool      playing = false;
 
+  InstEditParams *inst_edit_params = nullptr;
+  Button         *show_params_button = nullptr;
+
   Sample::Loop
   text_to_loop (const std::string& text)
   {
@@ -451,11 +454,8 @@ public:
     grid.add_widget (auto_tune_checkbox, 60, 61.5, 20, 2);
     connect (auto_tune_checkbox->signal_toggled, this, &InstEditWindow::on_auto_tune_changed);
 
-    auto show_params_button = new Button (this, "Show All Parameters...");
-    connect (show_params_button->signal_clicked, [&]() {
-      auto ie_params = new InstEditParams (this, &instrument);
-      connect (ie_params->signal_toggle_play, this, &InstEditWindow::on_toggle_play);
-    });
+    show_params_button = new Button (this, "Show All Parameters...");
+    connect (show_params_button->signal_clicked, this, &InstEditWindow::on_show_hide_params);
     grid.add_widget (show_params_button, 60, 64, 25, 3);
 
     update_auto_checkboxes();
@@ -484,6 +484,27 @@ public:
     vzoom_label->set_text (string_printf ("%.1f %%", factor * 100));
   }
   void
+  on_show_hide_params()
+  {
+    if (inst_edit_params)
+      {
+        // unfortunately both ways of destroying the param window result in a crash
+        // inst_edit_params->delete_later();
+        // delete inst_edit_params;
+        // inst_edit_params = nullptr;
+      }
+    else
+      {
+        inst_edit_params = new InstEditParams (this, &instrument);
+        connect (inst_edit_params->signal_toggle_play, this, &InstEditWindow::on_toggle_play);
+        connect (inst_edit_params->signal_closed, [this]() {
+          show_params_button->set_enabled (true);
+          inst_edit_params = nullptr;
+        });
+        show_params_button->set_enabled (false);
+      }
+  }
+  void
   on_save_clicked()
   {
     instrument.save ("/tmp/x.sminst");