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 #include "clipmanager.h"
25 DocClipBase::DocClipBase(ClipManager *clipManager, QDomElement xml, uint id):
26 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) {
27 int type = xml.attribute("type").toInt();
28 m_clipType = (CLIPTYPE) type;
29 m_name = xml.attribute("name");
30 m_xml.setAttribute("id", QString::number(id));
31 KUrl url = KUrl(xml.attribute("resource"));
32 int out = xml.attribute("out").toInt();
33 if (out != 0) setDuration(GenTime(out, 25));
34 if (m_name.isEmpty()) m_name = url.fileName();
37 m_thumbProd = new KThumb(clipManager, url);
38 if (m_clipType == AV || m_clipType == AUDIO) slotCreateAudioTimer();
40 //kDebug() << "type is video" << (m_clipType == AV) << " " << m_clipType;
45 DocClipBase::DocClipBase(const DocClipBase& clip) {
48 m_clipType = clip.clipType();
50 m_duration = clip.duration();
51 m_audioThumbCreated = clip.audioThumbCreated();
54 DocClipBase & DocClipBase::operator=(const DocClipBase & clip) {
55 DocClipBase::operator=(clip);
58 m_clipType = clip.clipType();
60 m_duration = clip.duration();
61 m_audioThumbCreated = clip.audioThumbCreated();
65 DocClipBase::~DocClipBase() {
66 if (m_thumbProd) delete m_thumbProd;
69 void DocClipBase::slotCreateAudioTimer() {
70 connect(m_thumbProd, SIGNAL(audioThumbReady(QMap <int, QMap <int, QByteArray> >)), this , SLOT(updateAudioThumbnail(QMap <int, QMap <int, QByteArray> >)));
71 connect(this, SIGNAL(getAudioThumbs()), this , SLOT(slotGetAudioThumbs()));
72 m_audioTimer = new QTimer(this);
73 connect(m_audioTimer, SIGNAL(timeout()), this, SLOT(slotGetAudioThumbs()));
76 void DocClipBase::slotRequestAudioThumbs() {
77 emit getAudioThumbs();
80 void DocClipBase::slotClearAudioCache() {
81 audioFrameChache.clear();
82 m_audioThumbCreated = false;
85 void DocClipBase::setGroup(const QString name, const QString id) {
86 m_xml.setAttribute("groupname", name);
87 m_xml.setAttribute("groupid", id);
90 KThumb *DocClipBase::thumbProducer() {
94 bool DocClipBase::audioThumbCreated() const {
95 return m_audioThumbCreated;
98 void DocClipBase::setName(const QString name) {
102 const QString & DocClipBase::name() const {
107 uint DocClipBase::getId() const {
111 void DocClipBase::setId(const uint &newId) {
115 const CLIPTYPE & DocClipBase::clipType() const {
119 void DocClipBase::setClipType(CLIPTYPE type) {
121 if (m_audioTimer == NULL && (m_clipType == AV || m_clipType == AUDIO))
122 slotCreateAudioTimer();
125 KUrl DocClipBase::fileURL() const {
126 QString res = m_xml.attribute("resource");
127 if (m_clipType != COLOR && !res.isEmpty()) return KUrl(res);
131 void DocClipBase::setProjectThumbFrame(const uint &ix) {
132 m_projectThumbFrame = ix;
135 uint DocClipBase::getProjectThumbFrame() const {
136 return m_projectThumbFrame;
139 void DocClipBase::setDescription(const QString & description) {
140 m_description = description;
143 const QString & DocClipBase::description() const {
144 return m_description;
147 void DocClipBase::setDuration(GenTime dur) {
151 const GenTime &DocClipBase::duration() const {
155 bool DocClipBase::hasFileSize() const {
161 QDomElement DocClipBase::toXML() const {
165 QDomElement clip = doc.createElement("kdenliveclip");
166 QDomText text = doc.createTextNode(description());
167 clip.appendChild(text);
168 doc.appendChild(clip);
173 DocClipBase *DocClipBase::
174 createClip(KdenliveDoc *doc, const QDomElement & element) {
175 DocClipBase *clip = 0;
177 QDomNode node = element;
179 if (element.tagName() != "kdenliveclip") {
181 "DocClipBase::createClip() element has unknown tagName : " <<
182 element.tagName() << endl;
186 QDomNode n = element.firstChild();
188 while (!n.isNull()) {
189 QDomElement e = n.toElement();
191 QString tagName = e.tagName();
192 if (e.tagName() == "avfile") {
193 // clip = DocClipAVFile::createClip(e);
194 } else if (e.tagName() == "DocTrackBaseList") {
195 // clip = DocClipProject::createClip(doc, e);
198 QDomText text = n.toText();
199 if (!text.isNull()) {
200 description = text.nodeValue();
207 kWarning() << "DocClipBase::createClip() unable to create clip" <<
210 // setup DocClipBase specifics of the clip.
211 clip->setDescription(description);
212 clip->setAudioThumbCreated(false);
217 void DocClipBase::setAudioThumbCreated(bool isDone) {
218 m_audioThumbCreated = isDone;
222 QDomDocument DocClipBase::generateSceneList(bool, bool) const {
225 void DocClipBase::setThumbnail(const QPixmap & pixmap) {
226 m_thumbnail = pixmap;
229 const QPixmap & DocClipBase::thumbnail() const {
233 void DocClipBase::updateAudioThumbnail(QMap<int, QMap<int, QByteArray> > data) {
234 kDebug() << "CLIPBASE RECIEDVED AUDIO DATA*********************************************";
235 audioFrameChache = data;
236 m_audioThumbCreated = true;
240 QList < GenTime > DocClipBase::snapMarkers() const {
241 QList < GenTime > markers;
243 for (uint count = 0; count < m_snapMarkers.count(); ++count) {
244 markers.append(m_snapMarkers[count].time());
250 QList < CommentedTime > DocClipBase::commentedSnapMarkers() const {
251 return m_snapMarkers;
254 void DocClipBase::setSnapMarkers(QList < CommentedTime > markers) {
255 m_snapMarkers = markers;
258 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) {
277 QList < CommentedTime >::Iterator it;
278 for (it = m_snapMarkers.begin(); it != m_snapMarkers.end(); ++it) {
279 if ((*it).time() == time)
282 if (it != m_snapMarkers.end()) {
283 (*it).setComment(comment);
286 "trying to edit Snap Marker that does not already exists" << endl;
290 QString DocClipBase::deleteSnapMarker(const GenTime & time) {
291 QString result = i18n("Marker");
292 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
294 while (itt != m_snapMarkers.end()) {
295 if ((*itt).time() == time)
300 if ((itt != m_snapMarkers.end()) && ((*itt).time() == time)) {
301 result = (*itt).comment();
302 m_snapMarkers.erase(itt);
308 GenTime DocClipBase::hasSnapMarkers(const GenTime & time) {
309 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
311 while (itt != m_snapMarkers.end()) {
312 if ((*itt).time() == time)
320 GenTime DocClipBase::findPreviousSnapMarker(const GenTime & currTime) {
322 for (it = 0; it < m_snapMarkers.count(); it++) {
323 if (m_snapMarkers[it].time() >= currTime)
326 if (it == 0) return GenTime();
327 else if (it == m_snapMarkers.count() - 1 && m_snapMarkers[it].time() < currTime)
328 return m_snapMarkers[it].time();
329 else return m_snapMarkers[it-1].time();
332 GenTime DocClipBase::findNextSnapMarker(const GenTime & currTime) {
334 for (it = 0; it < m_snapMarkers.count(); it++) {
335 if (m_snapMarkers[it].time() > currTime)
338 if (it < m_snapMarkers.count() && m_snapMarkers[it].time() > currTime) return m_snapMarkers[it].time();
342 QString DocClipBase::markerComment(GenTime t) {
343 QList < CommentedTime >::Iterator itt = m_snapMarkers.begin();
345 while (itt != m_snapMarkers.end()) {
346 if ((*itt).time() == t)
347 return (*itt).comment();
350 return QString::null;
353 void DocClipBase::setProperties(QMap <QString, QString> properties) {
354 m_properties = properties;
357 QMap <QString, QString> DocClipBase::properties() {
362 void DocClipBase::slotGetAudioThumbs() {
364 if (m_audioThumbCreated) {
365 if (m_audioTimer != NULL)
366 m_audioTimer->stop();
368 if (m_audioTimer != NULL)
369 m_audioTimer->start(2000);
370 double lengthInFrames = duration().frames(/*framesPerSecond()*/25);
371 m_thumbProd->getAudioThumbs(2, 0, lengthInFrames /*must be number of frames*/, 20);