Basic ffmpeg film viewer.
[dcpomatic.git] / src / wx / film_viewer.cc
1 /*
2     Copyright (C) 2012 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 /** @file  src/film_viewer.cc
21  *  @brief A wx widget to view a preview of a Film.
22  */
23
24 #include <iostream>
25 #include <iomanip>
26 #include <wx/tglbtn.h>
27 #include "lib/film.h"
28 #include "lib/format.h"
29 #include "lib/util.h"
30 #include "lib/job_manager.h"
31 #include "lib/options.h"
32 #include "lib/subtitle.h"
33 #include "film_viewer.h"
34 #include "wx_util.h"
35 #include "ffmpeg_player.h"
36
37 using std::string;
38 using std::pair;
39 using std::max;
40 using boost::shared_ptr;
41
42 FilmViewer::FilmViewer (shared_ptr<Film> f, wxWindow* p)
43         : wxPanel (p)
44         , _player (new FFmpegPlayer (this))
45 {
46         wxBoxSizer* v_sizer = new wxBoxSizer (wxVERTICAL);
47         SetSizer (v_sizer);
48
49         v_sizer->Add (_player->panel(), 1, wxEXPAND);
50
51         wxBoxSizer* h_sizer = new wxBoxSizer (wxHORIZONTAL);
52         h_sizer->Add (_player->play_button(), 0, wxEXPAND);
53         h_sizer->Add (_player->slider(), 1, wxEXPAND);
54
55         v_sizer->Add (h_sizer, 0, wxEXPAND);
56
57         set_film (_film);
58 }
59
60 void
61 FilmViewer::film_changed (Film::Property p)
62 {
63         ensure_ui_thread ();
64         
65         switch (p) {
66                 
67         case Film::CONTENT:
68                 _player->set_file (_film->content_path ());
69                 break;
70                 
71         case Film::CROP:
72         {
73                 Crop c = _film->crop ();
74                 _player->set_left_crop (c.left);
75                 _player->set_right_crop (c.right);
76                 _player->set_top_crop (c.top);
77                 _player->set_bottom_crop (c.bottom);
78         }
79         break;
80
81         case Film::FORMAT:
82                 if (_film->format()) {
83                         _player->set_ratio (_film->format()->ratio_as_float(_film));
84                 }
85                 break;
86                 
87         default:
88                 break;
89         }
90 }
91
92 void
93 FilmViewer::set_film (shared_ptr<Film> f)
94 {
95         if (_film == f) {
96                 return;
97         }
98         
99         _film = f;
100
101         if (!_film) {
102                 return;
103         }
104
105         _film->Changed.connect (bind (&FilmViewer::film_changed, this, _1));
106         film_changed (Film::CONTENT);
107         film_changed (Film::CROP);
108         film_changed (Film::FORMAT);
109 }