Take Film pointer out of Content.
[dcpomatic.git] / src / wx / player_information.cc
index 1b3d2809bbb286e212c54f5cb16cafb5e0589b89..5f480d5b4902832b14886a3aeb726c1d154fb7e8 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
 
     This file is part of DCP-o-matic.
 
 #include "wx_util.h"
 #include "film_viewer.h"
 #include "lib/playlist.h"
+#include "lib/compose.hpp"
 #include "lib/video_content.h"
+#include "lib/audio_content.h"
 #include "lib/dcp_content.h"
+#include "lib/film.h"
 
 using std::cout;
+using std::string;
 using boost::shared_ptr;
+using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
 using boost::optional;
 
-static int const dcp_lines = 4;
+/* This should be even */
+static int const dcp_lines = 6;
 
-PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
+PlayerInformation::PlayerInformation (wxWindow* parent, weak_ptr<FilmViewer> viewer)
        : wxPanel (parent)
        , _viewer (viewer)
        , _sizer (new wxBoxSizer (wxHORIZONTAL))
@@ -42,10 +48,21 @@ PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
 
        _dcp = new wxStaticText*[dcp_lines];
 
+       DCPOMATIC_ASSERT ((dcp_lines % 2) == 0);
+
        {
                wxSizer* s = new wxBoxSizer (wxVERTICAL);
                add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
-               for (int i = 0; i < dcp_lines; ++i) {
+               for (int i = 0; i < dcp_lines / 2; ++i) {
+                       _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
+               }
+               _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
+       }
+
+       {
+               wxSizer* s = new wxBoxSizer (wxVERTICAL);
+               add_label_to_sizer(s, this, wxT(" "), false, 0);
+               for (int i = dcp_lines / 2; i < dcp_lines; ++i) {
                        _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
                }
                _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
@@ -55,7 +72,8 @@ PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
                wxSizer* s = new wxBoxSizer (wxVERTICAL);
                add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
                _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
-               _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
+               _decode_resolution = add_label_to_sizer(s, this, wxT(""), false, 0);
+               _sizer->Add (s, 2, wxEXPAND | wxALL, 6);
        }
 
        SetSizerAndFit (_sizer);
@@ -70,15 +88,23 @@ PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
 void
 PlayerInformation::periodic_update ()
 {
-       checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), _viewer->dropped()));
+       shared_ptr<FilmViewer> fv = _viewer.lock ();
+       if (fv) {
+               checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), fv->dropped()));
+       }
 }
 
 void
 PlayerInformation::triggered_update ()
 {
+       shared_ptr<FilmViewer> fv = _viewer.lock ();
+       if (!fv) {
+               return;
+       }
+
        shared_ptr<DCPContent> dcp;
-       if (_viewer->film()) {
-               ContentList content = _viewer->film()->content();
+       if (fv->film()) {
+               ContentList content = fv->film()->content();
                if (content.size() == 1) {
                        dcp = dynamic_pointer_cast<DCPContent>(content.front());
                }
@@ -89,6 +115,7 @@ PlayerInformation::triggered_update ()
                for (int r = 1; r < dcp_lines; ++r) {
                        checked_set (_dcp[r], wxT(""));
                }
+               checked_set (_decode_resolution, wxT(""));
                return;
        }
 
@@ -108,16 +135,40 @@ PlayerInformation::triggered_update ()
        DCPOMATIC_ASSERT (dcp->video);
 
        checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
+       if (dcp->video_frame_rate()) {
+               checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
+       }
+       if (dcp->audio && !dcp->audio->streams().empty()) {
+               checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
+       }
+       if (!dcp->text.empty()) {
+               checked_set (_dcp[r++], _("Subtitles: yes"));
+       } else {
+               checked_set (_dcp[r++], _("Subtitles: no"));
+       }
 
        optional<double> vfr;
        vfr = dcp->video_frame_rate ();
        DCPOMATIC_ASSERT (vfr);
-       checked_set (
-               _dcp[r++],
-               wxString::Format(
-                       _("Length: %s (%ld frames)"),
-                       std_to_wx(time_to_hmsf(dcp->full_length(), lrint(*vfr))).data(),
-                       dcp->full_length().frames_round(*vfr)
-                       )
+
+       string const len = String::compose(
+               wx_to_std(_("Length: %1 (%2 frames)")),
+               time_to_hmsf(dcp->full_length(fv->film()), lrint(*vfr)),
+               dcp->full_length(fv->film()).frames_round(*vfr)
                );
+
+       checked_set (_dcp[r++], std_to_wx(len));
+
+       dcp::Size decode = dcp->video->size();
+       optional<int> reduction = fv->dcp_decode_reduction();
+       if (reduction) {
+               decode.width /= pow(2, *reduction);
+               decode.height /= pow(2, *reduction);
+       }
+
+       checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
+
+       DCPOMATIC_ASSERT(r <= dcp_lines);
+
+       _sizer->Layout ();
 }