Respond to gain in the audio dialog.
authorCarl Hetherington <cth@carlh.net>
Mon, 25 Feb 2013 00:28:03 +0000 (00:28 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 25 Feb 2013 00:28:03 +0000 (00:28 +0000)
src/wx/audio_dialog.cc
src/wx/audio_dialog.h
src/wx/audio_plot.cc
src/wx/audio_plot.h

index 11efc153c69c13e8c5a38c2d7f1395c4b2f17458..32864ca15974a9c400bb88da7c27efcbc75a17a0 100644 (file)
@@ -54,6 +54,9 @@ AudioDialog::AudioDialog (wxWindow* parent, boost::shared_ptr<Film> film)
 void
 AudioDialog::set_film (boost::shared_ptr<Film> f)
 {
+       _film_connection.disconnect ();
+       _film = f;
+       
        shared_ptr<AudioAnalysis> a;
 
        try {
@@ -70,6 +73,8 @@ AudioDialog::set_film (boost::shared_ptr<Film> f)
        }
 
        _channel->SetSelection (0);
+
+       _film_connection = f->Changed.connect (bind (&AudioDialog::film_changed, this, _1));
 }
 
 void
@@ -77,3 +82,11 @@ AudioDialog::channel_changed (wxCommandEvent &)
 {
        _plot->set_channel (_channel->GetSelection ());
 }
+
+void
+AudioDialog::film_changed (Film::Property p)
+{
+       if (p == Film::AUDIO_GAIN) {
+               _plot->set_gain (_film->audio_gain ());
+       }
+}
index 1e4563972f095fd0d16da554cfaf5b9aac560fd3..968fd0a122340f9021303dc2a799b68e868c1539 100644 (file)
@@ -18,7 +18,9 @@
 */
 
 #include <boost/shared_ptr.hpp>
+#include <boost/signals2.hpp>
 #include <wx/wx.h>
+#include "lib/film.h"
 
 class AudioPlot;
 class Film;
@@ -31,8 +33,11 @@ public:
        void set_film (boost::shared_ptr<Film>);
 
 private:
+       void film_changed (Film::Property);
        void channel_changed (wxCommandEvent &);
-       
+
+       boost::shared_ptr<Film> _film;
        AudioPlot* _plot;
        wxChoice* _channel;
+       boost::signals2::scoped_connection _film_connection;
 };
index cc2d8f6b428785f513ec9be74a478b2105608ef6..d438426c7f2dd2b55b4548f9e87a2194c9f4e169 100644 (file)
@@ -36,6 +36,7 @@ using boost::shared_ptr;
 AudioPlot::AudioPlot (wxWindow* parent)
        : wxPanel (parent)
        , _channel (0)
+       , _gain (0)
 {
        Connect (wxID_ANY, wxEVT_PAINT, wxPaintEventHandler (AudioPlot::paint), 0, this);
 
@@ -91,12 +92,12 @@ AudioPlot::paint (wxPaintEvent &)
 
        for (int i = 0; i < AudioPoint::COUNT; ++i) {
                path[i] = gc->CreatePath ();
-               path[i].MoveToPoint (0, height - (max (_analysis->get_point(_channel, 0)[i], -60.0f) + 60) * ys);
+               path[i].MoveToPoint (0, height - (max (_analysis->get_point(_channel, 0)[i], -60.0f) + 60 + _gain) * ys);
        }
 
        for (int i = 0; i < _analysis->points(_channel); ++i) {
                for (int j = 0; j < AudioPoint::COUNT; ++j) {
-                       path[j].AddLineToPoint (i * xs, height - (max (_analysis->get_point(_channel, i)[j], -60.0f) + 60) * ys);
+                       path[j].AddLineToPoint (i * xs, height - (max (_analysis->get_point(_channel, i)[j], -60.0f) + 60 + _gain) * ys);
                }
        }
 
@@ -108,3 +109,10 @@ AudioPlot::paint (wxPaintEvent &)
 
        delete gc;
 }
+
+void
+AudioPlot::set_gain (float g)
+{
+       _gain = g;
+       Refresh ();
+}
index 03bd793233bfb80409347331de46dbe6aca2d471..dfc1b18aef1b9dfb3d2b99f3ef04b9c8fd5e56a3 100644 (file)
@@ -30,10 +30,13 @@ public:
 
        void set_analysis (boost::shared_ptr<AudioAnalysis>);
        void set_channel (int c);
+       void set_gain (float);
 
 private:
        void paint (wxPaintEvent &);
 
        boost::shared_ptr<AudioAnalysis> _analysis;
        int _channel;
+       /** gain to apply in dB */
+       float _gain;
 };