summaryrefslogtreecommitdiff
path: root/src/wx
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2018-07-23 01:21:07 +0100
committerCarl Hetherington <cth@carlh.net>2018-07-23 01:21:07 +0100
commitded71cffd18962ebb6b9611a5eb6dfafe9e8e4ec (patch)
tree6da7f5da15b7b4cdeb82f7099b549abf537bf4fa /src/wx
parent07d75f41aed77e340d927cc092dc4e7d74d03897 (diff)
Get ccaps by asking the Player, rather than by listening to its emissions,
which is slightly cleaner and works when subtitles are emitted with an unknown end time. Also add CCAPs to the player.
Diffstat (limited to 'src/wx')
-rw-r--r--src/wx/closed_captions_dialog.cc34
-rw-r--r--src/wx/closed_captions_dialog.h15
-rw-r--r--src/wx/closed_captions_view.cc143
-rw-r--r--src/wx/closed_captions_view.h42
-rw-r--r--src/wx/film_viewer.cc16
-rw-r--r--src/wx/film_viewer.h1
6 files changed, 27 insertions, 224 deletions
diff --git a/src/wx/closed_captions_dialog.cc b/src/wx/closed_captions_dialog.cc
index 3463ac27a..0b2e63035 100644
--- a/src/wx/closed_captions_dialog.cc
+++ b/src/wx/closed_captions_dialog.cc
@@ -18,12 +18,15 @@
*/
-#include "closed_captions_view.h"
+#include "closed_captions_dialog.h"
+#include "lib/text_caption.h"
#include <boost/bind.hpp>
using std::list;
using std::cout;
using std::make_pair;
+using boost::shared_ptr;
+using boost::weak_ptr;
int const ClosedCaptionsDialog::_num_lines = 3;
int const ClosedCaptionsDialog::_num_chars_per_line = 30;
@@ -89,22 +92,14 @@ private:
};
void
-ClosedCaptionsDialog::refresh (DCPTime time)
+ClosedCaptionsDialog::update (DCPTime time)
{
+ shared_ptr<Player> player = _player.lock ();
+ DCPOMATIC_ASSERT (player);
list<TextCaption> to_show;
- list<Caption>::iterator i = _captions.begin ();
- while (i != _captions.end ()) {
- if (time > i->second.to) {
- list<Caption>::iterator tmp = i;
- ++i;
- _captions.erase (tmp);
- } else if (i->second.contains (time)) {
- BOOST_FOREACH (TextCaption j, i->first.text) {
- to_show.push_back (j);
- }
- ++i;
- } else {
- ++i;
+ BOOST_FOREACH (PlayerCaption i, player->closed_captions_for_frame(time)) {
+ BOOST_FOREACH (TextCaption j, i.text) {
+ to_show.push_back (j);
}
}
@@ -126,14 +121,13 @@ ClosedCaptionsDialog::refresh (DCPTime time)
}
void
-ClosedCaptionsDialog::caption (PlayerCaption caption, DCPTimePeriod period)
+ClosedCaptionsDialog::clear ()
{
- _captions.push_back (make_pair (caption, period));
+ Refresh ();
}
void
-ClosedCaptionsDialog::clear ()
+ClosedCaptionsDialog::set_player (weak_ptr<Player> player)
{
- _captions.clear ();
- Refresh ();
+ _player = player;
}
diff --git a/src/wx/closed_captions_dialog.h b/src/wx/closed_captions_dialog.h
index ca19cc95a..a599bc703 100644
--- a/src/wx/closed_captions_dialog.h
+++ b/src/wx/closed_captions_dialog.h
@@ -19,24 +19,25 @@
*/
#include "lib/dcpomatic_time.h"
-#include "lib/player_caption.h"
+#include "lib/player.h"
#include <wx/wx.h>
-class ClosedCaptionsView : public wxDialog
+class Player;
+
+class ClosedCaptionsDialog : public wxDialog
{
public:
- ClosedCaptionsView (wxWindow* parent);
+ ClosedCaptionsDialog (wxWindow* parent);
- void refresh (DCPTime);
- void caption (PlayerCaption, DCPTimePeriod);
+ void update (DCPTime);
void clear ();
+ void set_player (boost::weak_ptr<Player>);
private:
void paint ();
- typedef std::pair<PlayerCaption, DCPTimePeriod> Caption;
- std::list<Caption> _captions;
std::vector<wxString> _lines;
+ boost::weak_ptr<Player> _player;
static int const _num_lines;
static int const _num_chars_per_line;
};
diff --git a/src/wx/closed_captions_view.cc b/src/wx/closed_captions_view.cc
deleted file mode 100644
index be520057b..000000000
--- a/src/wx/closed_captions_view.cc
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- Copyright (C) 2018 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 "closed_captions_view.h"
-#include <boost/bind.hpp>
-
-using std::list;
-using std::cout;
-using std::make_pair;
-
-int const ClosedCaptionsDialog::_num_lines = 3;
-int const ClosedCaptionsDialog::_num_chars_per_line = 30;
-
-ClosedCaptionsDialog::ClosedCaptionsDialog (wxWindow* parent)
- : wxDialog (parent, wxID_ANY, _("Closed captions"), wxDefaultPosition, wxDefaultSize,
-#ifdef DCPOMATIC_OSX
- /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
- the window above all others (and not just our own) it's better than nothing for now.
- */
- wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
-#else
- wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
-#endif
- )
-
-{
- _lines.resize (_num_lines);
- Bind (wxEVT_PAINT, boost::bind (&ClosedCaptionsDialog::paint, this));
-}
-
-void
-ClosedCaptionsDialog::paint ()
-{
- wxPaintDC dc (this);
- dc.SetBackground (*wxBLACK_BRUSH);
- dc.Clear ();
- dc.SetTextForeground (*wxWHITE);
-
- /* Choose a font which fits vertically */
- int const line_height = dc.GetSize().GetHeight() / _num_lines;
- wxFont font (*wxNORMAL_FONT);
- font.SetPixelSize (wxSize (0, line_height * 0.8));
- dc.SetFont (font);
-
- for (int i = 0; i < _num_lines; ++i) {
- if (_lines[i].IsEmpty()) {
- dc.DrawText (wxString::Format("Line %d", i + 1), 8, line_height * i);
- } else {
- dc.DrawText (_lines[i], 8, line_height * i);
- }
- }
-}
-
-class ClosedCaptionSorter
-{
-public:
- bool operator() (TextCaption const & a, TextCaption const & b)
- {
- return from_top(a) < from_top(b);
- }
-
-private:
- float from_top (TextCaption const & c) const
- {
- switch (c.v_align()) {
- case dcp::VALIGN_TOP:
- return c.v_position();
- case dcp::VALIGN_CENTER:
- return c.v_position() + 0.5;
- case dcp::VALIGN_BOTTOM:
- return 1.0 - c.v_position();
- }
- DCPOMATIC_ASSERT (false);
- return 0;
- }
-};
-
-void
-ClosedCaptionsDialog::refresh (DCPTime time)
-{
- list<TextCaption> to_show;
- list<Caption>::iterator i = _captions.begin ();
- while (i != _captions.end ()) {
- if (time > i->second.to) {
- list<Caption>::iterator tmp = i;
- ++i;
- _captions.erase (tmp);
- } else if (i->second.contains (time)) {
- BOOST_FOREACH (TextCaption j, i->first.text) {
- to_show.push_back (j);
- }
- ++i;
- } else {
- ++i;
- }
- }
-
- for (int j = 0; j < _num_lines; ++j) {
- _lines[j] = "";
- }
-
- to_show.sort (ClosedCaptionSorter());
-
- list<TextCaption>::const_iterator j = to_show.begin();
- int k = 0;
- while (j != to_show.end() && k < _num_lines) {
- _lines[k] = j->text();
- ++j;
- ++k;
- }
-
- Refresh ();
-}
-
-void
-ClosedCaptionsDialog::caption (PlayerCaption caption, DCPTimePeriod period)
-{
- _captions.push_back (make_pair (caption, period));
-}
-
-void
-ClosedCaptionsDialog::clear ()
-{
- _captions.clear ();
- Refresh ();
-}
diff --git a/src/wx/closed_captions_view.h b/src/wx/closed_captions_view.h
deleted file mode 100644
index 9469b975c..000000000
--- a/src/wx/closed_captions_view.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- Copyright (C) 2018 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 "lib/dcpomatic_time.h"
-#include "lib/player_caption.h"
-#include <wx/wx.h>
-
-class ClosedCaptionsDialog : public wxDialog
-{
-public:
- ClosedCaptionsDialog (wxWindow* parent);
-
- void refresh (DCPTime);
- void caption (PlayerCaption, DCPTimePeriod);
- void clear ();
-
-private:
- void paint ();
-
- typedef std::pair<PlayerCaption, DCPTimePeriod> Caption;
- std::list<Caption> _captions;
- std::vector<wxString> _lines;
- static int const _num_lines;
- static int const _num_chars_per_line;
-};
diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc
index 9c714b562..651196d3c 100644
--- a/src/wx/film_viewer.cc
+++ b/src/wx/film_viewer.cc
@@ -26,7 +26,7 @@
#include "playhead_to_timecode_dialog.h"
#include "playhead_to_frame_dialog.h"
#include "wx_util.h"
-#include "closed_captions_view.h"
+#include "closed_captions_dialog.h"
#include "lib/film.h"
#include "lib/ratio.h"
#include "lib/util.h"
@@ -203,6 +203,7 @@ FilmViewer::set_film (shared_ptr<Film> film)
if (!_film) {
_player.reset ();
+ _closed_captions_dialog->set_player (_player);
recreate_butler ();
_frame.reset ();
refresh_panel ();
@@ -221,12 +222,13 @@ FilmViewer::set_film (shared_ptr<Film> film)
return;
}
+ _closed_captions_dialog->set_player (_player);
+
_player->set_always_burn_open_captions ();
_player->set_play_referenced ();
_film->Changed.connect (boost::bind (&FilmViewer::film_changed, this, _1));
_player->Changed.connect (boost::bind (&FilmViewer::player_changed, this, _1, _2));
- _player->Caption.connect (boost::bind (&FilmViewer::caption, this, _1, _2, _3));
/* Keep about 1 second's worth of history samples */
_latency_history_count = _film->audio_frame_rate() / _audio_block_size;
@@ -354,7 +356,7 @@ FilmViewer::display_player_video ()
refresh_panel ();
- _closed_captions_dialog->refresh (time());
+ _closed_captions_dialog->update (time());
}
void
@@ -948,11 +950,3 @@ FilmViewer::show_closed_captions ()
{
_closed_captions_dialog->Show();
}
-
-void
-FilmViewer::caption (PlayerCaption c, CaptionType t, DCPTimePeriod p)
-{
- if (t == CAPTION_CLOSED) {
- _closed_captions_dialog->caption (c, p);
- }
-}
diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h
index 6825ef2c0..266509a44 100644
--- a/src/wx/film_viewer.h
+++ b/src/wx/film_viewer.h
@@ -116,7 +116,6 @@ private:
DCPTime time () const;
Frame average_latency () const;
DCPTime one_video_frame () const;
- void caption (PlayerCaption caption, CaptionType type, DCPTimePeriod period);
boost::shared_ptr<Film> _film;
boost::shared_ptr<Player> _player;