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