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;
247 QList < GenTime > DocClipBase::snapMarkers() const
249 QList < GenTime > markers;
251 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
252 markers.append(m_snapMarkers[count].time());
258 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
260 return m_snapMarkers;
263 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
265 m_snapMarkers = markers;
268 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
270 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
271 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
272 if ((*it).time() >= time)
276 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
278 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
281 CommentedTime t(time, comment);
282 m_snapMarkers.insert(it, t);
287 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
289 QList < CommentedTime >::Iterator it;
290 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
291 if ((*it).time() == time)
294 if (it != m_snapMarkers.end()) {
295 (*it).setComment(comment);
298 "trying to edit Snap Marker that does not already exists" << endl;
302 QString DocClipBase::deleteSnapMarker(const GenTime & time)
304 QString result = i18n("Marker");
305 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
307 while (itt != m_snapMarkers.end()) {
308 if ((*itt).time() == time)
313 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
314 result = (*itt).comment();
315 m_snapMarkers.erase(itt);
321 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
323 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
325 while (itt != m_snapMarkers.end()) {
326 if ((*itt).time() == time)
334 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
337 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
338 if (m_snapMarkers[it].time() >= currTime)
341 if (it == 0) return GenTime();
342 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
343 return m_snapMarkers[it].time();
344 else return m_snapMarkers[it-1].time();
347 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
350 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
351 if (m_snapMarkers[it].time() > currTime)
354 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
358 QString DocClipBase::markerComment(GenTime t)
360 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
362 while (itt != m_snapMarkers.end()) {
363 if ((*itt).time() == t)
364 return (*itt).comment();
367 return QString::null;
371 QString DocClipBase::getTypeName(CLIPTYPE type)
376 result = i18n("Video Clip");
379 result = i18n("Color Clip");
382 result = i18n("Playlist Clip");
385 result = i18n("Image Clip");
388 result = i18n("Slideshow Clip");
391 result = i18n("Virtual Clip");
394 result = i18n("Audio Clip");
397 result = i18n("Mute Video Clip");
400 result = i18n("Text Clip");
403 result = i18n("None");
409 void DocClipBase::slotGetAudioThumbs(){
411 if (m_audioThumbCreated){
412 if (m_audioTimer!=NULL)
413 m_audioTimer->stop();
415 if (m_audioTimer!=NULL)
416 m_audioTimer->start(2000);
417 double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
418 m_thumbProd->getAudioThumbs( 2, 0, lengthInFrames /*must be number of frames*/, 20);