Commit a6c365a3 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Fix mix on very short AV clips broken, with test

parent 01949163
......@@ -937,12 +937,10 @@ bool TimelineModel::mixClip(int idToMove, const QString &mixId, int delta)
continue;
}
// Make sure we have enough space in clip to resize
int maxLengthLeft = m_allClips[previousClip]->getMaxDuration();
int maxLengthRight = m_allClips[s]->getMaxDuration();
// leftMax is the maximum frames we have to expand first clip on the right
leftMax = maxLengthLeft > -1 ? (maxLengthLeft - 1 - m_allClips[previousClip]->getOut()) : m_allClips[s]->getPlaytime();
leftMax = m_allClips[s]->getPlaytime();
// rightMax is the maximum frames we have to expand second clip on the left
rightMax = maxLengthRight > -1 ? (m_allClips[s]->getIn()) : m_allClips[previousClip]->getPlaytime();
rightMax = m_allClips[previousClip]->getPlaytime();
if (getTrackById_const(selectedTrack)->hasStartMix(previousClip)) {
int spaceBeforeMix = m_allClips[s]->getPosition() - (m_allClips[previousClip]->getPosition() + m_allClips[previousClip]->getMixDuration());
rightMax = rightMax == -1 ? spaceBeforeMix : qMin(rightMax, spaceBeforeMix);
......@@ -966,12 +964,10 @@ bool TimelineModel::mixClip(int idToMove, const QString &mixId, int delta)
} else {
// Mix at end of selected clip
// Make sure we have enough space in clip to resize
int maxLengthLeft = m_allClips[s]->getMaxDuration();
int maxLengthRight = m_allClips[nextClip]->getMaxDuration();
// leftMax is the maximum frames we have to expand first clip on the right
leftMax = maxLengthLeft > -1 ? (maxLengthLeft - 1 - m_allClips[s]->getOut()) : m_allClips[nextClip]->getPlaytime();
leftMax = m_allClips[nextClip]->getPlaytime();
// rightMax is the maximum frames we have to expand second clip on the left
rightMax = maxLengthRight > -1 ? (m_allClips[nextClip]->getIn()) : m_allClips[s]->getPlaytime();
rightMax = m_allClips[s]->getPlaytime();
if (getTrackById_const(selectedTrack)->hasStartMix(s)) {
int spaceBeforeMix = m_allClips[nextClip]->getPosition() - (m_allClips[s]->getPosition() + m_allClips[s]->getMixDuration());
rightMax = rightMax == -1 ? spaceBeforeMix : qMin(rightMax, spaceBeforeMix);
......@@ -1010,6 +1006,7 @@ bool TimelineModel::mixClip(int idToMove, const QString &mixId, int delta)
if (rightMax > -1) {
// Both clips have limited durations
mixDurations.first = qMin(mixDuration / 2, leftMax);
mixDurations.first = qMin(mixDurations.first, leftMax);
mixDurations.second = qMin(mixDuration - mixDuration / 2, rightMax);
int offset = mixDuration - (mixDurations.first + mixDurations.second);
if (offset > 0) {
......
......@@ -60,6 +60,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
int cid2;
int cid3;
int cid4;
int cid5;
REQUIRE(timeline->requestClipInsertion(binId, tid2, 100, cid1));
REQUIRE(timeline->requestItemResize(cid1, 10, true, true));
......@@ -89,6 +90,23 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
REQUIRE(timeline->getTrackById_const(tid1)->mixCount() == 0);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 0);
};
auto state0b = [&]() {
REQUIRE(timeline->getClipsCount() == 8);
REQUIRE(timeline->getClipPlaytime(cid1) == 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) == 10);
REQUIRE(timeline->getClipPosition(cid2) == 110);
REQUIRE(timeline->getClipPlaytime(cid5) == 10);
REQUIRE(timeline->getClipPosition(cid5) == 120);
REQUIRE(timeline->getClipPosition(cid3) == 500);
REQUIRE(timeline->getClipPlaytime(cid3) == 20);
REQUIRE(timeline->getClipPosition(cid4) == 520);
REQUIRE(timeline->getClipPlaytime(cid4) == 20);
REQUIRE(timeline->m_allClips[cid4]->getSubPlaylistIndex() == 0);
REQUIRE(timeline->getTrackById_const(tid1)->mixCount() == 0);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 0);
};
auto state1 = [&]() {
REQUIRE(timeline->getClipsCount() == 6);
......@@ -99,6 +117,18 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
REQUIRE(timeline->getTrackById_const(tid3)->mixCount() == 1);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 1);
};
auto state1b = [&]() {
REQUIRE(timeline->getClipsCount() == 8);
REQUIRE(timeline->getClipPlaytime(cid1) > 10);
REQUIRE(timeline->getClipPosition(cid1) == 100);
REQUIRE(timeline->getClipPlaytime(cid2) > 10);
REQUIRE(timeline->getClipPosition(cid2) < 110);
REQUIRE(timeline->getClipPlaytime(cid5) == 10);
REQUIRE(timeline->getClipPosition(cid5) == 120);
REQUIRE(timeline->getTrackById_const(tid3)->mixCount() == 1);
REQUIRE(timeline->getTrackById_const(tid2)->mixCount() == 1);
};
auto state3 = [&, mixDuration]() {
REQUIRE(timeline->getClipsCount() == 6);
......@@ -206,7 +236,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
{
state0();
// insert third color clip
int cid5;
cid5 = -1;
REQUIRE(timeline->requestClipInsertion(binId2, tid2, 540, cid5));
REQUIRE(timeline->requestItemResize(cid5, 20, true, true));
REQUIRE(timeline->getClipPosition(cid5) == 540);
......@@ -333,6 +363,53 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
undoStack->undo();
state0();
}
SECTION("Create chained mixes on AV clips")
{
// CID 1 length=10, pos=100, CID2 length=10, pos=110
// Default mix duration = 25 frames (12 before / 13 after)
// Resize CID2 so that it has some space to expand left
REQUIRE(timeline->requestItemResize(cid2, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid2, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid2, tid2, 110));
state0();
// Create a third AV clip and make some space
cid5 = -1;
REQUIRE(timeline->requestClipInsertion(binId, tid2, 120, cid5));
REQUIRE(timeline->requestItemResize(cid5, 30, true, true) == 30);
REQUIRE(timeline->requestItemResize(cid5, 10, false, true) == 10);
REQUIRE(timeline->requestClipMove(cid5, tid2, 120));
state0b();
// Resize clip, should resize the mix
REQUIRE(timeline->mixClip(cid2));
state1b();
REQUIRE(timeline->getTrackById_const(tid2)->mixIsReversed(cid2) == false);
int audio2 = timeline->getClipSplitPartner(cid2);
REQUIRE(timeline->getTrackById_const(tid3)->mixIsReversed(audio2) == false);
REQUIRE(timeline->mixClip(cid5));
REQUIRE(timeline->getTrackById_const(tid2)->mixIsReversed(cid2) == false);
REQUIRE(timeline->getTrackById_const(tid2)->mixIsReversed(cid5) == true);
int audio5 = timeline->getClipSplitPartner(cid5);
REQUIRE(timeline->getTrackById_const(tid3)->mixIsReversed(audio5) == true);
// Undo cid5 mix
undoStack->undo();
state1b();
// Undo cid2 mix
undoStack->undo();
// Undo cid5
undoStack->undo();
undoStack->undo();
undoStack->undo();
undoStack->undo();
state0();
}
SECTION("Create mix on color clip and resize")
{
......@@ -492,7 +569,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
SECTION("Test chained mixes on color clips")
{
// Add 2 more color clips
int cid5;
cid5 = -1;
int cid6;
int cid7;
state0();
......@@ -571,7 +648,7 @@ TEST_CASE("Simple Mix", "[SameTrackMix]")
SECTION("Test chained mixes and check mix direction")
{
// Add 2 more color clips
int cid5;
cid5 = -1;
int cid6;
int cid7;
state0();
......
Supports Markdown
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