1 /**************************1*************************************************
2 DocClipBase.cpp - description
4 begin : Fri Apr 12 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
20 #include "kdenlivesettings.h"
21 #include "docclipbase.h"
23 #include "clipmanager.h"
25 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id):
26 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) {
27 int type = xml.attribute("type").toInt();
28 m_clipType = (CLIPTYPE) type;
29 m_name = xml.attribute("name");
30 m_xml.setAttribute("id", QString::number(id));
31 KUrl url = KUrl(xml.attribute("resource"));
32 int out = xml.attribute("out").toInt();
33 if (out != 0) setDuration(GenTime(out, 25));
34 if (m_name.isEmpty()) m_name = url.fileName();
36 m_thumbProd = new KThumb(clipManager, url);
37 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
38 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
41 kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
43 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == UNKNOWN) {
44 m_audioTimer = new QTimer(this);
45 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
51 DocClipBase::DocClipBase(const DocClipBase& clip) {
54 m_clipType = clip.clipType();
56 m_duration = clip.duration();
57 m_audioThumbCreated = clip.audioThumbCreated();
60 DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
61 DocClipBase::operator=(clip);
64 m_clipType = clip.clipType();
66 m_duration = clip.duration();
67 m_audioThumbCreated = clip.audioThumbCreated();
71 DocClipBase::~DocClipBase() {
72 if (m_thumbProd) delete m_thumbProd;
75 void DocClipBase::slotRequestAudioThumbs() {
76 emit getAudioThumbs();
79 void DocClipBase::slotClearAudioCache() {
80 audioFrameChache.clear();
81 m_audioThumbCreated = false;
84 void DocClipBase::setGroup(const QString name, const QString id) {
85 m_xml.setAttribute("groupname", name);
86 m_xml.setAttribute("groupid", id);
89 KThumb *DocClipBase::thumbProducer() {
93 bool DocClipBase::audioThumbCreated() const {
94 return m_audioThumbCreated;
97 void DocClipBase::setName(const QString name) {
101 const QString & DocClipBase::name() const {
106 uint DocClipBase::getId() const {
110 void DocClipBase::setId(const uint &newId) {
114 const CLIPTYPE & DocClipBase::clipType() const {
118 void DocClipBase::setClipType(CLIPTYPE type) {
122 KUrl DocClipBase::fileURL() const {
123 QString res = m_xml.attribute("resource");
124 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
128 void DocClipBase::setProjectThumbFrame(const uint &ix) {
129 m_projectThumbFrame = ix;
132 uint DocClipBase::getProjectThumbFrame() const {
133 return m_projectThumbFrame;
136 void DocClipBase::setDescription(const QString & description) {
137 m_description = description;
140 const QString & DocClipBase::description() const {
141 return m_description;
144 void DocClipBase::setDuration(GenTime dur) {
148 const GenTime &DocClipBase::duration() const {
152 bool DocClipBase::hasFileSize() const {
158 QDomElement DocClipBase::toXML() const {
162 QDomElement clip = doc.createElement("kdenliveclip");
163 QDomText text = doc.createTextNode(description());
164 clip.appendChild(text);
165 doc.appendChild(clip);
170 DocClipBase *DocClipBase::
171 createClip(KdenliveDoc *doc, const QDomElement & element) {
172 DocClipBase *clip = 0;
174 QDomNode node = element;
176 if (element.tagName() != "kdenliveclip") {
178 "DocClipBase::createClip() element has unknown tagName : " <<
179 element.tagName() << endl;
183 QDomNode n = element.firstChild();
185 while (!n.isNull()) {
186 QDomElement e = n.toElement();
188 QString tagName = e.tagName();
189 if (e.tagName() == "avfile") {
190 // clip = DocClipAVFile::createClip(e);
191 } else if (e.tagName() == "DocTrackBaseList") {
192 // clip = DocClipProject::createClip(doc, e);
195 QDomText text = n.toText();
196 if (!text.isNull()) {
197 description = text.nodeValue();
204 kWarning() << "DocClipBase::createClip() unable to create clip" <<
207 // setup DocClipBase specifics of the clip.
208 clip->setDescription(description);
209 clip->setAudioThumbCreated(false);
214 void DocClipBase::setAudioThumbCreated(bool isDone) {
215 m_audioThumbCreated = isDone;
219 QDomDocument DocClipBase::generateSceneList(bool, bool) const {
222 void DocClipBase::setThumbnail(const QPixmap & pixmap) {
223 m_thumbnail = pixmap;
226 const QPixmap & DocClipBase::thumbnail() const {
230 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data) {
231 kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
232 audioFrameChache = data;
233 m_audioThumbCreated = true;
237 QList < GenTime > DocClipBase::snapMarkers() const {
238 QList < GenTime > markers;
240 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
241 markers.append(m_snapMarkers[count].time());
247 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const {
248 return m_snapMarkers;
251 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) {
252 m_snapMarkers = markers;
255 void DocClipBase::addSnapMarker(const GenTime & time, QString comment) {
256 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
257 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
258 if ((*it).time() >= time)
262 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
264 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
267 CommentedTime t(time, comment);
268 m_snapMarkers.insert(it, t);
273 void DocClipBase::editSnapMarker(const GenTime & time, QString comment) {
274 QList < CommentedTime >::Iterator it;
275 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
276 if ((*it).time() == time)
279 if (it != m_snapMarkers.end()) {
280 (*it).setComment(comment);
283 "trying to edit Snap Marker that does not already exists" << endl;
287 QString DocClipBase::deleteSnapMarker(const GenTime & time) {
288 QString result = i18n("Marker");
289 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
291 while (itt != m_snapMarkers.end()) {
292 if ((*itt).time() == time)
297 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
298 result = (*itt).comment();
299 m_snapMarkers.erase(itt);
305 GenTime DocClipBase::hasSnapMarkers(const GenTime & time) {
306 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
308 while (itt != m_snapMarkers.end()) {
309 if ((*itt).time() == time)
317 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) {
319 for (it = 0; it < m_snapMarkers.count(); it++) {
320 if (m_snapMarkers[it].time() >= currTime)
323 if (it == 0) return GenTime();
324 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
325 return m_snapMarkers[it].time();
326 else return m_snapMarkers[it-1].time();
329 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) {
331 for (it = 0; it < m_snapMarkers.count(); it++) {
332 if (m_snapMarkers[it].time() > currTime)
335 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
339 QString DocClipBase::markerComment(GenTime t) {
340 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
342 while (itt != m_snapMarkers.end()) {
343 if ((*itt).time() == t)
344 return (*itt).comment();
347 return QString::null;
350 void DocClipBase::setProperties(QMap <QString, QString> properties) {
351 m_properties = properties;
354 QMap <QString, QString> DocClipBase::properties() {
359 void DocClipBase::slotGetAudioThumbs() {
361 if (m_audioThumbCreated) {
362 if (m_audioTimer != NULL)
363 m_audioTimer->stop();
365 if (m_audioTimer != NULL)
366 m_audioTimer->start(2000);
367 double lengthInFrames = duration().frames(/*framesPerSecond()*/25);
368 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);