Separate out management of controls.
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012-2018 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 /** @file  src/film_viewer.h
22  *  @brief A wx widget to view `thumbnails' of a Film.
23  */
24
25 #include "lib/film.h"
26 #include "lib/config.h"
27 #include "lib/player_text.h"
28 #include <RtAudio.h>
29 #include <wx/wx.h>
30
31 class wxToggleButton;
32 class FFmpegPlayer;
33 class Image;
34 class RGBPlusAlphaImage;
35 class PlayerVideo;
36 class Player;
37 class Butler;
38 class ClosedCaptionsDialog;
39
40 /** @class FilmViewer
41  *  @brief A wx widget to view a preview of a Film.
42  */
43 class FilmViewer
44 {
45 public:
46         FilmViewer (wxWindow *);
47         ~FilmViewer ();
48
49         wxPanel* panel () const {
50                 return _panel;
51         }
52
53         void set_film (boost::shared_ptr<Film>);
54         boost::shared_ptr<Film> film () const {
55                 return _film;
56         }
57
58         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
59         DCPTime position () const {
60                 return _video_position;
61         }
62
63         void set_position (DCPTime p);
64         void set_position (boost::shared_ptr<Content> content, ContentTime p);
65         void set_coalesce_player_changes (bool c);
66         void set_dcp_decode_reduction (boost::optional<int> reduction);
67         boost::optional<int> dcp_decode_reduction () const;
68
69         void slow_refresh ();
70         bool quick_refresh ();
71
72         int dropped () const {
73                 return _dropped;
74         }
75
76         void start ();
77         bool stop ();
78         bool playing () const {
79                 return _playing;
80         }
81
82         void move (DCPTime by);
83         DCPTime one_video_frame () const;
84         void seek (DCPTime t, bool accurate);
85         DCPTime video_position () const {
86                 return _video_position;
87         }
88         void go_to (DCPTime t);
89         void set_outline_content (bool o);
90         void set_eyes (Eyes e);
91
92         int audio_callback (void* out, unsigned int frames);
93
94         void show_closed_captions ();
95
96         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
97         boost::signals2::signal<void ()> PositionChanged;
98         boost::signals2::signal<void ()> Started;
99         boost::signals2::signal<void ()> Stopped;
100         boost::signals2::signal<void ()> FilmChanged;
101
102 private:
103         void paint_panel ();
104         void panel_sized (wxSizeEvent &);
105         void timer ();
106         void calculate_sizes ();
107         void check_play_state ();
108         void player_change (ChangeType type, int, bool);
109         void get ();
110         void display_player_video ();
111         void film_change (ChangeType, Film::Property);
112         void timecode_clicked ();
113         void recreate_butler ();
114         void config_changed (Config::Property);
115         DCPTime time () const;
116         DCPTime uncorrected_time () const;
117         Frame average_latency () const;
118         void refresh_panel ();
119
120         boost::shared_ptr<Film> _film;
121         boost::shared_ptr<Player> _player;
122
123         /** The area that we put our image in */
124         wxPanel* _panel;
125         wxTimer _timer;
126         bool _coalesce_player_changes;
127         std::list<int> _pending_player_changes;
128
129         std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> _player_video;
130         boost::shared_ptr<const Image> _frame;
131         DCPTime _video_position;
132         Position<int> _inter_position;
133         dcp::Size _inter_size;
134
135         /** Size of our output (including padding if we have any) */
136         dcp::Size _out_size;
137         /** Size of the panel that we have available */
138         dcp::Size _panel_size;
139
140         RtAudio _audio;
141         int _audio_channels;
142         unsigned int _audio_block_size;
143         bool _playing;
144         boost::shared_ptr<Butler> _butler;
145
146         std::list<Frame> _latency_history;
147         /** Mutex to protect _latency_history */
148         mutable boost::mutex _latency_history_mutex;
149         int _latency_history_count;
150
151         int _dropped;
152         boost::optional<int> _dcp_decode_reduction;
153
154         ClosedCaptionsDialog* _closed_captions_dialog;
155
156         bool _outline_content;
157         Eyes _eyes;
158
159         boost::signals2::scoped_connection _config_changed_connection;
160 };