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