Progress on Bin-timeline communication, fix clip type detection, audio thumbs are back

parent ff9e8488
......@@ -59,8 +59,7 @@ ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, ProjectItemModel
m_duration = getStringDuration();
m_date = date;
m_description = ClipController::description();
m_type = clipType();
if (m_type == Audio) {
if (m_clipType == Audio) {
m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
} else {
m_thumbnail = thumb;
......@@ -75,17 +74,16 @@ ProjectClip::ProjectClip(const QString &id, const QIcon &thumb, ProjectItemModel
ProjectClip::ProjectClip(const QDomElement &description, const QIcon &thumb, ProjectItemModel *model, ProjectFolder *parent)
: AbstractProjectItem(AbstractProjectItem::ClipItem, description, model, parent)
, ClipController(pCore->binController(), ClipController::mediaUnavailable)
, ClipController(pCore->binController())
, m_abortAudioThumb(false)
, m_type(Unknown)
, m_thumbsProducer(nullptr)
{
Q_ASSERT(description.hasAttribute(QStringLiteral("id")));
m_clipStatus = StatusWaiting;
m_thumbnail = thumb;
if (description.hasAttribute(QStringLiteral("type"))) {
m_type = (ClipType)description.attribute(QStringLiteral("type")).toInt();
if (m_type == Audio) {
m_clipType = (ClipType)description.attribute(QStringLiteral("type")).toInt();
if (m_clipType == Audio) {
m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
}
}
......@@ -160,7 +158,7 @@ bool ProjectClip::audioThumbCreated() const
ClipType ProjectClip::clipType() const
{
return m_type;
return m_clipType;
}
bool ProjectClip::hasParent(const QString &id) const
......@@ -227,7 +225,7 @@ ProjectClip *ProjectClip::clipAt(int ix)
bool ProjectClip::hasUrl() const
{
if ((m_type != Color) && (m_type != Unknown)) {
if ((m_clipType != Color) && (m_clipType != Unknown)) {
return (!clipUrl().isEmpty());
}
return false;
......@@ -273,8 +271,8 @@ QDomElement ProjectClip::toXml(QDomDocument &document, bool includeMeta)
{
getProducerXML(document, includeMeta);
QDomElement prod = document.documentElement().firstChildElement(QStringLiteral("producer"));
if (m_type != Unknown) {
prod.setAttribute(QStringLiteral("type"), (int)m_type);
if (m_clipType != Unknown) {
prod.setAttribute(QStringLiteral("type"), (int)m_clipType);
}
return prod;
}
......@@ -318,11 +316,8 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool repl
m_date = date;
m_description = ClipController::description();
m_temporaryUrl.clear();
if (m_type == Unknown) {
m_type = clipType();
if (m_type == Audio) {
m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
}
if (m_clipType == Audio) {
m_thumbnail = KoIconUtils::themedIcon(QStringLiteral("audio-x-generic"));
}
m_duration = getStringDuration();
m_clipStatus = StatusReady;
......@@ -338,7 +333,7 @@ bool ProjectClip::setProducer(std::shared_ptr<Mlt::Producer> producer, bool repl
void ProjectClip::createAudioThumbs()
{
if (KdenliveSettings::audiothumbnails() && (m_type == AV || m_type == Audio || m_type == Playlist)) {
if (KdenliveSettings::audiothumbnails() && (m_clipType == AV || m_clipType == Audio || m_clipType == Playlist)) {
static_cast<ProjectItemModel *>(m_model)->bin()->requestAudioThumbs(m_id, duration().ms());
emit updateJobStatus(AbstractClipJob::THUMBJOB, JobWaiting, 0);
}
......@@ -400,7 +395,7 @@ const QString ProjectClip::getFileHash()
{
QByteArray fileData;
QByteArray fileHash;
switch (m_type) {
switch (m_clipType) {
case SlideShow:
fileData = clipUrl().toUtf8();
fileHash = QCryptographicHash::hash(fileData, QCryptographicHash::Md5);
......@@ -481,7 +476,7 @@ void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool r
while (i.hasNext()) {
i.next();
setProducerProperty(i.key(), i.value());
if (m_type == SlideShow && keys.contains(i.key())) {
if (m_clipType == SlideShow && keys.contains(i.key())) {
reload = true;
refreshOnly = false;
}
......@@ -510,7 +505,7 @@ void ProjectClip::setProperties(const QMap<QString, QString> &properties, bool r
} else if (properties.contains(QStringLiteral("resource")) || properties.contains(QStringLiteral("templatetext")) ||
properties.contains(QStringLiteral("autorotate"))) {
// Clip resource changed, update thumbnail
if (m_type != Color) {
if (m_clipType != Color) {
reloadProducer();
} else {
reload = true;
......@@ -615,7 +610,7 @@ bool ProjectClip::rename(const QString &name, int column)
return false;
}
// Rename clip
if (m_type == TextTemplate) {
if (m_clipType == TextTemplate) {
oldProperites.insert(QStringLiteral("templatetext"), m_description);
newProperites.insert(QStringLiteral("templatetext"), name);
} else {
......@@ -874,7 +869,7 @@ void ProjectClip::slotCreateAudioThumbs()
return;
}
bool jobFinished = false;
if (KdenliveSettings::ffmpegaudiothumbnails() && m_type != Playlist) {
if (KdenliveSettings::ffmpegaudiothumbnails() && m_clipType != Playlist) {
QStringList args;
QList<QTemporaryFile *> channelFiles;
for (int i = 0; i < channels; i++) {
......@@ -1140,10 +1135,10 @@ void ProjectClip::updateFfmpegProgress()
bool ProjectClip::isTransparent() const
{
if (m_type == Text) {
if (m_clipType == Text) {
return true;
}
return m_type == Image && getProducerIntProperty(QStringLiteral("kdenlive:transparency")) == 1;
return m_clipType == Image && getProducerIntProperty(QStringLiteral("kdenlive:transparency")) == 1;
}
QStringList ProjectClip::updatedAnalysisData(const QString &name, const QString &data, int offset)
......@@ -1220,7 +1215,7 @@ QImage ProjectClip::findCachedThumb(int pos)
bool ProjectClip::isSplittable() const
{
return (m_type == AV || m_type == Playlist);
return (m_clipType == AV || m_clipType == Playlist);
}
void ProjectClip::disableEffects(bool disable)
......
......@@ -222,7 +222,6 @@ private:
const QString getFileHash();
/** @brief Store clip url temporarily while the clip controller has not been created. */
QString m_temporaryUrl;
ClipType m_type;
Mlt::Producer *m_thumbsProducer;
QMutex m_producerMutex;
QMutex m_thumbMutex;
......
......@@ -37,6 +37,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <utility>
std::shared_ptr<Mlt::Producer> ClipController::mediaUnavailable;
ClipController::ClipController(std::shared_ptr<BinController> bincontroller, std::shared_ptr<Mlt::Producer> producer)
: selectedEffectIndex(1)
, m_audioThumbCreated(false)
......@@ -235,7 +236,7 @@ const QString ClipController::clipId()
if (m_masterProducer == nullptr) {
return QString();
}
return getProducerProperty(QStringLiteral("id"));
return getProducerProperty(QStringLiteral("kdenlive:id"));
}
// static
......@@ -263,6 +264,10 @@ QMap<QString, QString> ClipController::getPropertiesFromPrefix(const QString &pr
void ClipController::updateProducer(const std::shared_ptr<Mlt::Producer> &producer)
{
// TODO replace all track producers
if (!m_properties) {
// producer has not been initialized
return addMasterProducer(producer);
}
Mlt::Properties passProperties;
// Keep track of necessary properties
......
......@@ -616,10 +616,10 @@ void ProducerQueue::processFileProperties()
QList<int> video_list;
for (int i = 0; i < streams; ++i) {
QByteArray propertyName = QStringLiteral("meta.media.%1.stream.type").arg(i).toLocal8Bit();
QString type = producer->get(propertyName.data());
if (type == QLatin1String("audio")) {
QString stype = producer->get(propertyName.data());
if (stype == QLatin1String("audio")) {
audio_list.append(i);
} else if (type == QLatin1String("video")) {
} else if (stype == QLatin1String("video")) {
video_list.append(i);
}
}
......@@ -772,10 +772,10 @@ void ProducerQueue::processFileProperties()
// Find maximum stream index values
for (int ix = 0; ix < producer->get_int("meta.media.nb_streams"); ++ix) {
snprintf(property, sizeof(property), "meta.media.%d.stream.type", ix);
QString type = producer->get(property);
if (type == QLatin1String("video")) {
QString stype = producer->get(property);
if (stype == QLatin1String("video")) {
video_max = ix;
} else if (type == QLatin1String("audio")) {
} else if (stype == QLatin1String("audio")) {
audio_max = ix;
}
}
......
......@@ -35,7 +35,13 @@ ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::shared_ptr<Mlt::P
, m_effectStack(EffectStackModel::construct(m_producer))
, m_binClipId(binClipId)
{
checkLimitless();
m_producer->set("kdenlive:id", binClipId.toUtf8().constData());
ProjectClip *binClip = pCore->bin()->getBinClip(m_binClipId);
if (binClip) {
m_endlessResize = binClip->hasLimitedDuration();
} else {
m_endlessResize = false;
}
}
int ClipModel::construct(const std::weak_ptr<TimelineModel> &parent, const QString &binClipId, int id)
......@@ -175,17 +181,19 @@ void ClipModel::refreshProducerFromBin()
ProjectClip *binClip = pCore->bin()->getBinClip(m_binClipId);
std::shared_ptr<Mlt::Producer> originalProducer = binClip->originalProducer();
m_producer.reset(originalProducer->cut(in, out));
checkLimitless();
m_endlessResize = binClip->hasLimitedDuration();
}
// static
QStringList ClipModel::limitlessProducers()
QVariant ClipModel::getAudioWaveform()
{
return {QStringLiteral("qimage"), QStringLiteral("pixbuf"), QStringLiteral("color"), QStringLiteral("kdenlivetitle")};
ProjectClip *binClip = pCore->bin()->getBinClip(m_binClipId);
if (binClip) {
return QVariant::fromValue(binClip->audioFrameCache);
}
return QVariant();
}
void ClipModel::checkLimitless()
const QString &ClipModel::binId() const
{
QString serv = m_producer->get("mlt_service");
m_endlessResize = limitlessProducers().contains(serv);
return m_binClipId;
}
......@@ -67,8 +67,11 @@ public:
*/
int getPlaytime() const override;
/** @brief Returns the list of producers that can have limitless resizes */
static QStringList limitlessProducers();
/** @brief Returns audio cache data from bin clip to display audio thumbs */
QVariant getAudioWaveform();
/** @brief Returns the bin clip's id */
const QString &binId() const;
friend class TrackModel;
friend class TimelineModel;
......@@ -95,9 +98,6 @@ protected:
/* @brief This functions should be called when the producer of the binClip changes, to allow refresh */
void refreshProducerFromBin();
/** @brief Checks whether the current producers is limitless and set m_endlessResize acordingly */
void checkLimitless();
bool hasAudio() const;
bool isAudioOnly() const;
......
......@@ -216,14 +216,12 @@ QVariant TimelineItemModel::data(const QModelIndex &index, int role) const
return result;
}
case BinIdRole:
return clip->getProperty("kdenlive:id").toInt();
return clip->binId();
case ServiceRole:
return clip->getProperty("mlt_service");
break;
case AudioLevelsRole:
// TODO: get data from bin clip when interface is ready
// return QVariant::fromValue(pCore->bin()->audioFrameCache(clip->getProperty("kdenlive:id")));
return QVariant();
return clip->getAudioWaveform();
case HasAudio:
return clip->hasAudio();
case IsAudioRole:
......
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