Add space shortcut to start/stop playback (#1201).
[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_coalesce_player_changes (bool c);
59         void set_dcp_decode_reduction (boost::optional<int> reduction);
60         boost::optional<int> dcp_decode_reduction () const;
61
62         void slow_refresh ();
63         bool quick_refresh ();
64
65         int dropped () const {
66                 return _dropped;
67         }
68
69         void start ();
70         bool stop ();
71         bool playing () const {
72                 return _playing;
73         }
74
75         int audio_callback (void* out, unsigned int frames);
76
77         boost::signals2::signal<void (boost::weak_ptr<PlayerVideo>)> ImageChanged;
78
79 private:
80         void paint_panel ();
81         void panel_sized (wxSizeEvent &);
82         void slider_moved (bool page);
83         void slider_released ();
84         void play_clicked ();
85         void timer ();
86         void calculate_sizes ();
87         void check_play_state ();
88         void active_jobs_changed (boost::optional<std::string>);
89         void rewind_clicked (wxMouseEvent &);
90         void back_clicked (wxMouseEvent &);
91         void forward_clicked (wxMouseEvent &);
92         void player_changed (int, bool);
93         void update_position_label ();
94         void update_position_slider ();
95         void get ();
96         void display_player_video ();
97         void seek (DCPTime t, bool accurate);
98         void refresh_panel ();
99         void setup_sensitivity ();
100         void film_changed (Film::Property);
101         DCPTime nudge_amount (wxMouseEvent &);
102         void timecode_clicked ();
103         void frame_number_clicked ();
104         void go_to (DCPTime t);
105         void jump_to_selected_clicked ();
106         void recreate_butler ();
107         void config_changed (Config::Property);
108         DCPTime time () const;
109         Frame average_latency () const;
110         DCPTime one_video_frame () const;
111
112         boost::shared_ptr<Film> _film;
113         boost::shared_ptr<Player> _player;
114
115         wxSizer* _v_sizer;
116         /** The area that we put our image in */
117         wxPanel* _panel;
118         wxCheckBox* _outline_content;
119         wxRadioButton* _left_eye;
120         wxRadioButton* _right_eye;
121         wxCheckBox* _jump_to_selected;
122         wxSlider* _slider;
123         wxButton* _rewind_button;
124         wxButton* _back_button;
125         wxButton* _forward_button;
126         wxStaticText* _frame_number;
127         wxStaticText* _timecode;
128         wxToggleButton* _play_button;
129         wxTimer _timer;
130         bool _coalesce_player_changes;
131         std::list<int> _pending_player_changes;
132         bool _slider_being_moved;
133         bool _was_running_before_slider;
134
135         std::pair<boost::shared_ptr<PlayerVideo>, DCPTime> _player_video;
136         boost::shared_ptr<const Image> _frame;
137         DCPTime _video_position;
138         Position<int> _inter_position;
139         dcp::Size _inter_size;
140
141         /** Size of our output (including padding if we have any) */
142         dcp::Size _out_size;
143         /** Size of the panel that we have available */
144         dcp::Size _panel_size;
145
146         RtAudio _audio;
147         int _audio_channels;
148         unsigned int _audio_block_size;
149         bool _playing;
150         boost::shared_ptr<Butler> _butler;
151
152         std::list<Frame> _latency_history;
153         /** Mutex to protect _latency_history */
154         mutable boost::mutex _latency_history_mutex;
155         int _latency_history_count;
156
157         int _dropped;
158         boost::optional<int> _dcp_decode_reduction;
159
160         boost::signals2::scoped_connection _config_changed_connection;
161 };