]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Make Mlt error message more visible (they don't close automatically)
[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
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.
38   *@author Jason Wood
39   */
40
41 class Render;
42
43 class QTimer;
44 class QPixmap;
45
46 namespace Mlt
47 {
48 class Consumer;
49 class Playlist;
50 class Tractor;
51 class Frame;
52 class Producer;
53 class Filter;
54 class Profile;
55 class Service;
56 };
57
58
59 class MltErrorEvent : public QEvent
60 {
61 public:
62     MltErrorEvent(QString message) : QEvent(QEvent::User), m_message(message) {}
63     QString message() const {
64         return m_message;
65     }
66
67 private:
68     QString m_message;
69 };
70
71
72 class Render: public QObject
73 {
74 Q_OBJECT public:
75
76     enum FailStates { OK = 0,
77                       APP_NOEXIST
78                     };
79
80     Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0);
81     ~Render();
82
83     /** Seeks the renderer clip to the given time. */
84     void seek(GenTime time);
85     void seekToFrame(int pos);
86     int m_isBlocked;
87
88     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
89     QPixmap getImageThumbnail(KUrl url, int width, int height);
90
91     /** Return thumbnail for color clip */
92     //void getImage(int id, QString color, QPoint size);
93
94     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
95
96     /** Return thumbnail for image clip */
97     //void getImage(KUrl url, QPoint size);
98
99     /** Requests a particular frame from the given file.
100      *
101      * The pixmap will be returned by emitting the replyGetImage() signal.
102      * */
103     //void getImage(KUrl url, int frame, QPoint size);
104
105
106     /** Wraps the VEML command of the same name. Sets the current scene list to
107     be list. */
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());
113
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);
119     void switchPlay();
120     void pause();
121     /** stop playing */
122     void stop(const GenTime & startTime);
123     void setVolume(double volume);
124
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);
133
134     void saveZone(KUrl url, QString desc, QPoint zone);
135
136     /** Returns the name of the renderer. */
137     const QString & rendererName() const;
138
139     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
140     not playing anything. */
141     double playSpeed();
142     /** Returns the current seek position of the renderer. */
143     GenTime seekPosition() const;
144
145     void emitFrameNumber(double position);
146     void emitConsumerStopped();
147
148     /** Gives the aspect ratio of the consumer */
149     double consumerRatio() const;
150
151     void askForRefresh();
152     void doRefresh();
153
154     /** Save current producer frame as image */
155     void exportCurrentFrame(KUrl url, bool notify);
156
157     /** Turn on or off on screen display */
158     void refreshDisplay();
159     int resetProfile();
160     double fps() const;
161     int renderWidth() const;
162     int renderHeight() const;
163     /** get display aspect ratio */
164     double dar() const;
165
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);
196
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);
203
204     QList <Mlt::Producer *> producersList();
205     void updatePreviewSettings();
206     void setDropFrames(bool show);
207
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... */
210     QString m_name;
211     Mlt::Consumer * m_mltConsumer;
212     Mlt::Producer * m_mltProducer;
213     Mlt::Profile *m_mltProfile;
214     double m_framePosition;
215     double m_fps;
216
217     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
218     bool m_isZoneMode;
219     bool m_isLoopMode;
220     GenTime m_loopStart;
221     int m_originalOut;
222
223     /** true when monitor is in split view (several tracks at the same time) */
224     bool m_isSplitView;
225
226     Mlt::Producer *m_blackClip;
227     QString m_activeProfile;
228
229     QTimer *m_refreshTimer;
230     QTimer *m_osdTimer;
231
232     /** A human-readable description of this renderer. */
233     int m_winid;
234
235     /** Sets the description of this renderer to desc. */
236     void closeMlt();
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();
244
245 private slots:  // Private slots
246     /** refresh monitor display */
247     void refresh();
248     void slotOsdTimeout();
249     int connectPlaylist();
250     //void initSceneList();
251
252 signals:   // Signals
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);
255
256     /** emitted when the renderer recieves a reply to a getImage request. */
257     void replyGetImage(const QString &, const QPixmap &);
258
259     /** Emitted when the renderer stops, either playing or rendering. */
260     void stopped();
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();
277
278 public slots:  // Public slots
279     /** Start Consumer */
280     void start();
281     /** Stop Consumer */
282     void stop();
283     void clear();
284     int getLength();
285     /** If the file is readable by mlt, return true, otherwise false */
286     bool isValid(KUrl url);
287
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);
292
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);
297 };
298
299 #endif