projectclip.cpp 48.4 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 "projectfolder.h"
25
#include "projectsubclip.h"
26
#include "bin.h"
27
#include "timecode.h"
28 29
#include "doc/kthumb.h"
#include "kdenlivesettings.h"
30
#include "timeline/clip.h"
31
#include "project/projectcommands.h"
32
#include "mltcontroller/clipcontroller.h"
33
#include "lib/audio/audioStreamInfo.h"
34
#include "utils/KoIconUtils.h"
35
#include "mltcontroller/clippropertiescontroller.h"
36 37 38

#include <QDomElement>
#include <QFile>
39
#include <QDir>
Laurent Montel's avatar
Laurent Montel committed
40
#include "kdenlive_debug.h"
41
#include <QCryptographicHash>
42
#include <QtConcurrent>
43
#include <KLocalizedString>
44
#include <KMessageBox>
45

46
ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, ClipController *controller, ProjectFolder *parent) :
47
    AbstractProjectItem(AbstractProjectItem::ClipItem, id, parent)
48
    , m_abortAudioThumb(false)
Vincent Pinon's avatar
Vincent Pinon committed
49
    , m_controller(controller)
Laurent Montel's avatar
Laurent Montel committed
50
    , m_thumbsProducer(nullptr)
51
{
52
    m_clipStatus = StatusReady;
53 54
    m_name = m_controller->clipName();
    m_duration = m_controller->getStringDuration();
55
    m_date = m_controller->date;
56
    m_description = m_controller->description();
57
    m_type = m_controller->clipType();
58
    if (m_type == Audio) {
59
        m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
60 61 62
    } else {
        m_thumbnail = thumb;
    }
63 64
    // Make sure we have a hash for this clip
    hash();
65
    setParent(parent);
66
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
67
    bin()->loadSubClips(id, m_controller->getPropertiesFromPrefix(QStringLiteral("kdenlive:clipzone.")));
68
    connect(this, &ProjectClip::updateThumbProgress, bin(), &Bin::doUpdateThumbsProgress);
69
    createAudioThumbs();
70 71
}

72
ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, ProjectFolder *parent) :
73
    AbstractProjectItem(AbstractProjectItem::ClipItem, description, parent)
74
    , m_abortAudioThumb(false)
Laurent Montel's avatar
Laurent Montel committed
75
    , m_controller(nullptr)
76
    , m_type(Unknown)
Laurent Montel's avatar
Laurent Montel committed
77
    , m_thumbsProducer(nullptr)
78
{
Laurent Montel's avatar
Laurent Montel committed
79
    Q_ASSERT(description.hasAttribute(QStringLiteral("id")));
80
    m_clipStatus = StatusWaiting;
81
    m_thumbnail = thumb;
82 83
    if (description.hasAttribute(QStringLiteral("type"))) {
        m_type = (ClipType) description.attribute(QStringLiteral("type")).toInt();
84
        if (m_type == Audio) {
85
            m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
86
        }
87
    }
88
    m_temporaryUrl = getXmlProperty(description, QStringLiteral("resource"));
89
    QString clipName = getXmlProperty(description, QStringLiteral("kdenlive:clipname"));
90 91
    if (!clipName.isEmpty()) {
        m_name = clipName;
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
92
    } else if (!m_temporaryUrl.isEmpty()) {
93
        m_name = QFileInfo(m_temporaryUrl).fileName();
94 95
    } else {
        m_name = i18n("Untitled");
96
    }
97
    connect(this, &ProjectClip::updateJobStatus, this, &ProjectClip::setJobStatus);
98
    setParent(parent);
99
    connect(this, &ProjectClip::updateThumbProgress, bin(), &Bin::doUpdateThumbsProgress);
100 101 102 103
}

ProjectClip::~ProjectClip()
{
104
    // controller is deleted in bincontroller
105
    abortAudioThumbs();
106
    bin()->slotAbortAudioThumb(m_id, duration().ms());
107 108
    QMutexLocker audioLock(&m_audioMutex);
    m_thumbMutex.lock();
109
    m_requestedThumbs.clear();
110
    m_thumbMutex.unlock();
111
    m_thumbThread.waitForFinished();
112
    delete m_thumbsProducer;
113
    audioFrameCache.clear();
114 115
}

116 117 118
void ProjectClip::abortAudioThumbs()
{
    m_abortAudioThumb = true;
119
    emit doAbortAudioThumbs();
120 121
}

122 123
QString ProjectClip::getToolTip() const
{
124
    return url();
125 126
}

127
QString ProjectClip::getXmlProperty(const QDomElement &producer, const QString &propertyName, const QString &defaultValue)
128
{
129
    QString value = defaultValue;
130
    QDomNodeList props = producer.elementsByTagName(QStringLiteral("property"));
131
    for (int i = 0; i < props.count(); ++i) {
132
        if (props.at(i).toElement().attribute(QStringLiteral("name")) == propertyName) {
133 134 135 136 137 138 139
            value = props.at(i).firstChild().nodeValue();
            break;
        }
    }
    return value;
}

Laurent Montel's avatar
Laurent Montel committed
140
void ProjectClip::updateAudioThumbnail(const QVariantList &audioLevels)
141
{
142
    audioFrameCache = audioLevels;
143
    m_controller->audioThumbCreated = true;
144
    bin()->emitRefreshAudioThumbs(m_id);
145 146 147
    emit gotAudioData();
}

Laurent Montel's avatar
Laurent Montel committed
148
QList< CommentedTime > ProjectClip::commentedSnapMarkers() const
149
{
150 151 152
    if (m_controller) {
        return m_controller->commentedSnapMarkers();
    }
Laurent Montel's avatar
Laurent Montel committed
153
    return QList< CommentedTime > ();
154 155
}

156 157
QStringList ProjectClip::markersText(GenTime in, GenTime out) const
{
158 159 160
    if (m_controller) {
        return m_controller->markerComments(in, out);
    }
161 162 163
    return QStringList();
}

164 165
bool ProjectClip::audioThumbCreated() const
{
166
    return (m_controller && m_controller->audioThumbCreated);
167 168
}

169 170
ClipType ProjectClip::clipType() const
{
171
    return m_type;
172 173
}

174 175 176 177
bool ProjectClip::hasParent(const QString &id) const
{
    AbstractProjectItem *par = parent();
    while (par) {
178 179 180 181
        if (par->clipId() == id) {
            return true;
        }
        par = par->parent();
182 183 184 185
    }
    return false;
}

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

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

200 201
void ProjectClip::disableEffects(bool disable)
{
202 203 204
    if (m_controller) {
        m_controller->disableEffects(disable);
    }
205 206
}

207
ProjectSubClip *ProjectClip::getSubClip(int in, int out)
208 209
{
    for (int i = 0; i < count(); ++i) {
Vincent Pinon's avatar
Vincent Pinon committed
210
        ProjectSubClip *clip = static_cast<ProjectSubClip *>(at(i))->subClip(in, out);
211 212 213 214
        if (clip) {
            return clip;
        }
    }
Laurent Montel's avatar
Laurent Montel committed
215
    return nullptr;
216 217
}

218 219 220 221 222 223 224 225 226 227 228 229
QStringList ProjectClip::subClipIds() const
{
    QStringList subIds;
    for (int i = 0; i < count(); ++i) {
        AbstractProjectItem *clip = at(i);
        if (clip) {
            subIds << clip->clipId();
        }
    }
    return subIds;
}

230
ProjectClip *ProjectClip::clipAt(int ix)
231 232 233 234
{
    if (ix == index()) {
        return this;
    }
Laurent Montel's avatar
Laurent Montel committed
235
    return nullptr;
236 237
}

238
/*bool ProjectClip::isValid() const
239
{
240 241
    return m_controller->isValid();
}*/
242

243 244
bool ProjectClip::hasUrl() const
{
245
    if (m_controller && (m_type != Color) && (m_type != Unknown)) {
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
246
        return (!m_controller->clipUrl().isEmpty());
247
    }
248 249 250
    return false;
}

251
const QString ProjectClip::url() const
252
{
253 254 255
    if (m_controller) {
        return m_controller->clipUrl();
    }
256
    return m_temporaryUrl;
257 258 259 260
}

bool ProjectClip::hasLimitedDuration() const
{
261 262 263 264
    if (m_controller) {
        return m_controller->hasLimitedDuration();
    }
    return true;
265 266
}

267
GenTime ProjectClip::duration() const
268
{
269
    if (m_controller) {
270
        return m_controller->getPlaytime();
271
    }
272
    return GenTime();
273 274
}

275 276 277 278 279 280
int ProjectClip::frameDuration() const
{
    GenTime d = duration();
    return d.frames(m_controller->profile()->fps());
}

281
void ProjectClip::reloadProducer(bool refreshOnly)
282 283 284
{
    QDomDocument doc;
    QDomElement xml = toXml(doc);
285
    if (refreshOnly) {
286
        // set a special flag to request thumbnail only
287
        xml.setAttribute(QStringLiteral("refreshOnly"), QStringLiteral("1"));
288
    }
289
    bin()->reloadProducer(m_id, xml);
290 291 292 293
}

void ProjectClip::setCurrent(bool current, bool notify)
{
294
    Q_UNUSED(notify)
295
    if (current && m_controller) {
Jean-Baptiste Mardelle's avatar
cleanup  
Jean-Baptiste Mardelle committed
296
        bin()->openProducer(m_controller);
297
        bin()->editMasterEffect(m_controller);
298 299 300
    }
}

301
QDomElement ProjectClip::toXml(QDomDocument &document, bool includeMeta)
302
{
303
    if (m_controller) {
304
        m_controller->getProducerXML(document, includeMeta);
305 306 307 308 309
        QDomElement prod = document.documentElement().firstChildElement(QStringLiteral("producer"));
        if (m_type != Unknown) {
            prod.setAttribute(QStringLiteral("type"), (int) m_type);
        }
        return prod;
310
    } else {
311
        // We only have very basic infos, like id and url, pass them
312 313
        QDomElement prod = document.createElement(QStringLiteral("producer"));
        prod.setAttribute(QStringLiteral("id"), m_id);
314
        EffectsList::setProperty(prod, QStringLiteral("resource"), m_temporaryUrl);
315 316 317 318 319
        if (m_type != Unknown) {
            prod.setAttribute(QStringLiteral("type"), (int) m_type);
        }
        document.appendChild(prod);
        return prod;
320 321 322
    }
}

Laurent Montel's avatar
Laurent Montel committed
323
void ProjectClip::setThumbnail(const QImage &img)
324
{
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
325 326
    QPixmap thumb = roundedPixmap(QPixmap::fromImage(img));
    if (hasProxy() && !thumb.isNull()) {
327
        // Overlay proxy icon
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
328
        QPainter p(&thumb);
329
        QColor c(220, 220, 10, 200);
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
330
        QRect r(0, 0, thumb.height() / 2.5, thumb.height() / 2.5);
331 332 333 334 335 336 337 338
        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
339
    m_thumbnail = QIcon(thumb);
340
    emit thumbUpdated(img);
341 342 343
    bin()->emitItemUpdated(this);
}

344 345 346 347 348
QPixmap ProjectClip::thumbnail(int width, int height)
{
    return m_thumbnail.pixmap(width, height);
}

349
bool ProjectClip::setProducer(ClipController *controller, bool replaceProducer)
350
{
351
    if (!replaceProducer && m_controller) {
352
        qCDebug(KDENLIVE_LOG) << "// RECEIVED PRODUCER BUT WE ALREADY HAVE ONE\n----------";
353
        return false;
354
    }
355
    bool isNewProducer = true;
356 357
    if (m_controller) {
        // Replace clip for this controller
Laurent Montel's avatar
Laurent Montel committed
358
        resetProducerProperty(QStringLiteral("kdenlive:file_hash"));
359
        isNewProducer = false;
360
    } else if (controller) {
361 362
        // We did not yet have the controller, update info
        m_controller = controller;
363 364 365
        if (m_name.isEmpty()) {
            m_name = m_controller->clipName();
        }
366
        m_date = m_controller->date;
367
        m_description = m_controller->description();
368
        m_temporaryUrl.clear();
369 370 371
        if (m_type == Unknown) {
            m_type = m_controller->clipType();
            if (m_type == Audio) {
372
                m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
373 374
            }
        }
375
    }
376
    if (m_controller) {
Vincent Pinon's avatar
Vincent Pinon committed
377
        m_duration = m_controller->getStringDuration();
378
    }
379
    m_clipStatus = StatusReady;
380 381 382
    if (!hasProxy()) {
        bin()->emitRefreshPanel(m_id);
    }
383
    bin()->emitItemUpdated(this);
384
    // Make sure we have a hash for this clip
385
    getFileHash();
386
    createAudioThumbs();
387
    return isNewProducer;
388 389 390 391
}

void ProjectClip::createAudioThumbs()
{
392
    if (KdenliveSettings::audiothumbnails() && (m_type == AV || m_type == Audio || m_type == Playlist)) {
393 394
        bin()->requestAudioThumbs(m_id, duration().ms());
        emit updateJobStatus(AbstractClipJob::THUMBJOB, JobWaiting, 0);
395
    }
396 397
}

398
Mlt::Producer *ProjectClip::originalProducer()
399
{
400
    if (!m_controller) {
Laurent Montel's avatar
Laurent Montel committed
401
        return nullptr;
402 403
    }
    return &m_controller->originalProducer();
404 405
}

406 407 408 409 410 411
Mlt::Producer *ProjectClip::thumbProducer()
{
    QMutexLocker locker(&m_producerMutex);
    if (m_thumbsProducer) {
        return m_thumbsProducer;
    }
412
    if (!m_controller || m_controller->clipType() == Unknown) {
Laurent Montel's avatar
Laurent Montel committed
413
        return nullptr;
414 415
    }
    Mlt::Producer prod = m_controller->originalProducer();
416
    if (!prod.is_valid()) {
Laurent Montel's avatar
Laurent Montel committed
417
        return nullptr;
418
    }
419 420
    Clip clip(prod);
    if (KdenliveSettings::gpu_accel()) {
421
        m_thumbsProducer = clip.softClone(ClipController::getPassPropertiesList());
422 423 424 425
        Mlt::Filter scaler(*prod.profile(), "swscale");
        Mlt::Filter converter(*prod.profile(), "avcolor_space");
        m_thumbsProducer->attach(scaler);
        m_thumbsProducer->attach(converter);
426 427
    } else {
        m_thumbsProducer = clip.clone();
428 429 430 431
    }
    return m_thumbsProducer;
}

432 433 434 435 436
ClipController *ProjectClip::controller()
{
    return m_controller;
}

437
bool ProjectClip::isReady() const
438
{
Laurent Montel's avatar
Laurent Montel committed
439
    return m_controller != nullptr && m_clipStatus == StatusReady;
440 441
}

442
/*void ProjectClip::setZone(const QPoint &zone)
443 444
{
    m_zone = zone;
445
}*/
446 447 448

QPoint ProjectClip::zone() const
{
449 450
    int x = getProducerIntProperty(QStringLiteral("kdenlive:zone_in"));
    int y = getProducerIntProperty(QStringLiteral("kdenlive:zone_out"));
451
    return QPoint(x, y);
452 453
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
454 455 456 457 458 459 460 461
void ProjectClip::resetProducerProperty(const QString &name)
{
    if (m_controller) {
        m_controller->resetProperty(name);
    }
}

void ProjectClip::setProducerProperty(const QString &name, int data)
462
{
463
    if (m_controller) {
464
        m_controller->setProperty(name, data);
465 466 467
    }
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
468
void ProjectClip::setProducerProperty(const QString &name, double data)
469
{
470 471
    if (m_controller) {
        m_controller->setProperty(name, data);
472 473 474
    }
}

Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
475
void ProjectClip::setProducerProperty(const QString &name, const QString &data)
476
{
477 478
    if (m_controller) {
        m_controller->setProperty(name, data);
479 480 481
    }
}

Laurent Montel's avatar
Laurent Montel committed
482
QMap<QString, QString> ProjectClip::currentProperties(const QMap<QString, QString> &props)
483
{
Laurent Montel's avatar
Laurent Montel committed
484
    QMap<QString, QString> currentProps;
485 486 487 488 489 490 491 492 493 494 495
    if (!m_controller) {
        return currentProps;
    }
    QMap<QString, QString>::const_iterator i = props.constBegin();
    while (i != props.constEnd()) {
        currentProps.insert(i.key(), m_controller->property(i.key()));
        ++i;
    }
    return currentProps;
}

496 497 498 499 500 501 502 503
QColor ProjectClip::getProducerColorProperty(const QString &key) const
{
    if (m_controller) {
        return m_controller->color_property(key);
    }
    return QColor();
}

504 505 506 507 508 509 510 511
int ProjectClip::getProducerIntProperty(const QString &key) const
{
    int value = 0;
    if (m_controller) {
        value = m_controller->int_property(key);
    }
    return value;
}
512

513 514 515 516 517 518 519 520 521
qint64 ProjectClip::getProducerInt64Property(const QString &key) const
{
    qint64 value = 0;
    if (m_controller) {
        value = m_controller->int64_property(key);
    }
    return value;
}

522 523 524 525 526 527 528 529 530
double ProjectClip::getDoubleProducerProperty(const QString &key) const
{
    double value = 0;
    if (m_controller) {
        value = m_controller->double_property(key);
    }
    return value;
}

531
QString ProjectClip::getProducerProperty(const QString &key) const
532 533
{
    QString value;
534
    if (m_controller) {
535
        value = m_controller->property(key);
536 537 538 539 540 541
    }
    return value;
}

const QString ProjectClip::hash()
{
542
    if (m_controller) {
543
        QString clipHash = m_controller->property(QStringLiteral("kdenlive:file_hash"));
544 545
        if (!clipHash.isEmpty()) {
            return clipHash;
546
        }
547
    }
548
    return getFileHash();
549 550
}

551
const QString ProjectClip::getFileHash() const
552
{
553 554 555
    QByteArray fileData;
    QByteArray fileHash;
    switch (m_type) {
556
    case SlideShow:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
557
        fileData = m_controller ? m_controller->clipUrl().toUtf8() : m_temporaryUrl.toUtf8();
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Text:
        fileData = m_controller ? m_controller->property(QStringLiteral("xmldata")).toUtf8() : name().toUtf8();
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case QText:
        fileData = m_controller ? m_controller->property(QStringLiteral("text")).toUtf8() : name().toUtf8();
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    case Color:
        fileData = m_controller ? m_controller->property(QStringLiteral("resource")).toUtf8() : name().toUtf8();
        fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
        break;
    default:
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
573
        QFile file(m_controller ? m_controller->clipUrl() : m_temporaryUrl);
574 575 576 577 578
        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)
             */
579 580
            if (file.size() > 2000000) {
                fileData = file.read(1000000);
581
                if (file.seek(file.size() - 1000000)) {
582
                    fileData.append(file.readAll());
583 584
                }
            } else {
585
                fileData = file.readAll();
586
            }
587
            file.close();
588 589 590
            if (m_controller) {
                m_controller->setProperty(QStringLiteral("kdenlive:file_size"), QString::number(file.size()));
            }
591
            fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
592 593 594 595 596
        }
        break;
    }
    if (fileHash.isEmpty()) {
        return QString();
597 598 599
    }
    QString result = fileHash.toHex();
    if (m_controller) {
600
        m_controller->setProperty(QStringLiteral("kdenlive:file_hash"), result);
601
    }
602
    return result;
603
}
604 605 606

double ProjectClip::getOriginalFps() const
{
607 608 609
    if (!m_controller) {
        return 0;
    }
610 611
    return m_controller->originalFps();
}
612 613 614

bool ProjectClip::hasProxy() const
{
615
    QString proxy = getProducerProperty(QStringLiteral("kdenlive:proxy"));
616 617 618
    if (proxy.isEmpty() || proxy == QLatin1String("-")) {
        return false;
    }
619 620 621
    return true;
}

Laurent Montel's avatar
Laurent Montel committed
622
void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool refreshPanel)
623 624
{
    QMapIterator<QString, QString> i(properties);
Laurent Montel's avatar
Laurent Montel committed
625
    QMap<QString, QString> passProperties;
626
    bool refreshAnalysis = false;
627
    bool reload = false;
628
    bool refreshOnly = true;
629 630
    // Some properties also need to be passed to track producers
    QStringList timelineProperties;
Laurent Montel's avatar
Laurent Montel committed
631 632
    if (properties.contains(QStringLiteral("templatetext"))) {
        m_description = properties.value(QStringLiteral("templatetext"));
633 634 635
        bin()->emitItemUpdated(this);
        refreshPanel = true;
    }
636
    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");
637
    QStringList keys;
638
    keys << QStringLiteral("luma_duration") << QStringLiteral("luma_file") << QStringLiteral("fade") << QStringLiteral("ttl") << QStringLiteral("softness") << QStringLiteral("crop") << QStringLiteral("animation");
639 640
    while (i.hasNext()) {
        i.next();
Jean-Baptiste Mardelle's avatar
Jean-Baptiste Mardelle committed
641
        setProducerProperty(i.key(), i.value());
642 643
        if (m_type == SlideShow && keys.contains(i.key())) {
            reload = true;
644
            refreshOnly = false;
645
        }
646 647 648
        if (i.key().startsWith(QLatin1String("kdenlive:clipanalysis"))) {
            refreshAnalysis = true;
        }
649 650 651
        if (timelineProperties.contains(i.key())) {
            passProperties.insert(i.key(), i.value());
        }
652
    }
653 654
    if (properties.contains(QStringLiteral("kdenlive:proxy"))) {
        QString value = properties.value(QStringLiteral("kdenlive:proxy"));
655
        // If value is "-", that means user manually disabled proxy on this clip
656
        if (value.isEmpty() || value == QLatin1String("-")) {
657 658 659
            // reset proxy
            if (bin()->hasPendingJob(m_id, AbstractClipJob::PROXYJOB)) {
                bin()->discardJobs(m_id, AbstractClipJob::PROXYJOB);
660
            } else {
661 662
                reloadProducer();
            }
663
        } else {
664
            // A proxy was requested, make sure to keep original url
665
            setProducerProperty(QStringLiteral("kdenlive:originalurl"), url());
666
            bin()->startJob(m_id, AbstractClipJob::PROXYJOB);
667
        }
668
    } else if (properties.contains(QStringLiteral("resource")) || properties.contains(QStringLiteral("templatetext")) || properties.contains(QStringLiteral("autorotate"))) {
669
        // Clip resource changed, update thumbnail
670
        if (m_type != Color) {
671
            reloadProducer();
672 673
        } else {
            reload = true;
674
        }
675
    }
676
    if (properties.contains(QStringLiteral("xmldata")) || !passProperties.isEmpty()) {
677
        reload = true;
678
    }
679 680 681
    if (refreshAnalysis) {
        emit refreshAnalysisPanel();
    }
682
    if (properties.contains(QStringLiteral("length")) || properties.contains(QStringLiteral("kdenlive:duration"))) {
683 684 685 686
        m_duration = m_controller->getStringDuration();
        bin()->emitItemUpdated(this);
    }

687 688
    if (properties.contains(QStringLiteral("kdenlive:clipname"))) {
        m_name = properties.value(QStringLiteral("kdenlive:clipname"));
689
        refreshPanel = true;
690 691
        bin()->emitItemUpdated(this);
    }
692 693 694 695
    if (refreshPanel) {
        // Some of the clip properties have changed through a command, update properties panel
        emit refreshPropertiesPanel();
    }
696
    if (reload) {
697
        // producer has changed, refresh monitor and thumbnail
698
        reloadProducer(refreshOnly);
699
        bin()->refreshClip(m_id);
700
    }
701 702 703
    if (!passProperties.isEmpty()) {
        bin()->updateTimelineProducers(m_id, passProperties);
    }
704 705
}

706
void ProjectClip::setJobStatus(int jobType, int status, int progress, const QString &statusMessage)
707
{
708
    m_jobType = (AbstractClipJob::JOBTYPE) jobType;
709
    if (progress > 0) {
710 711 712
        if (m_jobProgress == progress) {
            return;
        }
713
        m_jobProgress = progress;
714
    } else {
715
        m_jobProgress = status;
716 717 718
        if (m_jobType == AbstractClipJob::PROXYJOB && (status == JobAborted || status == JobCrashed)) {
            setProducerProperty(QStringLiteral("kdenlive:proxy"), QStringLiteral("-"));
        }
719 720
        if ((status == JobAborted || status == JobCrashed  || status == JobDone) && !statusMessage.isEmpty()) {
            m_jobMessage = statusMessage;
721
            bin()->emitMessage(statusMessage, 100, OperationCompletedMessage);
722
        }
723 724 725
    }
    bin()->emitItemUpdated(this);
}
726

727 728
ClipPropertiesController *ProjectClip::buildProperties(QWidget *parent)
{
729
    ClipPropertiesController *panel = new ClipPropertiesController(bin()->projectTimecode(), m_controller, parent);
Laurent Montel's avatar
Laurent Montel committed
730 731
    connect(this, &ProjectClip::refreshPropertiesPanel, panel, &ClipPropertiesController::slotReloadProperties);
    connect(this, &ProjectClip::refreshAnalysisPanel, panel, &ClipPropertiesController::slotFillAnalysisData);
732 733 734
    return panel;
}

735 736
void ProjectClip::updateParentInfo(const QString &folderid, const QString &foldername)
{
737
    Q_UNUSED(foldername)
738
    m_controller->setProperty(QStringLiteral("kdenlive:folderid"), folderid);
739 740
}

Laurent Montel's avatar
Laurent Montel committed
741
bool ProjectClip::matches(const QString &condition)
742 743
{
    //TODO
744
    Q_UNUSED(condition)
745 746 747
    return true;
}

748
const QString ProjectClip::codec(bool audioCodec) const
749
{