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