1 /***************************************************************************
2 krender.h - description
4 begin : Fri Nov 22 2002
5 copyright : (C) 2002 by Jason Wood
6 email : jasonwood@blueyonder.co.uk
7 ***************************************************************************/
9 /***************************************************************************
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. *
16 ***************************************************************************/
22 #include "definitions.h"
33 /**Render encapsulates the client side of the interface to a renderer.
34 From Kdenlive's point of view, you treat the Render object as the
35 renderer, and simply use it as if it was local. Calls are asyncrhonous -
36 you send a call out, and then receive the return value through the
37 relevant signal that get's emitted once the call completes.
59 class MltErrorEvent : public QEvent
62 MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
63 QString message() const {
72 class Render: public QObject
76 enum FailStates { OK = 0,
80 Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0);
83 /** Seeks the renderer clip to the given time. */
84 void seek(GenTime time);
85 void seekToFrame(int pos);
86 void seekToFrameDiff(int diff);
89 //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
90 QPixmap getImageThumbnail(KUrl url, int width, int height);
92 /** Return thumbnail for color clip */
93 //void getImage(int id, QString color, QPoint size);
95 // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
97 /** Return thumbnail for image clip */
98 //void getImage(KUrl url, QPoint size);
100 /** Requests a particular frame from the given file.
102 * The pixmap will be returned by emitting the replyGetImage() signal.
104 //void getImage(KUrl url, int frame, QPoint size);
107 /** Wraps the VEML command of the same name. Sets the current scene list to
109 int setSceneList(QDomDocument list, int position = 0);
110 int setSceneList(QString playlist, int position = 0);
111 int setProducer(Mlt::Producer *producer, int position);
112 const QString sceneList();
113 bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
115 /** Wraps the VEML command of the same name. Tells the renderer to
116 play the current scene at the speed specified, relative to normal
117 playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
118 backwards. Does not specify start/stop times for playback.*/
119 void play(double speed);
123 void stop(const GenTime & startTime);
124 void setVolume(double volume);
126 QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
127 /** Wraps the VEML command of the same name. Tells the renderer to
128 play the current scene at the speed specified, relative to normal
129 playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
130 backwards. Specifes the start/stop times for playback.*/
131 void play(const GenTime & startTime);
132 void playZone(const GenTime & startTime, const GenTime & stopTime);
133 void loopZone(const GenTime & startTime, const GenTime & stopTime);
135 void saveZone(KUrl url, QString desc, QPoint zone);
137 /** Returns the name of the renderer. */
138 const QString & rendererName() const;
140 /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
141 not playing anything. */
143 /** Returns the current seek position of the renderer. */
144 GenTime seekPosition() const;
145 int seekFramePosition() const;
147 void emitFrameNumber(double position);
148 void emitConsumerStopped();
150 /** Gives the aspect ratio of the consumer */
151 double consumerRatio() const;
153 void askForRefresh();
156 /** Save current producer frame as image */
157 void exportCurrentFrame(KUrl url, bool notify);
159 /** Turn on or off on screen display */
160 void refreshDisplay();
163 int renderWidth() const;
164 int renderHeight() const;
165 /** get display aspect ratio */
168 /** Playlist manipulation */
169 void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
170 void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
171 void mltCutClip(int track, GenTime position);
172 void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
173 int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
174 int mltTrackDuration(int track);
175 bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
176 bool mltResizeClipStart(ItemInfo info, GenTime diff);
177 bool mltResizeClipCrop(ItemInfo info, GenTime diff);
178 bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
179 bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
180 bool mltRemoveClip(int track, GenTime position);
181 bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
182 bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
183 bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
184 void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
185 void mltChangeTrackState(int track, bool mute, bool blind);
186 bool mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
187 bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
188 void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
189 void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
190 void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
191 void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
192 void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
193 void mltDeleteTransparency(int pos, int track, int id);
194 void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
195 void mltInsertTrack(int ix, bool videoTrack);
196 void mltDeleteTrack(int ix);
197 void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
199 /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
200 This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
201 to the clip and 0.6 is the speed in percents. The newly created producer will have it's
202 "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
203 in the ClipManager list and speed is the current speed */
204 int mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod);
206 QList <Mlt::Producer *> producersList();
207 void updatePreviewSettings();
208 void setDropFrames(bool show);
210 private: // Private attributes & methods
211 /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
213 Mlt::Consumer * m_mltConsumer;
214 Mlt::Producer * m_mltProducer;
215 Mlt::Profile *m_mltProfile;
216 double m_framePosition;
219 /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
225 /** true when monitor is in split view (several tracks at the same time) */
228 Mlt::Producer *m_blackClip;
229 QString m_activeProfile;
231 QTimer *m_refreshTimer;
234 /** A human-readable description of this renderer. */
237 /** Sets the description of this renderer to desc. */
239 void mltCheckLength();
240 void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
241 QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
242 QMap<QString, Mlt::Producer *> m_slowmotionProducers;
243 void buildConsumer();
244 void resetZoneMode();
245 void fillSlowMotionProducers();
247 private slots: // Private slots
248 /** refresh monitor display */
250 void slotOsdTimeout();
251 int connectPlaylist();
252 //void initSceneList();
255 /** emitted when the renderer recieves a reply to a getFileProperties request. */
256 void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
258 /** emitted when the renderer recieves a reply to a getImage request. */
259 void replyGetImage(const QString &, const QPixmap &);
261 /** Emitted when the renderer stops, either playing or rendering. */
263 /** Emitted when the renderer starts playing. */
264 void playing(double);
265 /** Emitted when the renderer is rendering. */
266 void rendering(const GenTime &);
267 /** Emitted when rendering has finished */
268 void renderFinished();
269 /** Emitted when the current seek position has been changed by the renderer. */
270 // void positionChanged(const GenTime &);
271 /** Emitted when an error occurs within this renderer. */
272 void error(const QString &, const QString &);
273 void durationChanged(int);
274 void rendererPosition(int);
275 void rendererStopped(int);
276 void removeInvalidClip(const QString &, bool replaceProducer);
277 void refreshDocumentProducers();
278 void blockMonitors();
280 public slots: // Public slots
281 /** Start Consumer */
287 /** If the file is readable by mlt, return true, otherwise false */
288 bool isValid(KUrl url);
290 /** Wraps the VEML command of the same name. Requests the file properties
291 for the specified url from the renderer. Upon return, the result will be emitted
292 via replyGetFileProperties(). */
293 void getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer = true);
295 void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
296 static char *decodedString(QString str);
297 void mltSavePlaylist();
298 void slotSplitView(bool doit);