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"
29 #include "docclipbase.h"
31 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())
33 m_clipManager = new ClipManager(this);
36 if(KIO::NetAccess::download(url.path(), tmpFile, parent))
39 m_document.setContent(&file, false);
41 m_projectName = url.fileName();
42 KIO::NetAccess::removeTempFile(tmpFile);
46 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
50 // Creating new document
51 QDomElement westley = m_document.createElement("westley");
52 m_document.appendChild(westley);
53 QDomElement doc = m_document.createElement("kdenlivedoc");
54 doc.setAttribute("version", "0.6");
55 westley.appendChild(doc);
56 QDomElement props = m_document.createElement("properties");
57 doc.setAttribute("width", m_width);
58 doc.setAttribute("height", m_height);
59 doc.setAttribute("projectfps", m_fps);
60 doc.appendChild(props);
63 /*QDomElement westley = m_document.createElement("westley");
64 m_document.appendChild(westley);*/
67 QDomElement tractor = m_document.createElement("tractor");
68 QDomElement multitrack = m_document.createElement("multitrack");
69 QDomElement playlist = m_document.createElement("playlist");
70 QDomElement producer = m_document.createElement("producer");
71 /*producer.setAttribute("mlt_service", "colour");
72 producer.setAttribute("colour", "red");
73 playlist.appendChild(producer);*/
74 multitrack.appendChild(playlist);
75 QDomElement playlist1 = m_document.createElement("playlist");
76 playlist1.setAttribute("id", "playlist1");
77 playlist1.setAttribute("hide", "video");
78 multitrack.appendChild(playlist1);
79 QDomElement playlist2 = m_document.createElement("playlist");
80 playlist2.setAttribute("id", "playlist2");
81 playlist2.setAttribute("hide", "video");
82 multitrack.appendChild(playlist2);
83 QDomElement playlist3 = m_document.createElement("playlist");
84 multitrack.appendChild(playlist3);
85 playlist3.setAttribute("id", "playlist3");
86 QDomElement playlist4 = m_document.createElement("playlist");
87 multitrack.appendChild(playlist4);
88 playlist4.setAttribute("id", "playlist4");
89 QDomElement playlist5 = m_document.createElement("playlist");
90 multitrack.appendChild(playlist5);
91 playlist5.setAttribute("id", "playlist5");
92 tractor.appendChild(multitrack);
94 for (uint i = 2; i < 6 ; i++) {
95 QDomElement transition = m_document.createElement("transition");
96 transition.setAttribute("in", "0");
97 //TODO: Make audio mix last for all project duration
98 transition.setAttribute("out", "15000");
99 transition.setAttribute("a_track", QString::number(1));
100 transition.setAttribute("b_track", QString::number(i));
101 transition.setAttribute("mlt_service", "mix");
102 transition.setAttribute("combine", "1");
103 tractor.appendChild(transition);
106 doc.appendChild(tractor);
109 if (fps == 30000.0 / 1001.0 ) m_timecode.setFormat(30, true);
110 else m_timecode.setFormat((int) fps);
113 KdenliveDoc::~KdenliveDoc()
115 delete m_commandStack;
116 delete m_clipManager;
119 ClipManager *KdenliveDoc::clipManager()
121 return m_clipManager;
124 void KdenliveDoc::setThumbsProgress(KUrl url, int progress)
126 emit thumbsProgress(url, progress);
129 KUndoStack *KdenliveDoc::commandStack()
131 return m_commandStack;
134 void KdenliveDoc::setRenderer(Render *render)
137 if (m_render) m_render->setSceneList(m_document);
140 Render *KdenliveDoc::renderer()
145 void KdenliveDoc::updateClip(int id)
147 emit updateClipDisplay(id);
150 int KdenliveDoc::getFramePos(QString duration)
152 return m_timecode.getFrameCount(duration, m_fps);
155 QString KdenliveDoc::producerName(int id)
157 QString result = "unnamed";
158 QDomNodeList prods = producersList();
159 int ct = prods.count();
160 for (int i = 0; i < ct ; i++)
162 QDomElement e = prods.item(i).toElement();
163 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
164 result = e.attribute("name");
165 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
172 void KdenliveDoc::setProducerDuration(int id, int duration)
174 QDomNodeList prods = producersList();
175 int ct = prods.count();
176 for (int i = 0; i < ct ; i++)
178 QDomElement e = prods.item(i).toElement();
179 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
180 e.setAttribute("duration", QString::number(duration));
186 int KdenliveDoc::getProducerDuration(int id)
189 QDomNodeList prods = producersList();
190 int ct = prods.count();
191 for (int i = 0; i < ct ; i++)
193 QDomElement e = prods.item(i).toElement();
194 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
195 result = e.attribute("duration").toInt();
203 QDomDocument KdenliveDoc::generateSceneList()
206 QDomElement westley = doc.createElement("westley");
207 doc.appendChild(westley);
208 QDomElement prod = doc.createElement("producer");
211 QDomDocument KdenliveDoc::toXml()
216 Timecode KdenliveDoc::timecode()
221 QString KdenliveDoc::documentName()
223 return m_projectName;
226 QDomNodeList KdenliveDoc::producersList()
228 return m_document.elementsByTagName("producer");
231 void KdenliveDoc::setProducers(QDomElement doc)
233 QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
235 QDomNodeList list = m_document.elementsByTagName("producer");
236 int ct = list.count();
237 kDebug()<<"DELETING CHILD PRODUCERS: "<<ct;
238 for (int i = ct; i > 0; i--) {
239 kdenlivedocument.removeChild(list.item(i));
242 QDomNode n = doc.firstChild();
245 QDomElement e = n.toElement(); // try to convert the node to an element.
246 if(!e.isNull() && e.tagName() == "producer") {
247 kdenlivedocument.appendChild(m_document.importNode(e, true));
252 kDebug()<<"ADDING CHILD PRODS: "<<ct<<"\n";
253 //kDebug()<<m_document.toString();
256 double KdenliveDoc::fps()
261 int KdenliveDoc::width()
266 int KdenliveDoc::height()
271 KUrl KdenliveDoc::url()
276 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId)
278 kDebug()<<"///////// DOCUM, CREATING NEW CLIP, ID:"<<clipId;
279 DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
280 m_clipManager->addClip(clip);
281 emit addProjectClip(clip);
284 void KdenliveDoc::deleteProjectClip(const uint clipId)
286 emit deletTimelineClip(clipId);
287 m_clipManager->slotDeleteClip(clipId);
290 void KdenliveDoc::deleteClip(const uint clipId)
292 emit signalDeleteProjectClip(clipId);
293 m_clipManager->deleteClip(clipId);
296 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group)
298 kDebug()<<"///////// DOCUM, ADD CLP: "<<url;
299 m_clipManager->slotAddClipFile(url, group);
302 DocClipBase *KdenliveDoc::getBaseClip(int clipId)
304 return m_clipManager->getClipById(clipId);
307 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group)
309 m_clipManager->slotAddColorClipFile(name, color, duration, group);
312 #include "kdenlivedoc.moc"