Fix non-frame-aligned trims when using trim-to-playhead.
[dcpomatic.git] / src / wx / timing_panel.cc
index bd4177ffbaaae51f21926b9c3ebaedd31be44dfd..d7ed46f467eca85192d6b6c355cf375830a72d9b 100644 (file)
@@ -441,14 +441,15 @@ TimingPanel::film_changed (Film::Property p)
 void
 TimingPanel::trim_start_to_playhead_clicked ()
 {
-       DCPTime const ph = _viewer->position ();
+       shared_ptr<const Film> film = _parent->film ();
+       DCPTime const ph = _viewer->position().floor (film->video_frame_rate ());
        optional<DCPTime> new_ph;
 
        _viewer->set_coalesce_player_changes (true);
 
        BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
                if (i->position() < ph && ph < i->end ()) {
-                       FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
+                       FrameRateChange const frc = film->active_frame_rate_change (i->position ());
                        i->set_trim_start (i->trim_start() + ContentTime (ph - i->position (), frc));
                        new_ph = i->position ();
                }
@@ -464,10 +465,11 @@ TimingPanel::trim_start_to_playhead_clicked ()
 void
 TimingPanel::trim_end_to_playhead_clicked ()
 {
-       DCPTime const ph = _viewer->position ();
+       shared_ptr<const Film> film = _parent->film ();
+       DCPTime const ph = _viewer->position().floor (film->video_frame_rate ());
        BOOST_FOREACH (shared_ptr<Content> i, _parent->selected ()) {
                if (i->position() < ph && ph < i->end ()) {
-                       FrameRateChange const frc = _parent->film()->active_frame_rate_change (i->position ());
+                       FrameRateChange const frc = film->active_frame_rate_change (i->position ());
                        i->set_trim_end (ContentTime (i->position() + i->full_length() - ph - DCPTime::from_frames (1, frc.dcp), frc) - i->trim_start());
                }
        }