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 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id):
24 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) {
25 int type = xml.attribute("type").toInt();
26 m_clipType = (CLIPTYPE) type;
27 m_name = xml.attribute("name");
28 m_xml.setAttribute("id", QString::number(id));
29 KUrl url = KUrl(xml.attribute("resource"));
30 int out = xml.attribute("out").toInt();
31 if (out != 0) setDuration(GenTime(out, 25));
32 if (m_name.isEmpty()) m_name = url.fileName();
34 m_thumbProd = new KThumb(clipManager, url);
35 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
36 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
39 kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
41 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == UNKNOWN) {
42 m_audioTimer = new QTimer(this);
43 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
49 DocClipBase::DocClipBase(const DocClipBase& clip) {
52 m_clipType = clip.clipType();
54 m_duration = clip.duration();
55 m_audioThumbCreated = clip.audioThumbCreated();
58 DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
59 DocClipBase::operator=(clip);
62 m_clipType = clip.clipType();
64 m_duration = clip.duration();
65 m_audioThumbCreated = clip.audioThumbCreated();
69 DocClipBase::~DocClipBase() {
70 if (m_thumbProd) delete m_thumbProd;
73 void DocClipBase::slotRequestAudioThumbs() {
74 emit getAudioThumbs();
77 void DocClipBase::slotClearAudioCache() {
78 audioFrameChache.clear();
79 m_audioThumbCreated = false;
82 KThumb *DocClipBase::thumbProducer() {
86 bool DocClipBase::audioThumbCreated() const {
87 return m_audioThumbCreated;
90 void DocClipBase::setName(const QString name) {
94 const QString & DocClipBase::name() const {
99 uint DocClipBase::getId() const {
103 void DocClipBase::setId(const uint &newId) {
107 const CLIPTYPE & DocClipBase::clipType() const {
111 void DocClipBase::setClipType(CLIPTYPE type) {
115 KUrl DocClipBase::fileURL() const {
116 QString res = m_xml.attribute("resource");
117 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
121 void DocClipBase::setProjectThumbFrame(const uint &ix) {
122 m_projectThumbFrame = ix;
125 uint DocClipBase::getProjectThumbFrame() const {
126 return m_projectThumbFrame;
129 void DocClipBase::setDescription(const QString & description) {
130 m_description = description;
133 const QString & DocClipBase::description() const {
134 return m_description;
137 void DocClipBase::setDuration(GenTime dur) {
141 const GenTime &DocClipBase::duration() const {
145 bool DocClipBase::hasFileSize() const {
151 QDomElement DocClipBase::toXML() const {
155 QDomElement clip = doc.createElement("kdenliveclip");
156 QDomText text = doc.createTextNode(description());
157 clip.appendChild(text);
158 doc.appendChild(clip);
163 DocClipBase *DocClipBase::
164 createClip(KdenliveDoc *doc, const QDomElement & element) {
165 DocClipBase *clip = 0;
167 QDomNode node = element;
169 if (element.tagName() != "kdenliveclip") {
171 "DocClipBase::createClip() element has unknown tagName : " <<
172 element.tagName() << endl;
176 QDomNode n = element.firstChild();
178 while (!n.isNull()) {
179 QDomElement e = n.toElement();
181 QString tagName = e.tagName();
182 if (e.tagName() == "avfile") {
183 // clip = DocClipAVFile::createClip(e);
184 } else if (e.tagName() == "DocTrackBaseList") {
185 // clip = DocClipProject::createClip(doc, e);
188 QDomText text = n.toText();
189 if (!text.isNull()) {
190 description = text.nodeValue();
197 kWarning() << "DocClipBase::createClip() unable to create clip" <<
200 // setup DocClipBase specifics of the clip.
201 clip->setDescription(description);
202 clip->setAudioThumbCreated(false);
207 void DocClipBase::setAudioThumbCreated(bool isDone) {
208 m_audioThumbCreated = isDone;
212 QDomDocument DocClipBase::generateSceneList(bool, bool) const {
215 void DocClipBase::setThumbnail(const QPixmap & pixmap) {
216 m_thumbnail = pixmap;
219 const QPixmap & DocClipBase::thumbnail() const {
223 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data) {
224 kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
225 audioFrameChache = data;
226 m_audioThumbCreated = true;
230 QList < GenTime > DocClipBase::snapMarkers() const {
231 QList < GenTime > markers;
233 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
234 markers.append(m_snapMarkers[count].time());
240 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const {
241 return m_snapMarkers;
244 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) {
245 m_snapMarkers = markers;
248 void DocClipBase::addSnapMarker(const GenTime & time, QString comment) {
249 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
250 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
251 if ((*it).time() >= time)
255 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
257 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
260 CommentedTime t(time, comment);
261 m_snapMarkers.insert(it, t);
266 void DocClipBase::editSnapMarker(const GenTime & time, QString comment) {
267 QList < CommentedTime >::Iterator it;
268 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
269 if ((*it).time() == time)
272 if (it != m_snapMarkers.end()) {
273 (*it).setComment(comment);
276 "trying to edit Snap Marker that does not already exists" << endl;
280 QString DocClipBase::deleteSnapMarker(const GenTime & time) {
281 QString result = i18n("Marker");
282 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
284 while (itt != m_snapMarkers.end()) {
285 if ((*itt).time() == time)
290 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
291 result = (*itt).comment();
292 m_snapMarkers.erase(itt);
298 GenTime DocClipBase::hasSnapMarkers(const GenTime & time) {
299 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
301 while (itt != m_snapMarkers.end()) {
302 if ((*itt).time() == time)
310 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) {
312 for (it = 0; it < m_snapMarkers.count(); it++) {
313 if (m_snapMarkers[it].time() >= currTime)
316 if (it == 0) return GenTime();
317 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
318 return m_snapMarkers[it].time();
319 else return m_snapMarkers[it-1].time();
322 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) {
324 for (it = 0; it < m_snapMarkers.count(); it++) {
325 if (m_snapMarkers[it].time() > currTime)
328 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
332 QString DocClipBase::markerComment(GenTime t) {
333 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
335 while (itt != m_snapMarkers.end()) {
336 if ((*itt).time() == t)
337 return (*itt).comment();
340 return QString::null;
344 QString DocClipBase::getTypeName(CLIPTYPE type) {
348 result = i18n("Video Clip");
351 result = i18n("Color Clip");
354 result = i18n("Playlist Clip");
357 result = i18n("Image Clip");
360 result = i18n("Slideshow Clip");
363 result = i18n("Virtual Clip");
366 result = i18n("Audio Clip");
369 result = i18n("Mute Video Clip");
372 result = i18n("Text Clip");
375 result = i18n("None");
381 void DocClipBase::slotGetAudioThumbs() {
383 if (m_audioThumbCreated) {
384 if (m_audioTimer != NULL)
385 m_audioTimer->stop();
387 if (m_audioTimer != NULL)
388 m_audioTimer->start(2000);
389 double lengthInFrames = duration().frames(/*framesPerSecond()*/25);
390 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);