Add DCP size and length to player.
[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                 _sizer->Add (s, 1, wxEXPAND | wxALL, 6);
54         }
55
56         SetSizerAndFit (_sizer);
57
58         update ();
59 }
60
61 void
62 PlayerInformation::update ()
63 {
64         shared_ptr<DCPContent> dcp;
65         if (_viewer->film()) {
66                 ContentList content = _viewer->film()->content();
67                 if (content.size() == 1) {
68                         dcp = dynamic_pointer_cast<DCPContent>(content.front());
69                 }
70         }
71
72         if (!dcp) {
73                 checked_set (_cpl_name, _("No DCP loaded."));
74                 checked_set (_size, wxT(""));
75                 checked_set (_length, wxT(""));
76                 return;
77         }
78
79         DCPOMATIC_ASSERT (dcp->video);
80
81         checked_set (_cpl_name, std_to_wx(dcp->name()));
82         checked_set (_size, wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));
83
84         optional<double> vfr;
85         vfr = dcp->video_frame_rate ();
86         DCPOMATIC_ASSERT (vfr);
87         checked_set (
88                 _length,
89                 wxString::Format(
90                         _("Length: %s (%ld frames)"),
91                         std_to_wx(time_to_hmsf(dcp->full_length(), lrint(*vfr))).data(),
92                         dcp->full_length().frames_round(*vfr)
93                         )
94                 );
95 }