Basic jump to selected subtitle (#1200).
[dcpomatic.git] / src / wx / film_viewer.h
1 /*
2     Copyright (C) 2012-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 /** @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 <RtAudio.h>
28 #include <wx/wx.h>
29
30 class wxToggleButton;
31 class FFmpegPlayer;
32 class Image;
33 class RGBPlusAlphaImage;
34 class PlayerVideo;
35 class Player;
36 class Butler;
37
38 /** @class FilmViewer
39  *  @brief A wx widget to view a preview of a Film.
40  */
41 class FilmViewer : public wxPanel
42 {
43 public:
44         FilmViewer (wxWindow *, bool outline_content = true, bool jump_to_selected = true);
45         ~FilmViewer ();
46
47         void set_film (boost::shared_ptr<Film>);
48         boost::shared_ptr<Film> film () const {
49                 return _film;
50         }
51
52         /** @return our `playhead' position; this may not lie exactly on a frame boundary */
53         DCPTime position () const {
54                 return _video_position;
55         }
56
57         void set_position (DCPTime p);
58         void set_position (boost::shared_ptr<Content> content, ContentTime p);
59         void set_coalesce_player_changes (bool c);
60         void set_dcp_decode_reduction (boost::optional<int> reduction);
61         boost::optional<int> dcp_decode_reduction () const;
62
63         void slow_refresh ();
64         bool quick_refresh ();
65
66         int dropped () const {
67                 return _dropped;
68         }
69
70         void start ();
71         bool stop ();
72         bool playing () const {
73                 return _playing;
74         }
75
76         void back_frame ();
77         void forward_frame ();
78
79         int audio_callback (void* out, unsigned int frames);
80
81         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
82
83 private:
84         void paint_panel ();
85         void panel_sized (wxSizeEvent &);
86         void slider_moved (bool page);
87         void slider_released ();
88         void play_clicked ();
89         void timer ();
90         void calculate_sizes ();
91         void check_play_state ();
92         void active_jobs_changed (boost::optional<std::string>);
93         void rewind_clicked (wxMouseEvent &);
94         void back_clicked (wxKeyboardState& s);
95         void forward_clicked (wxKeyboardState &);
96         void player_changed (int, bool);
97         void update_position_label ();
98         void update_position_slider ();
99         void get ();
100         void display_player_video ();
101         void seek (DCPTime t, bool accurate);
102         void refresh_panel ();
103         void setup_sensitivity ();
104         void film_changed (Film::Property);
105         DCPTime nudge_amount (wxKeyboardState &);
106         void timecode_clicked ();
107         void frame_number_clicked ();
108         void go_to (DCPTime t);
109         void jump_to_selected_clicked ();
110         void recreate_butler ();
111         void config_changed (Config::Property);
112         DCPTime time () const;
113         Frame average_latency () const;
114         DCPTime one_video_frame () const;
115
116         boost::shared_ptr<Film> _film;
117         boost::shared_ptr<Player> _player;
118
119         wxSizer* _v_sizer;
120         /** The area that we put our image in */
121         wxPanel* _panel;
122         wxCheckBox* _outline_content;
123         wxRadioButton* _left_eye;
124         wxRadioButton* _right_eye;
125         wxCheckBox* _jump_to_selected;
126         wxSlider* _slider;
127         wxButton* _rewind_button;
128         wxButton* _back_button;
129         wxButton* _forward_button;
130         wxStaticText* _frame_number;
131         wxStaticText* _timecode;
132         wxToggleButton* _play_button;
133         wxTimer _timer;
134         bool _coalesce_player_changes;
135         std::list<int> _pending_player_changes;
136         bool _slider_being_moved;
137         bool _was_running_before_slider;
138
139         std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> _player_video;
140         boost::shared_ptr<const Image> _frame;
141         DCPTime _video_position;
142         Position<int> _inter_position;
143         dcp::Size _inter_size;
144
145         /** Size of our output (including padding if we have any) */
146         dcp::Size _out_size;
147         /** Size of the panel that we have available */
148         dcp::Size _panel_size;
149
150         RtAudio _audio;
151         int _audio_channels;
152         unsigned int _audio_block_size;
153         bool _playing;
154         boost::shared_ptr<Butler> _butler;
155
156         std::list<Frame> _latency_history;
157         /** Mutex to protect _latency_history */
158         mutable boost::mutex _latency_history_mutex;
159         int _latency_history_count;
160
161         int _dropped;
162         boost::optional<int> _dcp_decode_reduction;
163
164         boost::signals2::scoped_connection _config_changed_connection;
165 };