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