]> git.sesse.net Git - kdenlive/blob - src/clipmanager.cpp
Only create audio thumbs when they are enabled, clear cache when disabled
[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
27 ClipManager::ClipManager(KdenliveDoc *doc): m_doc(doc) {
28     m_clipIdCounter = 1;
29     m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
30 }
31
32 ClipManager::~ClipManager() {
33 }
34
35 void ClipManager::checkAudioThumbs() {
36     if (m_audioThumbsEnabled == KdenliveSettings::audiothumbnails()) return;
37     m_audioThumbsEnabled = KdenliveSettings::audiothumbnails();
38     for (int i = 0; i < m_clipList.count(); i++) {
39         if (m_audioThumbsEnabled) m_clipList.at(i)->slotRequestAudioThumbs();
40         else m_clipList.at(i)->slotClearAudioCache();
41     }
42 }
43
44 void ClipManager::setThumbsProgress(KUrl url, int progress) {
45     m_doc->setThumbsProgress(url, progress);
46 }
47
48
49 void ClipManager::addClip(DocClipBase *clip) {
50     m_clipList.append(clip);
51 }
52
53 void ClipManager::slotDeleteClip(uint clipId) {
54     for (int i = 0; i < m_clipList.count(); i++) {
55         if (m_clipList.at(i)->getId() == clipId) {
56             //m_clipList.removeAt(i);
57             AddClipCommand *command = new AddClipCommand(m_doc, m_clipList.at(i)->toXML(), clipId, false);
58             m_doc->commandStack()->push(command);
59             break;
60         }
61     }
62 }
63
64 void ClipManager::deleteClip(uint clipId) {
65     for (int i = 0; i < m_clipList.count(); i++) {
66         if (m_clipList.at(i)->getId() == clipId) {
67             m_clipList.removeAt(i);
68             break;
69         }
70     }
71 }
72
73 DocClipBase *ClipManager::getClipAt(int pos) {
74     return m_clipList.at(pos);
75 }
76
77 DocClipBase *ClipManager::getClipById(int clipId) {
78     kDebug() << "++++  CLIP MAN, LOOKING FOR CLIP ID: " << clipId;
79     for (int i = 0; i < m_clipList.count(); i++) {
80         if (m_clipList.at(i)->getId() == clipId) {
81             kDebug() << "++++  CLIP MAN, FOUND FOR CLIP ID: " << clipId;
82             return m_clipList.at(i);
83         }
84     }
85     return NULL;
86 }
87
88 void ClipManager::slotAddClipFile(const KUrl url, const QString group) {
89     kDebug() << "/////  CLIP MANAGER, ADDING CLIP: " << url;
90     QDomDocument doc;
91     QDomElement prod = doc.createElement("producer");
92     prod.setAttribute("resource", url.path());
93     uint id = m_clipIdCounter++;
94     prod.setAttribute("id", QString::number(id));
95     if (!group.isEmpty()) prod.setAttribute("group", group);
96     KMimeType::Ptr type = KMimeType::findByUrl(url);
97     if (type->name().startsWith("image/")) {
98         prod.setAttribute("type", (int) IMAGE);
99         prod.setAttribute("in", "0");
100         prod.setAttribute("out", m_doc->getFramePos(KdenliveSettings::image_duration()));
101     }
102     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
103     m_doc->commandStack()->push(command);
104 }
105
106 void ClipManager::slotAddColorClipFile(const QString name, const QString color, QString duration, const QString group) {
107     QDomDocument doc;
108     QDomElement prod = doc.createElement("producer");
109     prod.setAttribute("mlt_service", "colour");
110     prod.setAttribute("colour", color);
111     prod.setAttribute("type", (int) COLOR);
112     uint id = m_clipIdCounter++;
113     prod.setAttribute("id", QString::number(id));
114     prod.setAttribute("in", "0");
115     prod.setAttribute("out", m_doc->getFramePos(duration));
116     prod.setAttribute("name", name);
117     AddClipCommand *command = new AddClipCommand(m_doc, prod, id, true);
118     m_doc->commandStack()->push(command);
119 }
120