]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Make sure there is no write error when saving a file:
[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 <qdom.h>
22 #include <qstring.h>
23 #include <qmap.h>
24 #include <QList>
25
26 #include <kurl.h>
27
28 #include "gentime.h"
29 #include "definitions.h"
30
31 /**Render encapsulates the client side of the interface to a renderer.
32 From Kdenlive's point of view, you treat the Render object as the
33 renderer, and simply use it as if it was local. Calls are asyncrhonous -
34 you send a call out, and then receive the return value through the
35 relevant signal that get's emitted once the call completes.
36   *@author Jason Wood
37   */
38
39 class Render;
40
41 class QTimer;
42 class QPixmap;
43
44 namespace Mlt {
45 class Consumer;
46 class Playlist;
47 class Tractor;
48 class Frame;
49 class Producer;
50 class Filter;
51 class Profile;
52 class Multitrack;
53 };
54
55
56
57 class Render: public QObject {
58 Q_OBJECT public:
59
60     enum FailStates { OK = 0,
61                       APP_NOEXIST
62                     };
63
64     Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0);
65     ~Render();
66
67     /** Seeks the renderer clip to the given time. */
68     void seek(GenTime time);
69     void seekToFrame(int pos);
70     bool m_isBlocked;
71
72     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
73     QPixmap getImageThumbnail(KUrl url, int width, int height);
74
75     /** Return thumbnail for color clip */
76     //void getImage(int id, QString color, QPoint size);
77
78     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
79
80     /** Return thumbnail for image clip */
81     //void getImage(KUrl url, QPoint size);
82
83     /** Requests a particular frame from the given file.
84      *
85      * The pixmap will be returned by emitting the replyGetImage() signal.
86      * */
87     //void getImage(KUrl url, int frame, QPoint size);
88
89
90     /** Wraps the VEML command of the same name. Sets the current scene list to
91     be list. */
92     void setSceneList(QDomDocument list, int position = 0);
93     void setSceneList(QString playlist, int position = 0);
94     void setProducer(Mlt::Producer *producer, int position);
95     const QString sceneList();
96     bool saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
97
98     /** Wraps the VEML command of the same name. Tells the renderer to
99     play the current scene at the speed specified, relative to normal
100     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
101     backwards. Does not specify start/stop times for playback.*/
102     void play(double speed);
103     void switchPlay();
104     void pause();
105     /** stop playing */
106     void stop(const GenTime & startTime);
107     void setVolume(double volume);
108
109     QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
110     /** Wraps the VEML command of the same name. Tells the renderer to
111     play the current scene at the speed specified, relative to normal
112     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
113     backwards. Specifes the start/stop times for playback.*/
114     void play(const GenTime & startTime);
115     void playZone(const GenTime & startTime, const GenTime & stopTime);
116     void loopZone(const GenTime & startTime, const GenTime & stopTime);
117
118     void saveZone(KUrl url, QString desc, QPoint zone);
119
120     /** Returns the name of the renderer. */
121     const QString & rendererName() const;
122
123     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
124     not playing anything. */
125     double playSpeed();
126     /** Returns the current seek position of the renderer. */
127     GenTime seekPosition() const;
128
129     void emitFrameNumber(double position);
130     void emitConsumerStopped();
131
132     /** Gives the aspect ratio of the consumer */
133     double consumerRatio() const;
134
135     void askForRefresh();
136     void doRefresh();
137
138     /** Save current producer frame as image */
139     void exportCurrentFrame(KUrl url, bool notify);
140
141     /** Turn on or off on screen display */
142     void refreshDisplay();
143     int resetProfile();
144     double fps() const;
145     int renderWidth() const;
146     int renderHeight() const;
147     /** get display aspect ratio */
148     double dar() const;
149
150     /** Playlist manipulation */
151     void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
152     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
153     void mltCutClip(int track, GenTime position);
154     void mltInsertSpace(QMap <int, int> trackClipStartList, QMap <int, int> trackTransitionStartList, int track, const GenTime duration, const GenTime timeOffset);
155     int mltGetSpaceLength(const GenTime pos, int track, bool fromBlankStart);
156     int mltTrackDuration(int track);
157     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
158     bool mltResizeClipStart(ItemInfo info, GenTime diff);
159     bool mltResizeClipCrop(ItemInfo info, GenTime diff);
160     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart, Mlt::Producer *prod);
161     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart, Mlt::Producer *prod);
162     bool mltRemoveClip(int track, GenTime position);
163     bool mltRemoveEffect(int track, GenTime position, QString index, bool updateIndex, bool doRefresh = true);
164     bool mltAddEffect(int track, GenTime position, EffectsParameterList params, bool doRefresh = true);
165     bool mltEditEffect(int track, GenTime position, EffectsParameterList params);
166     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
167     void mltChangeTrackState(int track, bool mute, bool blind);
168     bool mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
169     bool mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
170     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
171     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
172     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
173     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
174     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
175     void mltDeleteTransparency(int pos, int track, int id);
176     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
177     void mltInsertTrack(int ix, bool videoTrack);
178     void mltDeleteTrack(int ix);
179     void mltUpdateClipProducer(int track, int pos, Mlt::Producer *prod);
180
181     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
182     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
183     to the clip and 0.6 is the speed in percents. The newly created producer will have it's
184     "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
185     in the ClipManager list and speed is the current speed */
186     int mltChangeClipSpeed(ItemInfo info, double speed, double oldspeed, Mlt::Producer *prod);
187
188     QList <Mlt::Producer *> producersList();
189     void updatePreviewSettings();
190
191 private:   // Private attributes & methods
192     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
193     QString m_name;
194     Mlt::Consumer * m_mltConsumer;
195     Mlt::Producer * m_mltProducer;
196     Mlt::Producer *m_mltTextProducer;
197     Mlt::Filter *m_osdInfo;
198     Mlt::Profile *m_mltProfile;
199     double m_framePosition;
200     double m_fps;
201
202     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
203     bool m_isZoneMode;
204     bool m_isLoopMode;
205     GenTime m_loopStart;
206     int m_originalOut;
207
208     /** true when monitor is in split view (several tracks at the same time) */
209     bool m_isSplitView;
210
211     Mlt::Producer *m_blackClip;
212     /** Holds the path to on screen display profile */
213     QString m_osdProfile;
214     QString m_activeProfile;
215
216     QTimer *refreshTimer;
217     QTimer *osdTimer;
218     KUrl m_exportedFile;
219
220     /** A human-readable description of this renderer. */
221     int m_winid;
222     int m_externalwinid;
223
224     /** Sets the description of this renderer to desc. */
225     void closeMlt();
226     void mltCheckLength();
227     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
228     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
229     void buildConsumer();
230     void resetZoneMode();
231     void fillSlowMotionProducers();
232
233 private slots:  // Private slots
234     /** refresh monitor display */
235     void refresh();
236     void slotOsdTimeout();
237     void connectPlaylist();
238     //void initSceneList();
239
240 signals:   // Signals
241     /** emitted when the renderer recieves a reply to a getFileProperties request. */
242     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &, bool);
243
244     /** emitted when the renderer recieves a reply to a getImage request. */
245     void replyGetImage(const QString &, const QPixmap &);
246
247     /** Emitted when the renderer stops, either playing or rendering. */
248     void stopped();
249     /** Emitted when the renderer starts playing. */
250     void playing(double);
251     /** Emitted when the renderer is rendering. */
252     void rendering(const GenTime &);
253     /** Emitted when rendering has finished */
254     void renderFinished();
255     /** Emitted when the current seek position has been changed by the renderer. */
256 //    void positionChanged(const GenTime &);
257     /** Emitted when an error occurs within this renderer. */
258     void error(const QString &, const QString &);
259     void durationChanged(int);
260     void rendererPosition(int);
261     void rendererStopped(int);
262     void removeInvalidClip(const QString &);
263
264 public slots:  // Public slots
265     /** Start Consumer */
266     void start();
267     /** Stop Consumer */
268     void stop();
269     void clear();
270     int getLength();
271     /** If the file is readable by mlt, return true, otherwise false */
272     bool isValid(KUrl url);
273
274     /** Wraps the VEML command of the same name. Requests the file properties
275     for the specified url from the renderer. Upon return, the result will be emitted
276     via replyGetFileProperties(). */
277     void getFileProperties(const QDomElement &xml, const QString &clipId, bool replaceProducer = true);
278
279     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
280     static char *decodedString(QString str);
281     void mltSavePlaylist();
282     void slotSplitView(bool doit);
283 };
284
285 #endif