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)
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(clipManager, 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()));
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 void DocClipBase::slotRequestAudioThumbs()
79 emit getAudioThumbs();
82 KThumb *DocClipBase::thumbProducer()
87 bool DocClipBase::audioThumbCreated() const
89 return m_audioThumbCreated;
92 void DocClipBase::setName(const QString name)
97 const QString & DocClipBase::name() const
103 uint DocClipBase::getId() const
108 void DocClipBase::setId( const uint &newId)
113 const CLIPTYPE & DocClipBase::clipType() const
118 void DocClipBase::setClipType(CLIPTYPE type)
123 KUrl DocClipBase::fileURL() const
125 QString res = m_xml.attribute("resource");
126 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
130 void DocClipBase::setProjectThumbFrame( const uint &ix)
132 m_projectThumbFrame = ix;
135 uint DocClipBase::getProjectThumbFrame() const
137 return m_projectThumbFrame;
140 void DocClipBase::setDescription(const QString & description)
142 m_description = description;
145 const QString & DocClipBase::description() const
147 return m_description;
150 void DocClipBase::setDuration(GenTime dur)
155 const GenTime &DocClipBase::duration() const
160 bool DocClipBase::hasFileSize() const
167 QDomElement DocClipBase::toXML() const
172 QDomElement clip = doc.createElement("kdenliveclip");
173 QDomText text = doc.createTextNode(description());
174 clip.appendChild(text);
175 doc.appendChild(clip);
180 DocClipBase *DocClipBase::
181 createClip(KdenliveDoc *doc, const QDomElement & element)
183 DocClipBase *clip = 0;
185 QDomNode node = element;
187 if (element.tagName() != "kdenliveclip") {
189 "DocClipBase::createClip() element has unknown tagName : " <<
190 element.tagName() << endl;
194 QDomNode n = element.firstChild();
196 while (!n.isNull()) {
197 QDomElement e = n.toElement();
199 QString tagName = e.tagName();
200 if (e.tagName() == "avfile") {
201 // clip = DocClipAVFile::createClip(e);
202 } else if (e.tagName() == "DocTrackBaseList") {
203 // clip = DocClipProject::createClip(doc, e);
206 QDomText text = n.toText();
207 if (!text.isNull()) {
208 description = text.nodeValue();
215 kWarning() << "DocClipBase::createClip() unable to create clip" <<
218 // setup DocClipBase specifics of the clip.
219 clip->setDescription(description);
220 clip->setAudioThumbCreated(false);
225 void DocClipBase::setAudioThumbCreated(bool isDone)
227 m_audioThumbCreated = isDone;
231 QDomDocument DocClipBase::generateSceneList(bool, bool) const
235 void DocClipBase::setThumbnail(const QPixmap & pixmap)
237 m_thumbnail = pixmap;
240 const QPixmap & DocClipBase::thumbnail() const
245 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
247 kDebug()<<"CLIPBASE RECIEDVED AUDIO DATA*********************************************";
248 audioFrameChache = data;
249 m_audioThumbCreated = true;
253 QList < GenTime > DocClipBase::snapMarkers() const
255 QList < GenTime > markers;
257 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
258 markers.append(m_snapMarkers[count].time());
264 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
266 return m_snapMarkers;
269 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
271 m_snapMarkers = markers;
274 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
276 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
277 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
278 if ((*it).time() >= time)
282 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
284 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
287 CommentedTime t(time, comment);
288 m_snapMarkers.insert(it, t);
293 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
295 QList < CommentedTime >::Iterator it;
296 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
297 if ((*it).time() == time)
300 if (it != m_snapMarkers.end()) {
301 (*it).setComment(comment);
304 "trying to edit Snap Marker that does not already exists" << endl;
308 QString DocClipBase::deleteSnapMarker(const GenTime & time)
310 QString result = i18n("Marker");
311 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
313 while (itt != m_snapMarkers.end()) {
314 if ((*itt).time() == time)
319 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
320 result = (*itt).comment();
321 m_snapMarkers.erase(itt);
327 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
329 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
331 while (itt != m_snapMarkers.end()) {
332 if ((*itt).time() == time)
340 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
343 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
344 if (m_snapMarkers[it].time() >= currTime)
347 if (it == 0) return GenTime();
348 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
349 return m_snapMarkers[it].time();
350 else return m_snapMarkers[it-1].time();
353 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
356 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
357 if (m_snapMarkers[it].time() > currTime)
360 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
364 QString DocClipBase::markerComment(GenTime t)
366 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
368 while (itt != m_snapMarkers.end()) {
369 if ((*itt).time() == t)
370 return (*itt).comment();
373 return QString::null;
377 QString DocClipBase::getTypeName(CLIPTYPE type)
382 result = i18n("Video Clip");
385 result = i18n("Color Clip");
388 result = i18n("Playlist Clip");
391 result = i18n("Image Clip");
394 result = i18n("Slideshow Clip");
397 result = i18n("Virtual Clip");
400 result = i18n("Audio Clip");
403 result = i18n("Mute Video Clip");
406 result = i18n("Text Clip");
409 result = i18n("None");
415 void DocClipBase::slotGetAudioThumbs(){
417 if (m_audioThumbCreated){
418 if (m_audioTimer!=NULL)
419 m_audioTimer->stop();
421 if (m_audioTimer!=NULL)
422 m_audioTimer->start(2000);
423 double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
424 m_thumbProd->getAudioThumbs( 2, 0, lengthInFrames /*must be number of frames*/, 20);