timeline: snap pointer and import operations to timebase

If frame rates are mixed, ensures that video doesn't end up falling or ending on half frames which potentially make the entire sequence awkward
This commit is contained in:
itsmattkc
2020-11-25 11:46:41 +11:00
parent c35005d1bf
commit b5cc13c10e
10 changed files with 75 additions and 34 deletions
+25 -5
View File
@@ -469,7 +469,7 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos)
}
// Validate ghosts that are being moved (clips from other track types do NOT get moved)
{
if (track_movement != 0) {
QVector<TimelineViewGhostItem*> validate_track_ghosts = parent()->GetGhostItems();
for (int i=0;i<validate_track_ghosts.size();i++) {
if (validate_track_ghosts.at(i)->GetTrack().type() != drag_track_type_) {
@@ -508,10 +508,11 @@ void PointerTool::ProcessDrag(const TimelineCoordinate &mouse_pos)
// Regenerate tooltip and force it to update (otherwise the tooltip won't move as written in the
// documentation, and could get in the way of the cursor)
rational tooltip_timebase = parent()->GetTimebaseForTrackType(drag_start_.GetTrack().type());
QToolTip::hideText();
QToolTip::showText(QCursor::pos(),
Timecode::timestamp_to_timecode(Timecode::time_to_timestamp(time_movement, parent()->GetToolTipTimebase()),
parent()->GetToolTipTimebase(),
Timecode::timestamp_to_timecode(Timecode::time_to_timestamp(time_movement, tooltip_timebase),
tooltip_timebase,
Core::instance()->GetTimecodeDisplay(),
true),
parent());
@@ -872,6 +873,8 @@ bool PointerTool::AddMovingTransitionsToClipGhost(Block* block,
rational PointerTool::ValidateInTrimming(rational movement)
{
bool first_ghost = true;
foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) {
if (ghost->GetMode() != Timeline::kTrimIn) {
continue;
@@ -880,8 +883,11 @@ rational PointerTool::ValidateInTrimming(rational movement)
rational earliest_in = RATIONAL_MIN;
rational latest_in = ghost->GetOut();
rational ghost_timebase = parent()->GetTimebaseForTrackType(ghost->GetTrack().type());
// If the ghost must be at least one frame in size, limit the latest allowed in point
if (!ghost->CanHaveZeroLength()) {
latest_in -= parent()->timebase();
latest_in -= ghost_timebase;
}
// Clamp adjusted value between the earliest and latest values
@@ -891,6 +897,11 @@ rational PointerTool::ValidateInTrimming(rational movement)
if (clamped != adjusted) {
movement = clamped - ghost->GetIn();
}
if (first_ghost) {
movement = SnapMovementToTimebase(ghost->GetIn(), movement, ghost_timebase);
first_ghost = false;
}
}
return movement;
@@ -898,6 +909,8 @@ rational PointerTool::ValidateInTrimming(rational movement)
rational PointerTool::ValidateOutTrimming(rational movement)
{
bool first_ghost = true;
foreach (TimelineViewGhostItem* ghost, parent()->GetGhostItems()) {
if (ghost->GetMode() != Timeline::kTrimOut) {
continue;
@@ -906,8 +919,10 @@ rational PointerTool::ValidateOutTrimming(rational movement)
// Determine earliest and latest out points
rational earliest_out = ghost->GetIn();
rational ghost_timebase = parent()->GetTimebaseForTrackType(ghost->GetTrack().type());
if (!ghost->CanHaveZeroLength()) {
earliest_out += parent()->timebase();
earliest_out += ghost_timebase;
}
rational latest_out = RATIONAL_MAX;
@@ -919,6 +934,11 @@ rational PointerTool::ValidateOutTrimming(rational movement)
if (clamped != adjusted) {
movement = clamped - ghost->GetOut();
}
if (first_ghost) {
movement = SnapMovementToTimebase(ghost->GetOut(), movement, ghost_timebase);
first_ghost = false;
}
}
return movement;