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);
88 //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
89 QPixmap getImageThumbnail(KUrl url, int width, int height);
91 /** Return thumbnail for color clip */
92 //void getImage(int id, QString color, QPoint size);
94 // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
96 /** Return thumbnail for image clip */
97 //void getImage(KUrl url, QPoint size);
99 /** Requests a particular frame from the given file.
101 * The pixmap will be returned by emitting the replyGetImage() signal.
103 //void getImage(KUrl url, int frame, QPoint size);
106 /** Wraps the VEML command of the same name. Sets the current scene list to
108 int setSceneList(QDomDocument list, int position = 0);
109 int setSceneList(QString playlist, int position = 0);
110 int setProducer(Mlt::Producer *producer, int position);
111 const QString sceneList();
112 bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
114 /** Wraps the VEML command of the same name. Tells the renderer to
115 play the current scene at the speed specified, relative to normal
116 playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
117 backwards. Does not specify start/stop times for playback.*/
118 void play(double speed);
122 void stop(const GenTime & startTime);
123 void setVolume(double volume);
125 QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
126 /** Wraps the VEML command of the same name. Tells the renderer to
127 play the current scene at the speed specified, relative to normal
128 playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
129 backwards. Specifes the start/stop times for playback.*/
130 void play(const GenTime & startTime);
131 void playZone(const GenTime & startTime, const GenTime & stopTime);
132 void loopZone(const GenTime & startTime, const GenTime & stopTime);
134 void saveZone(KUrl url, QString desc, QPoint zone);
136 /** Returns the name of the renderer. */
137 const QString & rendererName() const;
139 /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
140 not playing anything. */
142 /** Returns the current seek position of the renderer. */
143 GenTime seekPosition() const;
145 void emitFrameNumber(double position);
146 void emitConsumerStopped();
148 /** Gives the aspect ratio of the consumer */
149 double consumerRatio() const;
151 void askForRefresh();
154 /** Save current producer frame as image */
155 void exportCurrentFrame(KUrl url, bool notify);
157 /** Turn on or off on screen display */
158 void refreshDisplay();
161 int renderWidth() const;
162 int renderHeight() const;
163 /** get display aspect ratio */
166 /** Playlist manipulation */
167 void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
168 void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
169 void mltCutClip(int track, GenTime position);
170 void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
171 int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
172 int mltTrackDuration(int track);
173 bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
174 bool mltResizeClipStart(ItemInfo info, GenTime diff);
175 bool mltResizeClipCrop(ItemInfo info, GenTime diff);
176 bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
177 bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
178 bool mltRemoveClip(int track, GenTime position);
179 bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
180 bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
181 bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
182 void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
183 void mltChangeTrackState(int track, bool mute, bool blind);
184 bool mltMoveTransition(QString type, int startTrack, int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
185 bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
186 void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
187 void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
188 void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
189 void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
190 void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
191 void mltDeleteTransparency(int pos, int track, int id);
192 void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
193 void mltInsertTrack(int ix, bool videoTrack);
194 void mltDeleteTrack(int ix);
195 void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
197 /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
198 This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
199 to the clip and 0.6 is the speed in percents. The newly created producer will have it's
200 "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
201 in the ClipManager list and speed is the current speed */
202 int mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod);
204 QList <Mlt::Producer *> producersList();
205 void updatePreviewSettings();
206 void setDropFrames(bool show);
208 private: // Private attributes & methods
209 /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
211 Mlt::Consumer * m_mltConsumer;
212 Mlt::Producer * m_mltProducer;
213 Mlt::Profile *m_mltProfile;
214 double m_framePosition;
217 /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
223 /** true when monitor is in split view (several tracks at the same time) */
226 Mlt::Producer *m_blackClip;
227 QString m_activeProfile;
229 QTimer *m_refreshTimer;
232 /** A human-readable description of this renderer. */
235 /** Sets the description of this renderer to desc. */
237 void mltCheckLength();
238 void mltPasteEffects(Mlt::Producer *source, Mlt::Producer *dest);
239 QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
240 QMap<QString, Mlt::Producer *> m_slowmotionProducers;
241 void buildConsumer();
242 void resetZoneMode();
243 void fillSlowMotionProducers();
245 private slots: // Private slots
246 /** refresh monitor display */
248 void slotOsdTimeout();
249 int connectPlaylist();
250 //void initSceneList();
253 /** emitted when the renderer recieves a reply to a getFileProperties request. */
254 void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
256 /** emitted when the renderer recieves a reply to a getImage request. */
257 void replyGetImage(const QString &, const QPixmap &);
259 /** Emitted when the renderer stops, either playing or rendering. */
261 /** Emitted when the renderer starts playing. */
262 void playing(double);
263 /** Emitted when the renderer is rendering. */
264 void rendering(const GenTime &);
265 /** Emitted when rendering has finished */
266 void renderFinished();
267 /** Emitted when the current seek position has been changed by the renderer. */
268 // void positionChanged(const GenTime &);
269 /** Emitted when an error occurs within this renderer. */
270 void error(const QString &, const QString &);
271 void durationChanged(int);
272 void rendererPosition(int);
273 void rendererStopped(int);
274 void removeInvalidClip(const QString &, bool replaceProducer);
275 void refreshDocumentProducers();
276 void blockMonitors();
278 public slots: // Public slots
279 /** Start Consumer */
285 /** If the file is readable by mlt, return true, otherwise false */
286 bool isValid(KUrl url);
288 /** Wraps the VEML command of the same name. Requests the file properties
289 for the specified url from the renderer. Upon return, the result will be emitted
290 via replyGetFileProperties(). */
291 void getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer = true);
293 void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
294 static char *decodedString(QString str);
295 void mltSavePlaylist();
296 void slotSplitView(bool doit);