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