]> git.sesse.net Git - kdenlive/blob - src/monitormanager.cpp
* Cleanup monitor / MLT communication
[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         m_projectMonitor->raise();
61         emit raiseClipMonitor(false);
62     }
63     m_activeMonitor = name;
64 }
65
66 void MonitorManager::slotSwitchMonitors()
67 {
68     if (m_blocked || m_clipMonitor == NULL) return;
69     if (m_clipMonitor->isActive()) {
70         m_clipMonitor->stop();
71         m_projectMonitor->start();
72         m_projectMonitor->raise();
73         m_activeMonitor = m_projectMonitor->name();
74         emit raiseClipMonitor(false);
75     } else {
76         m_projectMonitor->stop();
77         m_clipMonitor->start();
78         m_activeMonitor = m_clipMonitor->name();
79         emit raiseClipMonitor(true);
80     }
81 }
82
83 void MonitorManager::stopActiveMonitor()
84 {
85     if (m_blocked) return;
86     if (m_clipMonitor->isActive()) m_clipMonitor->pause();
87     else m_projectMonitor->pause();
88 }
89
90 void MonitorManager::slotPlay()
91 {
92     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlay();
93     else m_projectMonitor->slotPlay();
94 }
95
96 void MonitorManager::slotPlayZone()
97 {
98     if (m_clipMonitor->isActive()) m_clipMonitor->slotPlayZone();
99     else m_projectMonitor->slotPlayZone();
100 }
101
102 void MonitorManager::slotLoopZone()
103 {
104     if (m_clipMonitor->isActive()) m_clipMonitor->slotLoopZone();
105     else m_projectMonitor->slotLoopZone();
106 }
107
108 void MonitorManager::slotRewind(double speed)
109 {
110     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewind(speed);
111     else m_projectMonitor->slotRewind(speed);
112 }
113
114 void MonitorManager::slotForward(double speed)
115 {
116     if (m_clipMonitor->isActive()) m_clipMonitor->slotForward(speed);
117     else m_projectMonitor->slotForward(speed);
118 }
119
120 void MonitorManager::slotRewindOneFrame()
121 {
122     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame();
123     else m_projectMonitor->slotRewindOneFrame();
124 }
125
126 void MonitorManager::slotForwardOneFrame()
127 {
128     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame();
129     else m_projectMonitor->slotForwardOneFrame();
130 }
131
132 void MonitorManager::slotRewindOneSecond()
133 {
134     if (m_clipMonitor->isActive()) m_clipMonitor->slotRewindOneFrame(m_timecode.fps());
135     else m_projectMonitor->slotRewindOneFrame(m_timecode.fps());
136 }
137
138 void MonitorManager::slotForwardOneSecond()
139 {
140     if (m_clipMonitor->isActive()) m_clipMonitor->slotForwardOneFrame(m_timecode.fps());
141     else m_projectMonitor->slotForwardOneFrame(m_timecode.fps());
142 }
143
144 void MonitorManager::slotStart()
145 {
146     if (m_clipMonitor->isActive()) m_clipMonitor->slotStart();
147     else m_projectMonitor->slotStart();
148 }
149
150 void MonitorManager::slotEnd()
151 {
152     if (m_clipMonitor->isActive()) m_clipMonitor->slotEnd();
153     else m_projectMonitor->slotEnd();
154 }
155
156 void MonitorManager::resetProfiles(Timecode tc)
157 {
158     if (m_blocked) return;
159     m_timecode = tc;
160     slotResetProfiles();
161     //QTimer::singleShot(300, this, SLOT(slotResetProfiles()));
162 }
163
164 void MonitorManager::slotResetProfiles()
165 {
166     if (m_blocked) return;
167     if (m_projectMonitor == NULL || m_clipMonitor == NULL) return;
168     activateMonitor("clip");
169     m_clipMonitor->resetProfile(KdenliveSettings::current_profile());
170     activateMonitor("project");
171     m_projectMonitor->resetProfile(KdenliveSettings::current_profile());
172     //m_projectMonitor->refreshMonitor(true);
173 }
174
175
176 #include "monitormanager.moc"