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()) {
32 m_clipManager = new ClipManager(this);
35 if (KIO::NetAccess::download(url.path(), tmpFile, parent)) {
37 m_document.setContent(&file, false);
39 m_projectName = url.fileName();
40 KIO::NetAccess::removeTempFile(tmpFile);
42 KMessageBox::error(parent, KIO::NetAccess::lastErrorString());
45 // Creating new document
46 QDomElement westley = m_document.createElement("westley");
47 m_document.appendChild(westley);
48 QDomElement doc = m_document.createElement("kdenlivedoc");
49 doc.setAttribute("version", "0.6");
50 westley.appendChild(doc);
51 QDomElement props = m_document.createElement("properties");
52 doc.setAttribute("width", m_width);
53 doc.setAttribute("height", m_height);
54 doc.setAttribute("projectfps", m_fps);
55 doc.appendChild(props);
58 /*QDomElement westley = m_document.createElement("westley");
59 m_document.appendChild(westley);*/
62 QDomElement tractor = m_document.createElement("tractor");
63 QDomElement multitrack = m_document.createElement("multitrack");
64 QDomElement playlist = m_document.createElement("playlist");
65 QDomElement producer = m_document.createElement("producer");
66 /*producer.setAttribute("mlt_service", "colour");
67 producer.setAttribute("colour", "red");
68 playlist.appendChild(producer);*/
69 multitrack.appendChild(playlist);
70 QDomElement playlist1 = m_document.createElement("playlist");
71 playlist1.setAttribute("id", "playlist1");
72 playlist1.setAttribute("hide", "video");
73 multitrack.appendChild(playlist1);
74 QDomElement playlist2 = m_document.createElement("playlist");
75 playlist2.setAttribute("id", "playlist2");
76 playlist2.setAttribute("hide", "video");
77 multitrack.appendChild(playlist2);
78 QDomElement playlist3 = m_document.createElement("playlist");
79 multitrack.appendChild(playlist3);
80 playlist3.setAttribute("id", "playlist3");
81 QDomElement playlist4 = m_document.createElement("playlist");
82 multitrack.appendChild(playlist4);
83 playlist4.setAttribute("id", "playlist4");
84 QDomElement playlist5 = m_document.createElement("playlist");
85 multitrack.appendChild(playlist5);
86 playlist5.setAttribute("id", "playlist5");
87 tractor.appendChild(multitrack);
89 for (uint i = 2; i < 6 ; i++) {
90 QDomElement transition = m_document.createElement("transition");
91 transition.setAttribute("in", "0");
92 //TODO: Make audio mix last for all project duration
93 transition.setAttribute("out", "15000");
94 transition.setAttribute("a_track", QString::number(1));
95 transition.setAttribute("b_track", QString::number(i));
96 transition.setAttribute("mlt_service", "mix");
97 transition.setAttribute("combine", "1");
98 tractor.appendChild(transition);
101 doc.appendChild(tractor);
104 if (fps == 30000.0 / 1001.0) m_timecode.setFormat(30, true);
105 else m_timecode.setFormat((int) fps);
108 KdenliveDoc::~KdenliveDoc() {
109 delete m_commandStack;
110 delete m_clipManager;
113 ClipManager *KdenliveDoc::clipManager() {
114 return m_clipManager;
117 void KdenliveDoc::setThumbsProgress(KUrl url, int progress) {
118 emit thumbsProgress(url, progress);
121 KUndoStack *KdenliveDoc::commandStack() {
122 return m_commandStack;
125 void KdenliveDoc::setRenderer(Render *render) {
127 if (m_render) m_render->setSceneList(m_document);
130 Render *KdenliveDoc::renderer() {
134 void KdenliveDoc::updateClip(int id) {
135 emit updateClipDisplay(id);
138 int KdenliveDoc::getFramePos(QString duration) {
139 return m_timecode.getFrameCount(duration, m_fps);
142 QString KdenliveDoc::producerName(int id) {
143 QString result = "unnamed";
144 QDomNodeList prods = producersList();
145 int ct = prods.count();
146 for (int i = 0; i < ct ; i++) {
147 QDomElement e = prods.item(i).toElement();
148 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
149 result = e.attribute("name");
150 if (result.isEmpty()) result = KUrl(e.attribute("resource")).fileName();
157 void KdenliveDoc::setProducerDuration(int id, int duration) {
158 QDomNodeList prods = producersList();
159 int ct = prods.count();
160 for (int i = 0; i < ct ; i++) {
161 QDomElement e = prods.item(i).toElement();
162 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
163 e.setAttribute("duration", QString::number(duration));
169 int KdenliveDoc::getProducerDuration(int id) {
171 QDomNodeList prods = producersList();
172 int ct = prods.count();
173 for (int i = 0; i < ct ; i++) {
174 QDomElement e = prods.item(i).toElement();
175 if (e.attribute("id") != "black" && e.attribute("id").toInt() == id) {
176 result = e.attribute("duration").toInt();
184 QDomDocument KdenliveDoc::generateSceneList() {
186 QDomElement westley = doc.createElement("westley");
187 doc.appendChild(westley);
188 QDomElement prod = doc.createElement("producer");
191 QDomDocument KdenliveDoc::toXml() {
195 Timecode KdenliveDoc::timecode() {
199 QString KdenliveDoc::documentName() {
200 return m_projectName;
203 QDomNodeList KdenliveDoc::producersList() {
204 return m_document.elementsByTagName("producer");
207 void KdenliveDoc::setProducers(QDomElement doc) {
208 QDomNode kdenlivedocument = m_document.elementsByTagName("kdenlivedoc").item(0);
210 QDomNodeList list = m_document.elementsByTagName("producer");
211 int ct = list.count();
212 kDebug() << "DELETING CHILD PRODUCERS: " << ct;
213 for (int i = ct; i > 0; i--) {
214 kdenlivedocument.removeChild(list.item(i));
217 QDomNode n = doc.firstChild();
219 while (!n.isNull()) {
220 QDomElement e = n.toElement(); // try to convert the node to an element.
221 if (!e.isNull() && e.tagName() == "producer") {
222 kdenlivedocument.appendChild(m_document.importNode(e, true));
227 kDebug() << "ADDING CHILD PRODS: " << ct << "\n";
228 //kDebug()<<m_document.toString();
231 double KdenliveDoc::fps() {
235 int KdenliveDoc::width() {
239 int KdenliveDoc::height() {
243 KUrl KdenliveDoc::url() {
247 void KdenliveDoc::addClip(const QDomElement &elem, const int clipId) {
248 kDebug() << "///////// DOCUM, CREATING NEW CLIP, ID:" << clipId;
249 DocClipBase *clip = new DocClipBase(m_clipManager, elem, clipId);
250 m_clipManager->addClip(clip);
251 emit addProjectClip(clip);
254 void KdenliveDoc::deleteProjectClip(const uint clipId) {
255 emit deletTimelineClip(clipId);
256 m_clipManager->slotDeleteClip(clipId);
259 void KdenliveDoc::deleteClip(const uint clipId) {
260 emit signalDeleteProjectClip(clipId);
261 m_clipManager->deleteClip(clipId);
264 void KdenliveDoc::slotAddClipFile(const KUrl url, const QString group) {
265 kDebug() << "///////// DOCUM, ADD CLP: " << url;
266 m_clipManager->slotAddClipFile(url, group);
269 DocClipBase *KdenliveDoc::getBaseClip(int clipId) {
270 return m_clipManager->getClipById(clipId);
273 void KdenliveDoc::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
274 m_clipManager->slotAddColorClipFile(name, color, duration, group);
277 #include "kdenlivedoc.moc"