]> git.sesse.net Git - kdenlive/blob - src/clipmanager.cpp
start implementing image / title transparency
[kdenlive] / src / clipmanager.cpp
1 /***************************************************************************
2  *   Copyright (C) 2008 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
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.                                   *
8  *                                                                         *
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.                          *
13  *                                                                         *
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  ***************************************************************************/
19 #include <KDebug>
20 #include <KFileDialog>
21
22 #include "addclipcommand.h"
23 #include "kdenlivesettings.h"
24 #include "clipmanager.h"
25 #include "docclipbase.h"
26 #include "kdenlivedoc.h"
27
28 ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) {
29     m_clipIdCounter = 1;
30     m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
31 }
32
33 ClipManager::~ClipManager() {
34     qDeleteAll(m_clipList);
35 }
36
37 void ClipManager::checkAudioThumbs() {
38     if (m_audioThumbsEnabled == KdenliveSettings::audiothumbnails()) return;
39     m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
40     for (int i = 0; i < m_clipList.count(); i++) {
41         if (m_audioThumbsEnabled) m_clipList.at(i)->slotRequestAudioThumbs();
42         else m_clipList.at(i)->slotClearAudioCache();
43     }
44 }
45
46 void ClipManager::setThumbsProgress(const QString &message, int progress) {
47     m_doc->setThumbsProgress(message, progress);
48 }
49
50 QList <DocClipBase*> ClipManager::documentClipList() {
51     return m_clipList;
52 }
53
54 void ClipManager::addClip(DocClipBase *clip) {
55     m_clipList.append(clip);
56     int id = clip->getId();
57     if (id >= m_clipIdCounter) m_clipIdCounter = id + 1;
58 }
59
60 void ClipManager::slotDeleteClip(uint clipId) {
61     for (int i = 0; i < m_clipList.count(); i++) {
62         if (m_clipList.at(i)->getId() == clipId) {
63             AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false);
64             m_doc->commandStack()->push(command);
65             break;
66         }
67     }
68 }
69
70 void ClipManager::deleteClip(uint clipId) {
71     for (int i = 0; i < m_clipList.count(); i++) {
72         if (m_clipList.at(i)->getId() == clipId) {
73             m_clipList.removeAt(i);
74             break;
75         }
76     }
77 }
78
79 DocClipBase *ClipManager::getClipAt(int pos) {
80     return m_clipList.at(pos);
81 }
82
83 DocClipBase *ClipManager::getClipById(int clipId) {
84     //kDebug() << "++++  CLIP MAN, LOOKING FOR CLIP ID: " << clipId;
85     for (int i = 0; i < m_clipList.count(); i++) {
86         if (m_clipList.at(i)->getId() == clipId) {
87             //kDebug() << "++++  CLIP MAN, FOUND FOR CLIP ID: " << clipId;
88             return m_clipList.at(i);
89         }
90     }
91     return NULL;
92 }
93
94 void ClipManager::slotAddClipFile(const KUrl url, const QString group, const int groupId) {
95     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << url;
96     QDomDocument doc;
97     QDomElement prod = doc.createElement("producer");
98     prod.setAttribute("resource", url.path());
99     uint id = m_clipIdCounter++;
100     prod.setAttribute("id", QString::number(id));
101     if (!group.isEmpty()) {
102         prod.setAttribute("groupname", group);
103         prod.setAttribute("groupid", groupId);
104     }
105     KMimeType::Ptr type = KMimeType::findByUrl(url);
106     if (type->name().startsWith("image/")) {
107         prod.setAttribute("type", (int) IMAGE);
108         prod.setAttribute("in", "0");
109         prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()) - 1);
110     }
111     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
112     m_doc->commandStack()->push(command);
113 }
114
115 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group, const int groupId) {
116     QDomDocument doc;
117     QDomElement prod = doc.createElement("producer");
118     prod.setAttribute("mlt_service", "colour");
119     prod.setAttribute("colour", color);
120     prod.setAttribute("type", (int) COLOR);
121     uint id = m_clipIdCounter++;
122     prod.setAttribute("id", QString::number(id));
123     prod.setAttribute("in", "0");
124     prod.setAttribute("out", m_doc->getFramePos(duration) - 1);
125     prod.setAttribute("name", name);
126     if (!group.isEmpty()) {
127         prod.setAttribute("groupname", group);
128         prod.setAttribute("groupid", groupId);
129     }
130     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
131     m_doc->commandStack()->push(command);
132 }
133
134 void ClipManager::slotAddSlideshowClipFile(const QString name, const QString path, int count, const QString duration, const bool loop, const bool fade, const QString &luma_duration, const QString &luma_file, const int softness, QString group, const int groupId) {
135     QDomDocument doc;
136     QDomElement prod = doc.createElement("producer");
137     prod.setAttribute("resource", path);
138     prod.setAttribute("type", (int) SLIDESHOW);
139     uint id = m_clipIdCounter++;
140     prod.setAttribute("id", QString::number(id));
141     prod.setAttribute("in", "0");
142     prod.setAttribute("out", m_doc->getFramePos(duration) * count - 1);
143     prod.setAttribute("ttl", m_doc->getFramePos(duration));
144     prod.setAttribute("luma_duration", m_doc->getFramePos(luma_duration));
145     prod.setAttribute("name", name);
146     prod.setAttribute("loop", loop);
147     prod.setAttribute("fade", fade);
148     prod.setAttribute("softness", QString::number(softness));
149     prod.setAttribute("luma_file", luma_file);
150     if (!group.isEmpty()) {
151         prod.setAttribute("groupname", group);
152         prod.setAttribute("groupid", groupId);
153     }
154     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
155     m_doc->commandStack()->push(command);
156 }
157
158
159
160 void ClipManager::slotAddTextClipFile(const QString path, const QString xml, const QString group, const int groupId) {
161     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << path;
162     QDomDocument doc;
163     QDomElement prod = doc.createElement("producer");
164     prod.setAttribute("resource", path + ".png");
165     prod.setAttribute("xml", path);
166     prod.setAttribute("xmldata", xml);
167     uint id = m_clipIdCounter++;
168     prod.setAttribute("id", QString::number(id));
169     if (!group.isEmpty()) {
170         prod.setAttribute("groupname", group);
171         prod.setAttribute("groupid", groupId);
172     }
173     prod.setAttribute("type", (int) TEXT);
174     prod.setAttribute("transparency", "1");
175     prod.setAttribute("in", "0");
176     prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()) - 1);
177     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
178     m_doc->commandStack()->push(command);
179 }
180
181 int ClipManager::getFreeClipId() {
182     return m_clipIdCounter++;
183 }
184
185