X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fdocclipbase.cpp;h=1ddf523b3298dd5987257b3201c107af88e01d1b;hb=d5e2d9e691b22dab741ed689df6d87478ba24c9f;hp=6e08b16ea051dce11072eab2bc5afb22ef567192;hpb=5adcd327aa408a2f21aa6aa8b62f8b29641fd2cc;p=kdenlive diff --git a/src/docclipbase.cpp b/src/docclipbase.cpp index 6e08b16e..1ddf523b 100644 --- a/src/docclipbase.cpp +++ b/src/docclipbase.cpp @@ -19,402 +19,465 @@ #include "kdenlivesettings.h" #include "docclipbase.h" +#include "kthumb.h" +#include "clipmanager.h" + +DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id): + m_id(id), m_description(QString()), m_refcount(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL), m_clipProducer(NULL) { + int type = xml.attribute("type").toInt(); + m_clipType = (CLIPTYPE) type; + m_name = xml.attribute("name"); + m_id = id; + + QDomNamedNodeMap attributes = xml.attributes(); + for (unsigned int i = 0; i < attributes.count(); i++) { + m_properties.insert(attributes.item(i).nodeName(), attributes.item(i).nodeValue()); + } -DocClipBase::DocClipBase(QDomElement xml, uint id): -m_xml(xml), m_id(id), m_description(""), m_refcount(0), m_projectThumbFrame(0), m_audioThumbCreated(false), m_duration(GenTime()), m_thumbProd(NULL), m_audioTimer(NULL) -{ - int type = xml.attribute("type").toInt(); - m_clipType = (CLIPTYPE) type; - m_name = xml.attribute("name"); - m_xml.setAttribute("id", QString::number(id)); - KUrl url = KUrl(xml.attribute("resource")); - int out = xml.attribute("out").toInt(); - if (out != 0) setDuration(GenTime(out, 25)); - if (m_name.isEmpty()) m_name = url.fileName(); - if (!url.isEmpty()){ - m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height()); - connect (m_thumbProd, SIGNAL (audioThumbReady(QMap >)), this , SLOT(updateAudioThumbnail(QMap > ))); - connect (this, SIGNAL (getAudioThumbs()), this , SLOT( slotGetAudioThumbs() ) ); - - } - kDebug() << "type is video" << (m_clipType==AV) << " " << m_clipType; - - if (m_clipType == AV || m_clipType==AUDIO || m_clipType==UNKNOWN){ - m_audioTimer = new QTimer( this ); - connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); - //TODO disabled until the crash cause is found - emit getAudioThumbs(); - } -} + KUrl url = KUrl(xml.attribute("resource")); + int out = xml.attribute("out").toInt(); + if (out != 0) { + setDuration(GenTime(out, KdenliveSettings::project_fps())); + } else { + out = xml.attribute("duration").toInt(); + if (out != 0) setDuration(GenTime(out, KdenliveSettings::project_fps())); + } + if (m_name.isEmpty()) m_name = url.fileName(); -DocClipBase::DocClipBase(const DocClipBase& clip) -{ - m_xml = clip.toXML(); - m_id = clip.getId(); - m_clipType = clip.clipType(); - m_name = clip.name(); - m_duration = clip.duration(); - m_audioThumbCreated = clip.audioThumbCreated(); + if (!url.isEmpty() && QFile::exists(url.path())) { + m_thumbProd = new KThumb(clipManager, url); + if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer(); + } + //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType; } -DocClipBase & DocClipBase::operator=(const DocClipBase & clip) -{ +/*DocClipBase & DocClipBase::operator=(const DocClipBase & clip) { DocClipBase::operator=(clip); - m_xml = clip.toXML(); m_id = clip.getId(); m_clipType = clip.clipType(); m_name = clip.name(); m_duration = clip.duration(); m_audioThumbCreated = clip.audioThumbCreated(); + m_properties = clip.properties(); return *this; +}*/ + +DocClipBase::~DocClipBase() { + if (m_thumbProd) delete m_thumbProd; + if (m_clipProducer) delete m_clipProducer; +} + +void DocClipBase::slotCreateAudioTimer() { + connect(m_thumbProd, SIGNAL(audioThumbReady(QMap >)), this , SLOT(updateAudioThumbnail(QMap >))); + connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs())); + m_audioTimer = new QTimer(this); + connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs())); } -DocClipBase::~DocClipBase() -{ - //if (m_thumbProd) delete m_thumbProd; +void DocClipBase::slotRequestAudioThumbs() { + emit getAudioThumbs(); } -KThumb *DocClipBase::thumbProducer() -{ - return m_thumbProd; +void DocClipBase::slotClearAudioCache() { + if (m_thumbProd) m_thumbProd->stopAudioThumbs(); + if (m_audioTimer != NULL) m_audioTimer->stop(); + audioFrameChache.clear(); + m_audioThumbCreated = false; } -bool DocClipBase::audioThumbCreated() const -{ - return m_audioThumbCreated; +KThumb *DocClipBase::thumbProducer() { + return m_thumbProd; } -void DocClipBase::setName(const QString name) -{ +bool DocClipBase::audioThumbCreated() const { + return m_audioThumbCreated; +} + +void DocClipBase::setName(const QString name) { m_name = name; } -const QString & DocClipBase::name() const -{ - +const QString & DocClipBase::name() const { + return m_name; } -uint DocClipBase::getId() const -{ +uint DocClipBase::getId() const { return m_id; } -void DocClipBase::setId( const uint &newId) -{ +void DocClipBase::setId(const uint &newId) { m_id = newId; } -const CLIPTYPE & DocClipBase::clipType() const -{ - return m_clipType; +const CLIPTYPE & DocClipBase::clipType() const { + return m_clipType; +} + +void DocClipBase::setClipType(CLIPTYPE type) { + m_clipType = type; + m_properties.insert("type", QString::number((int) type)); + if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO)) + slotCreateAudioTimer(); } -void DocClipBase::setClipType(CLIPTYPE type) -{ - m_clipType = type; +KUrl DocClipBase::fileURL() const { + QString res = m_properties.value("resource"); + if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); + return KUrl(); } -KUrl DocClipBase::fileURL() const -{ - QString res = m_xml.attribute("resource"); - if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res); - return KUrl(); +void DocClipBase::setClipThumbFrame(const uint &ix) { + m_properties.insert("thumbnail", QString::number((int) ix)); } -void DocClipBase::setProjectThumbFrame( const uint &ix) -{ - m_projectThumbFrame = ix; +uint DocClipBase::getClipThumbFrame() const { + return (uint) m_properties.value("thumbnail").toInt(); } -uint DocClipBase::getProjectThumbFrame() const -{ - return m_projectThumbFrame; +const QString DocClipBase::description() const { + return m_properties.value("description"); } -void DocClipBase::setDescription(const QString & description) -{ - m_description = description; +bool DocClipBase::isTransparent() const { + return (m_properties.value("transparency") == "1"); } -const QString & DocClipBase::description() const -{ - return m_description; +const QString DocClipBase::getProperty(const QString prop) const { + return m_properties.value(prop); } -void DocClipBase::setDuration(GenTime dur) -{ +void DocClipBase::setDuration(GenTime dur) { m_duration = dur; + m_properties.insert("duration", QString::number((int) dur.frames(KdenliveSettings::project_fps()))); } -const GenTime &DocClipBase::duration() const -{ +const GenTime &DocClipBase::duration() const { return m_duration; } -bool DocClipBase::hasFileSize() const -{ - return true; +const GenTime &DocClipBase::maxDuration() const { + if (m_clipType == COLOR || m_clipType == IMAGE || m_clipType == TEXT || (m_clipType == SLIDESHOW && m_properties.value("loop") == "1")) { + const GenTime dur(10000, KdenliveSettings::project_fps()); + return dur; + } + return m_duration; +} + +bool DocClipBase::hasFileSize() const { + return true; } // virtual -QDomElement DocClipBase::toXML() const -{ -/* +QDomElement DocClipBase::toXML() const { QDomDocument doc; - QDomElement clip = doc.createElement("kdenliveclip"); - QDomText text = doc.createTextNode(description()); - clip.appendChild(text); - doc.appendChild(clip); -*/ - return m_xml; + QDomElement clip = doc.createElement("producer"); + + QMapIterator i(m_properties); + while (i.hasNext()) { + i.next(); + if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value()); + } + //doc.appendChild(clip); + //kDebug()<<"/// CLIP XML: "<setDescription(description); - clip->setAudioThumbCreated(false); + // setup DocClipBase specifics of the clip. + QMap props; + props.insert("description", description); + clip->setProperties(props); + clip->setAudioThumbCreated(false); } return clip; } -void DocClipBase::setAudioThumbCreated(bool isDone) -{ +void DocClipBase::setAudioThumbCreated(bool isDone) { m_audioThumbCreated = isDone; } -QDomDocument DocClipBase::generateSceneList(bool, bool) const -{ -} - -void DocClipBase::setThumbnail(const QPixmap & pixmap) -{ +void DocClipBase::setThumbnail(const QPixmap & pixmap) { m_thumbnail = pixmap; } -const QPixmap & DocClipBase::thumbnail() const -{ +const QPixmap & DocClipBase::thumbnail() const { return m_thumbnail; } -void DocClipBase::updateAudioThumbnail(QMap > data) -{ +void DocClipBase::updateAudioThumbnail(QMap > data) { + kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************"; audioFrameChache = data; m_audioThumbCreated = true; + emit gotAudioData(); } -QList < GenTime > DocClipBase::snapMarkers() const -{ +QList < GenTime > DocClipBase::snapMarkers() const { QList < GenTime > markers; for (uint count = 0; count < m_snapMarkers.count(); ++count) { - markers.append(m_snapMarkers[count].time()); + markers.append(m_snapMarkers[count].time()); } return markers; } -QList < CommentedTime > DocClipBase::commentedSnapMarkers() const -{ +QList < CommentedTime > DocClipBase::commentedSnapMarkers() const { return m_snapMarkers; } -void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) -{ +void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) { m_snapMarkers = markers; } -void DocClipBase::addSnapMarker(const GenTime & time, QString comment) -{ +void DocClipBase::addSnapMarker(const GenTime & time, QString comment) { QList < CommentedTime >::Iterator it = m_snapMarkers.begin(); - for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) { - if ((*it).time() >= time) - break; + for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { + if ((*it).time() >= time) + break; } if ((it != m_snapMarkers.end()) && ((*it).time() == time)) { - kError() << - "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo" - << endl; + (*it).setComment(comment); + //kError() << "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"; } else { - CommentedTime t(time, comment); - m_snapMarkers.insert(it, t); + CommentedTime t(time, comment); + m_snapMarkers.insert(it, t); } } -void DocClipBase::editSnapMarker(const GenTime & time, QString comment) -{ +void DocClipBase::editSnapMarker(const GenTime & time, QString comment) { QList < CommentedTime >::Iterator it; - for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) { - if ((*it).time() == time) - break; + for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) { + if ((*it).time() == time) + break; } if (it != m_snapMarkers.end()) { - (*it).setComment(comment); + (*it).setComment(comment); } else { - kError() << - "trying to edit Snap Marker that does not already exists" << endl; + kError() << "trying to edit Snap Marker that does not already exists"; } } -QString DocClipBase::deleteSnapMarker(const GenTime & time) -{ +QString DocClipBase::deleteSnapMarker(const GenTime & time) { QString result = i18n("Marker"); QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == time) - break; - ++itt; + if ((*itt).time() == time) + break; + ++itt; } if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) { - result = (*itt).comment(); - m_snapMarkers.erase(itt); + result = (*itt).comment(); + m_snapMarkers.erase(itt); } return result; } -GenTime DocClipBase::hasSnapMarkers(const GenTime & time) -{ +GenTime DocClipBase::hasSnapMarkers(const GenTime & time) { QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == time) - return time; - ++itt; + if ((*itt).time() == time) + return time; + ++itt; } return GenTime(0.0); } -GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) -{ +GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) { int it; - for ( it = 0; it < m_snapMarkers.count(); it++ ) { - if (m_snapMarkers[it].time() >= currTime) - break; + for (it = 0; it < m_snapMarkers.count(); it++) { + if (m_snapMarkers[it].time() >= currTime) + break; } if (it == 0) return GenTime(); else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime) - return m_snapMarkers[it].time(); + return m_snapMarkers[it].time(); else return m_snapMarkers[it-1].time(); } -GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) -{ +GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) { int it; - for ( it = 0; it < m_snapMarkers.count(); it++ ) { - if (m_snapMarkers[it].time() > currTime) - break; + for (it = 0; it < m_snapMarkers.count(); it++) { + if (m_snapMarkers[it].time() > currTime) + break; } if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time(); return duration(); } -QString DocClipBase::markerComment(GenTime t) -{ +QString DocClipBase::markerComment(GenTime t) { QList < CommentedTime >::Iterator itt = m_snapMarkers.begin(); while (itt != m_snapMarkers.end()) { - if ((*itt).time() == t) - return (*itt).comment(); - ++itt; + if ((*itt).time() == t) + return (*itt).comment(); + ++itt; } return QString::null; } -//static -QString DocClipBase::getTypeName(CLIPTYPE type) -{ - QString result; - switch (type) { - case AV: - result = i18n("Video Clip"); - break; - case COLOR: - result = i18n("Color Clip"); - break; - case PLAYLIST: - result = i18n("Playlist Clip"); - break; - case IMAGE: - result = i18n("Image Clip"); - break; - case SLIDESHOW: - result = i18n("Slideshow Clip"); - break; - case VIRTUAL: - result = i18n("Virtual Clip"); - break; - case AUDIO: - result = i18n("Audio Clip"); - break; - case VIDEO: - result = i18n("Mute Video Clip"); - break; - case TEXT: - result = i18n("Text Clip"); - break; - default: - result = i18n("None"); - break; +void DocClipBase::setProducer(Mlt::Producer *producer) { + m_clipProducer = producer; + m_clipProducer->set("transparency", m_properties.value("transparency").toInt()); + if (m_thumbProd) m_thumbProd->setProducer(producer); +} + +Mlt::Producer *DocClipBase::producer() { + return m_clipProducer; +} + +void DocClipBase::slotRefreshProducer() { + if (m_clipProducer == NULL) return; + kDebug() << "//////////// REFRESH CLIP !!!!!!!!!!!!!!!!"; + if (m_clipType == SLIDESHOW) { + /*char *tmp = (char *) qstrdup(getProperty("resource").toUtf8().data()); + Mlt::Producer producer(*(m_clipProducer->profile()), tmp); + delete[] tmp; + delete m_clipProducer; + m_clipProducer = new Mlt::Producer(producer.get_producer()); + if (!getProperty("out").isEmpty()) m_clipProducer->set_in_and_out(getProperty("in").toInt(), getProperty("out").toInt());*/ + m_clipProducer->set("ttl", getProperty("ttl").toInt()); + //m_clipProducer->set("id", getProperty("id")); + if (getProperty("fade") == "1") { + // we want a fade filter effect + kDebug() << "//////////// FADE WANTED"; + Mlt::Service clipService(m_clipProducer->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(ct); + while (filter) { + if (filter->get("mlt_service") == "luma") { + break; + } + ct++; + filter = clipService.filter(ct); + } + + if (filter && filter->get("mlt_service") == "luma") { + filter->set("period", getProperty("ttl").toInt() - 1); + filter->set("luma.out", getProperty("luma_duration").toInt()); + QString resource = getProperty("luma_file"); + char *tmp = (char *) qstrdup(resource.toUtf8().data()); + filter->set("luma.resource", tmp); + delete[] tmp; + if (getProperty("softness") != QString()) { + int soft = getProperty("softness").toInt(); + filter->set("luma.softness", (double) soft / 100.0); + } + } else { + // filter does not exist, create it... + Mlt::Filter *filter = new Mlt::Filter(*(m_clipProducer->profile()), "luma"); + filter->set("period", getProperty("ttl").toInt() - 1); + filter->set("luma.out", getProperty("luma_duration").toInt()); + QString resource = getProperty("luma_file"); + char *tmp = (char *) qstrdup(resource.toUtf8().data()); + filter->set("luma.resource", tmp); + delete[] tmp; + if (getProperty("softness") != QString()) { + int soft = getProperty("softness").toInt(); + filter->set("luma.softness", (double) soft / 100.0); + } + clipService.attach(*filter); + } + } else { + kDebug() << "//////////// FADE NOT WANTED!!!"; + Mlt::Service clipService(m_clipProducer->get_service()); + int ct = 0; + Mlt::Filter *filter = clipService.filter(0); + while (filter) { + if (filter->get("mlt_service") == "luma") { + clipService.detach(*filter); + } else ct++; + filter = clipService.filter(ct); + } + } } - return result; } -void DocClipBase::slotGetAudioThumbs(){ - kDebug() << "getting audio data"; - if (m_audioThumbCreated){ - if (m_audioTimer!=NULL) - m_audioTimer->stop(); - }else{ - if (m_audioTimer!=NULL) - m_audioTimer->start(2000); - double lengthInFrames=duration().frames(/*framesPerSecond()*/25); - m_thumbProd->getAudioThumbs(fileURL(), 1, 0, lengthInFrames /*must be number of frames*/, 20); - } +void DocClipBase::setProperties(QMap properties) { + // changing clip type is not allowed + properties.remove("type"); + QMapIterator i(properties); + bool refreshProducer = false; + QStringList keys; + keys << "luma_duration" << "luma_file" << "fade" << "ttl" << "softness"; + while (i.hasNext()) { + i.next(); + m_properties.insert(i.key(), i.value()); + if (i.key() == "resource") m_thumbProd->updateClipUrl(KUrl(i.value())); + else if (i.key() == "out") setDuration(GenTime(i.value().toInt(), KdenliveSettings::project_fps())); + else if (m_clipType == SLIDESHOW && keys.contains(i.key())) refreshProducer = true; + else if (i.key() == "transparency") m_clipProducer->set("transparency", i.value().toInt()); + } + if (refreshProducer) slotRefreshProducer(); } +void DocClipBase::setProperty(QString key, QString value) { + m_properties.insert(key, value); + if (key == "resource") m_thumbProd->updateClipUrl(KUrl(value)); + else if (key == "out") setDuration(GenTime(value.toInt(), KdenliveSettings::project_fps())); + else if (key == "transparency") m_clipProducer->set("transparency", value.toInt()); +} + +QMap DocClipBase::properties() const { + return m_properties; +} + +void DocClipBase::slotGetAudioThumbs() { + if (m_thumbProd == NULL) return; + if (m_audioThumbCreated) { + if (m_audioTimer != NULL) + m_audioTimer->stop(); + } else { + if (m_audioTimer != NULL) + m_audioTimer->start(2000); + double lengthInFrames = duration().frames(/*framesPerSecond()*/25); + m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20); + } +} + + +