]> git.sesse.net Git - kdenlive/blob - src/renderer.h
cleanup and make play/loop section work
[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 #include <QWidget>
26
27 #include <kurl.h>
28
29 #include "gentime.h"
30 #include "definitions.h"
31
32 /**Render encapsulates the client side of the interface to a renderer.
33 From Kdenlive's point of view, you treat the Render object as the
34 renderer, and simply use it as if it was local. Calls are asyncrhonous -
35 you send a call out, and then recieve the return value through the
36 relevant signal that get's emitted once the call completes.
37   *@author Jason Wood
38   */
39
40 class Render;
41 //class EffectParamDesc;
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     QString sceneList();
96     void 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     /** 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     /** Returns the name of the renderer. */
118     const QString & rendererName() const;
119
120     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
121     not playing anything. */
122     double playSpeed();
123     /** Returns the current seek position of the renderer. */
124     GenTime seekPosition() const;
125
126     void emitFrameNumber(double position);
127     void emitConsumerStopped();
128
129     /** Gives the aspect ratio of the consumer */
130     double consumerRatio() const;
131
132     void askForRefresh();
133     void doRefresh();
134
135     /** Save current producer frame as image */
136     void exportCurrentFrame(KUrl url, bool notify);
137
138     /** Turn on or off on screen display */
139     void refreshDisplay();
140     int resetProfile();
141     const double fps() const;
142     const int renderWidth() const;
143     const int renderHeight() const;
144     /** get display aspect ratio */
145     const double dar() const;
146
147     /** Playlist manipulation */
148     void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
149     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
150     void mltCutClip(int track, GenTime position);
151     bool mltResizeClipEnd(ItemInfo info, GenTime clipDuration);
152     bool mltResizeClipStart(ItemInfo info, GenTime diff);
153     bool mltMoveClip(int startTrack, int endTrack, GenTime pos, GenTime moveStart);
154     bool mltMoveClip(int startTrack, int endTrack, int pos, int moveStart);
155     bool mltRemoveClip(int track, GenTime position);
156     bool mltRemoveEffect(int track, GenTime position, QString index, bool doRefresh = true);
157     bool mltAddEffect(int track, GenTime position, QHash <QString, QString> args, bool doRefresh = true);
158     bool mltEditEffect(int track, GenTime position, QHash <QString, QString> args);
159     void mltMoveEffect(int track, GenTime position, int oldPos, int newPos);
160     void mltChangeTrackState(int track, bool mute, bool blind);
161     void mltMoveTransition(QString type, int startTrack,  int newTrack, int newTransitionTrack, GenTime oldIn, GenTime oldOut, GenTime newIn, GenTime newOut);
162     void mltAddTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
163     void mltDeleteTransition(QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml, bool refresh = true);
164     void mltUpdateTransition(QString oldTag, QString tag, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
165     void mltUpdateTransitionParams(QString type, int a_track, int b_track, GenTime in, GenTime out, QDomElement xml);
166     void mltAddClipTransparency(ItemInfo info, int transitiontrack, int id);
167     void mltMoveTransparency(int startTime, int endTime, int startTrack, int endTrack, int id);
168     void mltDeleteTransparency(int pos, int track, int id);
169     void mltResizeTransparency(int oldStart, int newStart, int newEnd, int track, int id);
170
171     /** Change speed of a clip in playlist. To do this, we create a new "framebuffer" producer.
172     This new producer must have its "resource" param set to: video.mpg?0.6 where video.mpg is the path
173     to the clip and 0.6 is the speed in percents. The newly created producer will have it's
174     "id" parameter set to: "slowmotion:parentid:speed", where parentid is the id of the original clip
175     in the ClipManager list and speed is the current speed */
176     int mltChangeClipSpeed(ItemInfo info, double speed, Mlt::Producer *prod);
177
178 private:   // Private attributes & methods
179     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
180     QString m_name;
181     Mlt::Consumer * m_mltConsumer;
182     Mlt::Producer * m_mltProducer;
183     Mlt::Producer *m_mltTextProducer;
184     Mlt::Filter *m_osdInfo;
185     Mlt::Profile *m_mltProfile;
186     double m_framePosition;
187     double m_fps;
188
189     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
190     bool m_isZoneMode;
191     bool m_isLoopMode;
192     GenTime m_loopStart;
193
194     /** true when monitor is in split view (several tracks at the same time) */
195     bool m_isSplitView;
196
197     Mlt::Producer *m_blackClip;
198     /** Holds the path to on screen display profile */
199     QString m_osdProfile;
200
201     QTimer *refreshTimer;
202     QTimer *osdTimer;
203     KUrl m_exportedFile;
204
205     /** A human-readable description of this renderer. */
206     int m_winid;
207     int m_externalwinid;
208
209     /** Sets the description of this renderer to desc. */
210     void closeMlt();
211     void mltCheckLength(bool reload = true);
212     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
213     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
214     void buildConsumer();
215     void resetZoneMode();
216
217 private slots:  // Private slots
218     /** refresh monitor display */
219     void refresh();
220     void slotOsdTimeout();
221     void connectPlaylist();
222     //void initSceneList();
223
224 signals:   // Signals
225     /** emitted when the renderer recieves a reply to a getFileProperties request. */
226     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &);
227
228     /** emitted when the renderer recieves a reply to a getImage request. */
229     void replyGetImage(const QString & , int, const QPixmap &, int, int);
230     void replyGetImage(const QString &, const QPixmap &, int, int);
231
232     /** Emitted when the renderer stops, either playing or rendering. */
233     void stopped();
234     /** Emitted when the renderer starts playing. */
235     void playing(double);
236     /** Emitted when the renderer is rendering. */
237     void rendering(const GenTime &);
238     /** Emitted when rendering has finished */
239     void renderFinished();
240     /** Emitted when the current seek position has been changed by the renderer. */
241 //    void positionChanged(const GenTime &);
242     /** Emitted when an error occurs within this renderer. */
243     void error(const QString &, const QString &);
244     void durationChanged(int);
245     void rendererPosition(int);
246     void rendererStopped(int);
247     void removeInvalidClip(const QString &);
248
249 public slots:  // Public slots
250     /** Start Consumer */
251     void start();
252     /** Stop Consumer */
253     void stop();
254     void clear();
255     int getLength();
256     /** If the file is readable by mlt, return true, otherwise false */
257     bool isValid(KUrl url);
258
259     /** Wraps the VEML command of the same name. Requests the file properties
260     for the specified url from the renderer. Upon return, the result will be emitted
261     via replyGetFileProperties(). */
262     void getFileProperties(const QDomElement &xml, const QString &clipId);
263
264     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
265     static char *decodedString(QString str);
266     void mltSavePlaylist();
267     void slotSplitView(bool doit);
268 };
269
270 #endif