Accessor for ClosedCaptionsDialog.
[dcpomatic.git] / src / wx / markers_dialog.cc
1 /*
2     Copyright (C) 2019 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 #include "markers_dialog.h"
22 #include "wx_util.h"
23 #include "timecode.h"
24 #include "static_text.h"
25 #include "dcpomatic_button.h"
26 #include "check_box.h"
27 #include "film_viewer.h"
28 #include "lib/film.h"
29 #include <dcp/types.h>
30 #include <wx/gbsizer.h>
31 #include <boost/bind.hpp>
32 #include <iostream>
33
34 using std::cout;
35 using boost::bind;
36 using boost::shared_ptr;
37 using boost::weak_ptr;
38 using boost::optional;
39 using dcpomatic::DCPTime;
40
41 class Marker
42 {
43 public:
44         Marker (wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr<Film> film_, weak_ptr<FilmViewer> viewer_, wxString name, dcp::Marker type_)
45                 : film (film_)
46                 , viewer (viewer_)
47                 , type (type_)
48         {
49                 checkbox = new CheckBox(parent, name);
50                 grid->Add (checkbox, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
51                 timecode = new Timecode<DCPTime> (parent);
52                 grid->Add (timecode, wxGBPosition(row, 1));
53                 set_button = new Button (parent, _("Set from current position"));
54                 grid->Add (set_button, wxGBPosition(row, 2));
55
56                 shared_ptr<Film> f = film.lock ();
57                 DCPOMATIC_ASSERT (f);
58
59                 optional<DCPTime> t = f->marker (type);
60                 checkbox->SetValue (static_cast<bool>(t));
61                 if (t) {
62                         timecode->set (*t, f->video_frame_rate());
63                 }
64
65                 set_sensitivity ();
66
67                 set_button->Bind (wxEVT_BUTTON, bind(&Marker::set, this));
68                 checkbox->Bind (wxEVT_CHECKBOX, bind(&Marker::set_sensitivity, this));
69                 timecode->Changed.connect (bind(&Marker::changed, this));
70         }
71
72 private:
73         void set_sensitivity ()
74         {
75                 timecode->Enable (checkbox->GetValue());
76                 set_button->Enable (checkbox->GetValue());
77         }
78
79         void set ()
80         {
81                 shared_ptr<Film> f = film.lock ();
82                 DCPOMATIC_ASSERT (f);
83                 shared_ptr<FilmViewer> v = viewer.lock ();
84                 DCPOMATIC_ASSERT (v);
85                 timecode->set (v->position(), f->video_frame_rate());
86                 changed ();
87         }
88
89         void changed ()
90         {
91                 shared_ptr<Film> f = film.lock ();
92                 DCPOMATIC_ASSERT (f);
93                 if (checkbox->GetValue()) {
94                         f->set_marker (type, timecode->get(f->video_frame_rate()));
95                 } else {
96                         f->unset_marker (type);
97                 }
98         }
99
100         weak_ptr<Film> film;
101         weak_ptr<FilmViewer> viewer;
102         dcp::Marker type;
103         CheckBox* checkbox;
104         Timecode<dcpomatic::DCPTime>* timecode;
105         Button* set_button;
106 };
107
108 MarkersDialog::MarkersDialog (wxWindow* parent, weak_ptr<Film> film, weak_ptr<FilmViewer> viewer)
109         : wxDialog (parent, wxID_ANY, _("Markers"))
110         , _film (film)
111 {
112         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
113         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
114
115         int r = 0;
116         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of composition"), dcp::FFOC)));
117         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of composition"), dcp::LFOC)));
118         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of title credits"), dcp::FFTC)));
119         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of title credits"), dcp::LFTC)));
120         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of intermission"), dcp::FFOI)));
121         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of intermission"), dcp::LFOI)));
122         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of end credits"), dcp::FFEC)));
123         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of end credits"), dcp::LFEC)));
124         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of moving credits"), dcp::FFMC)));
125         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of moving credits"), dcp::LFMC)));
126
127         sizer->Add (grid, 0, wxALL, 8);
128         SetSizerAndFit (sizer);
129 }