CuteLogger
Fast and simple logging solution for Qt based applications
qmlfilter.h
1 /*
2  * Copyright (c) 2013-2021 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 <MltService.h>
27 #include <MltProducer.h>
28 #include <MltAnimation.h>
29 
30 #include "qmlmetadata.h"
31 #include "shotcut_mlt_properties.h"
32 
33 class AbstractJob;
34 class EncodeJob;
35 
36 class QmlFilter : public QObject
37 {
38  Q_OBJECT
39  Q_PROPERTY(bool isNew READ isNew)
40  Q_PROPERTY(QString path READ path)
41  Q_PROPERTY(QStringList presets READ presets NOTIFY presetsChanged)
42  Q_PROPERTY(int in READ in NOTIFY inChanged)
43  Q_PROPERTY(int out READ out NOTIFY outChanged)
44  Q_PROPERTY(int animateIn READ animateIn WRITE setAnimateIn NOTIFY animateInChanged)
45  Q_PROPERTY(int animateOut READ animateOut WRITE setAnimateOut NOTIFY animateOutChanged)
46  Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
47  Q_PROPERTY(bool blockSignals READ signalsBlocked WRITE blockSignals)
48 
49 public:
50  enum TimeFormat
51  {
52  TIME_FRAMES,
53  TIME_CLOCK,
54  TIME_TIMECODE_DF,
55  TIME_TIMECODE_NDF,
56  };
57  Q_ENUM(TimeFormat)
58 
59  enum CurrentFilterIndex {
60  NoCurrentFilter = -1,
61  DeselectCurrentFilter = -2
62  };
63  Q_ENUM(CurrentFilterIndex)
64 
65  explicit QmlFilter();
66  explicit QmlFilter(Mlt::Service& mltService, const QmlMetadata* metadata, QObject *parent = nullptr);
67  ~QmlFilter();
68 
69  bool isNew() const { return m_isNew; }
70  void setIsNew(bool isNew) { m_isNew = isNew; }
71 
72  Q_INVOKABLE QString get(QString name, int position = -1);
73  Q_INVOKABLE double getDouble(QString name, int position = -1);
74  Q_INVOKABLE QRectF getRect(QString name, int position = -1);
75  Q_INVOKABLE void removeRectPercents(QString name);
76  Q_INVOKABLE QStringList getGradient(QString name);
77  Q_INVOKABLE void set(QString name, QString value, int position = -1);
78  Q_INVOKABLE void set(QString name, double value,
79  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
80  Q_INVOKABLE void set(QString name, int value,
81  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
82  Q_INVOKABLE void set(QString name, bool value,
83  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
84  Q_INVOKABLE void set(QString name, double x, double y, double width, double height, double opacity = 1.0,
85  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
86  Q_INVOKABLE void set(QString name, const QRectF& rect, double opacity = 1.0,
87  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
88  Q_INVOKABLE void setGradient(QString name, const QStringList& gradient);
89  QString path() const { return m_path; }
90  Q_INVOKABLE void loadPresets();
91  QStringList presets() const { return m_presets; }
93  Q_INVOKABLE int savePreset(const QStringList& propertyNames, const QString& name = QString());
94  Q_INVOKABLE void deletePreset(const QString& name);
95  Q_INVOKABLE void analyze(bool isAudio = false);
96  Q_INVOKABLE static int framesFromTime(const QString& time);
97  Q_INVOKABLE static QString timeFromFrames(int frames, TimeFormat format = TIME_TIMECODE_DF);
98  Q_INVOKABLE void getHash();
99  Mlt::Producer& producer() { return m_producer; }
100  int in();
101  int out();
102  Mlt::Service& service() { return m_service; }
103  int animateIn();
104  void setAnimateIn(int value);
105  int animateOut();
106  void setAnimateOut(int value);
107  void clearAnimateInOut();
108  int duration();
109  Q_INVOKABLE void resetProperty(const QString& name);
110  Q_INVOKABLE void clearSimpleAnimation(const QString& name);
111  Mlt::Animation getAnimation(const QString& name);
112  Q_INVOKABLE int keyframeCount(const QString& name);
113  mlt_keyframe_type getKeyframeType(Mlt::Animation& animation, int position, mlt_keyframe_type defaultType);
114  Q_INVOKABLE int getNextKeyframePosition(const QString& name, int position);
115  Q_INVOKABLE int getPrevKeyframePosition(const QString& name, int position);
116  Q_INVOKABLE bool isAtLeastVersion(const QString& version);
117  Q_INVOKABLE static void deselect();
118  bool allowTrim() const;
119  bool allowAnimateIn() const;
120  bool allowAnimateOut() const;
121 
122 public slots:
123  void preset(const QString& name);
124 
125 signals:
126  void presetsChanged();
127  void analyzeFinished(bool isSuccess);
128  void changed();
129  void changed(QString name);
130  void inChanged(int delta);
131  void outChanged(int delta);
132  void animateInChanged();
133  void animateOutChanged();
134  void animateInOutChanged();
135  void durationChanged();
136  void propertyChanged(QString name); // Use to let QML know when a specific property has changed
137 
138 private:
139  const QmlMetadata* m_metadata;
140  Mlt::Service m_service;
141  Mlt::Producer m_producer;
142  QString m_path;
143  bool m_isNew;
144  QStringList m_presets;
145 
146  QString objectNameOrService();
147  int keyframeIndex(Mlt::Animation& animation, int position);
148 };
149 
150 class AnalyzeDelegate : public QObject
151 {
152  Q_OBJECT
153 public:
154  explicit AnalyzeDelegate(Mlt::Filter& filter);
155 
156 public slots:
157  void onAnalyzeFinished(AbstractJob *job, bool isSuccess);
158 
159 private:
160  QString resultsFromXml(const QString& fileName, const QString& serviceName);
161  void updateFilter(Mlt::Filter& filter, const QString& results);
162  void updateJob(EncodeJob* job, const QString& results);
163 
164  QUuid m_uuid;
165  QString m_serviceName;
166 };
167 
168 #endif // FILTER_H