Merge branch 'master' into content-rework-take5
[dcpomatic.git] / src / wx / film_viewer.cc
index f6d0f77dc59fc29256f0d305e8b3752e120b378d..cba19c07c2ba6d093d6e420d33f13f4803bc47e0 100644 (file)
@@ -37,6 +37,7 @@
 #include "lib/player.h"
 #include "lib/video_content.h"
 #include "lib/ffmpeg_content.h"
+#include "lib/imagemagick_content.h"
 #include "film_viewer.h"
 #include "wx_util.h"
 #include "video_decoder.h"
@@ -47,6 +48,8 @@ using std::max;
 using std::cout;
 using std::list;
 using boost::shared_ptr;
+using boost::dynamic_pointer_cast;
+using boost::weak_ptr;
 using libdcp::Size;
 
 FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
@@ -56,7 +59,6 @@ FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
        , _play_button (new wxToggleButton (this, wxID_ANY, _("Play")))
        , _display_frame_x (0)
        , _got_frame (false)
-       , _clear_required (false)
 {
        _panel->SetDoubleBuffered (true);
 #if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
@@ -99,7 +101,6 @@ FilmViewer::film_changed (Film::Property p)
                break;
        case Film::CONTENT:
        {
-               setup_player ();
                calculate_sizes ();
                get_frame ();
                _panel->Refresh ();
@@ -123,60 +124,47 @@ FilmViewer::film_changed (Film::Property p)
        }
 }
 
-void
-FilmViewer::setup_player ()
-{
-       _player = _film->player ();
-       _player->disable_audio ();
-       _player->disable_video_sync ();
-
-       /* Don't disable subtitles here as we may need them, and it's nice to be able to turn them
-          on and off without needing obtain a new Player.
-       */
-       
-       _player->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3));
-}
-
-void
-FilmViewer::film_content_changed (int p)
-{
-       if (p == VideoContentProperty::VIDEO_LENGTH || p == VideoContentProperty::VIDEO_SIZE) {
-               setup_player ();
-               calculate_sizes ();
-               get_frame ();
-               _panel->Refresh ();
-               _v_sizer->Layout ();
-       }
-}
-
 void
 FilmViewer::set_film (shared_ptr<Film> f)
 {
        if (_film == f) {
                return;
        }
-       
+
        _film = f;
 
+       _raw_frame.reset ();
+       _display_frame.reset ();
+       _panel->Refresh ();
+       _panel->Update ();
+
        if (!_film) {
                return;
        }
 
+       _player = f->player ();
+       _player->disable_audio ();
+       _player->disable_video_sync ();
+       /* Don't disable subtitles here as we may need them, and it's nice to be able to turn them
+          on and off without needing obtain a new Player.
+       */
+       
+       _player->Video.connect (bind (&FilmViewer::process_video, this, _1, _2, _3));
+       
        _film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1));
-       _film->ContentChanged.connect (boost::bind (&FilmViewer::film_content_changed, this, _1));
+       _film->ContentChanged.connect (boost::bind (&FilmViewer::film_content_changed, this, _1, _2));
 
        film_changed (Film::CONTENT);
        film_changed (Film::FORMAT);
        film_changed (Film::WITH_SUBTITLES);
        film_changed (Film::SUBTITLE_OFFSET);
        film_changed (Film::SUBTITLE_SCALE);
-       film_content_changed (FFmpegContentProperty::SUBTITLE_STREAM);
 }
 
 void
 FilmViewer::update_from_decoder ()
 {
-       if (!_player || _player->seek_to_last ()) {
+       if (!_player || _player->seek (_player->last_video_time ())) {
                return;
        }
 
@@ -211,11 +199,6 @@ FilmViewer::paint_panel (wxPaintEvent &)
 {
        wxPaintDC dc (_panel);
 
-       if (_clear_required) {
-               dc.Clear ();
-               _clear_required = false;
-       }
-
        if (!_display_frame || !_film || !_out_size.width || !_out_size.height) {
                dc.Clear ();
                return;
@@ -237,6 +220,22 @@ FilmViewer::paint_panel (wxPaintEvent &)
                wxBitmap sub_bitmap (sub);
                dc.DrawBitmap (sub_bitmap, _display_sub_position.x, _display_sub_position.y);
        }
+
+       if (_out_size.width < _panel_size.width) {
+               wxPen p (GetBackgroundColour ());
+               wxBrush b (GetBackgroundColour ());
+               dc.SetPen (p);
+               dc.SetBrush (b);
+               dc.DrawRectangle (_out_size.width, 0, _panel_size.width - _out_size.width, _panel_size.height);
+       }
+
+       if (_out_size.height < _panel_size.height) {
+               wxPen p (GetBackgroundColour ());
+               wxBrush b (GetBackgroundColour ());
+               dc.SetPen (p);
+               dc.SetBrush (b);
+               dc.DrawRectangle (0, _out_size.height, _panel_size.width, _panel_size.height - _out_size.height);
+       }               
 }
 
 
@@ -285,12 +284,7 @@ FilmViewer::raw_to_display ()
                return;
        }
 
-       libdcp::Size old_size;
-       if (_display_frame) {
-               old_size = _display_frame->size();
-       }
-
-       boost::shared_ptr<Image> input = _raw_frame;
+       shared_ptr<Image> input = _raw_frame;
 
        pair<string, string> const s = Filter::ffmpeg_strings (_film->filters());
        if (!s.second.empty ()) {
@@ -300,10 +294,6 @@ FilmViewer::raw_to_display ()
        /* Get a compacted image as we have to feed it to wxWidgets */
        _display_frame = input->scale_and_convert_to_rgb (_film_size, 0, _film->scaler(), false);
 
-       if (old_size != _display_frame->size()) {
-               _clear_required = true;
-       }
-
        if (_raw_sub) {
 
                /* Our output is already cropped by the decoder, so we need to account for that
@@ -409,7 +399,7 @@ FilmViewer::get_frame ()
                _display_frame.reset ();
                return;
        }
-       
+
        try {
                _got_frame = false;
                while (!_got_frame) {
@@ -448,3 +438,12 @@ FilmViewer::active_jobs_changed (bool a)
        _play_button->Enable (!a);
 }
 
+void
+FilmViewer::film_content_changed (weak_ptr<Content>, int p)
+{
+       if (p == VideoContentProperty::VIDEO_LENGTH) {
+               /* Force an update to our frame */
+               wxScrollEvent ev;
+               slider_moved (ev);
+       }
+}