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