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) {
25 int type = xml.attribute("type").toInt();
26 m_clipType = (CLIPTYPE) type;
27 m_name = xml.attribute("name");
28 m_xml.setAttribute("id", QString::number(id));
29 KUrl url = KUrl(xml.attribute("resource"));
30 int out = xml.attribute("out").toInt();
31 if (out != 0) setDuration(GenTime(out, 25));
32 if (m_name.isEmpty()) m_name = url.fileName();
34 m_thumbProd = new KThumb(clipManager, url, KdenliveSettings::track_height() * KdenliveSettings::project_display_ratio(), KdenliveSettings::track_height());
35 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
36 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
39 kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
41 if (m_clipType == AV || m_clipType == AUDIO || m_clipType == UNKNOWN) {
42 m_audioTimer = new QTimer(this);
43 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
49 DocClipBase::DocClipBase(const DocClipBase& clip) {
52 m_clipType = clip.clipType();
54 m_duration = clip.duration();
55 m_audioThumbCreated = clip.audioThumbCreated();
58 DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
59 DocClipBase::operator=(clip);
62 m_clipType = clip.clipType();
64 m_duration = clip.duration();
65 m_audioThumbCreated = clip.audioThumbCreated();
69 DocClipBase::~DocClipBase() {
70 //if (m_thumbProd) delete m_thumbProd;
73 void DocClipBase::slotRequestAudioThumbs() {
74 emit getAudioThumbs();
77 KThumb *DocClipBase::thumbProducer() {
81 bool DocClipBase::audioThumbCreated() const {
82 return m_audioThumbCreated;
85 void DocClipBase::setName(const QString name) {
89 const QString & DocClipBase::name() const {
94 uint DocClipBase::getId() const {
98 void DocClipBase::setId(const uint &newId) {
102 const CLIPTYPE & DocClipBase::clipType() const {
106 void DocClipBase::setClipType(CLIPTYPE type) {
110 KUrl DocClipBase::fileURL() const {
111 QString res = m_xml.attribute("resource");
112 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
116 void DocClipBase::setProjectThumbFrame(const uint &ix) {
117 m_projectThumbFrame = ix;
120 uint DocClipBase::getProjectThumbFrame() const {
121 return m_projectThumbFrame;
124 void DocClipBase::setDescription(const QString & description) {
125 m_description = description;
128 const QString & DocClipBase::description() const {
129 return m_description;
132 void DocClipBase::setDuration(GenTime dur) {
136 const GenTime &DocClipBase::duration() const {
140 bool DocClipBase::hasFileSize() const {
146 QDomElement DocClipBase::toXML() const {
150 QDomElement clip = doc.createElement("kdenliveclip");
151 QDomText text = doc.createTextNode(description());
152 clip.appendChild(text);
153 doc.appendChild(clip);
158 DocClipBase *DocClipBase::
159 createClip(KdenliveDoc *doc, const QDomElement & element) {
160 DocClipBase *clip = 0;
162 QDomNode node = element;
164 if (element.tagName() != "kdenliveclip") {
166 "DocClipBase::createClip() element has unknown tagName : " <<
167 element.tagName() << endl;
171 QDomNode n = element.firstChild();
173 while (!n.isNull()) {
174 QDomElement e = n.toElement();
176 QString tagName = e.tagName();
177 if (e.tagName() == "avfile") {
178 // clip = DocClipAVFile::createClip(e);
179 } else if (e.tagName() == "DocTrackBaseList") {
180 // clip = DocClipProject::createClip(doc, e);
183 QDomText text = n.toText();
184 if (!text.isNull()) {
185 description = text.nodeValue();
192 kWarning() << "DocClipBase::createClip() unable to create clip" <<
195 // setup DocClipBase specifics of the clip.
196 clip->setDescription(description);
197 clip->setAudioThumbCreated(false);
202 void DocClipBase::setAudioThumbCreated(bool isDone) {
203 m_audioThumbCreated = isDone;
207 QDomDocument DocClipBase::generateSceneList(bool, bool) const {
210 void DocClipBase::setThumbnail(const QPixmap & pixmap) {
211 m_thumbnail = pixmap;
214 const QPixmap & DocClipBase::thumbnail() const {
218 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data) {
219 kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
220 audioFrameChache = data;
221 m_audioThumbCreated = true;
225 QList < GenTime > DocClipBase::snapMarkers() const {
226 QList < GenTime > markers;
228 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
229 markers.append(m_snapMarkers[count].time());
235 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const {
236 return m_snapMarkers;
239 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) {
240 m_snapMarkers = markers;
243 void DocClipBase::addSnapMarker(const GenTime & time, QString comment) {
244 QList < CommentedTime >::Iterator it = m_snapMarkers.begin();
245 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
246 if ((*it).time() >= time)
250 if ((it != m_snapMarkers.end()) && ((*it).time() == time)) {
252 "trying to add Snap Marker that already exists, this will cause inconsistancies with undo/redo"
255 CommentedTime t(time, comment);
256 m_snapMarkers.insert(it, t);
261 void DocClipBase::editSnapMarker(const GenTime & time, QString comment) {
262 QList < CommentedTime >::Iterator it;
263 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
264 if ((*it).time() == time)
267 if (it != m_snapMarkers.end()) {
268 (*it).setComment(comment);
271 "trying to edit Snap Marker that does not already exists" << endl;
275 QString DocClipBase::deleteSnapMarker(const GenTime & time) {
276 QString result = i18n("Marker");
277 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
279 while (itt != m_snapMarkers.end()) {
280 if ((*itt).time() == time)
285 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
286 result = (*itt).comment();
287 m_snapMarkers.erase(itt);
293 GenTime DocClipBase::hasSnapMarkers(const GenTime & time) {
294 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
296 while (itt != m_snapMarkers.end()) {
297 if ((*itt).time() == time)
305 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) {
307 for (it = 0; it < m_snapMarkers.count(); it++) {
308 if (m_snapMarkers[it].time() >= currTime)
311 if (it == 0) return GenTime();
312 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
313 return m_snapMarkers[it].time();
314 else return m_snapMarkers[it-1].time();
317 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) {
319 for (it = 0; it < m_snapMarkers.count(); it++) {
320 if (m_snapMarkers[it].time() > currTime)
323 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
327 QString DocClipBase::markerComment(GenTime t) {
328 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
330 while (itt != m_snapMarkers.end()) {
331 if ((*itt).time() == t)
332 return (*itt).comment();
335 return QString::null;
339 QString DocClipBase::getTypeName(CLIPTYPE type) {
343 result = i18n("Video Clip");
346 result = i18n("Color Clip");
349 result = i18n("Playlist Clip");
352 result = i18n("Image Clip");
355 result = i18n("Slideshow Clip");
358 result = i18n("Virtual Clip");
361 result = i18n("Audio Clip");
364 result = i18n("Mute Video Clip");
367 result = i18n("Text Clip");
370 result = i18n("None");
376 void DocClipBase::slotGetAudioThumbs() {
378 if (m_audioThumbCreated) {
379 if (m_audioTimer != NULL)
380 m_audioTimer->stop();
382 if (m_audioTimer != NULL)
383 m_audioTimer->start(2000);
384 double lengthInFrames = duration().frames(/*framesPerSecond()*/25);
385 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);