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