Try again to fix Windows wxWidgets complain using compose to save all the mucking...
[dcpomatic.git] / src / wx / player_information.cc
1 /*
2     Copyright (C) 2017 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/dcp_content.h"
28
29 using std::cout;
30 using std::string;
31 using boost::shared_ptr;
32 using boost::dynamic_pointer_cast;
33 using boost::optional;
34
35 static int const dcp_lines = 4;
36
37 PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
38         : wxPanel (parent)
39         , _viewer (viewer)
40         , _sizer (new wxBoxSizer (wxHORIZONTAL))
41 {
42         wxFont title_font (*wxNORMAL_FONT);
43         title_font.SetWeight (wxFONTWEIGHT_BOLD);
44
45         _dcp = new wxStaticText*[dcp_lines];
46
47         {
48                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
49                 add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
50                 for (int i = 0; i < dcp_lines; ++i) {
51                         _dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
52                 }
53                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
54         }
55
56         {
57                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
58                 add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
59                 _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
60                 _decode_resolution = add_label_to_sizer(s, this, wxT(""), false, 0);
61                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
62         }
63
64         SetSizerAndFit (_sizer);
65
66         triggered_update ();
67
68         Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
69         _timer.reset (new wxTimer (this));
70         _timer->Start (500);
71 }
72
73 void
74 PlayerInformation::periodic_update ()
75 {
76         checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), _viewer->dropped()));
77 }
78
79 void
80 PlayerInformation::triggered_update ()
81 {
82         shared_ptr<DCPContent> dcp;
83         if (_viewer->film()) {
84                 ContentList content = _viewer->film()->content();
85                 if (content.size() == 1) {
86                         dcp = dynamic_pointer_cast<DCPContent>(content.front());
87                 }
88         }
89
90         if (!dcp) {
91                 checked_set (_dcp[0], _("No DCP loaded."));
92                 for (int r = 1; r < dcp_lines; ++r) {
93                         checked_set (_dcp[r], wxT(""));
94                 }
95                 checked_set (_decode_resolution, wxT(""));
96                 return;
97         }
98
99         int r = 0;
100         checked_set (_dcp[r++], std_to_wx(dcp->name()));
101
102         if (dcp->needs_assets()) {
103                 checked_set (_dcp[r], _("Needs OV"));
104                 return;
105         }
106
107         if (dcp->needs_kdm()) {
108                 checked_set (_dcp[r], _("Needs KDM"));
109                 return;
110         }
111
112         DCPOMATIC_ASSERT (dcp->video);
113
114         checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
115
116         optional<double> vfr;
117         vfr = dcp->video_frame_rate ();
118         DCPOMATIC_ASSERT (vfr);
119
120         string const len = String::compose(
121                 wx_to_std(_("Length: %1 (%2 frames)")),
122                 time_to_hmsf(dcp->full_length(), lrint(*vfr)),
123                 dcp->full_length().frames_round(*vfr)
124                 );
125
126         checked_set (_dcp[r++], std_to_wx(len));
127
128         dcp::Size decode = dcp->video->size();
129         optional<int> reduction = _viewer->dcp_decode_reduction();
130         if (reduction) {
131                 decode.width /= pow(2, *reduction);
132                 decode.height /= pow(2, *reduction);
133         }
134
135         checked_set (_decode_resolution, wxString::Format(_("Decode resolution: %dx%d"), decode.width, decode.height));
136 }