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