CuteLogger
Fast and simple logging solution for Qt based applications
qmlfilter.h
1 /*
2  * Copyright (c) 2013-2019 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef FILTER_H
19 #define FILTER_H
20 
21 #include <QObject>
22 #include <QString>
23 #include <QVariant>
24 #include <QRectF>
25 #include <QUuid>
26 #include <MltFilter.h>
27 #include <MltProducer.h>
28 #include <MltAnimation.h>
29 
30 #include "qmlmetadata.h"
31 #include "shotcut_mlt_properties.h"
32 
33 #define MLT_VERSION_CPP_UPDATED ((6<<16)+(17<<8))
34 
35 class AbstractJob;
36 class EncodeJob;
37 
38 class QmlFilter : public QObject
39 {
40  Q_OBJECT
41  Q_PROPERTY(bool isNew READ isNew)
42  Q_PROPERTY(QString path READ path)
43  Q_PROPERTY(QStringList presets READ presets NOTIFY presetsChanged)
44  Q_PROPERTY(int in READ in WRITE setIn NOTIFY inChanged)
45  Q_PROPERTY(int out READ out WRITE setOut NOTIFY outChanged)
46  Q_PROPERTY(int animateIn READ animateIn WRITE setAnimateIn NOTIFY animateInChanged)
47  Q_PROPERTY(int animateOut READ animateOut WRITE setAnimateOut NOTIFY animateOutChanged)
48  Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
49  Q_PROPERTY(bool blockSignals READ signalsBlocked WRITE blockSignals)
50 
51 public:
52  enum TimeFormat
53  {
54  TIME_FRAMES,
55  TIME_CLOCK,
56  TIME_TIMECODE_DF,
57  TIME_TIMECODE_NDF,
58  };
59  Q_ENUMS(TimeFormat)
60 
61  explicit QmlFilter();
62  explicit QmlFilter(Mlt::Filter& mltFilter, const QmlMetadata* metadata, QObject *parent = nullptr);
63  ~QmlFilter();
64 
65  bool isNew() const { return m_isNew; }
66  void setIsNew(bool isNew) { m_isNew = isNew; }
67 
68  Q_INVOKABLE QString get(QString name, int position = -1);
69  Q_INVOKABLE double getDouble(QString name, int position = -1);
70  Q_INVOKABLE QRectF getRect(QString name, int position = -1);
71  Q_INVOKABLE QStringList getGradient(QString name);
72  Q_INVOKABLE void set(QString name, QString value, int position = -1);
73  Q_INVOKABLE void set(QString name, double value,
74  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
75  Q_INVOKABLE void set(QString name, int value,
76  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
77  Q_INVOKABLE void set(QString name, bool value,
78  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
79  Q_INVOKABLE void set(QString name, double x, double y, double width, double height, double opacity = 1.0,
80  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
81  Q_INVOKABLE void set(QString name, const QRectF& rect, double opacity = 1.0,
82  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
83  Q_INVOKABLE void setGradient(QString name, const QStringList& gradient);
84  QString path() const { return m_path; }
85  Q_INVOKABLE void loadPresets();
86  QStringList presets() const { return m_presets; }
88  Q_INVOKABLE int savePreset(const QStringList& propertyNames, const QString& name = QString());
89  Q_INVOKABLE void deletePreset(const QString& name);
90  Q_INVOKABLE void analyze(bool isAudio = false);
91  Q_INVOKABLE static int framesFromTime(const QString& time);
92  Q_INVOKABLE static QString timeFromFrames(int frames, TimeFormat format = TIME_TIMECODE_DF);
93  Q_INVOKABLE void getHash();
94  Mlt::Producer& producer() { return m_producer; }
95  int in();
96  void setIn(int value);
97  int out();
98  void setOut(int value);
99  Mlt::Filter& filter() { return m_filter; }
100  int animateIn();
101  void setAnimateIn(int value);
102  int animateOut();
103  void setAnimateOut(int value);
104  int duration();
105  Q_INVOKABLE void resetProperty(const QString& name);
106  Q_INVOKABLE void clearSimpleAnimation(const QString& name);
107  Mlt::Animation getAnimation(const QString& name);
108  Q_INVOKABLE int keyframeCount(const QString& name);
109  mlt_keyframe_type getKeyframeType(Mlt::Animation& animation, int position, mlt_keyframe_type defaultType);
110  Q_INVOKABLE bool isAtLeastVersion(const QString& version);
111 
112 public slots:
113  void preset(const QString& name);
114 
115 signals:
116  void presetsChanged();
117  void analyzeFinished(bool isSuccess);
118  void changed();
119  void changed(QString name);
120  void inChanged(int delta);
121  void outChanged(int delta);
122  void animateInChanged();
123  void animateOutChanged();
124  void durationChanged();
125 
126 private:
127  const QmlMetadata* m_metadata;
128  Mlt::Filter m_filter;
129  Mlt::Producer m_producer;
130  QString m_path;
131  bool m_isNew;
132  QStringList m_presets;
133 
134  QString objectNameOrService();
135  int keyframeIndex(Mlt::Animation& animation, int position);
136 };
137 
138 class AnalyzeDelegate : public QObject
139 {
140  Q_OBJECT
141 public:
142  explicit AnalyzeDelegate(Mlt::Filter& filter);
143 
144 public slots:
145  void onAnalyzeFinished(AbstractJob *job, bool isSuccess);
146 
147 private:
148  QString resultsFromXml(const QString& fileName, const QString& serviceName);
149  void updateFilter(Mlt::Filter& filter, const QString& results);
150 #if LIBMLT_VERSION_INT >= MLT_VERSION_CPP_UPDATED
151  void updateJob(EncodeJob* job, const QString& results);
152 
153  QUuid m_uuid;
154  QString m_serviceName;
155 #else
156  Mlt::Filter m_filter;
157 #endif
158 };
159 
160 #endif // FILTER_H