]> git.sesse.net Git - kdenlive/blob - src/monitormanager.cpp
Merge branch 'master' of git://anongit.kde.org/kdenlive
[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 bool MonitorManager::activateMonitor(const QString &name)
67 {
68     if (m_clipMonitor == NULL || m_projectMonitor == NULL)
69         return false;
70     if (m_activeMonitor && m_activeMonitor->name() == name)
71         return false;
72     m_activeMonitor = NULL;
73     for (int i = 0; i < m_monitorsList.count(); i++) {
74         if (m_monitorsList.at(i)->name() == name) {
75             m_activeMonitor = m_monitorsList.at(i);
76         }
77         else m_monitorsList.at(i)->stop();
78     }
79     if (m_activeMonitor) {
80         m_activeMonitor->blockSignals(true);
81         m_activeMonitor->parentWidget()->raise();
82         m_activeMonitor->start();
83         m_activeMonitor->blockSignals(false);
84     }
85     emit checkColorScopes();
86     return (m_activeMonitor != NULL);
87 }
88
89 bool MonitorManager::isActive(const QString &name) const
90 {
91     return m_activeMonitor ? m_activeMonitor->name() == name: false;
92 }
93
94 void MonitorManager::slotSwitchMonitors(bool activateClip)
95 {
96     if (activateClip)
97         activateMonitor("clip");
98     else
99         activateMonitor("project");
100 }
101
102 void MonitorManager::stopActiveMonitor()
103 {
104     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->pause();
105     else m_projectMonitor->pause();
106 }
107
108 void MonitorManager::slotPlay()
109 {
110     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotPlay();
111     else m_projectMonitor->slotPlay();
112 }
113
114 void MonitorManager::slotPause()
115 {
116     stopActiveMonitor();
117 }
118
119 void MonitorManager::slotPlayZone()
120 {
121     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotPlayZone();
122     else m_projectMonitor->slotPlayZone();
123 }
124
125 void MonitorManager::slotLoopZone()
126 {
127     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotLoopZone();
128     else m_projectMonitor->slotLoopZone();
129 }
130
131 void MonitorManager::slotRewind(double speed)
132 {
133     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewind(speed);
134     else m_projectMonitor->slotRewind(speed);
135 }
136
137 void MonitorManager::slotForward(double speed)
138 {
139     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForward(speed);
140     else m_projectMonitor->slotForward(speed);
141 }
142
143 void MonitorManager::slotRewindOneFrame()
144 {
145     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewindOneFrame();
146     else m_projectMonitor->slotRewindOneFrame();
147 }
148
149 void MonitorManager::slotForwardOneFrame()
150 {
151     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForwardOneFrame();
152     else m_projectMonitor->slotForwardOneFrame();
153 }
154
155 void MonitorManager::slotRewindOneSecond()
156 {
157     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotRewindOneFrame(m_timecode.fps());
158     else m_projectMonitor->slotRewindOneFrame(m_timecode.fps());
159 }
160
161 void MonitorManager::slotForwardOneSecond()
162 {
163     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotForwardOneFrame(m_timecode.fps());
164     else m_projectMonitor->slotForwardOneFrame(m_timecode.fps());
165 }
166
167 void MonitorManager::slotStart()
168 {
169     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotStart();
170     else m_projectMonitor->slotStart();
171 }
172
173 void MonitorManager::slotEnd()
174 {
175     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->slotEnd();
176     else m_projectMonitor->slotEnd();
177 }
178
179 void MonitorManager::resetProfiles(Timecode tc)
180 {
181     m_timecode = tc;
182     slotResetProfiles();
183     //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
184 }
185
186 void MonitorManager::slotResetProfiles()
187 {
188     if (m_projectMonitor == NULL || m_clipMonitor == NULL) return;
189     blockSignals(true);
190     QString active = m_activeMonitor ? m_activeMonitor->name() : QString();
191     m_clipMonitor->resetProfile(KdenliveSettings::current_profile());
192     m_projectMonitor->resetProfile(KdenliveSettings::current_profile());
193     if (!active.isEmpty()) activateMonitor(active);
194     blockSignals(false);
195     if (m_activeMonitor) m_activeMonitor->parentWidget()->raise();
196     emit checkColorScopes();
197 }
198
199 void MonitorManager::slotRefreshCurrentMonitor(const QString &id)
200 {
201     // Clip producer was modified, check if clip is currently displayed in clip monitor
202     m_clipMonitor->reloadProducer(id);
203     if (m_activeMonitor == m_clipMonitor) m_clipMonitor->refreshMonitor();
204     else m_projectMonitor->refreshMonitor();
205 }
206
207 void MonitorManager::slotUpdateAudioMonitoring()
208 {
209     // if(...) added since they are 0x0 when the config wizard is running! --Granjow
210     if (m_clipMonitor) {
211         m_clipMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
212     }
213     if (m_projectMonitor) {
214         m_projectMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
215     }
216 }
217
218 void MonitorManager::clearScopeSource()
219 {
220     emit clearScopes();
221 }
222
223 void MonitorManager::updateScopeSource()
224 {
225     emit checkColorScopes();
226 }
227
228 AbstractRender *MonitorManager::activeRenderer()
229 {
230     if (m_activeMonitor) {
231         return m_activeMonitor->abstractRender();
232     }
233     return NULL;
234 }
235
236 #include "monitormanager.moc"