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