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