]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Introducing timeline edit mode, starting with overwrite mode (allows to move a clip...
[kdenlive] / src / renderer.h
1 /***************************************************************************
2                          krender.h  -  description
3                             -------------------
4    begin                : Fri Nov 22 2002
5    copyright            : (C) 2002 by Jason Wood
6    email                : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
8
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17
18 #ifndef RENDERER_H
19 #define RENDERER_H
20
21 #include "gentime.h"
22 #include "definitions.h"
23
24 #include <kurl.h>
25
26 #include <qdom.h>
27 #include <qstring.h>
28 #include <qmap.h>
29 #include <QList>
30 #include <QEvent>
31
32 #ifdef Q_WS_MAC
33 #include "videoglwidget.h"
34 #endif
35
36
37 /**Render encapsulates the client side of the interface to a renderer.
38 From Kdenlive's point of view, you treat the Render object as the
39 renderer, and simply use it as if it was local. Calls are asyncrhonous -
40 you send a call out, and then receive the return value through the
41 relevant signal that get's emitted once the call completes.
42   *@author Jason Wood
43   */
44
45 class Render;
46
47 class QTimer;
48 class QPixmap;
49
50 namespace Mlt
51 {
52 class Consumer;
53 class Playlist;
54 class Tractor;
55 class Frame;
56 class Producer;
57 class Filter;
58 class Profile;
59 class Service;
60 };
61
62
63 class MltErrorEvent : public QEvent
64 {
65 public:
66     MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
67     QString message() const {
68         return m_message;
69     }
70
71 private:
72     QString m_message;
73 };
74
75
76 class Render: public QObject
77 {
78 Q_OBJECT public:
79
80     enum FailStates { OK = 0,
81                       APP_NOEXIST
82                     };
83
84     Render(const QString & rendererName, int winid, int extid, QString profile = QString(), QWidget *parent = 0);
85     ~Render();
86
87     /** Seeks the renderer clip to the given time. */
88     void seek(GenTime time);
89     void seekToFrame(int pos);
90     void seekToFrameDiff(int diff);
91     int m_isBlocked;
92
93     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
94     QPixmap getImageThumbnail(KUrl url, int width, int height);
95
96     /** Return thumbnail for color clip */
97     //void getImage(int id, QString color, QPoint size);
98
99     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
100
101     /** Return thumbnail for image clip */
102     //void getImage(KUrl url, QPoint size);
103
104     /** Requests a particular frame from the given file.
105      *
106      * The pixmap will be returned by emitting the replyGetImage() signal.
107      * */
108     //void getImage(KUrl url, int frame, QPoint size);
109
110
111     /** Wraps the VEML command of the same name. Sets the current scene list to
112     be list. */
113     int setSceneList(QDomDocument list, int position = 0);
114     int setSceneList(QString playlist, int position = 0);
115     int setProducer(Mlt::Producer *producer, int position);
116     const QString sceneList();
117     bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
118
119     /** Wraps the VEML command of the same name. Tells the renderer to
120     play the current scene at the speed specified, relative to normal
121     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
122     backwards. Does not specify start/stop times for playback.*/
123     void play(double speed);
124     void switchPlay();
125     void pause();
126     /** stop playing */
127     void stop(const GenTime & startTime);
128     void setVolume(double volume);
129
130     QImage extractFrame(int frame_position, int width = -1, int height = -1);
131     /** Wraps the VEML command of the same name. Tells the renderer to
132     play the current scene at the speed specified, relative to normal
133     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
134     backwards. Specifes the start/stop times for playback.*/
135     void play(const GenTime & startTime);
136     void playZone(const GenTime & startTime, const GenTime & stopTime);
137     void loopZone(const GenTime & startTime, const GenTime & stopTime);
138
139     void saveZone(KUrl url, QString desc, QPoint zone);
140
141     /** Returns the name of the renderer. */
142     const QString & rendererName() const;
143
144     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
145     not playing anything. */
146     double playSpeed();
147     /** Returns the current seek position of the renderer. */
148     GenTime seekPosition() const;
149     int seekFramePosition() const;
150
151     void emitFrameNumber(double position);
152     void emitConsumerStopped();
153
154     /** Gives the aspect ratio of the consumer */
155     double consumerRatio() const;
156
157     void doRefresh();
158
159     /** Save current producer frame as image */
160     void exportCurrentFrame(KUrl url, bool notify);
161
162     /** Turn on or off on screen display */
163     void refreshDisplay();
164     int resetProfile(const QString profileName);
165     double fps() const;
166     int renderWidth() const;
167     int renderHeight() const;
168     /** get display aspect ratio */
169     double dar() const;
170
171     /** Playlist manipulation */
172     int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod, bool overwrite = false, bool push = false);
173     bool mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
174     void mltCutClip(int track, GenTime position);
175     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
176     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
177     int mltTrackDuration(int track);
178     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
179     bool mltResizeClipStart(ItemInfo info, GenTime diff);
180     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
181     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
182     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod, bool overwrite = false, bool insert = false);
183     bool mltRemoveClip(int track, GenTime position);
184     /** Delete an effect to a clip in MLT's playlist */
185     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
186     /** Add an effect to a clip in MLT's playlist */
187     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
188     /** Edit an effect parameters in MLT */
189     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
190     /** This only updates the "kdenlive_ix" (index) value of an effect */
191     void mltUpdateEffectPosition(int track, GenTime position, int oldPos, int newPos);
192     /** This changes the order of effects in MLT, inverting effects from oldPos and newPos, also updating the kdenlive_ix value */
193     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
194     /** This changes the state of a track, enabling / disabling audio and video */
195     void mltChangeTrackState(int track, bool mute, bool blind);
196     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
197     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
198     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
199     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
200     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
201     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
202     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
203     void mltDeleteTransparency(int pos, int track, int id);
204     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
205     void mltInsertTrack(int ix, bool videoTrack);
206     void mltDeleteTrack(int ix);
207     bool mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
208
209     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
210     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
211     to the clip and 0.6 is the speed in percents. The newly created producer will have it's
212     "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
213     in the ClipManager list and speed is the current speed */
214     int mltChangeClipSpeed(ItemInfo info, ItemInfo speedIndependantInfo, double speed, double oldspeed, int strobe, Mlt::Producer *prod);
215
216     const QList <Mlt::Producer *> producersList();
217     void updatePreviewSettings();
218     void setDropFrames(bool show);
219     QString updateSceneListFps(double current_fps, double new_fps, QString scene);
220 #ifdef Q_WS_MAC
221     void showFrame(Mlt::Frame&);
222 #endif
223
224 private:   // Private attributes & methods
225     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
226     QString m_name;
227     Mlt::Consumer * m_mltConsumer;
228     Mlt::Producer * m_mltProducer;
229     Mlt::Profile *m_mltProfile;
230     double m_framePosition;
231     double m_fps;
232
233     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
234     bool m_isZoneMode;
235     bool m_isLoopMode;
236     GenTime m_loopStart;
237     int m_originalOut;
238
239     /** true when monitor is in split view (several tracks at the same time) */
240     bool m_isSplitView;
241
242     Mlt::Producer *m_blackClip;
243     QString m_activeProfile;
244
245     QTimer *m_osdTimer;
246
247     /** A human-readable description of this renderer. */
248     int m_winid;
249
250 #ifdef Q_WS_MAC
251     VideoGLWidget *m_glWidget;
252 #endif
253
254     /** Sets the description of this renderer to desc. */
255     void closeMlt();
256     void mltCheckLength(Mlt::Tractor *tractor);
257     void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
258     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
259     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
260     void buildConsumer(const QString profileName);
261     void resetZoneMode();
262     void fillSlowMotionProducers();
263
264 private slots:  // Private slots
265     /** refresh monitor display */
266     void refresh();
267     void slotOsdTimeout();
268     int connectPlaylist();
269     //void initSceneList();
270
271 signals:   // Signals
272     /** emitted when the renderer recieves a reply to a getFileProperties request. */
273     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
274
275     /** emitted when the renderer recieves a reply to a getImage request. */
276     void replyGetImage(const QString &, const QPixmap &);
277
278     /** Emitted when the renderer stops, either playing or rendering. */
279     void stopped();
280     /** Emitted when the renderer starts playing. */
281     void playing(double);
282     /** Emitted when the renderer is rendering. */
283     void rendering(const GenTime &);
284     /** Emitted when rendering has finished */
285     void renderFinished();
286     /** Emitted when the current seek position has been changed by the renderer. */
287 //    void positionChanged(const GenTime &);
288     /** Emitted when an error occurs within this renderer. */
289     void error(const QString &, const QString &);
290     void durationChanged(int);
291     void rendererPosition(int);
292     void rendererStopped(int);
293     void removeInvalidClip(const QString &, bool replaceProducer);
294     void refreshDocumentProducers();
295     void blockMonitors();
296     /** Used on OS X - emitted when a frame's image is to be shown. */
297     void showImageSignal(QImage);
298
299 public slots:  // Public slots
300     /** Start Consumer */
301     void start();
302     /** Stop Consumer */
303     void stop();
304     int getLength();
305     /** If the file is readable by mlt, return true, otherwise false */
306     bool isValid(KUrl url);
307
308     /** Wraps the VEML command of the same name. Requests the file properties
309     for the specified url from the renderer. Upon return, the result will be emitted
310     via replyGetFileProperties(). */
311     void getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer = true);
312
313     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
314     static char *decodedString(QString str);
315     void mltSavePlaylist();
316     void slotSplitView(bool doit);
317 };
318
319 #endif