]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Fix broken loading of documents with several clips that are not in timeline
[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     void seekToFrameDiff(int diff);
87     int m_isBlocked;
88
89     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
90     QPixmap getImageThumbnail(KUrl url, int width, int height);
91
92     /** Return thumbnail for color clip */
93     //void getImage(int id, QString color, QPoint size);
94
95     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
96
97     /** Return thumbnail for image clip */
98     //void getImage(KUrl url, QPoint size);
99
100     /** Requests a particular frame from the given file.
101      *
102      * The pixmap will be returned by emitting the replyGetImage() signal.
103      * */
104     //void getImage(KUrl url, int frame, QPoint size);
105
106
107     /** Wraps the VEML command of the same name. Sets the current scene list to
108     be list. */
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());
114
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);
120     void switchPlay();
121     void pause();
122     /** stop playing */
123     void stop(const GenTime & startTime);
124     void setVolume(double volume);
125
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);
134
135     void saveZone(KUrl url, QString desc, QPoint zone);
136
137     /** Returns the name of the renderer. */
138     const QString & rendererName() const;
139
140     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
141     not playing anything. */
142     double playSpeed();
143     /** Returns the current seek position of the renderer. */
144     GenTime seekPosition() const;
145     int seekFramePosition() const;
146
147     void emitFrameNumber(double position);
148     void emitConsumerStopped();
149
150     /** Gives the aspect ratio of the consumer */
151     double consumerRatio() const;
152
153     void doRefresh();
154
155     /** Save current producer frame as image */
156     void exportCurrentFrame(KUrl url, bool notify);
157
158     /** Turn on or off on screen display */
159     void refreshDisplay();
160     int resetProfile();
161     double fps() const;
162     int renderWidth() const;
163     int renderHeight() const;
164     /** get display aspect ratio */
165     double dar() const;
166
167     /** Playlist manipulation */
168     int mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
169     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
170     void mltCutClip(int track, GenTime position);
171     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
172     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
173     int mltTrackDuration(int track);
174     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
175     bool mltResizeClipStart(ItemInfo info, GenTime diff);
176     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
177     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
178     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
179     bool mltRemoveClip(int track, GenTime position);
180     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
181     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
182     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
183     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
184     void mltChangeTrackState(int track, bool mute, bool blind);
185     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
186     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
187     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
188     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
189     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
190     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
191     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
192     void mltDeleteTransparency(int pos, int track, int id);
193     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
194     void mltInsertTrack(int ix, bool videoTrack);
195     void mltDeleteTrack(int ix);
196     void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
197
198     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
199     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
200     to the clip and 0.6 is the speed in percents. The newly created producer will have it's
201     "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
202     in the ClipManager list and speed is the current speed */
203     int mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, int strobe, Mlt::Producer *prod);
204
205     QList <Mlt::Producer *> producersList();
206     void updatePreviewSettings();
207     void setDropFrames(bool show);
208
209 private:   // Private attributes & methods
210     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
211     QString m_name;
212     Mlt::Consumer * m_mltConsumer;
213     Mlt::Producer * m_mltProducer;
214     Mlt::Profile *m_mltProfile;
215     double m_framePosition;
216     double m_fps;
217
218     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
219     bool m_isZoneMode;
220     bool m_isLoopMode;
221     GenTime m_loopStart;
222     int m_originalOut;
223
224     /** true when monitor is in split view (several tracks at the same time) */
225     bool m_isSplitView;
226
227     Mlt::Producer *m_blackClip;
228     QString m_activeProfile;
229
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(Mlt::Tractor *tractor);
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     int getLength();
284     /** If the file is readable by mlt, return true, otherwise false */
285     bool isValid(KUrl url);
286
287     /** Wraps the VEML command of the same name. Requests the file properties
288     for the specified url from the renderer. Upon return, the result will be emitted
289     via replyGetFileProperties(). */
290     void getFileProperties(const QDomElement xml, const QString &clipId, bool replaceProducer = true);
291
292     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
293     static char *decodedString(QString str);
294     void mltSavePlaylist();
295     void slotSplitView(bool doit);
296 };
297
298 #endif