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), 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 emit getAudioThumbs();
49 DocClipBase::DocClipBase(const DocClipBase& clip)
53 m_clipType = clip.clipType();
55 m_duration = clip.duration();
58 DocClipBase & DocClipBase::operator=(const DocClipBase & clip)
60 DocClipBase::operator=(clip);
63 m_clipType = clip.clipType();
65 m_duration = clip.duration();
69 DocClipBase::~DocClipBase()
71 //if (m_thumbProd) delete m_thumbProd;
74 KThumb *DocClipBase::thumbProducer()
79 void DocClipBase::setName(const QString name)
84 const QString & DocClipBase::name() const
90 uint DocClipBase::getId() const
95 void DocClipBase::setId( const uint &newId)
100 const CLIPTYPE & DocClipBase::clipType() const
105 void DocClipBase::setClipType(CLIPTYPE type)
110 const KUrl & DocClipBase::fileURL() const
112 QString res = m_xml.attribute("resource");
113 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
117 void DocClipBase::setProjectThumbFrame( const uint &ix)
119 m_projectThumbFrame = ix;
122 uint DocClipBase::getProjectThumbFrame() const
124 return m_projectThumbFrame;
127 void DocClipBase::setDescription(const QString & description)
129 m_description = description;
132 const QString & DocClipBase::description() const
134 return m_description;
137 void DocClipBase::setDuration(GenTime dur)
142 const GenTime &DocClipBase::duration() const
147 bool DocClipBase::hasFileSize() const
154 QDomElement DocClipBase::toXML() const
159 QDomElement clip = doc.createElement("kdenliveclip");
160 QDomText text = doc.createTextNode(description());
161 clip.appendChild(text);
162 doc.appendChild(clip);
167 DocClipBase *DocClipBase::
168 createClip(KdenliveDoc *doc, const QDomElement & element)
170 DocClipBase *clip = 0;
172 QDomNode node = element;
174 if (element.tagName() != "kdenliveclip") {
176 "DocClipBase::createClip() element has unknown tagName : " <<
177 element.tagName() << endl;
181 QDomNode n = element.firstChild();
183 while (!n.isNull()) {
184 QDomElement e = n.toElement();
186 QString tagName = e.tagName();
187 if (e.tagName() == "avfile") {
188 // clip = DocClipAVFile::createClip(e);
189 } else if (e.tagName() == "DocTrackBaseList") {
190 // clip = DocClipProject::createClip(doc, e);
193 QDomText text = n.toText();
194 if (!text.isNull()) {
195 description = text.nodeValue();
202 kWarning() << "DocClipBase::createClip() unable to create clip" <<
205 // setup DocClipBase specifics of the clip.
206 clip->setDescription(description);
207 clip->setAudioThumbCreated(false);
212 void DocClipBase::setAudioThumbCreated(bool isDone)
214 audioThumbCreated = isDone;
218 QDomDocument DocClipBase::generateSceneList(bool, bool) const
222 void DocClipBase::setThumbnail(const QPixmap & pixmap)
224 m_thumbnail = pixmap;
227 const QPixmap & DocClipBase::thumbnail() const
232 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
234 audioFrameChache = data;
235 audioThumbCreated = true;
238 QList < GenTime > DocClipBase::snapMarkers() const
240 QList < GenTime > markers;
242 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
243 markers.append(m_snapMarkers[count].time());
249 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
251 return m_snapMarkers;
254 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
256 m_snapMarkers = markers;
259 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
261 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
262 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
263 if ((*it).time() >= time)
267 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
269 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
272 CommentedTime t(time, comment);
273 m_snapMarkers.insert(it, t);
278 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
280 QList < CommentedTime >::Iterator it;
281 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
282 if ((*it).time() == time)
285 if (it != m_snapMarkers.end()) {
286 (*it).setComment(comment);
289 "trying to edit Snap Marker that does not already exists" << endl;
293 QString DocClipBase::deleteSnapMarker(const GenTime & time)
295 QString result = i18n("Marker");
296 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
298 while (itt != m_snapMarkers.end()) {
299 if ((*itt).time() == time)
304 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
305 result = (*itt).comment();
306 m_snapMarkers.erase(itt);
312 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
314 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
316 while (itt != m_snapMarkers.end()) {
317 if ((*itt).time() == time)
325 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
328 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
329 if (m_snapMarkers[it].time() >= currTime)
332 if (it == 0) return GenTime();
333 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
334 return m_snapMarkers[it].time();
335 else return m_snapMarkers[it-1].time();
338 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
341 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
342 if (m_snapMarkers[it].time() > currTime)
345 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
349 QString DocClipBase::markerComment(GenTime t)
351 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
353 while (itt != m_snapMarkers.end()) {
354 if ((*itt).time() == t)
355 return (*itt).comment();
358 return QString::null;
362 QString DocClipBase::getTypeName(CLIPTYPE type)
367 result = i18n("Video Clip");
370 result = i18n("Color Clip");
373 result = i18n("Playlist Clip");
376 result = i18n("Image Clip");
379 result = i18n("Slideshow Clip");
382 result = i18n("Virtual Clip");
385 result = i18n("Audio Clip");
388 result = i18n("Mute Video Clip");
391 result = i18n("Text Clip");
394 result = i18n("None");
400 void DocClipBase::slotGetAudioThumbs(){
401 kDebug() << "getting audio data";
402 if (audioThumbCreated){
403 if (m_audioTimer!=NULL)
404 m_audioTimer->stop();
406 if (m_audioTimer!=NULL)
407 m_audioTimer->start(2000);
408 double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
409 m_thumbProd->getAudioThumbs(fileURL(), 1, 0, 10 /*must be number of frames*/, 20);