GLUI: implement auto volume gain value text editor
authorStefan Westerfeld <stefan@space.twc.de>
Mon, 11 Mar 2019 18:07:05 +0000 (19:07 +0100)
committerStefan Westerfeld <stefan@space.twc.de>
Mon, 11 Mar 2019 18:07:05 +0000 (19:07 +0100)
Signed-off-by: Stefan Westerfeld <stefan@space.twc.de>
glui/sminsteditparams.hh
glui/smlineedit.hh
glui/smwidget.hh
glui/smwindow.cc
glui/smwindow.hh

index 7cfc845..88f9aed 100644 (file)
@@ -4,6 +4,7 @@
 #define SPECTMORPH_INST_EDIT_PARAMS_HH
 
 #include "smcheckbox.hh"
+#include "smparamlabel.hh"
 
 namespace SpectMorph
 {
@@ -14,6 +15,8 @@ class InstEditParams : public Window
 
   CheckBox   *auto_volume_checkbox = nullptr;
   ComboBox   *auto_volume_method_combobox = nullptr;
+  Label      *auto_volume_gain_label = nullptr;
+  ParamLabel *auto_volume_gain_param_label = nullptr;
 
   CheckBox   *auto_tune_checkbox = nullptr;
 public:
@@ -29,7 +32,7 @@ public:
     connect (auto_volume_checkbox->signal_toggled, this, &InstEditParams::on_auto_volume_changed);
     grid.add_widget (auto_volume_checkbox, 2, 2, 20, 2);
 
-    /*--- play mode ---*/
+    /*--- auto volume method ---*/
     auto_volume_method_combobox = new ComboBox (this);
     connect (auto_volume_method_combobox->signal_item_changed, this, &InstEditParams::on_auto_volume_method_changed);
     grid.add_widget (new Label (this, "Method"), 4, 4, 10, 3);
@@ -37,11 +40,20 @@ public:
     auto_volume_method_combobox->add_item ("From Loop"); // default
     auto_volume_method_combobox->add_item ("Global");
 
+    /*--- auto volume gain ---*/
+    auto_volume_gain_label = new Label (this, "Gain");
+    grid.add_widget (auto_volume_gain_label, 4, 7, 10, 3);
+
+    auto_volume_gain_param_label = new ParamLabel (this, "");
+    grid.add_widget (auto_volume_gain_param_label, 13, 7, 10, 3);
+
+    connect (auto_volume_gain_param_label->signal_value_changed, this, &InstEditParams::on_auto_volume_gain_changed);
+
     connect (instrument->signal_global_changed, this, &InstEditParams::on_global_changed);
 
     auto_tune_checkbox = new CheckBox (this, "Auto Tune");
     connect (auto_tune_checkbox->signal_toggled, this, &InstEditParams::on_auto_tune_changed);
-    grid.add_widget (auto_tune_checkbox, 2, 7, 20, 2);
+    grid.add_widget (auto_tune_checkbox, 2, 10, 20, 2);
 
     on_global_changed();
 
@@ -52,6 +64,7 @@ public:
   {
     auto_volume_checkbox->set_checked (instrument->auto_volume().enabled);
     auto_tune_checkbox->set_checked (instrument->auto_tune().enabled);
+    auto_volume_gain_param_label->set_text (string_printf ("%.2f dB", instrument->auto_volume().gain));
 
     if (instrument->auto_volume().method == Instrument::AutoVolume::GLOBAL)
       auto_volume_method_combobox->set_text ("Global");
@@ -80,6 +93,14 @@ public:
     this->instrument->set_auto_volume (av);
   }
   void
+  on_auto_volume_gain_changed (double gain)
+  {
+    Instrument::AutoVolume av = instrument->auto_volume();
+    av.gain = gain;
+
+    instrument->set_auto_volume (av);
+  }
+  void
   on_auto_tune_changed (bool new_value)
   {
     auto at = instrument->auto_tune();
index e1f1ccc..c72952f 100644 (file)
@@ -139,10 +139,16 @@ public:
     highlight = false;
     update();
   }
+  void
+  focus_out_event() override
+  {
+    signal_focus_out();
+  }
 
   Signal<std::string> signal_text_changed;
   Signal<>            signal_return_pressed;
   Signal<>            signal_esc_pressed;
+  Signal<>            signal_focus_out;
 };
 
 }
index 900df24..7e0b204 100644 (file)
@@ -291,6 +291,14 @@ public:
   {
   }
   virtual void
+  focus_event()
+  {
+  }
+  virtual void
+  focus_out_event()
+  {
+  }
+  virtual void
   key_press_event (const PuglEventKey& key_event)
   {
   }
index ef2e3d3..4f99b1a 100644 (file)
@@ -605,7 +605,15 @@ Window::on_event (const PuglEvent* event)
         ey = event->button.y / global_scale;
 
         mouse_widget = find_widget_xy (ex, ey);
-        mouse_widget->mouse_press (ex - mouse_widget->abs_x(), ey - mouse_widget->abs_y());
+        if (keyboard_focus_widget && keyboard_focus_release_on_click)
+          {
+            keyboard_focus_widget->focus_out_event();
+            keyboard_focus_widget = nullptr;
+          }
+        else
+          {
+            mouse_widget->mouse_press (ex - mouse_widget->abs_x(), ey - mouse_widget->abs_y());
+          }
 
         if (auto_redraw)
           update_full();
@@ -851,9 +859,11 @@ Window::set_close_callback (const std::function<void()>& callback)
 }
 
 void
-Window::set_keyboard_focus (Widget *widget)
+Window::set_keyboard_focus (Widget *widget, bool release_on_click)
 {
   keyboard_focus_widget = widget;
+  keyboard_focus_widget->focus_event();
+  keyboard_focus_release_on_click = release_on_click;
 }
 
 void
index 7092a6f..f62c0ef 100644 (file)
@@ -30,6 +30,7 @@ protected:
   Widget                   *enter_widget = nullptr;
   Widget                   *menu_widget = nullptr;
   Widget                   *keyboard_focus_widget = nullptr;
+  bool                      keyboard_focus_release_on_click = false;
   Widget                   *dialog_widget = nullptr;
   bool                      have_popup_window = false;
   std::unique_ptr<Window>   popup_window;
@@ -64,7 +65,7 @@ public:
   void need_update (Widget *widget, const Rect *changed_rect = nullptr);
   void on_widget_deleted (Widget *widget);
   void set_menu_widget (Widget *widget);
-  void set_keyboard_focus (Widget *widget);
+  void set_keyboard_focus (Widget *widget, bool release_on_click = false);
   void set_dialog_widget (Widget *widget);
   void set_close_callback (const std::function<void()>& callback);
   void set_popup_window (Window *window);