Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 244e4c3b authored by Nicolas Carion's avatar Nicolas Carion

[Timeline2] More fixes for compositions + tests

parent 6a491a99
......@@ -1147,16 +1147,20 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int positio
bool ok = true;
int old_trackId = getCompositionTrackId(compoId);
if (old_trackId != -1) {
Fun delete_operation = [this, compoId]() {
bool res = unplantComposition(compoId);
if (res) m_allCompositions[compoId]->setATrack(-1);
return res;
};
int oldAtrack = m_allCompositions[compoId]->getATrack();
Fun delete_reverse = [this, compoId, old_trackId, oldAtrack]() {
m_allCompositions[compoId]->setATrack(oldAtrack);
return replantCompositions(compoId);
};
Fun delete_operation = [](){return true;};
Fun delete_reverse = [](){return true;};
if (old_trackId != trackId) {
delete_operation = [this, compoId]() {
bool res = unplantComposition(compoId);
if (res) m_allCompositions[compoId]->setATrack(-1);
return res;
};
int oldAtrack = m_allCompositions[compoId]->getATrack();
delete_reverse = [this, compoId, oldAtrack]() {
m_allCompositions[compoId]->setATrack(oldAtrack);
return replantCompositions(compoId);
};
}
ok = delete_operation();
if (!ok) qDebug() << "Move failed because of first delete operation";
......@@ -1232,6 +1236,11 @@ bool TimelineModel::replantCompositions(int currentCompo)
aTrack = getTrackMltIndex(aTrack);
int ret = field->plant_transition(*m_allCompositions[compo.second].get(), aTrack , compo.first);
qDebug() << "Planting composition "<<compo.second<< "in "<<aTrack<<"/"<<compo.first<<"IN = "<<m_allCompositions[compo.second]->getIn()<<"OUT = "<<m_allCompositions[compo.second]->getOut()<<"ret="<<ret;
Mlt::Transition &transition = *m_allCompositions[compo.second].get();
mlt_service consumer = mlt_service_consumer(transition.get_service());
Q_ASSERT(consumer != nullptr);
if (ret != 0) {
return false;
}
......@@ -1243,9 +1252,16 @@ bool TimelineModel::unplantComposition(int compoId)
{
qDebug()<<"Unplanting"<<compoId;
Mlt::Transition &transition = *m_allCompositions[compoId].get();
mlt_service consumer = mlt_service_consumer(transition.get_service());
Q_ASSERT(consumer != nullptr);
m_tractor->field()->disconnect_service(transition);
transition.disconnect_all_producers();
return true;
int ret = transition.disconnect_all_producers();
mlt_service nextservice = mlt_service_get_producer(transition.get_service());
//mlt_service consumer = mlt_service_consumer(transition.get_service());
Q_ASSERT(nextservice == NULL);
//Q_ASSERT(consumer == nullptr);
return ret != 0;
}
bool TimelineModel::checkConsistency()
......@@ -1263,6 +1279,11 @@ bool TimelineModel::checkConsistency()
for (const auto & compo : m_allCompositions) {
if (getCompositionTrackId(compo.first) != -1 && m_allCompositions[compo.first]->getATrack() != -1) {
remaining_compo.insert(compo.first);
//check validity of the consumer
Mlt::Transition &transition = *m_allCompositions[compo.first].get();
mlt_service consumer = mlt_service_consumer(transition.get_service());
Q_ASSERT(consumer != nullptr);
}
}
QScopedPointer<Mlt::Field> field(m_tractor->field());
......@@ -1279,6 +1300,7 @@ bool TimelineModel::checkConsistency()
int currentIn = (int) mlt_transition_get_in(tr);
int currentOut = (int) mlt_transition_get_out(tr);
qDebug() << "looking composition IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack<<" / "<<currentATrack;
int foundId = -1;
//we iterate to try to find a matching compo
for (int compoId : remaining_compo) {
......@@ -1294,6 +1316,8 @@ bool TimelineModel::checkConsistency()
qDebug() << "Error, we didn't find matching composition IN: " << currentIn << ", OUT: " << currentOut << ", TRACK: " << currentTrack<<" / "<<currentATrack;
field->unlock();
return false;
} else {
qDebug() << "Found";
}
remaining_compo.erase(foundId);
}
......
......@@ -177,7 +177,7 @@ TEST_CASE("Composition manipulation", "[CompositionModel]")
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
}
SECTION("Resize orphan clip"){
SECTION("Resize orphan composition"){
int length = 12;
REQUIRE(timeline->requestItemResize(cid1, length, true));
REQUIRE(timeline->requestItemResize(cid2, length, true));
......@@ -203,7 +203,7 @@ TEST_CASE("Composition manipulation", "[CompositionModel]")
REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 3);
}
SECTION("Resize inserted clips"){
SECTION("Resize inserted compositions"){
int length = 12;
REQUIRE(timeline->requestItemResize(cid1, length, true));
REQUIRE(timeline->requestItemResize(cid2, length, true));
......@@ -234,5 +234,185 @@ TEST_CASE("Composition manipulation", "[CompositionModel]")
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
}
SECTION("Change track of resized compositions"){
int length = 12;
REQUIRE(timeline->requestItemResize(cid1, length, true));
REQUIRE(timeline->requestItemResize(cid2, length, true));
REQUIRE(timeline->requestCompositionMove(cid2, tid1, 5));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
REQUIRE(timeline->requestCompositionMove(cid1, tid2, 10));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid2) == 1);
REQUIRE(timeline->requestItemResize(cid1, 5, false));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getTrackCompositionsCount(tid2) == 0);
}
SECTION("Composition Move"){
int length = 12;
REQUIRE(timeline->requestItemResize(cid1, length, true));
REQUIRE(timeline->requestItemResize(cid2, length, true));
REQUIRE(timeline->requestCompositionMove(cid2, tid1, 5));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid2) == 5);
REQUIRE(timeline->requestCompositionMove(cid1, tid1, 5 + length));
auto state = [&]() {
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == 5 + length);
REQUIRE(timeline->getCompositionPosition(cid2) == 5);
};
state();
REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 3 + length));
state();
REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
state();
REQUIRE(timeline->requestCompositionMove(cid2, tid1, 0));
auto state2 = [&]() {
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == 5 + length);
REQUIRE(timeline->getCompositionPosition(cid2) == 0);
};
state2();
REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
state2();
REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, length - 5));
state2();
REQUIRE(timeline->requestCompositionMove(cid1, tid1, length));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length);
REQUIRE(timeline->getCompositionPosition(cid2) == 0);
REQUIRE(timeline->requestItemResize(cid2, length - 5, true));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length);
REQUIRE(timeline->getCompositionPosition(cid2) == 0);
// REQUIRE(timeline->allowCompositionMove(cid1, tid1, length - 5));
REQUIRE(timeline->requestCompositionMove(cid1, tid1, length - 5));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
REQUIRE(timeline->getCompositionPosition(cid2) == 0);
REQUIRE(timeline->requestItemResize(cid2, length - 10, false));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
REQUIRE(timeline->getCompositionPosition(cid2) == 5);
REQUIRE_FALSE(timeline->requestCompositionMove(cid1, tid1, 0));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
REQUIRE(timeline->getCompositionPosition(cid2) == 5);
REQUIRE(timeline->requestCompositionMove(cid2, tid1, 0));
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getCompositionPosition(cid1) == length - 5);
REQUIRE(timeline->getCompositionPosition(cid2) == 0);
}
SECTION ("Move and resize") {
int length = 12;
REQUIRE(timeline->requestItemResize(cid1, length, true));
REQUIRE(timeline->requestItemResize(cid2, length, true));
REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
REQUIRE(timeline->requestItemResize(cid1, length - 2, false));
REQUIRE(timeline->requestCompositionMove(cid1, tid1, 0));
auto state = [&](){
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 1);
REQUIRE(timeline->getCompositionPosition(cid1) == 0);
REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 2);
};
state();
REQUIRE(timeline->requestItemResize(cid1, length - 4, true));
REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4 + 1));
REQUIRE(timeline->requestItemResize(cid2, length - 2, false));
REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4 + 1));
auto state2 = [&](){
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionPosition(cid1) == 0);
REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 4);
REQUIRE(timeline->getCompositionPosition(cid2) == length - 4 + 1);
REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 2);
};
state2();
//the gap between the two clips is 1 frame, we try to resize them by 2 frames
REQUIRE_FALSE(timeline->requestItemResize(cid1, length - 2, true));
state2();
REQUIRE_FALSE(timeline->requestItemResize(cid2, length, false));
state2();
REQUIRE(timeline->requestCompositionMove(cid2, tid1, length - 4));
auto state3 = [&](){
REQUIRE(timeline->checkConsistency());
REQUIRE(timeline->getCompositionTrackId(cid1) == tid1);
REQUIRE(timeline->getCompositionTrackId(cid2) == tid1);
REQUIRE(timeline->getTrackCompositionsCount(tid1) == 2);
REQUIRE(timeline->getCompositionPosition(cid1) == 0);
REQUIRE(timeline->getCompositionPlaytime(cid1) == length - 4);
REQUIRE(timeline->getCompositionPosition(cid2) == length - 4);
REQUIRE(timeline->getCompositionPlaytime(cid2) == length - 2);
};
state3();
//Now the gap is 0 frames, the resize should still fail
REQUIRE_FALSE(timeline->requestItemResize(cid1, length - 2, true));
state3();
REQUIRE_FALSE(timeline->requestItemResize(cid2, length, false));
state3();
//We move cid1 out of the way
REQUIRE(timeline->requestCompositionMove(cid1, tid2, 0));
//now resize should work
REQUIRE(timeline->requestItemResize(cid1, length - 2, true));
REQUIRE(timeline->requestItemResize(cid2, length, false));
}
}
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