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

Fix confusions in composition a_trak (index vs MLT pos)

parent 92a968c3
......@@ -116,7 +116,7 @@ bool constructTimelineFromMelt(const std::shared_ptr<TimelineItemModel> &timelin
QString id(t.get("mlt_service"));
QString internal(t.get("internal_added"));
if (internal.isEmpty()) {
ok = timeline->requestCompositionInsertion(id, timeline->getTrackIndexFromPosition(t.get_b_track() - 1), timeline->getTrackIndexFromPosition(t.get_a_track() - 1), t.get_in(), t.get_length(), compoId, undo, redo);
ok = timeline->requestCompositionInsertion(id, timeline->getTrackIndexFromPosition(t.get_b_track() - 1), t.get_a_track(), t.get_in(), t.get_length(), compoId, undo, redo);
if (!ok) {
qDebug() << "ERROR : failed to insert composition in track " << t.get_b_track() << ", position" << t.get_in();
break;
......
......@@ -31,6 +31,7 @@ CompositionModel::CompositionModel(std::weak_ptr<TimelineModel> parent, Mlt::Tra
const QString &transitionId)
: MoveableItem<Mlt::Transition>(std::move(parent), id)
, AssetParameterModel(transition, transitionXml, transitionId, {ObjectType::TimelineComposition, m_id})
, a_track(-1)
{
}
......@@ -128,12 +129,15 @@ int CompositionModel::getPlaytime() const
int CompositionModel::getATrack() const
{
READ_LOCK();
return service()->get_int("a_track");
return a_track == -1 ? -1 : service()->get_int("a_track");
}
void CompositionModel::setATrack(int trackId)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(trackId != getCurrentTrackId()); // can't compose with same track
service()->set("a_track", trackId);
a_track = trackId;
if (a_track >= 0) {
service()->set("a_track", trackId);
}
}
......@@ -88,6 +88,9 @@ protected:
@param redo Lambda function containing the current redo queue. Will be updated with current operation
*/
bool requestResize(int size, bool right, Fun &undo, Fun &redo);
private:
int a_track;
};
#endif
......@@ -227,7 +227,7 @@ int TimelineModel::getNextTrackId(int trackId) const
return (it != m_allTracks.end()) ? (*it)->getId() : -1;
}
int TimelineModel::getPreviousVideoTrackId(int trackId) const
int TimelineModel::getPreviousVideoTrackPos(int trackId) const
{
READ_LOCK();
Q_ASSERT(isTrack(trackId));
......@@ -238,7 +238,7 @@ int TimelineModel::getPreviousVideoTrackId(int trackId) const
break;
}
}
return it == m_allTracks.begin() ? 0 : (*it)->getId();
return it == m_allTracks.begin() ? 0 : getTrackMltIndex((*it)->getId());
}
bool TimelineModel::requestClipMove(int clipId, int trackId, int position, bool updateView, Fun &undo, Fun &redo)
......@@ -1330,7 +1330,8 @@ bool TimelineModel::requestCompositionMove(int compoId, int trackId, int composi
Q_ASSERT(isComposition(compoId));
Q_ASSERT(isTrack(trackId));
if (compositionTrack == -1) {
compositionTrack = getPreviousVideoTrackId(trackId);
qDebug()<<"// compo track: "<<trackId<<", PREVIOUS TK: "<<getPreviousVideoTrackPos(trackId);
compositionTrack = getPreviousVideoTrackPos(trackId);
}
if (compositionTrack == -1) {
// it doesn't make sense to insert a composition on the last track
......@@ -1405,7 +1406,6 @@ bool TimelineModel::replantCompositions(int currentCompo)
{
// We ensure that the compositions are planted in a decreasing order of b_track.
// For that, there is no better option than to disconnect every composition and then reinsert everything in the correct order.
std::vector<std::pair<int, int>> compos;
for (const auto &compo : m_allCompositions) {
int trackId = compo.second->getCurrentTrackId();
......@@ -1419,16 +1419,14 @@ bool TimelineModel::replantCompositions(int currentCompo)
unplantComposition(compo.first);
}
}
// sort by decreasing b_track
std::sort(compos.begin(), compos.end(), [](const std::pair<int, int> &a, const std::pair<int, int> &b) { return a.first > b.first; });
// replant
QScopedPointer<Mlt::Field> field(m_tractor->field());
field->lock();
for (const auto &compo : compos) {
int aTrack = m_allCompositions[compo.second]->getATrack();
Q_ASSERT(aTrack != -1);
aTrack = aTrack == 0 ? 0 : 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;
......@@ -1437,9 +1435,11 @@ bool TimelineModel::replantCompositions(int currentCompo)
mlt_service consumer = mlt_service_consumer(transition.get_service());
Q_ASSERT(consumer != nullptr);
if (ret != 0) {
field->unlock();
return false;
}
}
field->unlock();
QModelIndex modelIndex = makeCompositionIndexFromID(currentCompo);
QVector<int> roles;
roles.push_back(ItemATrack);
......@@ -1453,13 +1453,16 @@ bool TimelineModel::unplantComposition(int 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);
QScopedPointer<Mlt::Field> field(m_tractor->field());
field->lock();
field->disconnect_service(transition);
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 == nullptr);
// Q_ASSERT(consumer == nullptr);
field->unlock();
return ret != 0;
}
......
......@@ -233,11 +233,10 @@ public:
*/
int getNextTrackId(int trackId) const;
/* @brief Returns the id of the track just above the given track in the order of the tracks
Return -1 if we give the last track
/* @brief Returns the MLT track index of the video track just below the given trackC
@param trackId Id of the track to test
*/
int getPreviousVideoTrackId(int trackId) const;
int getPreviousVideoTrackPos(int trackId) const;
/* @brief Move a clip to a specific position
This action is undoable
......
......@@ -615,7 +615,10 @@ int TimelineController::getCompositionATrack(int cid) const
void TimelineController::setCompositionATrack(int cid, int aTrack)
{
QScopedPointer<Mlt::Field> field(m_model->m_tractor->field());
field->lock();
m_model->getCompositionPtr(cid)->setATrack(aTrack);
field->unlock();
refreshItem(cid);
QModelIndex modelIndex = m_model->makeCompositionIndexFromID(cid);
QVector <int> roles;
......
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