2 Copyright (C) 2019-2021 Carl Hetherington <cth@carlh.net>
4 This file is part of DCP-o-matic.
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.
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.
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/>.
22 #include "check_box.h"
23 #include "dcpomatic_button.h"
24 #include "film_viewer.h"
25 #include "markers_dialog.h"
26 #include "static_text.h"
30 #include <dcp/types.h>
31 #include <wx/gbsizer.h>
32 #include <boost/bind/bind.hpp>
35 using std::make_shared;
36 using std::shared_ptr;
39 using boost::optional;
40 using dcpomatic::DCPTime;
46 Marker (wxWindow* parent, wxGridBagSizer* grid, int row, weak_ptr<Film> film_, weak_ptr<FilmViewer> viewer_, wxString name, dcp::Marker type_)
51 checkbox = new CheckBox(parent, name);
52 grid->Add (checkbox, wxGBPosition(row, 0), wxDefaultSpan, wxALIGN_CENTER_VERTICAL);
53 timecode = new Timecode<DCPTime> (parent);
54 grid->Add (timecode, wxGBPosition(row, 1));
55 set_button = new Button (parent, _("Set from current position"));
56 grid->Add (set_button, wxGBPosition(row, 2));
58 auto f = film.lock ();
61 auto t = f->marker (type);
62 checkbox->SetValue (static_cast<bool>(t));
64 timecode->set (*t, f->video_frame_rate());
69 set_button->Bind (wxEVT_BUTTON, bind(&Marker::set, this));
70 checkbox->Bind (wxEVT_CHECKBOX, bind(&Marker::checkbox_clicked, this));
71 timecode->Changed.connect (bind(&Marker::changed, this));
75 void checkbox_clicked ()
81 void set_sensitivity ()
83 timecode->Enable (checkbox->GetValue());
84 set_button->Enable (checkbox->GetValue());
89 auto f = film.lock ();
91 auto v = viewer.lock ();
93 timecode->set (v->position(), f->video_frame_rate());
99 auto f = film.lock ();
100 DCPOMATIC_ASSERT (f);
101 auto vfr = f->video_frame_rate();
102 auto tc = timecode->get(vfr);
103 if (tc >= f->length()) {
104 tc = f->length() - DCPTime::from_frames(1, vfr);
105 timecode->set (tc, vfr);
107 if (checkbox->GetValue()) {
108 f->set_marker (type, tc);
110 f->unset_marker (type);
115 weak_ptr<FilmViewer> viewer;
118 Timecode<dcpomatic::DCPTime>* timecode;
123 MarkersDialog::MarkersDialog (wxWindow* parent, weak_ptr<Film> film, weak_ptr<FilmViewer> viewer)
124 : wxDialog (parent, wxID_ANY, _("Markers"))
127 auto sizer = new wxBoxSizer (wxVERTICAL);
128 auto grid = new wxGridBagSizer (DCPOMATIC_SIZER_X_GAP, DCPOMATIC_SIZER_Y_GAP);
131 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("First frame of composition"), dcp::Marker::FFOC));
132 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("Last frame of composition"), dcp::Marker::LFOC));
133 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("First frame of title credits"), dcp::Marker::FFTC));
134 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("Last frame of title credits"), dcp::Marker::LFTC));
135 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("First frame of intermission"), dcp::Marker::FFOI));
136 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("Last frame of intermission"), dcp::Marker::LFOI));
137 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("First frame of end credits"), dcp::Marker::FFEC));
138 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("Last frame of end credits"), dcp::Marker::LFEC));
139 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("First frame of moving credits"), dcp::Marker::FFMC));
140 _markers.push_back (make_shared<Marker>(this, grid, r++, film, viewer, _("Last frame of moving credits"), dcp::Marker::LFMC));
142 sizer->Add (grid, 0, wxALL, 8);
144 auto buttons = CreateSeparatedButtonSizer (wxCLOSE);
146 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
149 SetSizerAndFit (sizer);