Basics of setting and storing SMPTE CPL markers.
[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
40 class Marker
41 {
42 public:
43         Marker (wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr<Film> film_, weak_ptr<FilmViewer> viewer_, wxString name, dcp::Marker type_)
44                 : film (film_)
45                 , viewer (viewer_)
46                 , type (type_)
47         {
48                 checkbox = new CheckBox(parent, name);
49                 grid->Add (checkbox, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
50                 timecode = new Timecode<DCPTime> (parent);
51                 grid->Add (timecode, wxGBPosition(row, 1));
52                 set_button = new Button (parent, _("Set from current position"));
53                 grid->Add (set_button, wxGBPosition(row, 2));
54
55                 shared_ptr<Film> f = film.lock ();
56                 DCPOMATIC_ASSERT (f);
57
58                 optional<DCPTime> t = f->marker (type);
59                 checkbox->SetValue (static_cast<bool>(t));
60                 if (t) {
61                         timecode->set (*t, f->video_frame_rate());
62                 }
63
64                 set_sensitivity ();
65
66                 set_button->Bind (wxEVT_BUTTON, bind(&Marker::set, this));
67                 checkbox->Bind (wxEVT_CHECKBOX, bind(&Marker::set_sensitivity, this));
68                 timecode->Changed.connect (bind(&Marker::changed, this));
69         }
70
71 private:
72         void set_sensitivity ()
73         {
74                 timecode->Enable (checkbox->GetValue());
75                 set_button->Enable (checkbox->GetValue());
76         }
77
78         void set ()
79         {
80                 shared_ptr<Film> f = film.lock ();
81                 DCPOMATIC_ASSERT (f);
82                 shared_ptr<FilmViewer> v = viewer.lock ();
83                 DCPOMATIC_ASSERT (v);
84                 timecode->set (v->position(), f->video_frame_rate());
85         }
86
87         void changed ()
88         {
89                 shared_ptr<Film> f = film.lock ();
90                 DCPOMATIC_ASSERT (f);
91                 if (checkbox->GetValue()) {
92                         f->set_marker (type, timecode->get(f->video_frame_rate()));
93                 } else {
94                         f->unset_marker (type);
95                 }
96         }
97
98         weak_ptr<Film> film;
99         weak_ptr<FilmViewer> viewer;
100         dcp::Marker type;
101         CheckBox* checkbox;
102         Timecode<DCPTime>* timecode;
103         Button* set_button;
104 };
105
106 MarkersDialog::MarkersDialog (wxWindow* parent, weak_ptr<Film> film, weak_ptr<FilmViewer> viewer)
107         : wxDialog (parent, wxID_ANY, _("Markers"))
108         , _film (film)
109 {
110         wxSizer* sizer = new wxBoxSizer (wxVERTICAL);
111         wxGridBagSizer* grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
112
113         int r = 0;
114         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of composition"), dcp::FFOC)));
115         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of composition"), dcp::LFOC)));
116         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of title credits"), dcp::FFTC)));
117         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of title credits"), dcp::LFTC)));
118         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of intermission"), dcp::FFOI)));
119         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of intermission"), dcp::LFOI)));
120         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of end credits"), dcp::FFEC)));
121         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of end credits"), dcp::LFEC)));
122         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("First frame of moving credits"), dcp::FFMC)));
123         _markers.push_back (shared_ptr<Marker>(new Marker(this, grid, r++, film, viewer, _("Last frame of moving credits"), dcp::LFMC)));
124
125         sizer->Add (grid, 0, wxALL, 8);
126         SetSizerAndFit (sizer);
127 }