projectclip.cpp 45.9 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 "timeline2/model/snapmodel.hpp"
36
#include "profiles/profilemodel.hpp"
Nicolas Carion's avatar
Nicolas Carion committed
37
#include "project/projectcommands.h"
38
#include "project/projectmanager.h"
Nicolas Carion's avatar
Nicolas Carion committed
39 40 41 42 43 44
#include "projectfolder.h"
#include "projectitemmodel.h"
#include "projectsubclip.h"
#include "timecode.h"
#include "timeline/clip.h"
#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);
Nicolas Carion's avatar
Nicolas Carion committed
76 77
    static_cast<ProjectItemModel *>(m_model)->bin()->loadSubClips(id, getPropertiesFromPrefix(QStringLiteral("kdenlive:clipzone.")));
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel *>(m_model)->bin(), &Bin::doUpdateThumbsProgress);
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")));
88
    m_clipStatus = StatusWaiting;
89
    m_thumbnail = thumb;
90
    if (description.hasAttribute(QStringLiteral("type"))) {
91 92
        m_clipType = (ClipType)description.attribute(QStringLiteral("type")).toInt();
        if (m_clipType == Audio) {
93
            m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
94
        }
95
    }
96
    m_temporaryUrl = getXmlProperty(description, QStringLiteral("resource"));
97
    QString clipName = getXmlProperty(description, QStringLiteral("kdenlive:clipname"));
98 99
    if (!clipName.isEmpty()) {
        m_name = clipName;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
100
    } else if (!m_temporaryUrl.isEmpty()) {
101
        m_name = QFileInfo(m_temporaryUrl).fileName();
102 103
    } else {
        m_name = i18n("Untitled");
104
    }
105
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
Nicolas Carion's avatar
Nicolas Carion committed
106
    connect(this, &ProjectClip::updateThumbProgress, static_cast<ProjectItemModel *>(m_model)->bin(), &Bin::doUpdateThumbsProgress);
107
    m_markerModel = std::make_shared<MarkerListModel>(m_id, pCore->projectManager()->current()->commandStack());
108 109 110 111
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

void ProjectClip::setCurrent(bool current, bool notify)
{
270 271
    Q_UNUSED(notify);
    if (current) {
272
        static_cast<ProjectItemModel *>(m_model)->bin()->openProducer(this);
Nicolas Carion's avatar
Nicolas Carion committed
273
        static_cast<ProjectItemModel *>(m_model)->bin()->requestShowEffectStack(getEffectStack());
274 275 276
    }
}

277
QDomElement ProjectClip::toXml(QDomDocument &document, bool includeMeta)
278
{
279 280
    getProducerXML(document, includeMeta);
    QDomElement prod = document.documentElement().firstChildElement(QStringLiteral("producer"));
281 282
    if (m_clipType != Unknown) {
        prod.setAttribute(QStringLiteral("type"), (int)m_clipType);
283
    }
284
    return prod;
285 286
}

Laurent Montel's avatar
Laurent Montel committed
287
void ProjectClip::setThumbnail(const QImage &img)
288
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
289 290
    QPixmap thumb = roundedPixmap(QPixmap::fromImage(img));
    if (hasProxy() && !thumb.isNull()) {
291
        // Overlay proxy icon
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
292
        QPainter p(&thumb);
293
        QColor c(220, 220, 10, 200);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
294
        QRect r(0, 0, thumb.height() / 2.5, thumb.height() / 2.5);
295 296 297 298 299 300 301 302
        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
303
    m_thumbnail = QIcon(thumb);
304
    emit thumbUpdated(img);
Nicolas Carion's avatar
Nicolas Carion committed
305
    static_cast<ProjectItemModel *>(m_model)->bin()->emitItemUpdated(this);
306 307
}

308 309 310 311 312
QPixmap ProjectClip::thumbnail(int width, int height)
{
    return m_thumbnail.pixmap(width, height);
}

313
bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool replaceProducer)
314
{
315 316
    Q_UNUSED(replaceProducer);

Nicolas Carion's avatar
Nicolas Carion committed
317
    updateProducer(std::move(producer));
318 319 320 321

    // Update info
    if (m_name.isEmpty()) {
        m_name = clipName();
322
    }
323 324 325
    m_date = date;
    m_description = ClipController::description();
    m_temporaryUrl.clear();
326 327
    if (m_clipType == Audio) {
        m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
328
    }
329
    m_duration = getStringDuration();
330
    m_clipStatus = StatusReady;
331
    if (!hasProxy()) {
Nicolas Carion's avatar
Nicolas Carion committed
332
        static_cast<ProjectItemModel *>(m_model)->bin()->emitRefreshPanel(m_id);
333
    }
Nicolas Carion's avatar
Nicolas Carion committed
334
    static_cast<ProjectItemModel *>(m_model)->bin()->emitItemUpdated(this);
335
    // Make sure we have a hash for this clip
336
    getFileHash();
337
    createAudioThumbs();
338
    return true;
339 340 341 342
}

void ProjectClip::createAudioThumbs()
{
343
    if (KdenliveSettings::audiothumbnails() && (m_clipType == AV || m_clipType == Audio || m_clipType == Playlist)) {
Nicolas Carion's avatar
Nicolas Carion committed
344
        static_cast<ProjectItemModel *>(m_model)->bin()->requestAudioThumbs(m_id, duration().ms());
345
        emit updateJobStatus(AbstractClipJob::THUMBJOB, JobWaiting, 0);
346
    }
347 348
}

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

375
bool ProjectClip::isReady() const
376
{
377
    return m_clipStatus == StatusReady;
378 379
}

380
/*void ProjectClip::setZone(const QPoint &zone)
381 382
{
    m_zone = zone;
383
}*/
384 385 386

QPoint ProjectClip::zone() const
{
387 388
    int x = getProducerIntProperty(QStringLiteral("kdenlive:zone_in"));
    int y = getProducerIntProperty(QStringLiteral("kdenlive:zone_out"));
389
    return QPoint(x, y);
390 391 392 393
}

const QString ProjectClip::hash()
{
394
    QString clipHash = getProducerProperty(QStringLiteral("kdenlive:file_hash"));
395 396
    if (!clipHash.isEmpty()) {
        return clipHash;
397
    }
398
    return getFileHash();
399 400
}

401
const QString ProjectClip::getFileHash()
402
{
403 404
    QByteArray fileData;
    QByteArray fileHash;
405
    switch (m_clipType) {
406
    case SlideShow:
407
        fileData = clipUrl().toUtf8();
408 409 410
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Text:
411
        fileData = getProducerProperty(QStringLiteral("xmldata")).toUtf8();
412 413 414
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case QText:
415
        fileData = getProducerProperty(QStringLiteral("text")).toUtf8();
416 417 418
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Color:
419
        fileData = getProducerProperty(QStringLiteral("resource")).toUtf8();
420 421 422
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    default:
423
        QFile file(clipUrl());
424 425 426 427 428
        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)
             */
429 430
            if (file.size() > 2000000) {
                fileData = file.read(1000000);
431
                if (file.seek(file.size() - 1000000)) {
432
                    fileData.append(file.readAll());
433 434
                }
            } else {
435
                fileData = file.readAll();
436
            }
437
            file.close();
Nicolas Carion's avatar
Nicolas Carion committed
438
            ClipController::setProducerProperty(QStringLiteral("kdenlive:file_size"), QString::number(file.size()));
439
            fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
440 441 442 443 444
        }
        break;
    }
    if (fileHash.isEmpty()) {
        return QString();
445 446
    }
    QString result = fileHash.toHex();
Nicolas Carion's avatar
Nicolas Carion committed
447
    ClipController::setProducerProperty(QStringLiteral("kdenlive:file_hash"), result);
448
    return result;
449
}
450 451 452

double ProjectClip::getOriginalFps() const
{
453
    return originalFps();
454
}
455 456 457

bool ProjectClip::hasProxy() const
{
458
    QString proxy = getProducerProperty(QStringLiteral("kdenlive:proxy"));
Nicolas Carion's avatar
Nicolas Carion committed
459
    return !proxy.isEmpty() || proxy == QLatin1String("-");
460 461
}

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

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

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

572 573
ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
{
Nicolas Carion's avatar
Nicolas Carion committed
574 575
    ClipPropertiesController *panel =
        new ClipPropertiesController(static_cast<ProjectItemModel *>(m_model)->bin()->projectTimecode(), static_cast<ClipController *>(this), parent);
Laurent Montel's avatar
Laurent Montel committed
576 577
    connect(this, &ProjectClip::refreshPropertiesPanel, panel, &ClipPropertiesController::slotReloadProperties);
    connect(this, &ProjectClip::refreshAnalysisPanel, panel, &ClipPropertiesController::slotFillAnalysisData);
578 579 580
    return panel;
}

581 582
void ProjectClip::updateParentInfo(const QString &folderid, const QString &foldername)
{
583
    Q_UNUSED(foldername);
Nicolas Carion's avatar
Nicolas Carion committed
584
    ClipController::setProducerProperty(QStringLiteral("kdenlive:folderid"), folderid);
585 586
}

Laurent Montel's avatar
Laurent Montel committed
587
bool ProjectClip::matches(const QString &condition)
588
{
Nicolas Carion's avatar
Nicolas Carion committed
589
    // TODO
590
    Q_UNUSED(condition)
591 592 593
    return true;
}

594
const QString ProjectClip::codec(bool audioCodec) const
595
{
596
    return codec(audioCodec);
597
}
598

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

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

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

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

682 683 684 685 686
CommentedTime ProjectClip::getMarker(const GenTime &pos) const
{
    return m_markerModel->getMarker(pos);
}

Nicolas Carion's avatar
Nicolas Carion committed
687
/*QVariant ProjectClip::getData(DataType type) const
688 689
{
    switch (type) {
690
    case AbstractProjectItem::IconOverlay:
691
        return hasEffects() ? QVariant("kdenlive-track_has_effect") : QVariant();
692 693 694
        break;
    default:
        break;
695
    }
Nicolas Carion's avatar
Nicolas Carion committed
696 697
    return AbstractProjectItem::getData(type);
    }*/
698

Laurent Montel's avatar
Laurent Montel committed
699
void ProjectClip::slotQueryIntraThumbs(const QList<int> &frames)
700 701 702 703 704 705 706