]> git.sesse.net Git - kdenlive/blob - src/renderer.h
Add recursive search when opening a document with missing clip, heavily based on...
[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 <QDir>
26 //#include <QWidget>
27
28 #include <kurl.h>
29
30 #include "gentime.h"
31 #include "definitions.h"
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 recieve 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 //class EffectParamDesc;
43 class QPixmap;
44
45 namespace Mlt {
46 class Consumer;
47 class Playlist;
48 class Tractor;
49 class Frame;
50 class Producer;
51 class Filter;
52 class Profile;
53 class Multitrack;
54 };
55
56
57
58 class Render: public QObject {
59 Q_OBJECT public:
60
61     enum FailStates { OK = 0,
62                       APP_NOEXIST
63                     };
64
65     Render(const QString & rendererName, int winid, int extid, QWidget *parent = 0);
66     ~Render();
67
68     /** Seeks the renderer clip to the given time. */
69     void seek(GenTime time);
70     void seekToFrame(int pos);
71     bool m_isBlocked;
72
73     //static QPixmap getVideoThumbnail(char *profile, QString file, int frame, int width, int height);
74     QPixmap getImageThumbnail(KUrl url, int width, int height);
75
76     /** Return thumbnail for color clip */
77     //void getImage(int id, QString color, QPoint size);
78
79     // static QPixmap frameThumbnail(Mlt::Frame *frame, int width, int height, bool border = false);
80
81     /** Return thumbnail for image clip */
82     //void getImage(KUrl url, QPoint size);
83
84     /** Requests a particular frame from the given file.
85      *
86      * The pixmap will be returned by emitting the replyGetImage() signal.
87      * */
88     //void getImage(KUrl url, int frame, QPoint size);
89
90
91     /** Wraps the VEML command of the same name. Sets the current scene list to
92     be list. */
93     void setSceneList(QDomDocument list, int position = 0);
94     void setSceneList(QString playlist, int position = 0);
95     void setProducer(Mlt::Producer *producer, int position);
96     QString sceneList();
97     void saveSceneList(QString path, QDomElement kdenliveData = QDomElement());
98
99     /** Wraps the VEML command of the same name. Tells the renderer to
100     play the current scene at the speed specified, relative to normal
101     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
102     backwards. Does not specify start/stop times for playback.*/
103     void play(double speed);
104     void switchPlay();
105     void pause();
106     /** stop playing */
107     void stop(const GenTime & startTime);
108     void setVolume(double volume);
109
110     QPixmap extractFrame(int frame_position, int width = -1, int height = -1);
111     /** Wraps the VEML command of the same name. Tells the renderer to
112     play the current scene at the speed specified, relative to normal
113     playback. e.g. 1.0 is normal speed, 0.0 is paused, -1.0 means play
114     backwards. Specifes the start/stop times for playback.*/
115     void play(const GenTime & startTime);
116     void playZone(const GenTime & startTime, const GenTime & stopTime);
117     void loopZone(const GenTime & startTime, const GenTime & stopTime);
118
119     void saveZone(KUrl url, QString desc, QPoint zone);
120
121     /** Returns the name of the renderer. */
122     const QString & rendererName() const;
123
124     /** Returns the speed at which the renderer is currently playing, 0.0 if the renderer is
125     not playing anything. */
126     double playSpeed();
127     /** Returns the current seek position of the renderer. */
128     GenTime seekPosition() const;
129
130     void emitFrameNumber(double position);
131     void emitConsumerStopped();
132
133     /** Gives the aspect ratio of the consumer */
134     double consumerRatio() const;
135
136     void askForRefresh();
137     void doRefresh();
138
139     /** Save current producer frame as image */
140     void exportCurrentFrame(KUrl url, bool notify);
141
142     /** Turn on or off on screen display */
143     void refreshDisplay();
144     int resetProfile();
145     const double fps() const;
146     const int renderWidth() const;
147     const int renderHeight() const;
148     /** get display aspect ratio */
149     const double dar() const;
150
151     /** Playlist manipulation */
152     void mltInsertClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
153     void mltUpdateClip(ItemInfo info, QDomElement element, Mlt::Producer *prod);
154     void mltCutClip(int track, GenTime position);
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     static QString searchFileRecursively(const QDir &dir, const QString &matchSize, const QString &matchHash);
184
185 private:   // Private attributes & methods
186     /** The name of this renderer - useful to identify the renderes by what they do - e.g. background rendering, workspace monitor, etc... */
187     QString m_name;
188     Mlt::Consumer * m_mltConsumer;
189     Mlt::Producer * m_mltProducer;
190     Mlt::Producer *m_mltTextProducer;
191     Mlt::Filter *m_osdInfo;
192     Mlt::Profile *m_mltProfile;
193     double m_framePosition;
194     double m_fps;
195
196     /** true if we are playing a zone (ie the in and out properties have been temporarily changed) */
197     bool m_isZoneMode;
198     bool m_isLoopMode;
199     GenTime m_loopStart;
200
201     /** true when monitor is in split view (several tracks at the same time) */
202     bool m_isSplitView;
203
204     Mlt::Producer *m_blackClip;
205     /** Holds the path to on screen display profile */
206     QString m_osdProfile;
207
208     QTimer *refreshTimer;
209     QTimer *osdTimer;
210     KUrl m_exportedFile;
211
212     /** A human-readable description of this renderer. */
213     int m_winid;
214     int m_externalwinid;
215
216     /** Sets the description of this renderer to desc. */
217     void closeMlt();
218     void mltCheckLength(bool reload = true);
219     QMap<QString, QString> mltGetTransitionParamsFromXml(QDomElement xml);
220     QMap<QString, Mlt::Producer *> m_slowmotionProducers;
221     void buildConsumer();
222     void resetZoneMode();
223
224 private slots:  // Private slots
225     /** refresh monitor display */
226     void refresh();
227     void slotOsdTimeout();
228     void connectPlaylist();
229     //void initSceneList();
230
231 signals:   // Signals
232     /** emitted when the renderer recieves a reply to a getFileProperties request. */
233     void replyGetFileProperties(const QString &clipId, Mlt::Producer*, const QMap < QString, QString > &, const QMap < QString, QString > &);
234
235     /** emitted when the renderer recieves a reply to a getImage request. */
236     void replyGetImage(const QString & , int, const QPixmap &, int, int);
237     void replyGetImage(const QString &, const QPixmap &, int, int);
238
239     /** Emitted when the renderer stops, either playing or rendering. */
240     void stopped();
241     /** Emitted when the renderer starts playing. */
242     void playing(double);
243     /** Emitted when the renderer is rendering. */
244     void rendering(const GenTime &);
245     /** Emitted when rendering has finished */
246     void renderFinished();
247     /** Emitted when the current seek position has been changed by the renderer. */
248 //    void positionChanged(const GenTime &);
249     /** Emitted when an error occurs within this renderer. */
250     void error(const QString &, const QString &);
251     void durationChanged(int);
252     void rendererPosition(int);
253     void rendererStopped(int);
254     void removeInvalidClip(const QString &);
255
256 public slots:  // Public slots
257     /** Start Consumer */
258     void start();
259     /** Stop Consumer */
260     void stop();
261     void clear();
262     int getLength();
263     /** If the file is readable by mlt, return true, otherwise false */
264     bool isValid(KUrl url);
265
266     /** Wraps the VEML command of the same name. Requests the file properties
267     for the specified url from the renderer. Upon return, the result will be emitted
268     via replyGetFileProperties(). */
269     void getFileProperties(const QDomElement &xml, const QString &clipId);
270
271     void exportFileToFirewire(QString srcFileName, int port, GenTime startTime, GenTime endTime);
272     static char *decodedString(QString str);
273     void mltSavePlaylist();
274     void slotSplitView(bool doit);
275 };
276
277 #endif