1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
21 #include <KStandardDirs>
22 #include <KMessageBox>
24 #include <KFileDialog>
25 #include <KIO/NetAccess>
28 #include "kdenlivedoc.h"
30 KdenliveDoc::KdenliveDoc(const KUrl &url, double fps, int width, int height, QWidget *parent):QObject(parent), m_render(NULL), m_url(url), m_fps(fps), m_width(width), m_height(height), m_projectName(NULL), m_commandStack(new KUndoStack())
32 m_clipManager = new ClipManager(this);
35 if(KIO::NetAccess::download(url.path(), tmpFile, parent))
38 m_document.setContent(&file, false);
40 m_projectName = url.fileName();
41 KIO::NetAccess::removeTempFile(tmpFile);
45 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
49 // Creating new document
50 QDomElement westley = m_document.createElement("westley");
51 m_document.appendChild(westley);
52 QDomElement doc = m_document.createElement("kdenlivedoc");
53 doc.setAttribute("version", "0.6");
54 westley.appendChild(doc);
55 QDomElement props = m_document.createElement("properties");
56 doc.setAttribute("width", m_width);
57 doc.setAttribute("height", m_height);
58 doc.setAttribute("projectfps", m_fps);
59 doc.appendChild(props);
62 /*QDomElement westley = m_document.createElement("westley");
63 m_document.appendChild(westley);*/
66 QDomElement tractor = m_document.createElement("tractor");
67 QDomElement multitrack = m_document.createElement("multitrack");
68 QDomElement playlist = m_document.createElement("playlist");
69 QDomElement producer = m_document.createElement("producer");
70 /*producer.setAttribute("mlt_service", "colour");
71 producer.setAttribute("colour", "red");
72 playlist.appendChild(producer);*/
73 multitrack.appendChild(playlist);
74 QDomElement playlist1 = m_document.createElement("playlist");
75 playlist1.setAttribute("id", "playlist1");
76 playlist1.setAttribute("hide", "video");
77 multitrack.appendChild(playlist1);
78 QDomElement playlist2 = m_document.createElement("playlist");
79 playlist2.setAttribute("id", "playlist2");
80 playlist2.setAttribute("hide", "video");
81 multitrack.appendChild(playlist2);
82 QDomElement playlist3 = m_document.createElement("playlist");
83 multitrack.appendChild(playlist3);
84 playlist3.setAttribute("id", "playlist3");
85 QDomElement playlist4 = m_document.createElement("playlist");
86 multitrack.appendChild(playlist4);
87 playlist4.setAttribute("id", "playlist4");
88 QDomElement playlist5 = m_document.createElement("playlist");
89 multitrack.appendChild(playlist5);
90 playlist5.setAttribute("id", "playlist5");
91 tractor.appendChild(multitrack);
93 for (uint i = 2; i < 6 ; i++) {
94 QDomElement transition = m_document.createElement("transition");
95 transition.setAttribute("in", "0");
96 //TODO: Make audio mix last for all project duration
97 transition.setAttribute("out", "15000");
98 transition.setAttribute("a_track", QString::number(1));
99 transition.setAttribute("b_track", QString::number(i));
100 transition.setAttribute("mlt_service", "mix");
101 transition.setAttribute("combine", "1");
102 tractor.appendChild(transition);
105 doc.appendChild(tractor);
108 if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
109 else m_timecode.setFormat((int) fps);
112 KdenliveDoc::~KdenliveDoc()
114 delete m_commandStack;
115 delete m_clipManager;
118 ClipManager *KdenliveDoc::clipManager()
120 return m_clipManager;
123 KUndoStack *KdenliveDoc::commandStack()
125 return m_commandStack;
128 void KdenliveDoc::setRenderer(Render *render)
131 if (m_render) m_render->setSceneList(m_document);
134 Render *KdenliveDoc::renderer()
139 void KdenliveDoc::updateClip(int id)
141 emit updateClipDisplay(id);
144 int KdenliveDoc::getFramePos(QString duration)
146 return m_timecode.getFrameCount(duration, m_fps);
149 QString KdenliveDoc::producerName(int id)
151 QString result = "unnamed";
152 QDomNodeList prods = producersList();
153 int ct = prods.count();
154 for (int i = 0; i < ct ; i++)
156 QDomElement e = prods.item(i).toElement();
157 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
158 result = e.attribute("name");
159 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
166 void KdenliveDoc::setProducerDuration(int id, int duration)
168 QDomNodeList prods = producersList();
169 int ct = prods.count();
170 for (int i = 0; i < ct ; i++)
172 QDomElement e = prods.item(i).toElement();
173 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
174 e.setAttribute("duration", QString::number(duration));
180 int KdenliveDoc::getProducerDuration(int id)
183 QDomNodeList prods = producersList();
184 int ct = prods.count();
185 for (int i = 0; i < ct ; i++)
187 QDomElement e = prods.item(i).toElement();
188 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
189 result = e.attribute("duration").toInt();
197 QDomDocument KdenliveDoc::generateSceneList()
200 QDomElement westley = doc.createElement("westley");
201 doc.appendChild(westley);
202 QDomElement prod = doc.createElement("producer");
205 QDomDocument KdenliveDoc::toXml()
210 Timecode KdenliveDoc::timecode()
215 QString KdenliveDoc::documentName()
217 return m_projectName;
220 QDomNodeList KdenliveDoc::producersList()
222 return m_document.elementsByTagName("producer");
225 void KdenliveDoc::setProducers(QDomElement doc)
227 QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
229 QDomNodeList list = m_document.elementsByTagName("producer");
230 int ct = list.count();
231 kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
232 for (int i = ct; i > 0; i--) {
233 kdenlivedocument.removeChild(list.item(i));
236 QDomNode n = doc.firstChild();
239 QDomElement e = n.toElement(); // try to convert the node to an element.
240 if(!e.isNull() && e.tagName() == "producer") {
241 kdenlivedocument.appendChild(m_document.importNode(e, true));
246 kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
247 //kDebug()<<m_document.toString();
250 double KdenliveDoc::fps()
255 int KdenliveDoc::width()
260 int KdenliveDoc::height()
265 KUrl KdenliveDoc::url()
270 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId)
272 kDebug()<<"///////// DOCUM, CREATING NEW CLIP, ID:"<<clipId;
273 DocClipBase *clip = new DocClipBase(elem, clipId);
274 m_clipManager->addClip(clip);
275 emit addProjectClip(clip);
278 void KdenliveDoc::deleteProjectClip(const uint clipId)
280 emit deletTimelineClip(clipId);
281 m_clipManager->slotDeleteClip(clipId);
284 void KdenliveDoc::deleteClip(const uint clipId)
286 emit signalDeleteProjectClip(clipId);
287 m_clipManager->deleteClip(clipId);
290 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group)
292 kDebug()<<"///////// DOCUM, ADD CLP: "<<url;
293 m_clipManager->slotAddClipFile(url, group);
296 DocClipBase *KdenliveDoc::getBaseClip(int clipId)
298 return m_clipManager->getClipById(clipId);
301 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group)
303 m_clipManager->slotAddColorClipFile(name, color, duration, group);
306 #include "kdenlivedoc.moc"