]> git.sesse.net Git - kdenlive/blob - src/monitormanager.cpp
Fix issue with monitor switching
[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 "kdenlivesettings.h"
23
24 #include <mlt++/Mlt.h>
25
26 #include <QObject>
27 #include <QTimer>
28
29
30 MonitorManager::MonitorManager(QWidget *parent) :
31         QObject(parent),
32         m_clipMonitor(NULL),
33         m_projectMonitor(NULL),
34         m_blocked(false)
35 {
36 }
37
38 Timecode MonitorManager::timecode()
39 {
40     return m_timecode;
41 }
42
43 void MonitorManager::initMonitors(Monitor *clipMonitor, Monitor *projectMonitor)
44 {
45     m_clipMonitor = clipMonitor;
46     m_projectMonitor = projectMonitor;
47 }
48
49 void MonitorManager::activateMonitor(QString name)
50 {
51     if (m_blocked || m_clipMonitor == NULL) return;
52     if (m_activeMonitor == name) return;
53     if (name == "clip") {
54         m_projectMonitor->stop();
55         m_clipMonitor->start();
56         emit raiseClipMonitor(true);
57     } else {
58         m_clipMonitor->stop();
59         m_projectMonitor->start();
60         emit raiseClipMonitor(false);
61     }
62     m_activeMonitor = name;
63 }
64
65 void MonitorManager::slotSwitchMonitors(bool activateClip)
66 {
67     if (m_blocked || m_clipMonitor == NULL) return;
68     if (!activateClip && m_clipMonitor->isActive()) {
69         m_clipMonitor->stop();
70         m_projectMonitor->start();
71         m_activeMonitor = m_projectMonitor->name();
72         emit raiseClipMonitor(false);
73     } else if (activateClip && m_projectMonitor->isActive()){
74         m_projectMonitor->stop();
75         m_clipMonitor->start();
76         m_activeMonitor = m_clipMonitor->name();
77         emit raiseClipMonitor(true);
78     }
79 }
80
81 void MonitorManager::stopActiveMonitor()
82 {
83     if (m_blocked) return;
84     if (m_clipMonitor->isActive()) m_clipMonitor->pause();
85     else m_projectMonitor->pause();
86 }
87
88 void MonitorManager::slotPlay()
89 {
90     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlay();
91     else m_projectMonitor->slotPlay();
92 }
93
94 void MonitorManager::slotPlayZone()
95 {
96     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlayZone();
97     else m_projectMonitor->slotPlayZone();
98 }
99
100 void MonitorManager::slotLoopZone()
101 {
102     if (m_clipMonitor->isActive()) m_clipMonitor->slotLoopZone();
103     else m_projectMonitor->slotLoopZone();
104 }
105
106 void MonitorManager::slotRewind(double speed)
107 {
108     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewind(speed);
109     else m_projectMonitor->slotRewind(speed);
110 }
111
112 void MonitorManager::slotForward(double speed)
113 {
114     if (m_clipMonitor->isActive()) m_clipMonitor->slotForward(speed);
115     else m_projectMonitor->slotForward(speed);
116 }
117
118 void MonitorManager::slotRewindOneFrame()
119 {
120     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame();
121     else m_projectMonitor->slotRewindOneFrame();
122 }
123
124 void MonitorManager::slotForwardOneFrame()
125 {
126     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame();
127     else m_projectMonitor->slotForwardOneFrame();
128 }
129
130 void MonitorManager::slotRewindOneSecond()
131 {
132     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame(m_timecode.fps());
133     else m_projectMonitor->slotRewindOneFrame(m_timecode.fps());
134 }
135
136 void MonitorManager::slotForwardOneSecond()
137 {
138     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame(m_timecode.fps());
139     else m_projectMonitor->slotForwardOneFrame(m_timecode.fps());
140 }
141
142 void MonitorManager::slotStart()
143 {
144     if (m_clipMonitor->isActive()) m_clipMonitor->slotStart();
145     else m_projectMonitor->slotStart();
146 }
147
148 void MonitorManager::slotEnd()
149 {
150     if (m_clipMonitor->isActive()) m_clipMonitor->slotEnd();
151     else m_projectMonitor->slotEnd();
152 }
153
154 void MonitorManager::resetProfiles(Timecode tc)
155 {
156     if (m_blocked) return;
157     m_timecode = tc;
158     slotResetProfiles();
159     //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
160 }
161
162 void MonitorManager::slotResetProfiles()
163 {
164     if (m_blocked) return;
165     if (m_projectMonitor == NULL || m_clipMonitor == NULL) return;
166     activateMonitor("clip");
167     m_clipMonitor->resetProfile(KdenliveSettings::current_profile());
168     activateMonitor("project");
169     m_projectMonitor->resetProfile(KdenliveSettings::current_profile());
170     //m_projectMonitor->refreshMonitor(true);
171 }
172
173
174 #include "monitormanager.moc"