From: Carl Hetherington Date: Sun, 14 Jun 2015 00:34:55 +0000 (+0100) Subject: Add buttons to set trim from current playhead position (#372). X-Git-Tag: v2.1.3~3 X-Git-Url: https://main.carlh.net/gitweb/?a=commitdiff_plain;h=1420c529d7e196f96ddf9580efdc09fa01c55d58;p=dcpomatic.git Add buttons to set trim from current playhead position (#372). --- diff --git a/ChangeLog b/ChangeLog index 562e3d38e..a81b1589f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-06-14 Carl Hetherington + + * Add buttons to set trim from current `playhead' + position (#372). + 2015-06-13 Carl Hetherington * Version 2.1.2 released. diff --git a/src/tools/dcpomatic.cc b/src/tools/dcpomatic.cc index e3e52d091..5fea90504 100644 --- a/src/tools/dcpomatic.cc +++ b/src/tools/dcpomatic.cc @@ -214,8 +214,8 @@ public: */ wxPanel* overall_panel = new wxPanel (this, wxID_ANY); - _film_editor = new FilmEditor (overall_panel); _film_viewer = new FilmViewer (overall_panel); + _film_editor = new FilmEditor (overall_panel, _film_viewer); JobManagerView* job_manager_view = new JobManagerView (overall_panel); wxBoxSizer* right_sizer = new wxBoxSizer (wxVERTICAL); diff --git a/src/wx/content_panel.cc b/src/wx/content_panel.cc index 0b2700d28..a6d013434 100644 --- a/src/wx/content_panel.cc +++ b/src/wx/content_panel.cc @@ -48,7 +48,7 @@ using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; -ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr f) +ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr f, FilmViewer* viewer) : _timeline_dialog (0) , _film (f) , _generally_sensitive (true) @@ -109,7 +109,7 @@ ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr f) _panels.push_back (_audio_panel); _subtitle_panel = new SubtitlePanel (this); _panels.push_back (_subtitle_panel); - _timing_panel = new TimingPanel (this); + _timing_panel = new TimingPanel (this, viewer); _panels.push_back (_timing_panel); _content->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, boost::bind (&ContentPanel::selection_changed, this)); diff --git a/src/wx/content_panel.h b/src/wx/content_panel.h index 0f5e28ac4..d48ee26c1 100644 --- a/src/wx/content_panel.h +++ b/src/wx/content_panel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,11 +32,12 @@ class TimelineDialog; class FilmEditor; class ContentSubPanel; class Film; +class FilmViewer; class ContentPanel : public boost::noncopyable { public: - ContentPanel (wxNotebook *, boost::shared_ptr); + ContentPanel (wxNotebook *, boost::shared_ptr, FilmViewer* viewer); boost::shared_ptr film () const { return _film; diff --git a/src/wx/film_editor.cc b/src/wx/film_editor.cc index 944ff3572..bbfafa8c5 100644 --- a/src/wx/film_editor.cc +++ b/src/wx/film_editor.cc @@ -17,8 +17,8 @@ */ -/** @file src/film_editor.cc - * @brief A wx widget to edit a film's metadata, and perform various functions. +/** @file src/wx/film_editor.cc + * @brief FilmEditor class. */ #include "lib/film.h" @@ -37,7 +37,7 @@ using std::cout; using boost::shared_ptr; /** @param f Film to edit */ -FilmEditor::FilmEditor (wxWindow* parent) +FilmEditor::FilmEditor (wxWindow* parent, FilmViewer* viewer) : wxPanel (parent) { wxBoxSizer* s = new wxBoxSizer (wxVERTICAL); @@ -45,7 +45,7 @@ FilmEditor::FilmEditor (wxWindow* parent) _main_notebook = new wxNotebook (this, wxID_ANY); s->Add (_main_notebook, 1); - _content_panel = new ContentPanel (_main_notebook, _film); + _content_panel = new ContentPanel (_main_notebook, _film, viewer); _main_notebook->AddPage (_content_panel->panel (), _("Content"), true); _dcp_panel = new DCPPanel (_main_notebook, _film); _main_notebook->AddPage (_dcp_panel->panel (), _("DCP"), false); diff --git a/src/wx/film_editor.h b/src/wx/film_editor.h index 25749fffa..768be9d3c 100644 --- a/src/wx/film_editor.h +++ b/src/wx/film_editor.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,20 +17,19 @@ */ -/** @file src/film_editor.h - * @brief A wx widget to edit a film's metadata, and perform various functions. +/** @file src/wx/film_editor.h + * @brief FilmEditor class. */ +#include "lib/film.h" #include #include -#include "lib/film.h" -class wxSpinCtrl; class wxNotebook; class Film; -class Ratio; class ContentPanel; class DCPPanel; +class FilmViewer; /** @class FilmEditor * @brief A wx widget to edit a film's metadata, and perform various functions. @@ -38,7 +37,7 @@ class DCPPanel; class FilmEditor : public wxPanel { public: - FilmEditor (wxWindow *); + FilmEditor (wxWindow *, FilmViewer* viewer); void set_film (boost::shared_ptr); diff --git a/src/wx/film_viewer.cc b/src/wx/film_viewer.cc index e33a3c118..bdbfc6c03 100644 --- a/src/wx/film_viewer.cc +++ b/src/wx/film_viewer.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2014 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -130,8 +130,7 @@ FilmViewer::set_film (shared_ptr f) _frame.reset (); - _slider->SetValue (0); - set_position_text (); + update_position (); if (!_film) { return; @@ -213,7 +212,7 @@ FilmViewer::get (DCPTime p, bool accurate) _position = p; } - set_position_text (); + update_position (); refresh_panel (); _last_get_accurate = accurate; @@ -223,18 +222,8 @@ void FilmViewer::timer () { get (_position + DCPTime::from_frames (1, _film->video_frame_rate ()), true); - - DCPTime const len = _film->length (); - - if (len.get ()) { - int const new_slider_position = 4096 * _position.get() / len.get(); - if (new_slider_position != _slider->GetValue()) { - _slider->SetValue (new_slider_position); - } - } } - void FilmViewer::paint_panel () { @@ -348,13 +337,23 @@ FilmViewer::check_play_state () } void -FilmViewer::set_position_text () +FilmViewer::update_position () { if (!_film) { + _slider->SetValue (0); _frame_number->SetLabel ("0"); _timecode->SetLabel ("0:0:0.0"); return; } + + DCPTime const len = _film->length (); + + if (len.get ()) { + int const new_slider_position = 4096 * _position.get() / len.get(); + if (new_slider_position != _slider->GetValue()) { + _slider->SetValue (new_slider_position); + } + } double const fps = _film->video_frame_rate (); /* Count frame number from 1 ... not sure if this is the best idea */ diff --git a/src/wx/film_viewer.h b/src/wx/film_viewer.h index e502c6f45..9e4a454ea 100644 --- a/src/wx/film_viewer.h +++ b/src/wx/film_viewer.h @@ -40,6 +40,10 @@ public: void set_film (boost::shared_ptr); + DCPTime position () const { + return _position; + } + private: void paint_panel (); void panel_sized (wxSizeEvent &); @@ -52,7 +56,7 @@ private: void back_clicked (); void forward_clicked (); void player_changed (bool); - void set_position_text (); + void update_position (); void get (DCPTime, bool); void refresh_panel (); void setup_sensitivity (); diff --git a/src/wx/timing_panel.cc b/src/wx/timing_panel.cc index 74c1756a5..03189ecf5 100644 --- a/src/wx/timing_panel.cc +++ b/src/wx/timing_panel.cc @@ -22,8 +22,10 @@ #include "lib/raw_convert.h" #include "timing_panel.h" #include "wx_util.h" +#include "film_viewer.h" #include "timecode.h" #include "content_panel.h" +#include #include using std::cout; @@ -32,9 +34,10 @@ using std::set; using boost::shared_ptr; using boost::dynamic_pointer_cast; -TimingPanel::TimingPanel (ContentPanel* p) +TimingPanel::TimingPanel (ContentPanel* p, FilmViewer* viewer) /* horrid hack for apparent lack of context support with wxWidgets i18n code */ : ContentSubPanel (p, S_("Timing|Timing")) + , _viewer (viewer) { wxFlexGridSizer* grid = new wxFlexGridSizer (2, 4, 4); _sizer->Add (grid, 0, wxALL, 8); @@ -82,9 +85,15 @@ TimingPanel::TimingPanel (ContentPanel* p) add_label_to_sizer (grid, this, _("Trim from start"), true); _trim_start = new Timecode (this); grid->Add (_trim_start); + _trim_start_to_playhead = new wxButton (this, wxID_ANY, _("Trim up to current position")); + grid->AddSpacer (0); + grid->Add (_trim_start_to_playhead); add_label_to_sizer (grid, this, _("Trim from end"), true); _trim_end = new Timecode (this); grid->Add (_trim_end); + _trim_end_to_playhead = new wxButton (this, wxID_ANY, _("Trim after current position")); + grid->AddSpacer (0); + grid->Add (_trim_end_to_playhead); add_label_to_sizer (grid, this, _("Play length"), true); _play_length = new Timecode (this); grid->Add (_play_length); @@ -127,7 +136,9 @@ TimingPanel::TimingPanel (ContentPanel* p) _position->Changed.connect (boost::bind (&TimingPanel::position_changed, this)); _full_length->Changed.connect (boost::bind (&TimingPanel::full_length_changed, this)); _trim_start->Changed.connect (boost::bind (&TimingPanel::trim_start_changed, this)); + _trim_start_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_start_to_playhead_clicked, this)); _trim_end->Changed.connect (boost::bind (&TimingPanel::trim_end_changed, this)); + _trim_end_to_playhead->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::trim_end_to_playhead_clicked, this)); _play_length->Changed.connect (boost::bind (&TimingPanel::play_length_changed, this)); _video_frame_rate->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&TimingPanel::video_frame_rate_changed, this)); _set_video_frame_rate->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimingPanel::set_video_frame_rate, this)); @@ -364,3 +375,26 @@ TimingPanel::film_changed (Film::Property p) update_play_length (); } } + +void +TimingPanel::trim_start_to_playhead_clicked () +{ + DCPTime const ph = _viewer->position (); + BOOST_FOREACH (shared_ptr i, _parent->selected ()) { + if (i->position() < ph && ph < i->end ()) { + i->set_trim_start (i->trim_start() + ph - i->position ()); + } + } +} + +void +TimingPanel::trim_end_to_playhead_clicked () +{ + DCPTime const ph = _viewer->position (); + BOOST_FOREACH (shared_ptr i, _parent->selected ()) { + if (i->position() < ph && ph < i->end ()) { + i->set_trim_end (i->position() + i->full_length() - i->trim_start() - ph); + } + + } +} diff --git a/src/wx/timing_panel.h b/src/wx/timing_panel.h index 5f7095d8c..e300e4975 100644 --- a/src/wx/timing_panel.h +++ b/src/wx/timing_panel.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2013 Carl Hetherington + Copyright (C) 2012-2015 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,10 +20,12 @@ #include "content_sub_panel.h" #include "timecode.h" +class FilmViewer; + class TimingPanel : public ContentSubPanel { public: - TimingPanel (ContentPanel *); + TimingPanel (ContentPanel *, FilmViewer* viewer); void film_changed (Film::Property); void film_content_changed (int); @@ -33,16 +35,22 @@ private: void position_changed (); void full_length_changed (); void trim_start_changed (); + void trim_start_to_playhead_clicked (); void trim_end_changed (); + void trim_end_to_playhead_clicked (); void play_length_changed (); void video_frame_rate_changed (); void set_video_frame_rate (); void update_full_length (); void update_play_length (); + + FilmViewer* _viewer; Timecode* _position; Timecode* _full_length; Timecode* _trim_start; + wxButton* _trim_start_to_playhead; + wxButton* _trim_end_to_playhead; Timecode* _trim_end; Timecode* _play_length; wxTextCtrl* _video_frame_rate;