Add buttons to set trim from current playhead position (#372).
authorCarl Hetherington <cth@carlh.net>
Sun, 14 Jun 2015 00:34:55 +0000 (01:34 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 14 Jun 2015 00:34:55 +0000 (01:34 +0100)
ChangeLog
src/tools/dcpomatic.cc
src/wx/content_panel.cc
src/wx/content_panel.h
src/wx/film_editor.cc
src/wx/film_editor.h
src/wx/film_viewer.cc
src/wx/film_viewer.h
src/wx/timing_panel.cc
src/wx/timing_panel.h

index 562e3d38e1ef7efbd12b357e2d587fcb66faffcc..a81b1589f46abe731c546c1f0837190a4bbaa972 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2015-06-14  Carl Hetherington  <cth@carlh.net>
+
+       * Add buttons to set trim from current `playhead'
+       position (#372).
+
 2015-06-13  Carl Hetherington  <cth@carlh.net>
 
        * Version 2.1.2 released.
index e3e52d09153346bb4f60e66a0fdc2ff0f9dd3756..5fea90504be49b9a7009224eb36ee903ad3360f3 100644 (file)
@@ -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);
index 0b2700d283376721dffa22b213fc1651658db0ff..a6d0134348f2f45757781c8de72f47695019b4bd 100644 (file)
@@ -48,7 +48,7 @@ using boost::shared_ptr;
 using boost::weak_ptr;
 using boost::dynamic_pointer_cast;
 
-ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> f)
+ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> f, FilmViewer* viewer)
        : _timeline_dialog (0)
        , _film (f)
        , _generally_sensitive (true)
@@ -109,7 +109,7 @@ ContentPanel::ContentPanel (wxNotebook* n, boost::shared_ptr<Film> 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));
index 0f5e28ac491f8317ed30c39a0418c17f3de0ec95..d48ee26c1ded308843bad01ebbcb7ba8e0b46d46 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     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<Film>);
+       ContentPanel (wxNotebook *, boost::shared_ptr<Film>, FilmViewer* viewer);
 
        boost::shared_ptr<Film> film () const {
                return _film;
index 944ff357256e140e7a98efa16a3008bb02288d83..bbfafa8c5595900a15df507036cfa88ec9c6e454 100644 (file)
@@ -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);
index 25749fffaf10ec8d3120ee1f02a442fa31ecde11..768be9d3cd826fd15a2b429e6cac80bdc7bd9527 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     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
 
 */
  
-/** @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 <wx/wx.h>
 #include <boost/signals2.hpp>
-#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<Film>);
 
index e33a3c118dc92eedf9f63bb1b79c88c88d1834d8..bdbfc6c03ea780a6564a3a06b5c5e530ff81a2df 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2014 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     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<Film> 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 */
index e502c6f45cd2922e3d9fe90c32fe7553c67d83a6..9e4a454ea5d40cbae64300b8cbb60499abd8ee1e 100644 (file)
@@ -40,6 +40,10 @@ public:
 
        void set_film (boost::shared_ptr<Film>);
 
+       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 ();
index 74c1756a5205221edc15dbec4fd585a07d833961..03189ecf5fd259be68927273d4d1263c399b1e55 100644 (file)
 #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 <boost/foreach.hpp>
 #include <set>
 
 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<DCPTime> (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<DCPTime> (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<DCPTime> (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<Content> 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<Content> i, _parent->selected ()) {
+               if (i->position() < ph && ph < i->end ()) {
+                       i->set_trim_end (i->position() + i->full_length() - i->trim_start() - ph);
+               }
+               
+       }
+}
index 5f7095d8c369ff2eee2d887e436be178e1886c86..e300e4975cf32b698dca2a1b2b452b9d164070d2 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2012-2013 Carl Hetherington <cth@carlh.net>
+    Copyright (C) 2012-2015 Carl Hetherington <cth@carlh.net>
 
     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
 #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<DCPTime>* _position;
        Timecode<DCPTime>* _full_length;
        Timecode<DCPTime>* _trim_start;
+       wxButton* _trim_start_to_playhead;
+       wxButton* _trim_end_to_playhead;
        Timecode<DCPTime>* _trim_end;
        Timecode<DCPTime>* _play_length;
        wxTextCtrl* _video_frame_rate;