CuteLogger
Fast and simple logging solution for Qt based applications
qmlfilter.h
1 /*
2  * Copyright (c) 2013-2018 Meltytech, LLC
3  * Author: Dan Dennedy <dan@dennedy.org>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef FILTER_H
20 #define FILTER_H
21 
22 #include <QObject>
23 #include <QString>
24 #include <QVariant>
25 #include <QRectF>
26 #include <MltFilter.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 
35 class QmlFilter : public QObject
36 {
37  Q_OBJECT
38  Q_PROPERTY(bool isNew READ isNew)
39  Q_PROPERTY(QString path READ path)
40  Q_PROPERTY(QStringList presets READ presets NOTIFY presetsChanged)
41  Q_PROPERTY(int in READ in WRITE setIn NOTIFY inChanged)
42  Q_PROPERTY(int out READ out WRITE setOut NOTIFY outChanged)
43  Q_PROPERTY(int animateIn READ animateIn WRITE setAnimateIn NOTIFY animateInChanged)
44  Q_PROPERTY(int animateOut READ animateOut WRITE setAnimateOut NOTIFY animateOutChanged)
45  Q_PROPERTY(int duration READ duration NOTIFY durationChanged)
46  Q_PROPERTY(bool blockSignals WRITE blockSignals)
47 
48 public:
49  enum TimeFormat
50  {
51  TIME_FRAMES,
52  TIME_CLOCK,
53  TIME_TIMECODE_DF,
54  TIME_TIMECODE_NDF,
55  };
56  Q_ENUMS(TimeFormat)
57 
58  explicit QmlFilter();
59  explicit QmlFilter(Mlt::Filter& mltFilter, const QmlMetadata* metadata, QObject *parent = 0);
60  ~QmlFilter();
61 
62  bool isNew() const { return m_isNew; }
63  void setIsNew(bool isNew) { m_isNew = isNew; }
64 
65  Q_INVOKABLE QString get(QString name, int position = -1);
66  Q_INVOKABLE double getDouble(QString name, int position = -1);
67  Q_INVOKABLE QRectF getRect(QString name, int position = -1);
68  Q_INVOKABLE void set(QString name, QString value, int position = -1);
69  Q_INVOKABLE void set(QString name, double value,
70  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
71  Q_INVOKABLE void set(QString name, int value,
72  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
73  Q_INVOKABLE void set(QString name, bool value,
74  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
75  Q_INVOKABLE void set(QString name, double x, double y, double width, double height, double opacity = 1.0,
76  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
77  Q_INVOKABLE void set(QString name, const QRectF& rect, double opacity = 1.0,
78  int position = -1, mlt_keyframe_type keyframeType = mlt_keyframe_type(-1));
79  QString path() const { return m_path; }
80  Q_INVOKABLE void loadPresets();
81  QStringList presets() const { return m_presets; }
83  Q_INVOKABLE int savePreset(const QStringList& propertyNames, const QString& name = QString());
84  Q_INVOKABLE void deletePreset(const QString& name);
85  Q_INVOKABLE void analyze(bool isAudio = false);
86  Q_INVOKABLE static int framesFromTime(const QString& time);
87  Q_INVOKABLE static QString timeFromFrames(int frames, TimeFormat format = TIME_TIMECODE_DF);
88  Q_INVOKABLE void getHash();
89  Mlt::Producer& producer() { return m_producer; }
90  int in();
91  void setIn(int value);
92  int out();
93  void setOut(int value);
94  Mlt::Filter& filter() { return m_filter; }
95  int animateIn();
96  void setAnimateIn(int value);
97  int animateOut();
98  void setAnimateOut(int value);
99  int duration();
100  Q_INVOKABLE void resetProperty(const QString& name);
101  Q_INVOKABLE void clearSimpleAnimation(const QString& name);
102  Mlt::Animation getAnimation(const QString& name);
103  Q_INVOKABLE int keyframeCount(const QString& name);
104 
105 public slots:
106  void preset(const QString& name);
107 
108 signals:
109  void presetsChanged();
110  void analyzeFinished(bool isSuccess);
111  void changed();
112  void changed(QString name);
113  void inChanged(int delta);
114  void outChanged(int delta);
115  void animateInChanged();
116  void animateOutChanged();
117  void durationChanged();
118 
119 private:
120  const QmlMetadata* m_metadata;
121  Mlt::Filter m_filter;
122  Mlt::Producer m_producer;
123  QString m_path;
124  bool m_isNew;
125  QStringList m_presets;
126 
127  QString objectNameOrService();
128  int keyframeIndex(Mlt::Animation& animation, int position);
129  mlt_keyframe_type getKeyframeType(Mlt::Animation& animation, int position, mlt_keyframe_type defaultType = mlt_keyframe_linear);
130 };
131 
132 class AnalyzeDelegate : public QObject
133 {
134  Q_OBJECT
135 public:
136  explicit AnalyzeDelegate(Mlt::Filter& filter);
137 
138 public slots:
139  void onAnalyzeFinished(AbstractJob *job, bool isSuccess);
140 
141 private:
142  Mlt::Filter m_filter;
143 };
144 
145 #endif // FILTER_H