Use a SpinCtrlDouble for audio gain, and change its representation
authorCarl Hetherington <cth@carlh.net>
Mon, 9 Jun 2014 22:56:33 +0000 (23:56 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 9 Jun 2014 22:56:33 +0000 (23:56 +0100)
from float to double.

Requested-by: Mattias Mattsson
ChangeLog
src/lib/audio_content.cc
src/lib/audio_content.h
src/wx/audio_panel.cc
src/wx/audio_panel.h
src/wx/content_widget.h
src/wx/wx_util.cc
src/wx/wx_util.h

index 4ad416fcce2329aec4bc860da3340b2a1ecbfefc..c03d54e9aaf68e31ca6bbe8755b6432295a79667 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
 2014-06-09  Carl Hetherington  <cth@carlh.net>
 
+       * Make audio gain a floating-point value in the UI (#367).
+
        * Work-around out-of-memory crashes with large start trims (#252).
 
        * Version 1.69.24 released.
index bf00b672a67d75188de664093ab9d67605fa88f7..29d159a29a9603f330eb6100ed6c42743a33c630 100644 (file)
@@ -98,7 +98,7 @@ AudioContent::as_xml (xmlpp::Node* node) const
 
 
 void
-AudioContent::set_audio_gain (float g)
+AudioContent::set_audio_gain (double g)
 {
        {
                boost::mutex::scoped_lock lm (_mutex);
index 2a1216d86f81bd63596ef63c21b862a0a6747904..2c324a3a4966e0dad899c10f24f3f99115317420 100644 (file)
@@ -62,10 +62,10 @@ public:
        
        boost::signals2::connection analyse_audio (boost::function<void()>);
 
-       void set_audio_gain (float);
+       void set_audio_gain (double);
        void set_audio_delay (int);
        
-       float audio_gain () const {
+       double audio_gain () const {
                boost::mutex::scoped_lock lm (_mutex);
                return _audio_gain;
        }
@@ -77,7 +77,7 @@ public:
 
 private:
        /** Gain to apply to audio in dB */
-       float _audio_gain;
+       double _audio_gain;
        /** Delay to apply to audio (positive moves audio later) in milliseconds */
        int _audio_delay;
 };
index 1c679d336c003fc7404f64ddff9b55cc88d46eec..72cb9fe6a2475cce46a7c483234cbecaac1e056c 100644 (file)
@@ -50,9 +50,9 @@ AudioPanel::AudioPanel (FilmEditor* e)
        ++r;
 
        add_label_to_grid_bag_sizer (grid, this, _("Audio Gain"), true, wxGBPosition (r, 0));
-       _gain = new ContentSpinCtrl<AudioContent> (
+       _gain = new ContentSpinCtrlDouble<AudioContent> (
                this,
-               new wxSpinCtrl (this),
+               new wxSpinCtrlDouble (this),
                AudioContentProperty::AUDIO_GAIN,
                boost::mem_fn (&AudioContent::audio_gain),
                boost::mem_fn (&AudioContent::set_audio_gain)
@@ -88,6 +88,8 @@ AudioPanel::AudioPanel (FilmEditor* e)
        _sizer->Add (_mapping, 1, wxEXPAND | wxALL, 6);
 
        _gain->wrapped()->SetRange (-60, 60);
+       _gain->wrapped()->SetDigits (1);
+       _gain->wrapped()->SetIncrement (0.5);
        _delay->wrapped()->SetRange (-1000, 1000);
 
        _stream->Bind                (wxEVT_COMMAND_CHOICE_SELECTED,  boost::bind (&AudioPanel::stream_changed, this));
index f1b932e7cee2602d1421f32b593e855206e6e365..2ba5a9ffc051de25e29200d4b28f952cdaff9db8 100644 (file)
@@ -21,7 +21,7 @@
 #include "film_editor_panel.h"
 #include "content_widget.h"
 
-class wxSpinCtrl;
+class wxSpinCtrlDouble;
 class wxButton;
 class wxChoice;
 class wxStaticText;
@@ -44,7 +44,7 @@ private:
        void mapping_changed (AudioMapping);
        void setup_stream_description ();
 
-       ContentSpinCtrl<AudioContent>* _gain;
+       ContentSpinCtrlDouble<AudioContent>* _gain;
        wxButton* _gain_calculate_button;
        wxButton* _show;
        ContentSpinCtrl<AudioContent>* _delay;
index 30501c1a95f513700289e31fe183874e473ade80..ca94850065bf4f1e9e75a865a4b463435789bd24 100644 (file)
@@ -222,6 +222,30 @@ public:
        }
 };
 
+template <class S>
+class ContentSpinCtrlDouble : public ContentWidget<S, wxSpinCtrlDouble, double, double>
+{
+public:
+       ContentSpinCtrlDouble (
+               wxWindow* parent,
+               wxSpinCtrlDouble* wrapped,
+               int property,
+               boost::function<double (S*)> getter,
+               boost::function<void (S*, double)> setter
+               )
+               : ContentWidget<S, wxSpinCtrlDouble, double, double> (
+                       parent,
+                       wrapped,
+                       property,
+                       getter, setter,
+                       &caster<double, double>,
+                       &caster<double, double>
+                       )
+       {
+               wrapped->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ContentWidget<S, wxSpinCtrlDouble, double, double>::view_changed, this));
+       }
+};
+
 template <class S, class U>
 class ContentChoice : public ContentWidget<S, wxChoice, U, int>
 {
index 96278b82bac0d1197a26ae68da601c9084a912a3..b73cd490dfffcae386c8f88b460d5e74be9cb23c 100644 (file)
@@ -189,6 +189,15 @@ checked_set (wxSpinCtrl* widget, int value)
        }
 }
 
+void
+checked_set (wxSpinCtrlDouble* widget, double value)
+{
+       /* XXX: completely arbitrary epsilon */
+       if (fabs (widget->GetValue() - value) < 1e-16) {
+               widget->SetValue (value);
+       }
+}
+
 void
 checked_set (wxChoice* widget, int value)
 {
@@ -297,6 +306,12 @@ wx_get (wxChoice* w)
        return w->GetSelection ();
 }
 
+double
+wx_get (wxSpinCtrlDouble* w)
+{
+       return w->GetValue ();
+}
+
 void
 run_gui_loop ()
 {
index 56ed500f6887974a2e0c1f7af60bef4ca43fcdff..12a7115d5b3d472e8be9394435df884ff7d19b97 100644 (file)
@@ -31,6 +31,7 @@
 
 class wxFilePickerCtrl;
 class wxSpinCtrl;
+class wxSpinCtrlDouble;
 class wxGridBagSizer;
 
 #define DCPOMATIC_SIZER_X_GAP 8
@@ -86,6 +87,7 @@ extern std::string string_client_data (wxClientData* o);
 
 extern void checked_set (wxFilePickerCtrl* widget, std::string value);
 extern void checked_set (wxSpinCtrl* widget, int value);
+extern void checked_set (wxSpinCtrlDouble* widget, double value);
 extern void checked_set (wxChoice* widget, int value);
 extern void checked_set (wxChoice* widget, std::string value);
 extern void checked_set (wxTextCtrl* widget, std::string value);
@@ -95,6 +97,7 @@ extern void checked_set (wxStaticText* widget, std::string value);
 
 extern int wx_get (wxChoice* widget);
 extern int wx_get (wxSpinCtrl* widget);
+extern double wx_get (wxSpinCtrlDouble* widget);
 
 /* GTK 2.24.17 has a buggy GtkFileChooserButton and it was put in Ubuntu 13.04.
    This also seems to apply to 2.24.20 in Ubuntu 13.10 and 2.24.23 in Ubuntu 14.04.