Commit 437c5d70 authored by Nicolas Carion's avatar Nicolas Carion

more thorough consistency checking

parent 70b2c190
......@@ -381,7 +381,8 @@ bool EffectStackModel::appendEffect(const QString &effectId, bool makeCurrent)
return res;
}
bool EffectStackModel::adjustStackLength(bool adjustFromEnd, int oldIn, int oldDuration, int newIn, int duration, int offset, Fun &undo, Fun &redo, bool logUndo)
bool EffectStackModel::adjustStackLength(bool adjustFromEnd, int oldIn, int oldDuration, int newIn, int duration, int offset, Fun &undo, Fun &redo,
bool logUndo)
{
QWriteLocker locker(&m_lock);
const int fadeInDuration = getFadePosition(true);
......@@ -866,20 +867,18 @@ bool EffectStackModel::checkConsistency()
qDebug() << "ERROR: unavailable service";
return false;
}
if (ptr->filter_count() != (int)allFilters.size()) {
// MLT inserts some default normalizer filters that are not managed by Kdenlive, which explains why the filter count is not equal
int kdenliveFilterCount = 0;
for (int i = 0; i < ptr->filter_count(); i++) {
std::shared_ptr<Mlt::Filter> filt(ptr->filter(i));
if (filt->get("kdenlive_id") != NULL) {
kdenliveFilterCount++;
}
// qDebug() << "FILTER: "<<i<<" : "<<ptr->filter(i)->get("mlt_service");
}
if (kdenliveFilterCount != (int)allFilters.size()) {
qDebug() << "ERROR: Wrong filter count: " << kdenliveFilterCount << " = " << allFilters.size();
return false;
// MLT inserts some default normalizer filters that are not managed by Kdenlive, which explains why the filter count is not equal
int kdenliveFilterCount = 0;
for (int i = 0; i < ptr->filter_count(); i++) {
std::shared_ptr<Mlt::Filter> filt(ptr->filter(i));
if (filt->get("kdenlive_id") != NULL) {
kdenliveFilterCount++;
}
// qDebug() << "FILTER: "<<i<<" : "<<ptr->filter(i)->get("mlt_service");
}
if (kdenliveFilterCount != (int)allFilters.size()) {
qDebug() << "ERROR: Wrong filter count: " << kdenliveFilterCount << " = " << allFilters.size();
return false;
}
int ct = 0;
......
......@@ -140,6 +140,9 @@ public:
/* @brief Delete active effect from stack */
void removeCurrentEffect();
/* @brief This is a convenience function that helps check if the tree is in a valid state */
bool checkConsistency() override;
public slots:
/* @brief Delete an effect from the stack */
void removeEffect(std::shared_ptr<EffectItemModel> effect);
......@@ -151,8 +154,6 @@ protected:
/* @brief Deregister the existence of a new element*/
void deregisterItem(int id, TreeItem *item) override;
/* @brief This is a convenience function that helps check if the tree is in a valid state */
bool checkConsistency() override;
std::weak_ptr<Mlt::Service> m_masterService;
std::vector<std::weak_ptr<Mlt::Service>> m_childServices;
......
......@@ -212,7 +212,8 @@ bool ClipModel::requestResize(int size, bool right, Fun &undo, Fun &redo, bool l
}
return false;
};
qDebug() << "----------\n-----------\n// ADJUSTING EFFECT LENGTH, LOGUNDO " << logUndo << ", " << old_in << "/" << inPoint << ", " << m_producer->get_playtime();
qDebug() << "----------\n-----------\n// ADJUSTING EFFECT LENGTH, LOGUNDO " << logUndo << ", " << old_in << "/" << inPoint << ", "
<< m_producer->get_playtime();
if (logUndo) {
adjustEffectLength(right, old_in, inPoint, old_out - old_in, m_producer->get_playtime(), offset, reverse, operation, logUndo);
}
......@@ -633,3 +634,34 @@ QDomElement ClipModel::toXml(QDomDocument &document)
container.appendChild(m_effectStack->toXml(document));
return container;
}
bool ClipModel::checkConsistency()
{
if (!m_effectStack->checkConsistency()) {
qDebug() << "Consistency check failed for effecstack";
return false;
}
std::shared_ptr<ProjectClip> binClip = pCore->projectItemModel()->getClipByBinID(m_binClipId);
auto instances = binClip->timelineInstances();
bool found = false;
for (const auto &i : instances) {
if (i == m_id) {
found = true;
break;
}
}
if (!found) {
qDebug() << "ERROR: binClip doesn't acknowledge timeline clip existence";
return false;
}
if (m_currentState == PlaylistState::VideoOnly && !m_canBeVideo) {
qDebug() << "ERROR: clip is in video state but doesn't have video";
return false;
}
if (m_currentState == PlaylistState::AudioOnly && !m_canBeAudio) {
qDebug() << "ERROR: clip is in video state but doesn't have video";
return false;
}
return true;
}
......@@ -187,6 +187,9 @@ protected:
bool isAudioOnly() const;
double getSpeed() const;
/*@brief This is a debug function to ensure the clip is in a valid state */
bool checkConsistency();
protected:
std::shared_ptr<Mlt::Producer> m_producer;
std::shared_ptr<Mlt::Producer> getProducer();
......
......@@ -701,8 +701,8 @@ int TimelineModel::suggestClipMove(int clipId, int trackId, int position, int cu
}
}
int snapped = requestBestSnapPos(position, m_allClips[clipId]->getPlaytime(), m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(), cursorPosition,
snapDistance);
int snapped = requestBestSnapPos(position, m_allClips[clipId]->getPlaytime(), m_editMode == TimelineMode::NormalEdit ? ignored_pts : std::vector<int>(),
cursorPosition, snapDistance);
// qDebug() << "Starting suggestion " << clipId << position << currentPos << "snapped to " << snapped;
if (snapped >= 0) {
position = snapped;
......@@ -876,7 +876,7 @@ bool TimelineModel::requestClipCreation(const QString &binClipId, int &id, Playl
bid = binClipId.section(QLatin1Char('/'), 0, 0);
}
if (!pCore->projectItemModel()->hasClip(bid)) {
qDebug()<<" / / / /MASTER CLIP NOT FOUND";
qDebug() << " / / / /MASTER CLIP NOT FOUND";
return false;
}
std::shared_ptr<ProjectClip> master = pCore->projectItemModel()->getClipByBinID(bid);
......@@ -1292,8 +1292,14 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
// Sort clips. We need to delete from right to left to avoid confusing the view, and compositions from top to bottom
std::vector<int> sorted_clips(all_items.begin(), all_items.end());
std::sort(sorted_clips.begin(), sorted_clips.end(), [this, delta_track](int clipId1, int clipId2) {
int p1 = isClip(clipId1) ? m_allClips[clipId1]->getPosition() : delta_track < 0 ? getTrackMltIndex(m_allCompositions[clipId1]->getCurrentTrackId()) : delta_track > 0 ? -getTrackMltIndex(m_allCompositions[clipId1]->getCurrentTrackId()) : m_allCompositions[clipId1]->getPosition();
int p2 = isClip(clipId2) ? m_allClips[clipId2]->getPosition() : delta_track < 0 ? getTrackMltIndex(m_allCompositions[clipId2]->getCurrentTrackId()) : delta_track > 0 ? -getTrackMltIndex(m_allCompositions[clipId2]->getCurrentTrackId()) : m_allCompositions[clipId2]->getPosition();
int p1 = isClip(clipId1) ? m_allClips[clipId1]->getPosition()
: delta_track < 0 ? getTrackMltIndex(m_allCompositions[clipId1]->getCurrentTrackId())
: delta_track > 0 ? -getTrackMltIndex(m_allCompositions[clipId1]->getCurrentTrackId())
: m_allCompositions[clipId1]->getPosition();
int p2 = isClip(clipId2) ? m_allClips[clipId2]->getPosition()
: delta_track < 0 ? getTrackMltIndex(m_allCompositions[clipId2]->getCurrentTrackId())
: delta_track > 0 ? -getTrackMltIndex(m_allCompositions[clipId2]->getCurrentTrackId())
: m_allCompositions[clipId2]->getPosition();
return p2 <= p1;
});
......@@ -1334,7 +1340,7 @@ bool TimelineModel::requestGroupMove(int clipId, int groupId, int delta_track, i
ok = ok && getTrackById(old_trackId)->requestClipDeletion(item, updateThisView, finalMove, local_undo, local_redo);
old_position[item] = m_allClips[item]->getPosition();
} else {
//ok = ok && getTrackById(old_trackId)->requestCompositionDeletion(item, updateThisView, finalMove, local_undo, local_redo);
// ok = ok && getTrackById(old_trackId)->requestCompositionDeletion(item, updateThisView, finalMove, local_undo, local_redo);
old_position[item] = m_allCompositions[item]->getPosition();
old_forced_track[item] = m_allCompositions[item]->getForcedTrack();
}
......@@ -2480,6 +2486,10 @@ bool TimelineModel::checkConsistency()
snaps[clip->getPosition()] += 1;
snaps[clip->getPosition() + clip->getPlaytime()] += 1;
}
if (!clip->checkConsistency()) {
qDebug() << "Consistency check failed for clip" << cp.first;
return false;
}
}
for (const auto &cp : m_allCompositions) {
auto clip = (cp.second);
......
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