Fix tests, improve mix behavior with resize undo/redo

parent 97503c9b
......@@ -2719,13 +2719,19 @@ int TimelineModel::requestItemSpeedChange(int itemId, int size, bool right, int
return proposed_size > 0 ? proposed_size : size;
}
bool TimelineModel::removeMix(int cid)
bool TimelineModel::removeMixWithUndo(int cid, Fun &undo, Fun &redo)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
int tid = getItemTrackId(cid);
MixInfo mixData = getTrackById_const(tid)->getMixInfo(cid).first;
bool res = getTrackById(tid)->requestRemoveMix({mixData.firstClipId,mixData.secondClipId}, undo, redo);
return res;
}
bool TimelineModel::removeMix(int cid)
{
Fun undo = []() { return true; };
Fun redo = []() { return true; };
bool res = removeMixWithUndo(cid, undo, redo);
if (res) {
PUSH_UNDO(undo, redo, i18n("Remove mix"));
} else {
......@@ -2767,11 +2773,12 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
std::pair<MixInfo, MixInfo> mixData = getTrackById_const(tid)->getMixInfo(itemId);
if (in + size <= mixData.second.secondClipInOut.first + m_allClips[mixData.second.secondClipId]->getMixDuration() - m_allClips[mixData.second.secondClipId]->getMixCutPosition()) {
// Clip resized outside of mix zone, mix will be deleted
bool res = removeMix(mixData.second.secondClipId);
bool res = removeMixWithUndo(mixData.second.secondClipId, undo, redo);
if (res) {
return m_allClips[itemId]->getPlaytime();
size = m_allClips[itemId]->getPlaytime();
} else {
return -1;
}
return -1;
} else {
// Mix was resized, update cut position
int currentMixDuration = m_allClips[mixData.second.secondClipId]->getMixDuration();
......@@ -2818,7 +2825,6 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
}
}
}
if (!allowSingleResize && m_groups->isInGroup(itemId)) {
int groupId = m_groups->getRootId(itemId);
std::unordered_set<int> items = m_groups->getLeaves(groupId);
......@@ -2851,8 +2857,9 @@ int TimelineModel::requestItemResize(int itemId, int size, bool right, bool logU
tracksWithMixes << tid;
}
std::pair<MixInfo, MixInfo> mixData = getTrackById_const(tid)->getMixInfo(id);
if (end - offset <= mixData.second.secondClipInOut.first) {
if (end - offset <= mixData.second.secondClipInOut.first + m_allClips[mixData.second.secondClipId]->getMixDuration() - m_allClips[mixData.second.secondClipId]->getMixCutPosition()) {
// Resized outside mix
bool res = removeMixWithUndo(mixData.second.secondClipId, undo, redo);
Fun sync_mix_undo = [this, tid, mixData]() {
getTrackById_const(tid)->createMix(mixData.second, getTrackById_const(tid)->isAudioTrack());
getTrackById_const(tid)->syncronizeMixes(true);
......@@ -4925,7 +4932,7 @@ void TimelineModel::plantMix(int tid, Mlt::Transition *t)
getTrackById_const(tid)->loadMix(t);
}
bool TimelineModel::resizeStartMix(int cid, int duration)
bool TimelineModel::resizeStartMix(int cid, int duration, bool singleResize)
{
Q_ASSERT(isClip(cid));
int tid = m_allClips[cid]->getCurrentTrackId();
......@@ -4935,7 +4942,7 @@ bool TimelineModel::resizeStartMix(int cid, int duration)
int clipToResize = mixData.first.firstClipId;
Q_ASSERT(isClip(clipToResize));
int updatedDuration = m_allClips[cid]->getPosition() + duration - m_allClips[clipToResize]->getPosition();
int result = requestItemResize(clipToResize, updatedDuration, true, true, 0, false);
int result = requestItemResize(clipToResize, updatedDuration, true, true, 0, singleResize);
return result > -1;
}
}
......
......@@ -424,6 +424,7 @@ public:
/** @brief Plant a same track composition in track tid
*/
void plantMix(int tid, Mlt::Transition *t);
bool removeMixWithUndo(int cid, Fun &undo, Fun &redo);
bool removeMix(int cid);
protected:
......@@ -705,7 +706,7 @@ public:
void importMasterEffects(std::weak_ptr<Mlt::Service> service);
/** @brief Create a mix selection with currently selected clip. If delta = -1, mix with previous clip, +1 with next clip and 0 will check cursor position*/
bool mixClip(int idToMove = -1, int delta = 0);
Q_INVOKABLE bool resizeStartMix(int cid, int duration);
Q_INVOKABLE bool resizeStartMix(int cid, int duration, bool singleResize);
protected:
/* @brief Register a new track. This is a call-back meant to be called from TrackModel
......
......@@ -418,7 +418,7 @@ Rectangle {
mixCutPos.anchors.right = undefined
}
onReleased: {
controller.resizeStartMix(clipRoot.clipId, Math.round(Math.max(0, x) / clipRoot.timeScale))
controller.resizeStartMix(clipRoot.clipId, Math.round(Math.max(0, x) / clipRoot.timeScale), mouse.modifiers & Qt.ShiftModifier)
root.autoScrolling = timeline.autoScroll
if (sizeChanged) {
sizeChanged = false
......
......@@ -265,19 +265,19 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
SECTION("Create mix on color clip and resize")
{
state0();
REQUIRE(timeline->mixClip(cid4));
state2();
// CID 3 length=20, pos=500, CID4 length=20, pos=520
// Default mix duration = 25 frames (12 before / 13 after)
REQUIRE(timeline->mixClip(cid4));
state2();
// Resize left clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid3, 16, true, true) == 16);
REQUIRE(timeline->requestItemResize(cid3, 24, true, true) == 24);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 1);
REQUIRE(timeline->m_allClips[cid3]->getSubPlaylistIndex() == 0);
REQUIRE(timeline->m_allClips[cid4]->getSubPlaylistIndex() == 1);
undoStack->undo();
state2();
// Resize left clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid3, 4, true, true) == 4);
REQUIRE(timeline->requestItemResize(cid3, 4, true, true) == 20);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 0);
REQUIRE(timeline->m_allClips[cid3]->getSubPlaylistIndex() == 0);
REQUIRE(timeline->m_allClips[cid4]->getSubPlaylistIndex() == 0);
......@@ -317,7 +317,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
// CID 1 length=30, pos=100, CID2 length=30, pos=130
// Default mix duration = 25 frames (12 before / 13 after)
// Resize left clip, should resize the mix
REQUIRE(timeline->requestItemResize(cid1, 25, true, true) == 25);
REQUIRE(timeline->requestItemResize(cid1, 35, true, true) == 35);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 1);
REQUIRE(timeline->getTrackById_const(tid3)->mixCount() == 1);
REQUIRE(timeline->m_allClips[cid1]->getSubPlaylistIndex() == 0);
......@@ -325,7 +325,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
undoStack->undo();
state3();
// Resize left clip outside mix zone, should delete the mix
REQUIRE(timeline->requestItemResize(cid1, 10, true, true) == 10);
REQUIRE(timeline->requestItemResize(cid1, 10, true, true) == 30);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 0);
REQUIRE(timeline->getTrackById_const(tid3)->mixCount() == 0);
REQUIRE(timeline->m_allClips[cid1]->getSubPlaylistIndex() == 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment