Relayout player information after it changes. Should help with #1185.
[dcpomatic.git] / src / wx / player_information.cc
1 /*
2     Copyright (C) 2017-2018 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "player_information.h"
22 #include "wx_util.h"
23 #include "film_viewer.h"
24 #include "lib/playlist.h"
25 #include "lib/compose.hpp"
26 #include "lib/video_content.h"
27 #include "lib/audio_content.h"
28 #include "lib/dcp_content.h"
29
30 using std::cout;
31 using std::string;
32 using boost::shared_ptr;
33 using boost::dynamic_pointer_cast;
34 using boost::optional;
35
36 /* This should be even */
37 static int const dcp_lines = 6;
38
39 PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
40         : wxPanel (parent)
41         , _viewer (viewer)
42         , _sizer (new wxBoxSizer (wxHORIZONTAL))
43 {
44         wxFont title_font (*wxNORMAL_FONT);
45         title_font.SetWeight (wxFONTWEIGHT_BOLD);
46
47         _dcp = new wxStaticText*[dcp_lines];
48
49         DCPOMATIC_ASSERT ((dcp_lines % 2) == 0);
50
51         {
52                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
53                 add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
54                 for (int i = 0; i < dcp_lines / 2; ++i) {
55                         _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
56                 }
57                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
58         }
59
60         {
61                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
62                 add_label_to_sizer(s, this, wxT(" "), false, 0);
63                 for (int i = dcp_lines / 2; i < dcp_lines; ++i) {
64                         _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
65                 }
66                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
67         }
68
69         {
70                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
71                 add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
72                 _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
73                 _decode_resolution = add_label_to_sizer(s, this, wxT(""), false, 0);
74                 _sizer->Add (s, 2, wxEXPAND | wxALL, 6);
75         }
76
77         SetSizerAndFit (_sizer);
78
79         triggered_update ();
80
81         Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
82         _timer.reset (new wxTimer (this));
83         _timer->Start (500);
84 }
85
86 void
87 PlayerInformation::periodic_update ()
88 {
89         checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), _viewer->dropped()));
90 }
91
92 void
93 PlayerInformation::triggered_update ()
94 {
95         shared_ptr<DCPContent> dcp;
96         if (_viewer->film()) {
97                 ContentList content = _viewer->film()->content();
98                 if (content.size() == 1) {
99                         dcp = dynamic_pointer_cast<DCPContent>(content.front());
100                 }
101         }
102
103         if (!dcp) {
104                 checked_set (_dcp[0], _("No DCP loaded."));
105                 for (int r = 1; r < dcp_lines; ++r) {
106                         checked_set (_dcp[r], wxT(""));
107                 }
108                 checked_set (_decode_resolution, wxT(""));
109                 return;
110         }
111
112         int r = 0;
113         checked_set (_dcp[r++], std_to_wx(dcp->name()));
114
115         if (dcp->needs_assets()) {
116                 checked_set (_dcp[r], _("Needs OV"));
117                 return;
118         }
119
120         if (dcp->needs_kdm()) {
121                 checked_set (_dcp[r], _("Needs KDM"));
122                 return;
123         }
124
125         DCPOMATIC_ASSERT (dcp->video);
126
127         checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
128         if (dcp->video_frame_rate()) {
129                 checked_set (_dcp[r++], wxString::Format(_("Frame rate: %d"), (int) lrint(*dcp->video_frame_rate())));
130         }
131         if (dcp->audio && !dcp->audio->streams().empty()) {
132                 checked_set (_dcp[r++], wxString::Format(_("Audio channels: %d"), dcp->audio->streams().front()->channels()));
133         }
134         if (dcp->subtitle) {
135                 checked_set (_dcp[r++], _("Subtitles: yes"));
136         } else {
137                 checked_set (_dcp[r++], _("Subtitles: no"));
138         }
139
140         optional<double> vfr;
141         vfr = dcp->video_frame_rate ();
142         DCPOMATIC_ASSERT (vfr);
143
144         string const len = String::compose(
145                 wx_to_std(_("Length: %1 (%2 frames)")),
146                 time_to_hmsf(dcp->full_length(), lrint(*vfr)),
147                 dcp->full_length().frames_round(*vfr)
148                 );
149
150         checked_set (_dcp[r++], std_to_wx(len));
151
152         dcp::Size decode = dcp->video->size();
153         optional<int> reduction = _viewer->dcp_decode_reduction();
154         if (reduction) {
155                 decode.width /= pow(2, *reduction);
156                 decode.height /= pow(2, *reduction);
157         }
158
159         checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
160
161         DCPOMATIC_ASSERT(r <= dcp_lines);
162
163         _sizer->Layout ();
164 }