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