]> git.sesse.net Git - kdenlive/blob - src/monitormanager.cpp
Make jog shuttle buttons work, based on patch from P. Fleury,
[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_blocked(false)
36 {
37 }
38
39 Timecode MonitorManager::timecode()
40 {
41     return m_timecode;
42 }
43
44 void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
45 {
46     m_clipMonitor = clipMonitor;
47     m_projectMonitor = projectMonitor;
48 }
49
50 void MonitorManager::activateMonitor(QString name)
51 {
52     if (m_blocked || m_clipMonitor == NULL || m_projectMonitor == NULL)
53         return;
54     if (m_activeMonitor == name)
55         return;
56     if (name == "clip") {
57         m_projectMonitor->stop();
58         m_clipMonitor->start();
59         emit raiseClipMonitor(true);
60     } else {
61         m_clipMonitor->stop();
62         m_projectMonitor->start();
63         emit raiseClipMonitor(false);
64     }
65     m_activeMonitor = name;
66     emit checkColorScopes();
67 }
68
69 void MonitorManager::slotSwitchMonitors(bool activateClip)
70 {
71     if (activateClip)
72         activateMonitor("clip");
73     else
74         activateMonitor("project");
75 }
76
77 void MonitorManager::stopActiveMonitor()
78 {
79     if (m_blocked) return;
80     if (m_clipMonitor->isActive()) m_clipMonitor->pause();
81     else m_projectMonitor->pause();
82 }
83
84 void MonitorManager::slotPlay()
85 {
86     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlay();
87     else m_projectMonitor->slotPlay();
88 }
89
90 void MonitorManager::slotPause()
91 {
92   stopActiveMonitor();
93 }
94
95 void MonitorManager::slotPlayZone()
96 {
97     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlayZone();
98     else m_projectMonitor->slotPlayZone();
99 }
100
101 void MonitorManager::slotLoopZone()
102 {
103     if (m_clipMonitor->isActive()) m_clipMonitor->slotLoopZone();
104     else m_projectMonitor->slotLoopZone();
105 }
106
107 void MonitorManager::slotRewind(double speed)
108 {
109     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewind(speed);
110     else m_projectMonitor->slotRewind(speed);
111 }
112
113 void MonitorManager::slotForward(double speed)
114 {
115     if (m_clipMonitor->isActive()) m_clipMonitor->slotForward(speed);
116     else m_projectMonitor->slotForward(speed);
117 }
118
119 void MonitorManager::slotRewindOneFrame()
120 {
121     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame();
122     else m_projectMonitor->slotRewindOneFrame();
123 }
124
125 void MonitorManager::slotForwardOneFrame()
126 {
127     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame();
128     else m_projectMonitor->slotForwardOneFrame();
129 }
130
131 void MonitorManager::slotRewindOneSecond()
132 {
133     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame(m_timecode.fps());
134     else m_projectMonitor->slotRewindOneFrame(m_timecode.fps());
135 }
136
137 void MonitorManager::slotForwardOneSecond()
138 {
139     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame(m_timecode.fps());
140     else m_projectMonitor->slotForwardOneFrame(m_timecode.fps());
141 }
142
143 void MonitorManager::slotStart()
144 {
145     if (m_clipMonitor->isActive()) m_clipMonitor->slotStart();
146     else m_projectMonitor->slotStart();
147 }
148
149 void MonitorManager::slotEnd()
150 {
151     if (m_clipMonitor->isActive()) m_clipMonitor->slotEnd();
152     else m_projectMonitor->slotEnd();
153 }
154
155 void MonitorManager::resetProfiles(Timecode tc)
156 {
157     if (m_blocked) return;
158     m_timecode = tc;
159     slotResetProfiles();
160     //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
161 }
162
163 void MonitorManager::slotResetProfiles()
164 {
165     if (m_blocked) return;
166     if (m_projectMonitor == NULL || m_clipMonitor == NULL) return;
167     QString active = m_activeMonitor;
168     activateMonitor("clip");
169     m_clipMonitor->resetProfile(KdenliveSettings::current_profile());
170     m_clipMonitor->updateTimecodeFormat();
171     activateMonitor("project");
172     m_projectMonitor->resetProfile(KdenliveSettings::current_profile());
173     m_projectMonitor->updateTimecodeFormat();
174     //m_projectMonitor->refreshMonitor(true);
175     activateMonitor(active);
176 }
177
178 void MonitorManager::slotRefreshCurrentMonitor()
179 {
180     if (m_clipMonitor->isActive()) m_clipMonitor->refreshMonitor();
181     else m_projectMonitor->refreshMonitor();
182 }
183
184 void MonitorManager::slotUpdateAudioMonitoring()
185 {
186     m_clipMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
187     m_projectMonitor->render->analyseAudio = KdenliveSettings::monitor_audio();
188 }
189
190 #include "monitormanager.moc"