summaryrefslogtreecommitdiff
path: root/src/wx/player_information.cc
blob: 1b3d2809bbb286e212c54f5cb16cafb5e0589b89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
    Copyright (C) 2017 Carl Hetherington <cth@carlh.net>

    This file is part of DCP-o-matic.

    DCP-o-matic is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    DCP-o-matic is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "player_information.h"
#include "wx_util.h"
#include "film_viewer.h"
#include "lib/playlist.h"
#include "lib/video_content.h"
#include "lib/dcp_content.h"

using std::cout;
using boost::shared_ptr;
using boost::dynamic_pointer_cast;
using boost::optional;

static int const dcp_lines = 4;

PlayerInformation::PlayerInformation (wxWindow* parent, FilmViewer* viewer)
	: wxPanel (parent)
	, _viewer (viewer)
	, _sizer (new wxBoxSizer (wxHORIZONTAL))
{
	wxFont title_font (*wxNORMAL_FONT);
	title_font.SetWeight (wxFONTWEIGHT_BOLD);

	_dcp = new wxStaticText*[dcp_lines];

	{
		wxSizer* s = new wxBoxSizer (wxVERTICAL);
		add_label_to_sizer(s, this, _("DCP"), false, 0)->SetFont(title_font);
		for (int i = 0; i < dcp_lines; ++i) {
			_dcp[i] = add_label_to_sizer(s, this, wxT(""), false, 0);
		}
		_sizer->Add (s, 1, wxEXPAND | wxALL, 6);
	}

	{
		wxSizer* s = new wxBoxSizer (wxVERTICAL);
		add_label_to_sizer(s, this, _("Performance"), false, 0)->SetFont(title_font);
		_dropped = add_label_to_sizer(s, this, wxT(""), false, 0);
		_sizer->Add (s, 1, wxEXPAND | wxALL, 6);
	}

	SetSizerAndFit (_sizer);

	triggered_update ();

	Bind (wxEVT_TIMER, boost::bind (&PlayerInformation::periodic_update, this));
	_timer.reset (new wxTimer (this));
	_timer->Start (500);
}

void
PlayerInformation::periodic_update ()
{
	checked_set (_dropped, wxString::Format(_("Dropped frames: %d"), _viewer->dropped()));
}

void
PlayerInformation::triggered_update ()
{
	shared_ptr<DCPContent> dcp;
	if (_viewer->film()) {
		ContentList content = _viewer->film()->content();
		if (content.size() == 1) {
			dcp = dynamic_pointer_cast<DCPContent>(content.front());
		}
	}

	if (!dcp) {
		checked_set (_dcp[0], _("No DCP loaded."));
		for (int r = 1; r < dcp_lines; ++r) {
			checked_set (_dcp[r], wxT(""));
		}
		return;
	}

	int r = 0;
	checked_set (_dcp[r++], std_to_wx(dcp->name()));

	if (dcp->needs_assets()) {
		checked_set (_dcp[r], _("Needs OV"));
		return;
	}

	if (dcp->needs_kdm()) {
		checked_set (_dcp[r], _("Needs KDM"));
		return;
	}

	DCPOMATIC_ASSERT (dcp->video);

	checked_set (_dcp[r++], wxString::Format(_("Size: %dx%d"), dcp->video->size().width, dcp->video->size().height));

	optional<double> vfr;
	vfr = dcp->video_frame_rate ();
	DCPOMATIC_ASSERT (vfr);
	checked_set (
		_dcp[r++],
		wxString::Format(
			_("Length: %s (%ld frames)"),
			std_to_wx(time_to_hmsf(dcp->full_length(), lrint(*vfr))).data(),
			dcp->full_length().frames_round(*vfr)
			)
		);
}