File indexing completed on 2025-02-09 05:45:52
0001 /* 0002 SPDX-FileCopyrightText: 2018-2022 Jean-Baptiste Mardelle <jb@kdenlive.org> 0003 SPDX-FileCopyrightText: 2018-2019 Nicolas Carion <french.ebook.lover@gmail.com> 0004 SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 #include "test_utils.hpp" 0007 // test specific headers 0008 #include "bin/binplaylist.hpp" 0009 #include "doc/kdenlivedoc.h" 0010 0011 using namespace fakeit; 0012 0013 TEST_CASE("Test of timewarping", "[Timewarp]") 0014 { 0015 auto binModel = pCore->projectItemModel(); 0016 binModel->clean(); 0017 std::shared_ptr<DocUndoStack> undoStack = std::make_shared<DocUndoStack>(nullptr); 0018 0019 // Create document 0020 KdenliveDoc document(undoStack, {0, 2}); 0021 Mock<KdenliveDoc> docMock(document); 0022 0023 pCore->projectManager()->m_project = &document; 0024 QDateTime documentDate = QDateTime::currentDateTime(); 0025 pCore->projectManager()->updateTimeline(false, QString(), QString(), documentDate, 0); 0026 auto timeline = document.getTimeline(document.uuid()); 0027 pCore->projectManager()->m_activeTimelineModel = timeline; 0028 pCore->projectManager()->testSetActiveDocument(&document, timeline); 0029 0030 KdenliveDoc::next_id = 0; 0031 0032 QString binId = createProducer(pCore->getProjectProfile(), "red", binModel); 0033 QString binId2 = createProducer(pCore->getProjectProfile(), "blue", binModel); 0034 QString binId3 = createProducerWithSound(pCore->getProjectProfile(), binModel); 0035 0036 int cid1 = ClipModel::construct(timeline, binId, -1, PlaylistState::VideoOnly); 0037 int tid1 = timeline->getTrackIndexFromPosition(1); 0038 int tid2 = timeline->getTrackIndexFromPosition(0); 0039 Q_UNUSED(tid1); 0040 Q_UNUSED(tid2); 0041 int cid2 = ClipModel::construct(timeline, binId2, -1, PlaylistState::VideoOnly); 0042 int cid3 = ClipModel::construct(timeline, binId3, -1, PlaylistState::VideoOnly); 0043 0044 timeline->m_allClips[cid1]->m_endlessResize = false; 0045 timeline->m_allClips[cid2]->m_endlessResize = false; 0046 timeline->m_allClips[cid3]->m_endlessResize = false; 0047 0048 SECTION("Timewarping orphan clip") 0049 { 0050 int originalDuration = timeline->getClipPlaytime(cid3); 0051 REQUIRE(timeline->checkConsistency()); 0052 REQUIRE(timeline->getClipTrackId(cid3) == -1); 0053 REQUIRE(timeline->getClipSpeed(cid3) == 1.); 0054 0055 std::function<bool(void)> undo = []() { return true; }; 0056 std::function<bool(void)> redo = []() { return true; }; 0057 0058 REQUIRE(timeline->requestClipTimeWarp(cid3, 0.1, false, true, undo, redo)); 0059 0060 REQUIRE(timeline->getClipSpeed(cid3) == 0.1); 0061 INFO(timeline->m_allClips[cid3]->getIn()); 0062 INFO(timeline->m_allClips[cid3]->getOut()); 0063 REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1); 0064 0065 undo(); 0066 0067 REQUIRE(timeline->getClipSpeed(cid3) == 1.); 0068 REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration); 0069 0070 redo(); 0071 0072 REQUIRE(timeline->getClipSpeed(cid3) == 0.1); 0073 REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1); 0074 0075 std::function<bool(void)> undo2 = []() { return true; }; 0076 std::function<bool(void)> redo2 = []() { return true; }; 0077 REQUIRE(timeline->requestClipTimeWarp(cid3, 1.2, false, true, undo2, redo2)); 0078 0079 REQUIRE(timeline->getClipSpeed(cid3) == 1.2); 0080 REQUIRE(timeline->getClipPlaytime(cid3) == int(originalDuration / 1.2)); 0081 0082 undo2(); 0083 REQUIRE(timeline->getClipSpeed(cid3) == 0.1); 0084 REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration / 0.1); 0085 0086 undo(); 0087 REQUIRE(timeline->getClipSpeed(cid3) == 1.); 0088 REQUIRE(timeline->getClipPlaytime(cid3) == originalDuration); 0089 0090 // Finally, we test that setting a very high speed isn't possible. 0091 // Specifically, it must be impossible to make the clip shorter than one frame 0092 int curLength = timeline->getClipPlaytime(cid3); 0093 0094 // This is the limit, should work 0095 REQUIRE(timeline->requestClipTimeWarp(cid3, double(curLength), false, true, undo2, redo2)); 0096 0097 REQUIRE(timeline->getClipSpeed(cid3) == double(curLength)); 0098 REQUIRE(timeline->getClipPlaytime(cid3) == 1); 0099 0100 // This is the higher than the limit, should not work 0101 // (we have some error margin in duration rounding, multiply by 10) 0102 REQUIRE_FALSE(timeline->requestClipTimeWarp(cid3, double(curLength) * 10, false, true, undo2, redo2)); 0103 } 0104 pCore->projectManager()->closeCurrentDocument(false, false); 0105 }