]> git.sesse.net Git - kdenlive/blob - src/monitor.h
Try to fix the concurrency issues causing crash in the avformat producer
[kdenlive] / src / monitor.h
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 #ifndef MONITOR_H
21 #define MONITOR_H
22
23
24 #include "gentime.h"
25 #include "renderer.h"
26 #include "timecodedisplay.h"
27 #include "abstractmonitor.h"
28 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
29 #include "videoglwidget.h"
30 #endif
31
32 #include <QLabel>
33 #include <QDomElement>
34 #include <QToolBar>
35 #include <QSlider>
36
37 #include <KIcon>
38 #include <KAction>
39 #include <KRestrictedLine>
40
41 class SmallRuler;
42 class DocClipBase;
43 class AbstractClipItem;
44 class Transition;
45 class ClipItem;
46 class MonitorEditWidget;
47 class Monitor;
48 class MonitorManager;
49
50 class VideoContainer : public QFrame
51 {
52     Q_OBJECT
53 public:
54     VideoContainer(Monitor *parent = 0);
55     void switchFullScreen();
56
57 protected:
58     virtual void mouseDoubleClickEvent(QMouseEvent * event);
59     virtual void mousePressEvent(QMouseEvent * event);
60     virtual void mouseReleaseEvent(QMouseEvent *event);
61     virtual void mouseMoveEvent(QMouseEvent *event);
62     void keyPressEvent(QKeyEvent *event);
63     virtual void wheelEvent(QWheelEvent * event);
64
65 private:
66     Qt::WindowFlags m_baseFlags;
67     Monitor *m_monitor;
68 };
69
70 class MonitorRefresh : public QWidget
71 {
72     Q_OBJECT
73 public:
74     MonitorRefresh(QWidget *parent = 0);
75     void setRenderer(Render* render);
76
77 protected:
78     virtual void resizeEvent(QResizeEvent *event);
79
80 private:
81     Render *m_renderer;
82
83 signals:
84     void switchFullScreen();
85     void switchPlay();
86     void mouseSeek(int, bool);
87 };
88
89 class Overlay : public QLabel
90 {
91     Q_OBJECT
92 public:
93     Overlay(QWidget* parent = 0);
94     void setOverlayText(const QString &, bool isZone = true);
95
96 private:
97     bool m_isZone;
98
99 protected:
100     virtual void mouseDoubleClickEvent ( QMouseEvent * event );
101     virtual void mousePressEvent ( QMouseEvent * event );
102     virtual void mouseReleaseEvent ( QMouseEvent * event );
103     
104 signals:
105     void editMarker();
106 };
107
108 class Monitor : public AbstractMonitor
109 {
110     Q_OBJECT
111
112 public:
113     Monitor(QString name, MonitorManager *manager, QString profile = QString(), QWidget *parent = 0);
114     ~Monitor();
115     Render *render;
116     AbstractRender *abstractRender();
117     void resetProfile(const QString &profile);
118     const QString name() const;
119     void resetSize();
120     bool isActive() const;
121     void pause();
122     void setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMenu *markerMenu = NULL, QAction *loopClip = NULL);
123     const QString sceneList();
124     DocClipBase *activeClip();
125     GenTime position();
126     void checkOverlay();
127     void updateTimecodeFormat();
128     void updateMarkers(DocClipBase *source);
129     MonitorEditWidget *getEffectEdit();
130     QWidget *container();
131     QFrame *m_volumePopup;
132
133 protected:
134     virtual void mousePressEvent(QMouseEvent * event);
135     virtual void mouseReleaseEvent(QMouseEvent * event);
136
137     /** @brief Move to another position on mouse wheel event.
138      *
139      * Moves towards the end of the clip/timeline on mouse wheel down/back, the
140      * opposite on mouse wheel up/forward.
141      * Ctrl + wheel moves by a second, without Ctrl it moves by a single frame. */
142     virtual void wheelEvent(QWheelEvent * event);
143     virtual void mouseMoveEvent(QMouseEvent *event);
144     virtual QStringList mimeTypes() const;
145     /*virtual void dragMoveEvent(QDragMoveEvent * event);
146     virtual Qt::DropActions supportedDropActions() const;*/
147
148     //virtual void resizeEvent(QResizeEvent * event);
149     //virtual void paintEvent(QPaintEvent * event);
150
151 private:
152     QString m_name;
153     MonitorManager *m_monitorManager;
154     DocClipBase *m_currentClip;
155     SmallRuler *m_ruler;
156     Overlay *m_overlay;
157     double m_scale;
158     int m_length;
159     bool m_dragStarted;
160     MonitorRefresh *m_monitorRefresh;
161     KIcon m_playIcon;
162     KIcon m_pauseIcon;
163     TimecodeDisplay *m_timePos;
164     QAction *m_playAction;
165     /** Has to be available so we can enable and disable it. */
166     QAction *m_loopClipAction;
167     QMenu *m_contextMenu;
168     QMenu *m_configMenu;
169     QMenu *m_playMenu;
170     QMenu *m_markerMenu;
171     QPoint m_DragStartPosition;
172     MonitorEditWidget *m_effectWidget;
173     VideoContainer *m_videoBox;
174     /** Selected clip/transition in timeline. Used for looping it. */
175     AbstractClipItem *m_selectedClip;
176     /** true if selected clip is transition, false = selected clip is clip.
177      *  Necessary because sometimes we get two signals, e.g. we get a clip and we get selected transition = NULL. */
178     bool m_loopClipTransition;
179
180 #if defined(Q_WS_MAC) || defined(USE_OPEN_GL)
181     VideoGLWidget *m_glWidget;
182     bool createOpenGlWidget(QWidget *parent, const QString profile);
183 #endif
184
185     GenTime getSnapForPos(bool previous);
186     Qt::WindowFlags m_baseFlags;
187     QToolBar *m_toolbar;
188     QWidget *m_volumeWidget;
189     QSlider *m_audioSlider;
190     QAction *m_editMarker;
191
192 private slots:
193     void seekCursor(int pos);
194     void rendererStopped(int pos);
195     void slotExtractCurrentFrame();
196     void slotSetThumbFrame();
197     void slotSetSizeOneToOne();
198     void slotSetSizeOneToTwo();
199     void slotSaveZone();
200     void slotSeek();
201     void setClipZone(QPoint pos);
202     void slotSwitchMonitorInfo(bool show);
203     void slotSwitchDropFrames(bool show);
204     void slotGoToMarker(QAction *action);
205     void slotSetVolume(int volume);
206     void slotShowVolume();
207     void slotEditMarker();
208
209 public slots:
210     void slotOpenFile(const QString &);
211     void slotSetClipProducer(DocClipBase *clip, QPoint zone = QPoint(), int position = -1);
212     void updateClipProducer(Mlt::Producer *prod);
213     void refreshMonitor(bool visible);
214     void refreshMonitor();
215     void slotSeek(int pos);
216     void stop();
217     void start();
218     void activateMonitor();
219     void slotPlay();
220     void slotPlayZone();
221     void slotLoopZone();
222     /** @brief Loops the selected item (clip or transition). */
223     void slotLoopClip();
224     void slotForward(double speed = 0);
225     void slotRewind(double speed = 0);
226     void slotRewindOneFrame(int diff = 1);
227     void slotForwardOneFrame(int diff = 1);
228     void saveSceneList(QString path, QDomElement info = QDomElement());
229     void slotStart();
230     void slotEnd();
231     void slotSetZoneStart();
232     void slotSetZoneEnd();
233     void slotZoneStart();
234     void slotZoneEnd();
235     void slotZoneMoved(int start, int end);
236     void slotSeekToNextSnap();
237     void slotSeekToPreviousSnap();
238     void adjustRulerSize(int length);
239     void setTimePos(const QString &pos);
240     QStringList getZoneInfo() const;
241     void slotEffectScene(bool show = true);
242     bool effectSceneDisplayed();
243
244     /** @brief Sets m_selectedClip to @param item. Used for looping it. */
245     void slotSetSelectedClip(AbstractClipItem *item);
246     void slotSetSelectedClip(ClipItem *item);
247     void slotSetSelectedClip(Transition *item);
248     void slotMouseSeek(int eventDelta, bool fast);
249     void slotSwitchFullScreen();
250
251 signals:
252     void renderPosition(int);
253     void durationChanged(int);
254     void refreshClipThumbnail(const QString &, bool);
255     void adjustMonitorSize();
256     void zoneUpdated(QPoint);
257     void saveZone(Render *, QPoint, DocClipBase *);
258     /** @brief  Editing transitions / effects over the monitor requires the renderer to send frames as QImage.
259      *      This causes a major slowdown, so we only enable it if required */
260     void requestFrameForAnalysis(bool);
261 };
262
263 #endif