#include "kthumb.h"
#include "clipmanager.h"
-DocClipBase::DocClipBase(ClipManager *clipManager, 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) {
+DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, const QString &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_xml.setAttribute("id", QString::number(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());
+ }
+
KUrl url = KUrl(xml.attribute("resource"));
int out = xml.attribute("out").toInt();
- if (out != 0) setDuration(GenTime(out, 25));
+ 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();
- if (!url.isEmpty()) {
+ 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(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();
-}
-
-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() {
}
void DocClipBase::slotClearAudioCache() {
+ if (m_thumbProd) m_thumbProd->stopAudioThumbs();
+ if (m_audioTimer != NULL) m_audioTimer->stop();
audioFrameChache.clear();
m_audioThumbCreated = false;
}
-void DocClipBase::setGroup(const QString name, const QString id) {
- m_xml.setAttribute("groupname", name);
- m_xml.setAttribute("groupid", id);
-}
-
KThumb *DocClipBase::thumbProducer() {
return m_thumbProd;
}
return m_name;
}
-uint DocClipBase::getId() const {
+const QString &DocClipBase::getId() const {
return m_id;
}
-void DocClipBase::setId(const uint &newId) {
+void DocClipBase::setId(const QString &newId) {
m_id = newId;
}
void DocClipBase::setClipType(CLIPTYPE type) {
m_clipType = type;
- if (m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
+ m_properties.insert("type", QString::number((int) type));
+ if (m_thumbProd && m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
slotCreateAudioTimer();
}
KUrl DocClipBase::fileURL() const {
- QString res = m_xml.attribute("resource");
+ QString res = m_properties.value("resource");
if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
return KUrl();
}
-void DocClipBase::setProjectThumbFrame(const uint &ix) {
- m_projectThumbFrame = ix;
+void DocClipBase::setClipThumbFrame(const uint &ix) {
+ m_properties.insert("thumbnail", QString::number((int) ix));
}
-uint DocClipBase::getProjectThumbFrame() const {
- return m_projectThumbFrame;
+uint DocClipBase::getClipThumbFrame() const {
+ return (uint) m_properties.value("thumbnail").toInt();
}
-void DocClipBase::setDescription(const QString & description) {
- m_description = description;
+const QString DocClipBase::description() const {
+ return m_properties.value("description");
}
-const QString & DocClipBase::description() const {
- return m_description;
+bool DocClipBase::isTransparent() const {
+ return (m_properties.value("transparency") == "1");
+}
+
+const QString DocClipBase::getProperty(const QString prop) const {
+ return m_properties.value(prop);
}
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 {
return m_duration;
}
+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 {
- /*
- QDomDocument doc;
+ QDomDocument doc;
+
+ QDomElement clip = doc.createElement("producer");
- QDomElement clip = doc.createElement("kdenliveclip");
- QDomText text = doc.createTextNode(description());
- clip.appendChild(text);
- doc.appendChild(clip);
- */
- return m_xml;
+ QMapIterator<QString, QString> i(m_properties);
+ while (i.hasNext()) {
+ i.next();
+ if (!i.value().isEmpty()) clip.setAttribute(i.key(), i.value());
+ }
+ //doc.appendChild(clip);
+ //kDebug()<<"/// CLIP XML: "<<doc.toString();
+ return clip;
}
DocClipBase *DocClipBase::
node.normalize();
if (element.tagName() != "kdenliveclip") {
kWarning() <<
- "DocClipBase::createClip() element has unknown tagName : " <<
- element.tagName() << endl;
+ "DocClipBase::createClip() element has unknown tagName : " << element.tagName();
return 0;
}
n = n.nextSibling();
}
if (clip == 0) {
- kWarning() << "DocClipBase::createClip() unable to create clip" <<
- endl;
+ kWarning() << "DocClipBase::createClip() unable to create clip";
} else {
// setup DocClipBase specifics of the clip.
- clip->setDescription(description);
+ QMap <QString, QString> props;
+ props.insert("description", description);
+ clip->setProperties(props);
clip->setAudioThumbCreated(false);
}
return clip;
}
-QDomDocument DocClipBase::generateSceneList(bool, bool) const {
-}
-
void DocClipBase::setThumbnail(const QPixmap & pixmap) {
m_thumbnail = pixmap;
}
}
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);
if (it != m_snapMarkers.end()) {
(*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";
}
}
return QString::null;
}
+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);
+ }
+ }
+ }
+}
+
void DocClipBase::setProperties(QMap <QString, QString> properties) {
- m_properties = properties;
+ // changing clip type is not allowed
+ properties.remove("type");
+ QMapIterator<QString, QString> 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();
}
-QMap <QString, QString> DocClipBase::properties() {
- return m_properties;
+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 <QString, QString> DocClipBase::properties() const {
+ return m_properties;
+}
void DocClipBase::slotGetAudioThumbs() {
-
+ if (m_thumbProd == NULL) return;
if (m_audioThumbCreated) {
if (m_audioTimer != NULL)
m_audioTimer->stop();