File: timewarptest.cpp

package info (click to toggle)
kdenlive 25.12.0-1
  • links: PTS
  • area: main
  • in suites: forky
  • size: 125,912 kB
  • sloc: cpp: 206,648; xml: 11,857; python: 1,139; ansic: 1,054; javascript: 578; sh: 389; makefile: 15
file content (102 lines) | stat: -rw-r--r-- 4,299 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
    SPDX-FileCopyrightText: 2018-2022 Jean-Baptiste Mardelle <jb@kdenlive.org>
    SPDX-FileCopyrightText: 2018-2019 Nicolas Carion <french.ebook.lover@gmail.com>
    SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "test_utils.hpp"
// test specific headers
#include "bin/binplaylist.hpp"
#include "doc/kdenlivedoc.h"

using namespace fakeit;

TEST_CASE("Test of timewarping", "[Timewarp]")
{
    auto binModel = pCore->projectItemModel();
    binModel->clean();
    std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr);

    // Create document
    KdenliveDoc document(undoStack);
    pCore->projectManager()->testSetDocument(&document);
    QDateTime documentDate = QDateTime::currentDateTime();
    KdenliveTests::updateTimeline(false, QString(), QString(), documentDate, 0);
    auto timeline = document.getTimeline(document.uuid());
    pCore->projectManager()->testSetActiveTimeline(timeline);

    KdenliveTests::resetNextId();

    QString binId = KdenliveTests::createProducer(pCore->getProjectProfile(), "red", binModel);
    QString binId2 = KdenliveTests::createProducer(pCore->getProjectProfile(), "blue", binModel);
    QString binId3 = KdenliveTests::createProducerWithSound(pCore->getProjectProfile(), binModel);

    int cid1 = ClipModel::construct(timeline, binId, -1, PlaylistState::VideoOnly);
    int tid1 = timeline->getTrackIndexFromPosition(1);
    int tid2 = timeline->getTrackIndexFromPosition(0);
    Q_UNUSED(tid1);
    Q_UNUSED(tid2);
    int cid2 = ClipModel::construct(timeline, binId2, -1, PlaylistState::VideoOnly);
    int cid3 = ClipModel::construct(timeline, binId3, -1, PlaylistState::VideoOnly);

    KdenliveTests::makeFiniteClipEnd(timeline, cid1);
    KdenliveTests::makeFiniteClipEnd(timeline, cid2);
    KdenliveTests::makeFiniteClipEnd(timeline, cid3);

    SECTION("Timewarping orphan clip")
    {
        int originalDuration = timeline->getClipPlaytime(cid3);
        REQUIRE(timeline->checkConsistency());
        REQUIRE(timeline->getClipTrackId(cid3) == -1);
        REQUIRE(timeline->getClipSpeed(cid3) == 1.);

        std::function<bool(void)> undo = []() { return true; };
        std::function<bool(void)> redo = []() { return true; };

        REQUIRE(timeline->requestClipTimeWarp(cid3, 0.1, false, true, undo, redo));

        REQUIRE(timeline->getClipSpeed(cid3) == 0.1);
        INFO(timeline->getClipIn(cid3));
        INFO(timeline->getClipPlaytime(cid3));
        REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1);

        undo();

        REQUIRE(timeline->getClipSpeed(cid3) == 1.);
        REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration);

        redo();

        REQUIRE(timeline->getClipSpeed(cid3) == 0.1);
        REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1);

        std::function<bool(void)> undo2 = []() { return true; };
        std::function<bool(void)> redo2 = []() { return true; };
        REQUIRE(timeline->requestClipTimeWarp(cid3, 1.2, false, true, undo2, redo2));

        REQUIRE(timeline->getClipSpeed(cid3) == 1.2);
        REQUIRE(timeline->getClipPlaytime(cid3) == int(originalDuration / 1.2));

        undo2();
        REQUIRE(timeline->getClipSpeed(cid3) == 0.1);
        REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1);

        undo();
        REQUIRE(timeline->getClipSpeed(cid3) == 1.);
        REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration);

        // Finally, we test that setting a very high speed isn't possible.
        // Specifically, it must be impossible to make the clip shorter than one frame
        int curLength = timeline->getClipPlaytime(cid3);

        // This is the limit, should work
        REQUIRE(timeline->requestClipTimeWarp(cid3, double(curLength), false, true, undo2, redo2));

        REQUIRE(timeline->getClipSpeed(cid3) == double(curLength));
        REQUIRE(timeline->getClipPlaytime(cid3) == 1);

        // This is the higher than the limit, should not work
        // (we have some error margin in duration rounding, multiply by 10)
        REQUIRE_FALSE(timeline->requestClipTimeWarp(cid3, double(curLength) * 10, false, true, undo2, redo2));
    }
    pCore->projectManager()->closeCurrentDocument(false, false);
}