]> git.sesse.net Git - kdenlive/blob - src/monitormanager.cpp
Cleaning code style of Definitions.
[kdenlive] / src / monitormanager.cpp
1 /***************************************************************************
2  *   Copyright (C) 2007 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
20
21 #include "monitormanager.h"
22 #include "renderer.h"
23 #include "kdenlivesettings.h"
24 #include "kdenlivedoc.h"
25
26 #include <mlt++/Mlt.h>
27
28 #include <QObject>
29 #include <QTimer>
30 #include <KDebug>
31
32
33 MonitorManager::MonitorManager(QWidget *parent) :
34         QObject(parent),
35         m_document(NULL),
36         m_clipMonitor(NULL),
37         m_projectMonitor(NULL),
38         m_activeMonitor(NULL)
39 {
40 }
41
42 Timecode MonitorManager::timecode() const
43 {
44     return m_timecode;
45 }
46
47 void MonitorManager::setDocument(KdenliveDoc *doc)
48 {
49     m_document = doc;
50 }
51
52 void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor, RecMonitor *recMonitor)
53 {
54     m_clipMonitor = clipMonitor;
55     m_projectMonitor = projectMonitor;
56     
57     connect(m_clipMonitor->render, SIGNAL(activateMonitor(Kdenlive::MonitorId)), this, SLOT(activateMonitor(Kdenlive::MonitorId)));
58     connect(m_projectMonitor->render, SIGNAL(activateMonitor(Kdenlive::MonitorId)), this, SLOT(activateMonitor(Kdenlive::MonitorId)));
59
60     m_monitorsList.append(clipMonitor);
61     m_monitorsList.append(projectMonitor);
62     if (recMonitor)
63         m_monitorsList.append(recMonitor);
64 }
65
66 void MonitorManager::appendMonitor(AbstractMonitor *monitor)
67 {
68     if (!m_monitorsList.contains(monitor)) m_monitorsList.append(monitor);
69 }
70
71 void MonitorManager::removeMonitor(AbstractMonitor *monitor)
72 {
73     m_monitorsList.removeAll(monitor);
74 }
75
76 AbstractMonitor* MonitorManager::monitor(Kdenlive::MonitorId monitorName)
77 {
78     AbstractMonitor *monitor = NULL;
79     for (int i = 0; i < m_monitorsList.size(); ++i) {
80         if (m_monitorsList[i]->id() == monitorName) {
81         monitor = m_monitorsList.at(i);
82         }
83     }
84     return monitor;
85 }
86
87 void MonitorManager::setConsumerProperty(const QString &name, const QString &value)
88 {
89     if (m_clipMonitor) m_clipMonitor->render->setConsumerProperty(name, value);
90     if (m_projectMonitor) m_projectMonitor->render->setConsumerProperty(name, value);
91 }
92
93 bool MonitorManager::activateMonitor(Kdenlive::MonitorId name, bool forceRefresh)
94 {
95     if (m_clipMonitor == NULL || m_projectMonitor == NULL)
96         return false;
97     if (m_activeMonitor && m_activeMonitor->id() == name) {
98         if (forceRefresh) m_activeMonitor->start();
99         return false;
100     }
101     m_activeMonitor = NULL;
102     for (int i = 0; i < m_monitorsList.count(); ++i) {
103         if (m_monitorsList.at(i)->id() == name) {
104             m_activeMonitor = m_monitorsList.at(i);
105         }
106         else m_monitorsList.at(i)->stop();
107     }
108     if (m_activeMonitor) {
109         m_activeMonitor->blockSignals(true);
110         m_activeMonitor->parentWidget()->raise();
111         m_activeMonitor->blockSignals(false);
112         m_activeMonitor->start();
113         
114     }
115     emit checkColorScopes();
116     return (m_activeMonitor != NULL);
117 }
118
119 bool MonitorManager::isActive(Kdenlive::MonitorId id) const
120 {
121     return m_activeMonitor ? m_activeMonitor->id() == id: false;
122 }
123
124 void MonitorManager::slotSwitchMonitors(bool activateClip)
125 {
126     if (activateClip)
127         activateMonitor(Kdenlive::ClipMonitor);
128     else
129         activateMonitor(Kdenlive::ProjectMonitor);
130 }
131
132 void MonitorManager::stopActiveMonitor()
133 {
134     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->pause();
135     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->pause();
136 }
137
138 void MonitorManager::slotPlay()
139 {
140     if (m_activeMonitor) m_activeMonitor->slotPlay();
141 }
142
143 void MonitorManager::slotPause()
144 {
145     stopActiveMonitor();
146 }
147
148 void MonitorManager::slotPlayZone()
149 {
150     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotPlayZone();
151     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotPlayZone();
152 }
153
154 void MonitorManager::slotLoopZone()
155 {
156     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotLoopZone();
157     else m_projectMonitor->slotLoopZone();
158 }
159
160 void MonitorManager::slotRewind(double speed)
161 {
162     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewind(speed);
163     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotRewind(speed);
164 }
165
166 void MonitorManager::slotForward(double speed)
167 {
168     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForward(speed);
169     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotForward(speed);
170 }
171
172 void MonitorManager::slotRewindOneFrame()
173 {
174     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewindOneFrame();
175     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotRewindOneFrame();
176 }
177
178 void MonitorManager::slotForwardOneFrame()
179 {
180     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForwardOneFrame();
181     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotForwardOneFrame();
182 }
183
184 void MonitorManager::slotRewindOneSecond()
185 {
186     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewindOneFrame(m_timecode.fps());
187     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotRewindOneFrame(m_timecode.fps());
188 }
189
190 void MonitorManager::slotForwardOneSecond()
191 {
192     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForwardOneFrame(m_timecode.fps());
193     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotForwardOneFrame(m_timecode.fps());
194 }
195
196 void MonitorManager::slotStart()
197 {
198     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotStart();
199     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotStart();
200 }
201
202 void MonitorManager::slotEnd()
203 {
204     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotEnd();
205     else if (m_activeMonitor == m_projectMonitor) m_projectMonitor->slotEnd();
206 }
207
208 void MonitorManager::resetProfiles(const Timecode &tc)
209 {
210     m_timecode = tc;
211     slotResetProfiles();
212     //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
213 }
214
215 void MonitorManager::slotResetProfiles()
216 {
217     if (m_projectMonitor == NULL || m_clipMonitor == NULL) {
218         return;
219     }
220     blockSignals(true);
221     Kdenlive::MonitorId active = m_activeMonitor ? m_activeMonitor->id() : Kdenlive::NoMonitor;
222     m_clipMonitor->resetProfile(KdenliveSettings::current_profile());
223     m_projectMonitor->resetProfile(KdenliveSettings::current_profile());
224     if (active != Kdenlive::NoMonitor) activateMonitor(active);
225     blockSignals(false);
226     if (m_activeMonitor) m_activeMonitor->parentWidget()->raise();
227     emit checkColorScopes();
228 }
229
230 void MonitorManager::slotRefreshCurrentMonitor(const QString &id)
231 {
232     // Clip producer was modified, check if clip is currently displayed in clip monitor
233     m_clipMonitor->reloadProducer(id);
234     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->refreshMonitor();
235     else m_projectMonitor->refreshMonitor();
236 }
237
238 void MonitorManager::slotUpdateAudioMonitoring()
239 {
240     // if(...) added since they are 0x0 when the config wizard is running! --Granjow
241     /*if (m_clipMonitor) {
242         m_clipMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
243     }
244     if (m_projectMonitor) {
245         m_projectMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
246     }*/
247     for (int i = 0; i < m_monitorsList.count(); ++i) {
248         if (m_monitorsList.at(i)->abstractRender()) m_monitorsList.at(i)->abstractRender()->analyseAudio = KdenliveSettings::monitor_audio();
249     }
250 }
251
252 void MonitorManager::clearScopeSource()
253 {
254     emit clearScopes();
255 }
256
257 void MonitorManager::updateScopeSource()
258 {
259     emit checkColorScopes();
260 }
261
262 AbstractRender *MonitorManager::activeRenderer()
263 {
264     if (m_activeMonitor) {
265         return m_activeMonitor->abstractRender();
266     }
267     return NULL;
268 }
269
270 void MonitorManager::slotSwitchFullscreen()
271 {
272     if (m_activeMonitor) m_activeMonitor->slotSwitchFullScreen();
273 }
274
275 QString MonitorManager::getProjectFolder() const
276 {
277     if (m_document == NULL) {
278         kDebug()<<" + + +NULL DOC!!";
279         return QString();
280     }
281     return m_document->projectFolder().path(KUrl::AddTrailingSlash);
282 }
283
284
285 #include "monitormanager.moc"