projectclip.cpp 45.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
Copyright (C) 2012  Till Theato <root@ttill.de>
Copyright (C) 2014  Jean-Baptiste Mardelle <jb@kdenlive.org>
This file is part of Kdenlive. See www.kdenlive.org.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License or (at your option) version 3 or any later version
accepted by the membership of KDE e.V. (or its successor approved
11
by the membership of KDE e.V.), which shall act as a proxy
12 13 14 15 16 17 18 19 20 21 22 23 24
defined in Section 14 of version 3 of the license.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "projectclip.h"
#include "bin.h"
Nicolas Carion's avatar
Nicolas Carion committed
25
#include "core.h"
26 27
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
28 29
#include "doc/kthumb.h"
#include "kdenlivesettings.h"
30
#include "lib/audio/audioStreamInfo.h"
Nicolas Carion's avatar
Nicolas Carion committed
31 32
#include "mltcontroller/bincontroller.h"
#include "mltcontroller/clipcontroller.h"
33
#include "mltcontroller/clippropertiescontroller.h"
34
#include "model/markerlistmodel.hpp"
35
#include "profiles/profilemodel.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
36
#include "project/projectcommands.h"
37
#include "project/projectmanager.h"
Nicolas Carion's avatar
Nicolas Carion committed
38 39 40 41 42
#include "projectfolder.h"
#include "projectitemmodel.h"
#include "projectsubclip.h"
#include "timecode.h"
#include "timeline/clip.h"
Nicolas Carion's avatar
style  
Nicolas Carion committed
43
#include "timeline2/model/snapmodel.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
44
#include "utils/KoIconUtils.h"
45

Laurent Montel's avatar
Laurent Montel committed
46
#include "kdenlive_debug.h"
47
#include <KLocalizedString>
48
#include <KMessageBox>
Nicolas Carion's avatar
Nicolas Carion committed
49 50 51 52 53
#include <QCryptographicHash>
#include <QDir>
#include <QDomElement>
#include <QFile>
#include <QtConcurrent>
Nicolas Carion's avatar
Nicolas Carion committed
54
#include <utility>
55

Nicolas Carion's avatar
Nicolas Carion committed
56
ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, ProjectItemModel *model, std::shared_ptr<Mlt::Producer> producer, ProjectFolder *parent)
57 58 59 60
    : AbstractProjectItem(AbstractProjectItem::ClipItem, id, model, parent)
    , ClipController(pCore->binController(), producer)
    , m_abortAudioThumb(false)
    , m_thumbsProducer(nullptr)
61
{
62
    m_markerModel = std::make_shared<MarkerListModel>(id, pCore->projectManager()->current()->commandStack());
63
    m_clipStatus = StatusReady;
64 65 66 67
    m_name = clipName();
    m_duration = getStringDuration();
    m_date = date;
    m_description = ClipController::description();
68
    if (m_clipType == Audio) {
69
        m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
70 71 72
    } else {
        m_thumbnail = thumb;
    }
73 74
    // Make sure we have a hash for this clip
    hash();
75
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
76 77
    static_cast<ProjectItemModel *>(m_model)->loadSubClips(id, getPropertiesFromPrefix(QStringLiteral("kdenlive:clipzone.")));
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel *>(m_model), &ProjectItemModel::updateThumbProgress);
78
    createAudioThumbs();
79 80
}

Nicolas Carion's avatar
Nicolas Carion committed
81
ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, ProjectItemModel *model, ProjectFolder *parent)
82
    : AbstractProjectItem(AbstractProjectItem::ClipItem, description, model, parent)
83
    , ClipController(pCore->binController())
84 85
    , m_abortAudioThumb(false)
    , m_thumbsProducer(nullptr)
86
{
Laurent Montel's avatar
Laurent Montel committed
87
    Q_ASSERT(description.hasAttribute(QStringLiteral("id")));
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
88
    m_markerModel = std::make_shared<MarkerListModel>(description.attribute(QStringLiteral("id")), pCore->projectManager()->current()->commandStack());
89
    m_clipStatus = StatusWaiting;
90
    m_thumbnail = thumb;
91
    if (description.hasAttribute(QStringLiteral("type"))) {
92 93
        m_clipType = (ClipType)description.attribute(QStringLiteral("type")).toInt();
        if (m_clipType == Audio) {
94
            m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
95
        }
96
    }
97
    m_temporaryUrl = getXmlProperty(description, QStringLiteral("resource"));
98
    QString clipName = getXmlProperty(description, QStringLiteral("kdenlive:clipname"));
99 100
    if (!clipName.isEmpty()) {
        m_name = clipName;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
101
    } else if (!m_temporaryUrl.isEmpty()) {
102
        m_name = QFileInfo(m_temporaryUrl).fileName();
103 104
    } else {
        m_name = i18n("Untitled");
105
    }
106
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
107
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel *>(m_model), &ProjectItemModel::updateThumbProgress);
108
    m_markerModel = std::make_shared<MarkerListModel>(m_id, pCore->projectManager()->current()->commandStack());
109 110 111 112
}

ProjectClip::~ProjectClip()
{
113
    // controller is deleted in bincontroller
114
    abortAudioThumbs();
115
    emit static_cast<ProjectItemModel *>(m_model)->abortAudioThumb(m_id, duration().ms());
116 117
    QMutexLocker audioLock(&m_audioMutex);
    m_thumbMutex.lock();
118
    m_requestedThumbs.clear();
119
    m_thumbMutex.unlock();
120
    m_thumbThread.waitForFinished();
121
    delete m_thumbsProducer;
122
    audioFrameCache.clear();
123 124
}

125 126 127
void ProjectClip::abortAudioThumbs()
{
    m_abortAudioThumb = true;
128
    emit doAbortAudioThumbs();
129 130
}

131 132
QString ProjectClip::getToolTip() const
{
133
    return url();
134 135
}

136
QString ProjectClip::getXmlProperty(const QDomElement &producer, const QString &propertyName, const QString &defaultValue)
137
{
138
    QString value = defaultValue;
139
    QDomNodeList props = producer.elementsByTagName(QStringLiteral("property"));
140
    for (int i = 0; i < props.count(); ++i) {
141
        if (props.at(i).toElement().attribute(QStringLiteral("name")) == propertyName) {
142 143 144 145 146 147 148
            value = props.at(i).firstChild().nodeValue();
            break;
        }
    }
    return value;
}

Laurent Montel's avatar
Laurent Montel committed
149
void ProjectClip::updateAudioThumbnail(const QVariantList &audioLevels)
150
{
151
    audioFrameCache = audioLevels;
152
    m_audioThumbCreated = true;
153
    emit static_cast<ProjectItemModel *>(m_model)->refreshAudioThumbs(m_id);
154 155 156
    emit gotAudioData();
}

157 158
QStringList ProjectClip::markersText(GenTime in, GenTime out) const
{
159
    return markerComments(in, out);
160 161
}

162 163
bool ProjectClip::audioThumbCreated() const
{
164
    return (m_audioThumbCreated);
165 166
}

167 168
ClipType ProjectClip::clipType() const
{
169
    return m_clipType;
170 171
}

172 173 174
bool ProjectClip::hasParent(const QString &id) const
{
    AbstractProjectItem *par = parent();
Nicolas Carion's avatar
Nicolas Carion committed
175
    while (par != nullptr) {
176 177 178 179
        if (par->clipId() == id) {
            return true;
        }
        par = par->parent();
180 181 182 183
    }
    return false;
}

184
ProjectClip *ProjectClip::clip(const QString &id)
185 186 187 188
{
    if (id == m_id) {
        return this;
    }
Laurent Montel's avatar
Laurent Montel committed
189
    return nullptr;
190 191
}

192
ProjectFolder *ProjectClip::folder(const QString &id)
193
{
194
    Q_UNUSED(id)
Laurent Montel's avatar
Laurent Montel committed
195
    return nullptr;
196 197
}

198
ProjectSubClip *ProjectClip::getSubClip(int in, int out)
199
{
200 201
    for (int i = 0; i < childCount(); ++i) {
        ProjectSubClip *clip = static_cast<ProjectSubClip *>(child(i))->subClip(in, out);
202 203 204 205
        if (clip) {
            return clip;
        }
    }
Laurent Montel's avatar
Laurent Montel committed
206
    return nullptr;
207 208
}

209 210 211
QStringList ProjectClip::subClipIds() const
{
    QStringList subIds;
212
    for (int i = 0; i < childCount(); ++i) {
Nicolas Carion's avatar
Nicolas Carion committed
213
        AbstractProjectItem *clip = static_cast<AbstractProjectItem *>(child(i));
214 215 216 217 218 219 220
        if (clip) {
            subIds << clip->clipId();
        }
    }
    return subIds;
}

221
ProjectClip *ProjectClip::clipAt(int ix)
222
{
Nicolas Carion's avatar
Nicolas Carion committed
223
    if (ix == row()) {
224 225
        return this;
    }
Laurent Montel's avatar
Laurent Montel committed
226
    return nullptr;
227 228
}

229
/*bool ProjectClip::isValid() const
230
{
231 232
    return m_controller->isValid();
}*/
233

234 235
bool ProjectClip::hasUrl() const
{
236
    if ((m_clipType != Color) && (m_clipType != Unknown)) {
237
        return (!clipUrl().isEmpty());
238
    }
239 240 241
    return false;
}

242
const QString ProjectClip::url() const
243
{
244
    return clipUrl();
245 246
}

247
GenTime ProjectClip::duration() const
248
{
249
    return getPlaytime();
250 251
}

252 253 254
int ProjectClip::frameDuration() const
{
    GenTime d = duration();
255
    return d.frames(pCore->getCurrentFps());
256 257
}

258
void ProjectClip::reloadProducer(bool refreshOnly)
259 260 261
{
    QDomDocument doc;
    QDomElement xml = toXml(doc);
262
    if (refreshOnly) {
263
        // set a special flag to request thumbnail only
264
        xml.setAttribute(QStringLiteral("refreshOnly"), QStringLiteral("1"));
265
    }
266
    emit static_cast<ProjectItemModel *>(m_model)->reloadProducer(m_id, xml);
267 268
}

269
QDomElement ProjectClip::toXml(QDomDocument &document, bool includeMeta)
270
{
271 272
    getProducerXML(document, includeMeta);
    QDomElement prod = document.documentElement().firstChildElement(QStringLiteral("producer"));
273 274
    if (m_clipType != Unknown) {
        prod.setAttribute(QStringLiteral("type"), (int)m_clipType);
275
    }
276
    return prod;
277 278
}

Laurent Montel's avatar
Laurent Montel committed
279
void ProjectClip::setThumbnail(const QImage &img)
280
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
281 282
    QPixmap thumb = roundedPixmap(QPixmap::fromImage(img));
    if (hasProxy() && !thumb.isNull()) {
283
        // Overlay proxy icon
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
284
        QPainter p(&thumb);
285
        QColor c(220, 220, 10, 200);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
286
        QRect r(0, 0, thumb.height() / 2.5, thumb.height() / 2.5);
287 288 289 290 291 292 293 294
        p.fillRect(r, c);
        QFont font = p.font();
        font.setPixelSize(r.height());
        font.setBold(true);
        p.setFont(font);
        p.setPen(Qt::black);
        p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
    }
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
295
    m_thumbnail = QIcon(thumb);
296
    emit thumbUpdated(img);
297
    static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
298 299
}

300 301 302 303 304
QPixmap ProjectClip::thumbnail(int width, int height)
{
    return m_thumbnail.pixmap(width, height);
}

305
bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool replaceProducer)
306
{
307 308
    Q_UNUSED(replaceProducer);

Nicolas Carion's avatar
Nicolas Carion committed
309
    updateProducer(std::move(producer));
310 311 312 313

    // Update info
    if (m_name.isEmpty()) {
        m_name = clipName();
314
    }
315 316 317
    m_date = date;
    m_description = ClipController::description();
    m_temporaryUrl.clear();
318 319
    if (m_clipType == Audio) {
        m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
320
    }
321
    m_duration = getStringDuration();
322
    m_clipStatus = StatusReady;
323
    if (!hasProxy()) {
324
        emit static_cast<ProjectItemModel *>(m_model)->refreshPanel(m_id);
325
    }
326
    static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
327
    // Make sure we have a hash for this clip
328
    getFileHash();
329
    createAudioThumbs();
330
    return true;
331 332 333 334
}

void ProjectClip::createAudioThumbs()
{
335
    if (KdenliveSettings::audiothumbnails() && (m_clipType == AV || m_clipType == Audio || m_clipType == Playlist)) {
336
        emit static_cast<ProjectItemModel *>(m_model)->requestAudioThumbs(m_id, duration().ms());
337
        emit updateJobStatus(AbstractClipJob::THUMBJOB, JobWaiting, 0);
338
    }
339 340
}

341 342 343 344 345 346
Mlt::Producer *ProjectClip::thumbProducer()
{
    QMutexLocker locker(&m_producerMutex);
    if (m_thumbsProducer) {
        return m_thumbsProducer;
    }
347
    if (clipType() == Unknown) {
Laurent Montel's avatar
Laurent Montel committed
348
        return nullptr;
349
    }
350 351
    std::shared_ptr<Mlt::Producer> prod = originalProducer();
    if (!prod->is_valid()) {
Laurent Montel's avatar
Laurent Montel committed
352
        return nullptr;
353
    }
354
    Clip clip(*prod.get());
355
    if (KdenliveSettings::gpu_accel()) {
356
        m_thumbsProducer = clip.softClone(ClipController::getPassPropertiesList());
357 358
        Mlt::Filter scaler(*prod->profile(), "swscale");
        Mlt::Filter converter(*prod->profile(), "avcolor_space");
359 360
        m_thumbsProducer->attach(scaler);
        m_thumbsProducer->attach(converter);
361 362
    } else {
        m_thumbsProducer = clip.clone();
363 364 365 366
    }
    return m_thumbsProducer;
}

367
bool ProjectClip::isReady() const
368
{
369
    return m_clipStatus == StatusReady;
370 371
}

372
/*void ProjectClip::setZone(const QPoint &zone)
373 374
{
    m_zone = zone;
375
}*/
376 377 378

QPoint ProjectClip::zone() const
{
379 380
    int x = getProducerIntProperty(QStringLiteral("kdenlive:zone_in"));
    int y = getProducerIntProperty(QStringLiteral("kdenlive:zone_out"));
381
    return QPoint(x, y);
382 383 384 385
}

const QString ProjectClip::hash()
{
386
    QString clipHash = getProducerProperty(QStringLiteral("kdenlive:file_hash"));
387 388
    if (!clipHash.isEmpty()) {
        return clipHash;
389
    }
390
    return getFileHash();
391 392
}

393
const QString ProjectClip::getFileHash()
394
{
395 396
    QByteArray fileData;
    QByteArray fileHash;
397
    switch (m_clipType) {
398
    case SlideShow:
399
        fileData = clipUrl().toUtf8();
400 401 402
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Text:
403
        fileData = getProducerProperty(QStringLiteral("xmldata")).toUtf8();
404 405 406
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case QText:
407
        fileData = getProducerProperty(QStringLiteral("text")).toUtf8();
408 409 410
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Color:
411
        fileData = getProducerProperty(QStringLiteral("resource")).toUtf8();
412 413 414
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    default:
415
        QFile file(clipUrl());
416 417 418 419 420
        if (file.open(QIODevice::ReadOnly)) { // write size and hash only if resource points to a file
            /*
             * 1 MB = 1 second per 450 files (or faster)
             * 10 MB = 9 seconds per 450 files (or faster)
             */
421 422
            if (file.size() > 2000000) {
                fileData = file.read(1000000);
423
                if (file.seek(file.size() - 1000000)) {
424
                    fileData.append(file.readAll());
425 426
                }
            } else {
427
                fileData = file.readAll();
428
            }
429
            file.close();
Nicolas Carion's avatar
Nicolas Carion committed
430
            ClipController::setProducerProperty(QStringLiteral("kdenlive:file_size"), QString::number(file.size()));
431
            fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
432 433 434 435 436
        }
        break;
    }
    if (fileHash.isEmpty()) {
        return QString();
437 438
    }
    QString result = fileHash.toHex();
Nicolas Carion's avatar
Nicolas Carion committed
439
    ClipController::setProducerProperty(QStringLiteral("kdenlive:file_hash"), result);
440
    return result;
441
}
442 443 444

double ProjectClip::getOriginalFps() const
{
445
    return originalFps();
446
}
447 448 449

bool ProjectClip::hasProxy() const
{
450
    QString proxy = getProducerProperty(QStringLiteral("kdenlive:proxy"));
Nicolas Carion's avatar
Nicolas Carion committed
451
    return !proxy.isEmpty() || proxy == QLatin1String("-");
452 453
}

Laurent Montel's avatar
Laurent Montel committed
454
void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool refreshPanel)
455 456
{
    QMapIterator<QString, QString> i(properties);
Laurent Montel's avatar
Laurent Montel committed
457
    QMap<QString, QString> passProperties;
458
    bool refreshAnalysis = false;
459
    bool reload = false;
460
    bool refreshOnly = true;
461 462
    // Some properties also need to be passed to track producers
    QStringList timelineProperties;
Laurent Montel's avatar
Laurent Montel committed
463 464
    if (properties.contains(QStringLiteral("templatetext"))) {
        m_description = properties.value(QStringLiteral("templatetext"));
465
        static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
466 467
        refreshPanel = true;
    }
Nicolas Carion's avatar
Nicolas Carion committed
468 469 470 471
    timelineProperties << QStringLiteral("force_aspect_ratio") << QStringLiteral("video_index") << QStringLiteral("audio_index")
                       << QStringLiteral("set.force_full_luma") << QStringLiteral("full_luma") << QStringLiteral("threads")
                       << QStringLiteral("force_colorspace") << QStringLiteral("force_tff") << QStringLiteral("force_progressive")
                       << QStringLiteral("force_fps");
472
    QStringList keys;
Nicolas Carion's avatar
Nicolas Carion committed
473 474
    keys << QStringLiteral("luma_duration") << QStringLiteral("luma_file") << QStringLiteral("fade") << QStringLiteral("ttl") << QStringLiteral("softness")
         << QStringLiteral("crop") << QStringLiteral("animation");
475 476
    while (i.hasNext()) {
        i.next();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
477
        setProducerProperty(i.key(), i.value());
478
        if (m_clipType == SlideShow && keys.contains(i.key())) {
479
            reload = true;
480
            refreshOnly = false;
481
        }
482 483 484
        if (i.key().startsWith(QLatin1String("kdenlive:clipanalysis"))) {
            refreshAnalysis = true;
        }
485 486 487
        if (timelineProperties.contains(i.key())) {
            passProperties.insert(i.key(), i.value());
        }
488
    }
489 490
    if (properties.contains(QStringLiteral("kdenlive:proxy"))) {
        QString value = properties.value(QStringLiteral("kdenlive:proxy"));
491
        // If value is "-", that means user manually disabled proxy on this clip
492
        if (value.isEmpty() || value == QLatin1String("-")) {
493
            // reset proxy
Nicolas Carion's avatar
Nicolas Carion committed
494 495
            if (static_cast<ProjectItemModel *>(m_model)->bin()->hasPendingJob(m_id, AbstractClipJob::PROXYJOB)) {
                static_cast<ProjectItemModel *>(m_model)->bin()->discardJobs(m_id, AbstractClipJob::PROXYJOB);
496
            } else {
497 498
                reloadProducer();
            }
499
        } else {
500
            // A proxy was requested, make sure to keep original url
501
            setProducerProperty(QStringLiteral("kdenlive:originalurl"), url());
Nicolas Carion's avatar
Nicolas Carion committed
502
            static_cast<ProjectItemModel *>(m_model)->bin()->startJob(m_id, AbstractClipJob::PROXYJOB);
503
        }
Nicolas Carion's avatar
Nicolas Carion committed
504 505
    } else if (properties.contains(QStringLiteral("resource")) || properties.contains(QStringLiteral("templatetext")) ||
               properties.contains(QStringLiteral("autorotate"))) {
506
        // Clip resource changed, update thumbnail
507
        if (m_clipType != Color) {
508
            reloadProducer();
509 510
        } else {
            reload = true;
511
        }
512
    }
513
    if (properties.contains(QStringLiteral("xmldata")) || !passProperties.isEmpty()) {
514
        reload = true;
515
    }
516 517 518
    if (refreshAnalysis) {
        emit refreshAnalysisPanel();
    }
519
    if (properties.contains(QStringLiteral("length")) || properties.contains(QStringLiteral("kdenlive:duration"))) {
520
        m_duration = getStringDuration();
521
        static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
522 523
        refreshOnly = false;
        reload = true;
524 525
    }

526 527
    if (properties.contains(QStringLiteral("kdenlive:clipname"))) {
        m_name = properties.value(QStringLiteral("kdenlive:clipname"));
528
        refreshPanel = true;
529
        static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
530
    }
531 532 533 534
    if (refreshPanel) {
        // Some of the clip properties have changed through a command, update properties panel
        emit refreshPropertiesPanel();
    }
535
    if (reload) {
536
        // producer has changed, refresh monitor and thumbnail
537
        reloadProducer(refreshOnly);
Nicolas Carion's avatar
Nicolas Carion committed
538
        static_cast<ProjectItemModel *>(m_model)->bin()->refreshClip(m_id);
539
    }
540
    if (!passProperties.isEmpty()) {
Nicolas Carion's avatar
Nicolas Carion committed
541
        static_cast<ProjectItemModel *>(m_model)->bin()->updateTimelineProducers(m_id, passProperties);
542
    }
543 544
}

545
void ProjectClip::setJobStatus(int jobType, int status, int progress, const QString &statusMessage)
546
{
Nicolas Carion's avatar
Nicolas Carion committed
547
    m_jobType = (AbstractClipJob::JOBTYPE)jobType;
548
    if (progress > 0) {
549 550 551
        if (m_jobProgress == progress) {
            return;
        }
552
        m_jobProgress = progress;
553
    } else {
554
        m_jobProgress = status;
555 556 557
        if (m_jobType == AbstractClipJob::PROXYJOB && (status == JobAborted || status == JobCrashed)) {
            setProducerProperty(QStringLiteral("kdenlive:proxy"), QStringLiteral("-"));
        }
Nicolas Carion's avatar
Nicolas Carion committed
558
        if ((status == JobAborted || status == JobCrashed || status == JobDone) && !statusMessage.isEmpty()) {
559
            m_jobMessage = statusMessage;
Nicolas Carion's avatar
Nicolas Carion committed
560
            static_cast<ProjectItemModel *>(m_model)->bin()->emitMessage(statusMessage, 100, OperationCompletedMessage);
561
        }
562
    }
563
    static_cast<ProjectItemModel *>(m_model)->onItemUpdated(this);
564
}
565

566 567
ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
{
Nicolas Carion's avatar
Nicolas Carion committed
568 569
    ClipPropertiesController *panel =
        new ClipPropertiesController(static_cast<ProjectItemModel *>(m_model)->bin()->projectTimecode(), static_cast<ClipController *>(this), parent);
Laurent Montel's avatar
Laurent Montel committed
570 571
    connect(this, &ProjectClip::refreshPropertiesPanel, panel, &ClipPropertiesController::slotReloadProperties);
    connect(this, &ProjectClip::refreshAnalysisPanel, panel, &ClipPropertiesController::slotFillAnalysisData);
572 573 574
    return panel;
}

575 576
void ProjectClip::updateParentInfo(const QString &folderid, const QString &foldername)
{
577
    Q_UNUSED(foldername);
Nicolas Carion's avatar
Nicolas Carion committed
578
    ClipController::setProducerProperty(QStringLiteral("kdenlive:folderid"), folderid);
579 580
}

Laurent Montel's avatar
Laurent Montel committed
581
bool ProjectClip::matches(const QString &condition)
582
{
Nicolas Carion's avatar
Nicolas Carion committed
583
    // TODO
584
    Q_UNUSED(condition)
585 586 587
    return true;
}

588
const QString ProjectClip::codec(bool audioCodec) const
589
{
590
    return codec(audioCodec);
591
}
592

593
bool ProjectClip::rename(const QString &name, int column)
594
{
Laurent Montel's avatar
Laurent Montel committed
595 596
    QMap<QString, QString> newProperites;
    QMap<QString, QString> oldProperites;
597 598
    bool edited = false;
    switch (column) {
599 600 601 602
    case 0:
        if (m_name == name) {
            return false;
        }
603
        // Rename clip
604 605
        oldProperites.insert(QStringLiteral("kdenlive:clipname"), m_name);
        newProperites.insert(QStringLiteral("kdenlive:clipname"), name);
606 607 608
        m_name = name;
        edited = true;
        break;
609 610 611 612
    case 2:
        if (m_description == name) {
            return false;
        }
613
        // Rename clip
614
        if (m_clipType == TextTemplate) {
615 616 617 618 619 620
            oldProperites.insert(QStringLiteral("templatetext"), m_description);
            newProperites.insert(QStringLiteral("templatetext"), name);
        } else {
            oldProperites.insert(QStringLiteral("kdenlive:description"), m_description);
            newProperites.insert(QStringLiteral("kdenlive:description"), name);
        }
621 622 623 624 625
        m_description = name;
        edited = true;
        break;
    }
    if (edited) {
Nicolas Carion's avatar
Nicolas Carion committed
626
        static_cast<ProjectItemModel *>(m_model)->bin()->slotEditClipCommand(m_id, oldProperites, newProperites);
627 628
    }
    return edited;
629 630
}

Laurent Montel's avatar
Laurent Montel committed
631
void ProjectClip::addClipMarker(QList<CommentedTime> newMarkers, QUndoCommand *groupCommand)
632
{
Laurent Montel's avatar
Laurent Montel committed
633
    QList<CommentedTime> oldMarkers;
634
    for (int i = 0; i < newMarkers.count(); ++i) {
635
        CommentedTime oldMarker = markerAt(newMarkers.at(i).time());
636 637 638 639 640 641
        if (oldMarker == CommentedTime()) {
            oldMarker = newMarkers.at(i);
            oldMarker.setMarkerType(-1);
        }
        oldMarkers << oldMarker;
    }
Nicolas Carion's avatar
Nicolas Carion committed
642
    (void)new AddMarkerCommand(this, oldMarkers, newMarkers, groupCommand);
643 644 645 646
}

bool ProjectClip::deleteClipMarkers(QUndoCommand *command)
{
Laurent Montel's avatar
Laurent Montel committed
647
    QList<CommentedTime> markers = commentedSnapMarkers();
648 649 650
    if (markers.isEmpty()) {
        return false;
    }
Laurent Montel's avatar
Laurent Montel committed
651
    QList<CommentedTime> newMarkers;
652 653 654 655 656 657
    for (int i = 0; i < markers.size(); ++i) {
        CommentedTime marker = markers.at(i);
        marker.setMarkerType(-1);
        newMarkers << marker;
    }
    new AddMarkerCommand(this, markers, newMarkers, command);
658
    return true;
659 660
}

Laurent Montel's avatar
Laurent Montel committed
661
void ProjectClip::addMarkers(QList<CommentedTime> &markers)
662 663
{
    for (int i = 0; i < markers.count(); ++i) {
664
        if (markers.at(i).markerType() < 0) {
665
            m_markerModel->removeMarker(markers.at(i).time());
666
        } else {
667
            m_markerModel->addMarker(markers.at(i).time(), markers.at(i).comment(), markers.at(i).markerType());
668
        }
669 670
    }
    // refresh markers in clip monitor
Nicolas Carion's avatar
Nicolas Carion committed
671
    static_cast<ProjectItemModel *>(m_model)->bin()->refreshClipMarkers(m_id);
672 673 674
    // refresh markers in timeline clips
    emit refreshClipDisplay();
}
675

676 677 678 679 680
CommentedTime ProjectClip::getMarker(const GenTime &pos) const
{
    return m_markerModel->getMarker(pos);
}

Nicolas Carion's avatar
Nicolas Carion committed
681
/*QVariant ProjectClip::getData(DataType type) const
682 683
{
    switch (type) {
684
    case AbstractProjectItem::IconOverlay:
685
        return hasEffects() ? QVariant("kdenlive-track_has_effect") : QVariant();
686 687 688
        break;
    default:
        break;
689
    }
Nicolas Carion's avatar
Nicolas Carion committed
690 691
    return AbstractProjectItem::getData(type);
    }*/
692

Laurent Montel's avatar
Laurent Montel committed
693
void ProjectClip::slotQueryIntraThumbs(const QList<int> &frames)
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
{
    QMutexLocker lock(&m_intraThumbMutex);
    for (int i = 0; i < frames.count(); i++) {
        if (!m_intraThumbs.contains(frames.at(