enable ripple deleting

This commit is contained in:
itsmattkc
2019-04-06 16:12:07 +11:00
parent 9833634815
commit 8ed09cdccf
10 changed files with 137 additions and 124 deletions
+3 -2
View File
@@ -27,8 +27,9 @@ CrossDissolveTransition::CrossDissolveTransition(Clip* c, Clip* s, const EffectM
} }
void CrossDissolveTransition::process_coords(double progress, GLTextureCoords& coords, int data) { void CrossDissolveTransition::process_coords(double progress, GLTextureCoords& coords, int data) {
if (!(data == kTransitionClosing && secondary_clip != nullptr)) { if (data == kTransitionClosing) {
if (data == kTransitionClosing) progress = 1.0 - progress; coords.opacity *= (1.0 - progress);
} else {
coords.opacity *= progress; coords.opacity *= progress;
} }
} }
+10 -5
View File
@@ -628,22 +628,27 @@ void Timeline::copy(bool del) {
} }
void Timeline::ripple_delete() { void Timeline::ripple_delete() {
if (sequence_ != nullptr) { if (sequence_ != nullptr) {
QVector<Selection> selections = sequence_->Selections(); QVector<Selection> selections = sequence_->Selections();
if (selections.isEmpty()) { if (!selections.isEmpty()) {
sequence_->RippleDeleteEmptySpace(cursor_track, cursor_frame);
} else if (olive::config.hover_focus && get_focused_panel() == this) {
ComboAction* ca = new ComboAction(); ComboAction* ca = new ComboAction();
sequence_->DeleteAreas(ca, selections, true, true); sequence_->DeleteAreas(ca, selections, true, true);
olive::undo_stack.push(ca); olive::undo_stack.push(ca);
} else if (olive::config.hover_focus && get_focused_panel() == this) {
ComboAction* ca = new ComboAction();
sequence_->RippleDeleteEmptySpace(ca, cursor_track, cursor_frame);
olive::undo_stack.push(ca);
} }
} }
repaint_timeline();
} }
void Timeline::ripple_delete_empty_space() void Timeline::ripple_delete_empty_space()
+7
View File
@@ -1,5 +1,12 @@
#include "ghost.h" #include "ghost.h"
Ghost::Ghost() :
transition(nullptr),
track_movement(0),
clip(nullptr)
{
}
Selection Ghost::ToSelection() const Selection Ghost::ToSelection() const
{ {
return Selection(in, out, track->Sibling(track_movement)); return Selection(in, out, track->Sibling(track_movement));
+2
View File
@@ -17,6 +17,8 @@ enum TrimType {
} }
struct Ghost { struct Ghost {
Ghost();
Clip* clip; Clip* clip;
long in; long in;
+39 -44
View File
@@ -628,6 +628,10 @@ void Sequence::Split()
void Sequence::DeleteAreas(ComboAction* ca, QVector<Selection> areas, bool deselect_areas, bool ripple) void Sequence::DeleteAreas(ComboAction* ca, QVector<Selection> areas, bool deselect_areas, bool ripple)
{ {
if (areas.isEmpty()) {
return;
}
Selection::Tidy(areas); Selection::Tidy(areas);
panel_graph_editor->set_row(nullptr); panel_graph_editor->set_row(nullptr);
@@ -690,16 +694,22 @@ void Sequence::DeleteAreas(ComboAction* ca, QVector<Selection> areas, bool desel
} }
// deselect selected clip areas // deselect selected clip areas
long minimum_in = LONG_MAX;
long minimum_length = LONG_MAX;
if (deselect_areas) { if (deselect_areas) {
QVector<Selection> area_copy = areas; QVector<Selection> area_copy = areas;
for (int i=0;i<area_copy.size();i++) { for (int i=0;i<area_copy.size();i++) {
const Selection& s = area_copy.at(i); const Selection& s = area_copy.at(i);
s.track()->DeselectArea(s.in(), s.out()); s.track()->DeselectArea(s.in(), s.out());
// Get ripple point and ripple length
minimum_in = qMin(minimum_in, s.in());
minimum_length = qMin(minimum_length, s.in() - s.out());
} }
} }
if (ripple) { if (ripple) {
RippleDeleteArea(ca, minimum_in, minimum_length);
} }
olive::timeline::RelinkClips(pre_clips, post_clips); olive::timeline::RelinkClips(pre_clips, post_clips);
@@ -776,7 +786,7 @@ bool Sequence::SplitClipAtPositions(ComboAction *ca, Clip* clip, QVector<long> p
return split_occurred; return split_occurred;
} }
void Sequence::RippleDeleteEmptySpace(Track* track, long point) void Sequence::RippleDeleteEmptySpace(ComboAction* ca, Track* track, long point)
{ {
QVector<Clip*> track_clips = track->GetAllClips(); QVector<Clip*> track_clips = track->GetAllClips();
@@ -805,6 +815,11 @@ void Sequence::RippleDeleteEmptySpace(Track* track, long point)
// We now know the maximum ripple we could do to clear this empty space, but we need to ensure it won't cause // We now know the maximum ripple we could do to clear this empty space, but we need to ensure it won't cause
// overlaps of clips in other tracks // overlaps of clips in other tracks
RippleDeleteArea(ca, point, ripple_end - ripple_start);
}
void Sequence::RippleDeleteArea(ComboAction* ca, long ripple_point, long ripple_length) {
for (int i=0;i<track_lists_.size();i++) { for (int i=0;i<track_lists_.size();i++) {
TrackList* tl = track_lists_.at(i); TrackList* tl = track_lists_.at(i);
@@ -812,66 +827,46 @@ void Sequence::RippleDeleteEmptySpace(Track* track, long point)
Track* t = tl->TrackAt(j); Track* t = tl->TrackAt(j);
// We've already tested `track`, so we don't need to test it again // We've already tested `track`, so we don't need to test it again
if (t != track) { long first_in_point_after_point = LONG_MAX;
long out_point_just_before_first_in_point = LONG_MIN;
long first_in_point_after_point = LONG_MAX; QVector<Clip*> track_clips = t->GetAllClips();
long out_point_just_before_first_in_point = LONG_MIN;
QVector<Clip*> track_clips = t->GetAllClips(); // Find the in point of the clip directly after the point
for (int k=0;k<track_clips.size();k++) {
Clip* c = track_clips.at(k);
// Find the in point of the clip directly after the point if (c->timeline_in() >= ripple_point) {
first_in_point_after_point = qMin(first_in_point_after_point, c->timeline_in());
}
}
// Ensure we found a valid in point before proceeding
if (first_in_point_after_point != LONG_MAX) {
// Find the out point of the clip directly before the clip found above
for (int k=0;k<track_clips.size();k++) { for (int k=0;k<track_clips.size();k++) {
Clip* c = track_clips.at(k); Clip* c = track_clips.at(k);
if (c->timeline_in() > point) { if (c->timeline_out() <= first_in_point_after_point) {
first_in_point_after_point = qMin(first_in_point_after_point, c->timeline_in()); out_point_just_before_first_in_point = qMax(out_point_just_before_first_in_point, c->timeline_out());
} }
} }
// Ensure we found a valid in point before proceeding long ripple_test = first_in_point_after_point - out_point_just_before_first_in_point + ripple_length;
if (first_in_point_after_point != LONG_MAX) {
// Find the out point of the clip directly before the clip found above if (ripple_test < 0) {
for (int k=0;k<track_clips.size();k++) { ripple_length -= ripple_test;
Clip* c = track_clips.at(k);
if (c->timeline_out() < first_in_point_after_point) {
out_point_just_before_first_in_point = qMax(out_point_just_before_first_in_point, c->timeline_out());
}
}
long gap_between_clips = first_in_point_after_point - out_point_just_before_first_in_point;
if (gap_between_clips > (ripple_end - ripple_start)) {
ripple_end = ripple_start + gap_between_clips;
}
} }
} }
} }
} }
if (ripple_start != ripple_end) { if (ripple_length != 0) {
ComboAction* ca = new ComboAction(); Ripple(ca, ripple_point, ripple_length);
Ripple(ca, ripple_start, ripple_start - ripple_end);
olive::undo_stack.push(ca);
}
}
/*
QVector<int> Sequence::SelectedClipIndexes()
{
QVector<int> selected_clips;
for (int i=0;i<clips.size();i++) {
Clip* c = clips.at(i).get();
if (c != nullptr && IsClipSelected(c, true)) {
selected_clips.append(i);
}
} }
return selected_clips;
} }
*/
Effect *Sequence::GetSelectedGizmo() Effect *Sequence::GetSelectedGizmo()
{ {
+2 -1
View File
@@ -94,7 +94,8 @@ public:
bool SplitAllClipsAtPoint(ComboAction *ca, long point); bool SplitAllClipsAtPoint(ComboAction *ca, long point);
bool SplitClipAtPositions(ComboAction* ca, Clip *clip, QVector<long> positions, bool relink = true); bool SplitClipAtPositions(ComboAction* ca, Clip *clip, QVector<long> positions, bool relink = true);
void RippleDeleteEmptySpace(Track *track, long point); void RippleDeleteEmptySpace(ComboAction *ca, Track *track, long point);
void RippleDeleteArea(ComboAction* ca, long ripple_point, long ripple_length);
Effect* GetSelectedGizmo(); Effect* GetSelectedGizmo();
+1 -1
View File
@@ -210,7 +210,7 @@ void FocusFilter::delete_function() {
ComboAction* ca = new ComboAction(); ComboAction* ca = new ComboAction();
top_sequence->DeleteAreas(ca, top_sequence->Selections(), true); top_sequence->DeleteAreas(ca, top_sequence->Selections(), true);
olive::undo_stack.push(ca); olive::undo_stack.push(ca);
Timeline::GetTopTimeline()->repaint_timeline(); update_ui(false);
} }
} }
} }
+42 -46
View File
@@ -647,14 +647,12 @@ void TimelineView::mousePressEvent(QMouseEvent *event) {
g.in = g.old_in = g.out = g.old_out = ParentTimeline()->drag_frame_start; g.in = g.old_in = g.out = g.old_out = ParentTimeline()->drag_frame_start;
g.track = ParentTimeline()->drag_track_start; g.track = ParentTimeline()->drag_track_start;
g.track_movement = 0;
if (g.track == nullptr) { if (g.track == nullptr) {
g.track = track_list_->Last(); g.track = track_list_->Last();
g.track_movement = getTrackIndexFromScreenPoint(event->pos().x()) - g.track->Index(); ParentTimeline()->drag_track_start = track_list_->Last();
g.track_movement = getTrackIndexFromScreenPoint(event->pos().y()) - g.track->Index();
} }
g.transition = nullptr;
g.clip = nullptr;
g.trim_type = olive::timeline::TRIM_OUT; g.trim_type = olive::timeline::TRIM_OUT;
ParentTimeline()->ghosts.append(g); ParentTimeline()->ghosts.append(g);
@@ -1010,7 +1008,7 @@ void TimelineView::mouseReleaseEvent(QMouseEvent *event) {
panel_sequence_viewer->cue_recording(qMin(g.in, g.out), qMax(g.in, g.out), g.track); panel_sequence_viewer->cue_recording(qMin(g.in, g.out), qMax(g.in, g.out), g.track);
ParentTimeline()->creating = false; ParentTimeline()->creating = false;
} else if (g.in != g.out) { } else if (g.in != g.out) {
ClipPtr c = std::make_shared<Clip>(g.track); ClipPtr c = std::make_shared<Clip>(g.track->Sibling(g.track_movement));
c->set_media(nullptr, 0); c->set_media(nullptr, 0);
c->set_timeline_in(qMin(g.in, g.out)); c->set_timeline_in(qMin(g.in, g.out));
c->set_timeline_out(qMax(g.in, g.out)); c->set_timeline_out(qMax(g.in, g.out));
@@ -1097,6 +1095,7 @@ void TimelineView::mouseReleaseEvent(QMouseEvent *event) {
} }
if (process_moving) { if (process_moving) {
const Ghost& first_ghost = ParentTimeline()->ghosts.at(0); const Ghost& first_ghost = ParentTimeline()->ghosts.at(0);
// start a ripple movement // start a ripple movement
@@ -1462,7 +1461,16 @@ void TimelineView::mouseReleaseEvent(QMouseEvent *event) {
} }
} }
} }
// move selections to match new ghosts
QVector<Selection> new_selections;
for (int i=0;i<ParentTimeline()->ghosts.size();i++) {
new_selections.append(ParentTimeline()->ghosts.at(i).ToSelection());
}
ca->append(new SetSelectionsCommand(sequence(), sequence()->Selections(), new_selections));
push_undo = true; push_undo = true;
} }
} else if (ParentTimeline()->selecting || ParentTimeline()->rect_select_proc) { } else if (ParentTimeline()->selecting || ParentTimeline()->rect_select_proc) {
} else if (ParentTimeline()->transition_tool_proc) { } else if (ParentTimeline()->transition_tool_proc) {
@@ -1561,7 +1569,6 @@ void TimelineView::init_ghosts() {
Clip* c = g.clip; Clip* c = g.clip;
g.track = c->track(); g.track = c->track();
g.track_movement = 0;
g.clip_in = g.old_clip_in = c->clip_in(); g.clip_in = g.old_clip_in = c->clip_in();
if (olive::timeline::current_tool == olive::timeline::TIMELINE_TOOL_SLIP) { if (olive::timeline::current_tool == olive::timeline::TIMELINE_TOOL_SLIP) {
@@ -1632,7 +1639,6 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
int effective_tool = olive::timeline::current_tool; int effective_tool = olive::timeline::current_tool;
if (ParentTimeline()->importing || ParentTimeline()->creating) effective_tool = olive::timeline::TIMELINE_TOOL_POINTER; if (ParentTimeline()->importing || ParentTimeline()->creating) effective_tool = olive::timeline::TIMELINE_TOOL_POINTER;
Track* mouse_track = getTrackFromScreenPoint(mouse_pos.y());
long frame_diff = (lock_frame) ? 0 : ParentTimeline()->getTimelineFrameFromScreenPoint(mouse_pos.x()) - ParentTimeline()->drag_frame_start; long frame_diff = (lock_frame) ? 0 : ParentTimeline()->getTimelineFrameFromScreenPoint(mouse_pos.x()) - ParentTimeline()->drag_frame_start;
long validator; long validator;
long earliest_in_point = LONG_MAX; long earliest_in_point = LONG_MAX;
@@ -1918,7 +1924,6 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
g.out = g.old_out + ghost_diff; g.out = g.old_out + ghost_diff;
} }
} else if (clips_are_movable) { } else if (clips_are_movable) {
g.track_movement = 0;
g.in = g.old_in + frame_diff; g.in = g.old_in + frame_diff;
g.out = g.old_out + frame_diff; g.out = g.old_out + frame_diff;
@@ -1931,7 +1936,7 @@ void TimelineView::update_ghosts(const QPoint& mouse_pos, bool lock_frame) {
g.track_movement = getTrackIndexFromScreenPoint(mouse_pos.y()); g.track_movement = getTrackIndexFromScreenPoint(mouse_pos.y());
} else if (g.track->type() == track_list_->type()) { } else if (g.track->type() == track_list_->type() && g.transition == nullptr) {
g.track_movement = track_diff; g.track_movement = track_diff;
@@ -2254,52 +2259,43 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
if (c != nullptr) { if (c != nullptr) {
Ghost g; Ghost g;
g.transition = nullptr;
// check if whole clip is added // check if whole clip is selected
bool add = false; bool add = c->IsSelected();
// check if a transition is selected (prioritize transition selection)
// (only the pointer tool supports moving transitions)
if (olive::timeline::current_tool == olive::timeline::TIMELINE_TOOL_POINTER
&& (c->opening_transition != nullptr || c->closing_transition != nullptr)) {
// check if any selections contain a whole transition
if (c->IsTransitionSelected(kTransitionOpening)) {
g.transition = c->opening_transition;
add = true;
} else if (c->IsTransitionSelected(kTransitionClosing)) {
g.transition = c->closing_transition;
add = true;
}
}
// if a transition isn't selected, check if the whole clip is
if (!add) { if (!add) {
add = c->IsSelected(); // check if a transition is selected
} // (only the pointer tool supports moving transitions)
if (olive::timeline::current_tool == olive::timeline::TIMELINE_TOOL_POINTER
&& (c->opening_transition != nullptr || c->closing_transition != nullptr)) {
if (add) { // check if any selections contain a whole transition
if (c->IsTransitionSelected(kTransitionOpening)) {
if (g.transition != nullptr) { g.transition = c->opening_transition;
add = true;
// transition may be a dual transition, check if it's already been added elsewhere } else if (c->IsTransitionSelected(kTransitionClosing)) {
for (int j=0;j<ParentTimeline()->ghosts.size();j++) { g.transition = c->closing_transition;
if (ParentTimeline()->ghosts.at(j).transition == g.transition) { add = true;
add = false;
break;
}
} }
} }
}
if (add) { if (add && g.transition != nullptr) {
g.clip = c;
g.trim_type = ParentTimeline()->trim_type; // transition may be a shared transition, check if it's already been added elsewhere
ParentTimeline()->ghosts.append(g); for (int j=0;j<ParentTimeline()->ghosts.size();j++) {
if (ParentTimeline()->ghosts.at(j).transition == g.transition) {
add = false;
break;
}
} }
}
if (add) {
g.clip = c;
g.trim_type = ParentTimeline()->trim_type;
ParentTimeline()->ghosts.append(g);
} }
} }
} }
@@ -2489,7 +2485,7 @@ void TimelineView::mouseMoveEvent(QMouseEvent *event) {
// See if this track touches this rectangle at all // See if this track touches this rectangle at all
if (!(track_bottom < rect_top if (!(track_bottom < rect_top
|| track_top > rect_bottom)) { || track_top > rect_bottom)) {
// Loop through track's clips for clips touching this rectangle // Loop through track's clips for clips touching this rectangle
for (int i=0;i<track->ClipCount();i++) { for (int i=0;i<track->ClipCount();i++) {
+29 -23
View File
@@ -88,11 +88,13 @@ void MoveClipAction::doRedo() {
} }
} }
DeleteClipAction::DeleteClipAction(Clip *clip) DeleteClipAction::DeleteClipAction(Clip *clip) :
done_(false)
{ {
// Get shared_ptr object to take ownership of this Clip // Get shared_ptr object to take ownership of this Clip
clip_ = clip->track()->GetClipObjectFromRawPtr(clip); clip_ = clip->track()->GetClipObjectFromRawPtr(clip);
doRedo();
} }
void DeleteClipAction::doUndo() { void DeleteClipAction::doUndo() {
@@ -101,30 +103,38 @@ void DeleteClipAction::doUndo() {
// restore links to this clip // restore links to this clip
for (int i=0;i<clips_linked_to_this_one_.size();i++) { for (int i=0;i<clips_linked_to_this_one_.size();i++) {
clips_linked_to_this_one_.append(clip_.get()); clips_linked_to_this_one_.at(i)->linked.append(clip_.get());
} }
done_ = false;
} }
void DeleteClipAction::doRedo() { void DeleteClipAction::doRedo() {
// remove ref to clip if (!done_) {
if (clip_->IsOpen()) {
clip_->Close(true);
}
clip_->track()->RemoveClip(clip_.get()); // remove ref to clip
if (clip_->IsOpen()) {
clip_->Close(true);
}
// delete link to this clip clip_->track()->RemoveClip(clip_.get());
QVector<Clip*> clips = clip_->track()->sequence()->GetAllClips();
for (int i=0;i<clips.size();i++) {
Clip* c = clips.at(i);
for (int j=0;j<c->linked.size();j++) { // delete link to this clip
if (c->linked.at(j) == clip_.get()) { QVector<Clip*> clips = clip_->track()->sequence()->GetAllClips();
c->linked.removeAt(j); for (int i=0;i<clips.size();i++) {
clips_linked_to_this_one_.append(c); Clip* c = clips.at(i);
break;
for (int j=0;j<c->linked.size();j++) {
if (c->linked.at(j) == clip_.get()) {
c->linked.removeAt(j);
clips_linked_to_this_one_.append(c);
break;
}
} }
} }
done_ = true;
} }
} }
@@ -783,23 +793,19 @@ void SetBool::doRedo() {
SetSelectionsCommand::SetSelectionsCommand(Sequence *s, SetSelectionsCommand::SetSelectionsCommand(Sequence *s,
const QVector<Selection> &old_data, const QVector<Selection> &old_data,
const QVector<Selection> &new_data) : const QVector<Selection> &new_data) :
seq_(s),
old_data_(old_data), old_data_(old_data),
new_data_(new_data), new_data_(new_data)
done_(true)
{ {
} }
void SetSelectionsCommand::doUndo() { void SetSelectionsCommand::doUndo() {
seq_->SetSelections(old_data_); seq_->SetSelections(old_data_);
done_ = false;
} }
void SetSelectionsCommand::doRedo() { void SetSelectionsCommand::doRedo() {
if (!done_) { seq_->SetSelections(new_data_);
seq_->SetSelections(new_data_);
done_ = true;
}
} }
EditSequenceCommand::EditSequenceCommand(Media* i, SequencePtr s) { EditSequenceCommand::EditSequenceCommand(Media* i, SequencePtr s) {
+1 -1
View File
@@ -119,6 +119,7 @@ public:
private: private:
ClipPtr clip_; ClipPtr clip_;
QVector<Clip*> clips_linked_to_this_one_; QVector<Clip*> clips_linked_to_this_one_;
bool done_;
}; };
class AddEffectCommand : public OliveAction { class AddEffectCommand : public OliveAction {
@@ -417,7 +418,6 @@ private:
QVector<Selection> old_data_; QVector<Selection> old_data_;
QVector<Selection> new_data_; QVector<Selection> new_data_;
Sequence* seq_; Sequence* seq_;
bool done_;
}; };
class EditSequenceCommand : public OliveAction { class EditSequenceCommand : public OliveAction {