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)
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 emit getAudioThumbs();
47 DocClipBase::DocClipBase(const DocClipBase& clip)
51 m_clipType = clip.clipType();
53 m_duration = clip.duration();
56 DocClipBase & DocClipBase::operator=(const DocClipBase & clip)
58 DocClipBase::operator=(clip);
61 m_clipType = clip.clipType();
63 m_duration = clip.duration();
67 DocClipBase::~DocClipBase()
69 //if (m_thumbProd) delete m_thumbProd;
72 KThumb *DocClipBase::thumbProducer()
77 void DocClipBase::setName(const QString name)
82 const QString & DocClipBase::name() const
88 uint DocClipBase::getId() const
93 void DocClipBase::setId( const uint &newId)
98 const CLIPTYPE & DocClipBase::clipType() const
103 void DocClipBase::setClipType(CLIPTYPE type)
108 const KUrl & DocClipBase::fileURL() const
110 QString res = m_xml.attribute("resource");
111 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
115 void DocClipBase::setProjectThumbFrame( const uint &ix)
117 m_projectThumbFrame = ix;
120 uint DocClipBase::getProjectThumbFrame() const
122 return m_projectThumbFrame;
125 void DocClipBase::setDescription(const QString & description)
127 m_description = description;
130 const QString & DocClipBase::description() const
132 return m_description;
135 void DocClipBase::setDuration(GenTime dur)
140 const GenTime &DocClipBase::duration() const
145 bool DocClipBase::hasFileSize() const
152 QDomElement DocClipBase::toXML() const
157 QDomElement clip = doc.createElement("kdenliveclip");
158 QDomText text = doc.createTextNode(description());
159 clip.appendChild(text);
160 doc.appendChild(clip);
165 DocClipBase *DocClipBase::
166 createClip(KdenliveDoc *doc, const QDomElement & element)
168 DocClipBase *clip = 0;
170 QDomNode node = element;
172 if (element.tagName() != "kdenliveclip") {
174 "DocClipBase::createClip() element has unknown tagName : " <<
175 element.tagName() << endl;
179 QDomNode n = element.firstChild();
181 while (!n.isNull()) {
182 QDomElement e = n.toElement();
184 QString tagName = e.tagName();
185 if (e.tagName() == "avfile") {
186 // clip = DocClipAVFile::createClip(e);
187 } else if (e.tagName() == "DocTrackBaseList") {
188 // clip = DocClipProject::createClip(doc, e);
191 QDomText text = n.toText();
192 if (!text.isNull()) {
193 description = text.nodeValue();
200 kWarning() << "DocClipBase::createClip() unable to create clip" <<
203 // setup DocClipBase specifics of the clip.
204 clip->setDescription(description);
205 clip->setAudioThumbCreated(false);
210 void DocClipBase::setAudioThumbCreated(bool isDone)
212 audioThumbCreated = isDone;
216 QDomDocument DocClipBase::generateSceneList(bool, bool) const
220 void DocClipBase::setThumbnail(const QPixmap & pixmap)
222 m_thumbnail = pixmap;
225 const QPixmap & DocClipBase::thumbnail() const
230 void DocClipBase::updateAudioThumbnail(QMap<int,QMap<int,QByteArray> > data)
232 audioFrameChache = data;
233 audioThumbCreated = true;
236 QList < GenTime > DocClipBase::snapMarkers() const
238 QList < GenTime > markers;
240 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
241 markers.append(m_snapMarkers[count].time());
247 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const
249 return m_snapMarkers;
252 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers)
254 m_snapMarkers = markers;
257 void DocClipBase::addSnapMarker(const GenTime & time, QString comment)
259 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
260 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
261 if ((*it).time() >= time)
265 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
267 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
270 CommentedTime t(time, comment);
271 m_snapMarkers.insert(it, t);
276 void DocClipBase::editSnapMarker(const GenTime & time, QString comment)
278 QList < CommentedTime >::Iterator it;
279 for ( it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it ) {
280 if ((*it).time() == time)
283 if (it != m_snapMarkers.end()) {
284 (*it).setComment(comment);
287 "trying to edit Snap Marker that does not already exists" << endl;
291 QString DocClipBase::deleteSnapMarker(const GenTime & time)
293 QString result = i18n("Marker");
294 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
296 while (itt != m_snapMarkers.end()) {
297 if ((*itt).time() == time)
302 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
303 result = (*itt).comment();
304 m_snapMarkers.erase(itt);
310 GenTime DocClipBase::hasSnapMarkers(const GenTime & time)
312 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
314 while (itt != m_snapMarkers.end()) {
315 if ((*itt).time() == time)
323 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime)
326 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
327 if (m_snapMarkers[it].time() >= currTime)
330 if (it == 0) return GenTime();
331 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
332 return m_snapMarkers[it].time();
333 else return m_snapMarkers[it-1].time();
336 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime)
339 for ( it = 0; it < m_snapMarkers.count(); it++ ) {
340 if (m_snapMarkers[it].time() > currTime)
343 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
347 QString DocClipBase::markerComment(GenTime t)
349 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
351 while (itt != m_snapMarkers.end()) {
352 if ((*itt).time() == t)
353 return (*itt).comment();
356 return QString::null;
360 QString DocClipBase::getTypeName(CLIPTYPE type)
365 result = i18n("Video Clip");
368 result = i18n("Color Clip");
371 result = i18n("Playlist Clip");
374 result = i18n("Image Clip");
377 result = i18n("Slideshow Clip");
380 result = i18n("Virtual Clip");
383 result = i18n("Audio Clip");
386 result = i18n("Mute Video Clip");
389 result = i18n("Text Clip");
392 result = i18n("None");
398 void DocClipBase::slotGetAudioThumbs(){
399 kDebug() << "getting audio data";
400 double lengthInFrames=duration().frames(/*framesPerSecond()*/25);
401 m_thumbProd->getAudioThumbs(fileURL(), 1, 0, lengthInFrames, 20);