Primitive dropped frame count in display.
[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 PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
34         : wxPanel (parent)
35         , _viewer (viewer)
36         , _sizer (new wxBoxSizer (wxHORIZONTAL))
37 {
38         wxFont title_font (*wxNORMAL_FONT);
39         title_font.SetWeight (wxFONTWEIGHT_BOLD);
40
41         {
42                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
43                 add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
44                 _cpl_name = add_label_to_sizer(s, this, wxT(""), false, 0);
45                 _size = add_label_to_sizer(s, this, wxT(""), false, 0);
46                 _length = add_label_to_sizer(s, this, wxT(""), false, 0);
47                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
48         }
49
50         {
51                 wxSizer* s = new wxBoxSizer (wxVERTICAL);
52                 add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
53                 _dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
54                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
55         }
56
57         SetSizerAndFit (_sizer);
58
59         triggered_update ();
60
61         Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
62         _timer.reset (new wxTimer (this));
63         _timer->Start (500);
64 }
65
66 void
67 PlayerInformation::periodic_update ()
68 {
69         checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), _viewer->dropped()));
70 }
71
72 void
73 PlayerInformation::triggered_update ()
74 {
75         shared_ptr<DCPContent> dcp;
76         if (_viewer->film()) {
77                 ContentList content = _viewer->film()->content();
78                 if (content.size() == 1) {
79                         dcp = dynamic_pointer_cast<DCPContent>(content.front());
80                 }
81         }
82
83         if (!dcp) {
84                 checked_set (_cpl_name, _("No DCP loaded."));
85                 checked_set (_size, wxT(""));
86                 checked_set (_length, wxT(""));
87                 return;
88         }
89
90         DCPOMATIC_ASSERT (dcp->video);
91
92         checked_set (_cpl_name, std_to_wx(dcp->name()));
93         checked_set (_size, wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
94
95         optional<double> vfr;
96         vfr = dcp->video_frame_rate ();
97         DCPOMATIC_ASSERT (vfr);
98         checked_set (
99                 _length,
100                 wxString::Format(
101                         _("Length: %s (%ld frames)"),
102                         std_to_wx(time_to_hmsf(dcp->full_length(), lrint(*vfr))).data(),
103                         dcp->full_length().frames_round(*vfr)
104                         )
105                 );
106 }