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(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)
26 int type = xml.attribute("type").toInt();
27 m_clipType = (CLIPTYPE) type;
28 m_name = xml.attribute("name");
29 m_xml.setAttribute("id", QString::number(id));
30 KUrl url = KUrl(xml.attribute("resource"));
31 int out = xml.attribute("out").toInt();
32 if (out != 0) setDuration(GenTime(out, 25));
33 if (m_name.isEmpty()) m_name = url.fileName();
35 m_thumbProd = new KThumb(url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
36 connect (m_thumbProd, SIGNAL (audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> > )));
37 connect (this, SIGNAL (getAudioThumbs()), this , SLOT( slotGetAudioThumbs() ) );
40 kDebug() << "type is video" << (m_clipType==AV) << " " << m_clipType;
42 if (m_clipType == AV || m_clipType==AUDIO || m_clipType==UNKNOWN){
43 m_audioTimer = new QTimer( this );
44 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
45 //TODO disabled until the crash cause is found
46 emit getAudioThumbs();
50 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)
62 DocClipBase::operator=(clip);
65 m_clipType = clip.clipType();
67 m_duration = clip.duration();
68 m_audioThumbCreated = clip.audioThumbCreated();
72 DocClipBase::~DocClipBase()
74 //if (m_thumbProd) delete m_thumbProd;
77 KThumb *DocClipBase::thumbProducer()
82 bool DocClipBase::audioThumbCreated() const
84 return m_audioThumbCreated;
87 void DocClipBase::setName(const QString name)
92 const QString & DocClipBase::name() const
98 uint DocClipBase::getId() const
103 void DocClipBase::setId( const uint &newId)
108 const CLIPTYPE & DocClipBase::clipType() const
113 void DocClipBase::setClipType(CLIPTYPE type)
118 KUrl DocClipBase::fileURL() const
120 QString res = m_xml.attribute("resource");
121 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
125 void DocClipBase::setProjectThumbFrame( const uint &ix)
127 m_projectThumbFrame = ix;
130 uint DocClipBase::getProjectThumbFrame() const
132 return m_projectThumbFrame;
135 void DocClipBase::setDescription(const QString & description)
137 m_description = description;
140 const QString & DocClipBase::description() const
142 return m_description;
145 void DocClipBase::setDuration(GenTime dur)
150 const GenTime &DocClipBase::duration() const
155 bool DocClipBase::hasFileSize() const
162 QDomElement DocClipBase::toXML() const
167 QDomElement clip = doc.createElement("kdenliveclip");
168 QDomText text = doc.createTextNode(description());
169 clip.appendChild(text);
170 doc.appendChild(clip);
175 DocClipBase *DocClipBase::
176 createClip(KdenliveDoc *doc, const QDomElement & element)
178 DocClipBase *clip = 0;
180 QDomNode node = element;
182 if (element.tagName() != "kdenliveclip") {
184 "DocClipBase::createClip() element has unknown tagName : " <<
185 element.tagName() << endl;
189 QDomNode n = element.firstChild();
191 while (!n.isNull()) {
192 QDomElement e = n.toElement();
194 QString tagName = e.tagName();
195 if (e.tagName() == "avfile") {
196 // clip = DocClipAVFile::createClip(e);
197 } else if (e.tagName() == "DocTrackBaseList") {
198 // clip = DocClipProject::createClip(doc, e);
201 QDomText text = n.toText();
202 if (!text.isNull()) {
203 description = text.nodeValue();
210 kWarning() << "DocClipBase::createClip() unable to create clip" <<
213 // setup DocClipBase specifics of the clip.
214 clip->setDescription(description);
215 clip->setAudioThumbCreated(false);
220 void DocClipBase::setAudioThumbCreated(bool isDone)
222 m_audioThumbCreated = isDone;
226 QDomDocument DocClipBase::generateSceneList(bool, bool) const
230 void DocClipBase::setThumbnail(const QPixmap & pixmap)
232 m_thumbnail = pixmap;
235 const QPixmap & DocClipBase::thumbnail() const
240 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
242 audioFrameChache = data;
243 m_audioThumbCreated = true;
246 QList < GenTime > DocClipBase::snapMarkers() const
248 QList < GenTime > markers;
250 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
251 markers.append(m_snapMarkers[count].time());
257 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
259 return m_snapMarkers;
262 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
264 m_snapMarkers = markers;
267 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
269 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
270 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
271 if ((*it).time() >= time)
275 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
277 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
280 CommentedTime t(time, comment);
281 m_snapMarkers.insert(it, t);
286 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
288 QList < CommentedTime >::Iterator it;
289 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
290 if ((*it).time() == time)
293 if (it != m_snapMarkers.end()) {
294 (*it).setComment(comment);
297 "trying to edit Snap Marker that does not already exists" << endl;
301 QString DocClipBase::deleteSnapMarker(const GenTime & time)
303 QString result = i18n("Marker");
304 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
306 while (itt != m_snapMarkers.end()) {
307 if ((*itt).time() == time)
312 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
313 result = (*itt).comment();
314 m_snapMarkers.erase(itt);
320 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
322 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
324 while (itt != m_snapMarkers.end()) {
325 if ((*itt).time() == time)
333 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
336 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
337 if (m_snapMarkers[it].time() >= currTime)
340 if (it == 0) return GenTime();
341 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
342 return m_snapMarkers[it].time();
343 else return m_snapMarkers[it-1].time();
346 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
349 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
350 if (m_snapMarkers[it].time() > currTime)
353 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
357 QString DocClipBase::markerComment(GenTime t)
359 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
361 while (itt != m_snapMarkers.end()) {
362 if ((*itt).time() == t)
363 return (*itt).comment();
366 return QString::null;
370 QString DocClipBase::getTypeName(CLIPTYPE type)
375 result = i18n("Video Clip");
378 result = i18n("Color Clip");
381 result = i18n("Playlist Clip");
384 result = i18n("Image Clip");
387 result = i18n("Slideshow Clip");
390 result = i18n("Virtual Clip");
393 result = i18n("Audio Clip");
396 result = i18n("Mute Video Clip");
399 result = i18n("Text Clip");
402 result = i18n("None");
408 void DocClipBase::slotGetAudioThumbs(){
409 kDebug() << "getting audio data";
410 if (m_audioThumbCreated){
411 if (m_audioTimer!=NULL)
412 m_audioTimer->stop();
414 if (m_audioTimer!=NULL)
415 m_audioTimer->start(2000);
416 double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
417 m_thumbProd->getAudioThumbs(fileURL(), 1, 0, lengthInFrames /*must be number of frames*/, 20);