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