Modify the downmix mapping so that we include Ls, Rs and Lfe (#1281).
[dcpomatic.git] / src / wx / film_viewer.cc
index ade45d766879ab4030f5dfcdc80fc9ea6b462535..a7e040bb5c51335d64b1239e327e7d6f4b7a45fd 100644 (file)
@@ -251,13 +251,18 @@ FilmViewer::recreate_butler ()
                        map.set (i, i, 1);
                }
        } else {
-               /* Special case: stereo output, at least 3 channel input, map L+R to L/R and
-                  C to both, all 3dB down.
+               /* Special case: stereo output, at least 3 channel input.
+                  Map so that Lt = L(-3dB) + Ls(-3dB) + C(-6dB) + Lfe(-10dB)
+                              Rt = R(-3dB) + Rs(-3dB) + C(-6dB) + Lfe(-10dB)
                */
-               map.set (0, 0, 1 / sqrt(2)); // L -> L
-               map.set (1, 1, 1 / sqrt(2)); // R -> R
-               map.set (2, 0, 1 / sqrt(2)); // C -> L
-               map.set (2, 1, 1 / sqrt(2)); // C -> R
+               map.set (dcp::LEFT,   0, 1 / sqrt(2)); // L -> Lt
+               map.set (dcp::RIGHT,  1, 1 / sqrt(2)); // R -> Rt
+               map.set (dcp::CENTRE, 0, 1 / 2.0); // C -> Lt
+               map.set (dcp::CENTRE, 1, 1 / 2.0); // C -> Rt
+               map.set (dcp::LFE,    0, 1 / sqrt(10)); // Lfe -> Lt
+               map.set (dcp::LFE,    1, 1 / sqrt(10)); // Lfe -> Rt
+               map.set (dcp::LS,     0, 1 / sqrt(2)); // Ls -> Lt
+               map.set (dcp::RS,     1, 1 / sqrt(2)); // Rs -> Rt
        }
 
        _butler.reset (new Butler (_player, _film->log(), map, _audio_channels));
@@ -373,7 +378,7 @@ FilmViewer::paint_panel ()
 {
        wxPaintDC dc (_panel);
 
-       if (!_frame || !_film || !_out_size.width || !_out_size.height) {
+       if (!_frame || !_film || !_out_size.width || !_out_size.height || _out_size != _frame->size()) {
                dc.Clear ();
                return;
        }
@@ -421,6 +426,7 @@ FilmViewer::slider_moved (bool page)
        }
 
        DCPTime t (_slider->GetValue() * _film->length().get() / 4096);
+       t = t.round (_film->video_frame_rate());
        /* Ensure that we hit the end of the film at the end of the slider */
        if (t >= _film->length ()) {
                t = _film->length() - one_video_frame();
@@ -505,6 +511,10 @@ FilmViewer::check_play_state ()
 void
 FilmViewer::start ()
 {
+       if (!_film) {
+               return;
+       }
+
        if (_audio.isStreamOpen()) {
                _audio.setStreamTime (_video_position.seconds());
                _audio.startStream ();
@@ -576,7 +586,7 @@ FilmViewer::active_jobs_changed (optional<string> j)
 }
 
 DCPTime
-FilmViewer::nudge_amount (wxMouseEvent& ev)
+FilmViewer::nudge_amount (wxKeyboardState& ev)
 {
        DCPTime amount = one_video_frame ();
 
@@ -615,17 +625,35 @@ FilmViewer::rewind_clicked (wxMouseEvent& ev)
 }
 
 void
-FilmViewer::back_clicked (wxMouseEvent& ev)
+FilmViewer::back_frame ()
+{
+       if (!_film) {
+               return;
+       }
+
+       go_to (_video_position - one_video_frame());
+}
+
+void
+FilmViewer::forward_frame ()
+{
+       if (!_film) {
+               return;
+       }
+
+       go_to (_video_position + one_video_frame());
+}
+
+void
+FilmViewer::back_clicked (wxKeyboardState& ev)
 {
        go_to (_video_position - nudge_amount (ev));
-       ev.Skip ();
 }
 
 void
-FilmViewer::forward_clicked (wxMouseEvent& ev)
+FilmViewer::forward_clicked (wxKeyboardState& ev)
 {
        go_to (_video_position + nudge_amount (ev));
-       ev.Skip ();
 }
 
 void
@@ -796,7 +824,7 @@ FilmViewer::config_changed (Config::Property p)
                _audio.closeStream ();
        }
 
-       if (Config::instance()->sound()) {
+       if (Config::instance()->sound() && _audio.getDeviceCount() > 0) {
                unsigned int st = 0;
                if (Config::instance()->sound_output()) {
                        while (st < _audio.getDeviceCount()) {