CuteLogger
Fast and simple logging solution for Qt based applications
mltcontroller.h
1/*
2 * Copyright (c) 2011-2025 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 MLTCONTROLLER_H
19#define MLTCONTROLLER_H
20
21#include "transportcontrol.h"
22
23#include "settings.h"
24
25#include <Mlt.h>
26#include <QImage>
27#include <QMutex>
28#include <QScopedPointer>
29#include <QString>
30#include <QTemporaryFile>
31#include <QUuid>
32
33#define MLT_LC_CATEGORY LC_ALL
34#define MLT_LC_NAME "LC_ALL"
35
36#define kAudioIndexProperty "astream"
37#define kVideoIndexProperty "vstream"
38
39namespace Mlt {
40
41const int kMaxImageDurationSecs = 3600 * 4;
42extern const QString XmlMimeType;
43
44class TransportControl : public TransportControllable
45{
46 Q_OBJECT
47public slots:
48 void play(double speed = 1.0) override;
49 void pause(int position = -1) override;
50 void stop() override;
51 void seek(int position) override;
52 void rewind(bool forceChangeDirection) override;
53 void fastForward(bool forceChangeDirection) override;
54 void previous(int currentPosition) override;
55 void next(int currentPosition) override;
56 void setIn(int) override;
57 void setOut(int) override;
58};
59
60class Controller
61{
62protected:
63 Controller();
64 virtual int reconfigure(bool isMulti) = 0;
65
66public:
67 enum {
68 FILTER_INDEX_ALL = -1,
69 FILTER_INDEX_ENABLED = -2,
70 };
71
72 static Controller &singleton(QObject *parent = nullptr);
73 virtual ~Controller();
74 static void destroy();
75
76 virtual QObject *videoWidget() = 0;
77 virtual int setProducer(Mlt::Producer *, bool isMulti = false);
78 virtual int open(const QString &url, const QString &urlToSave, bool skipConvert = false);
79 bool openXML(const QString &filename);
80 virtual void close();
81 virtual int displayWidth() const = 0;
82 virtual int displayHeight() const = 0;
83
84 void closeConsumer();
85 virtual void play(double speed = 1.0);
86 bool isPaused() const;
87 virtual void pause(int position = -1);
88 void stop();
89 bool enableJack(bool enable = true);
90 void setVolume(double volume, bool muteOnPause = true);
91 double volume() const;
92 void onWindowResize();
93 virtual void seek(int position);
94 virtual void refreshConsumer(bool scrubAudio = false);
95 bool saveXML(const QString &filename,
96 Service *service = nullptr,
97 bool withRelativePaths = true,
98 QTemporaryFile *tempFile = nullptr,
99 bool proxy = false,
100 QString projectNote = QString());
101 QString XML(Service *service = nullptr, bool withProfile = false, bool withMetadata = true);
102 int consumerChanged();
103 void setProfile(const QString &profile_name);
104 void setAudioChannels(int audioChannels);
105 void setProcessingMode(ShotcutSettings::ProcessingMode mode);
106 QString resource() const;
107 bool isSeekable(Mlt::Producer *p = nullptr) const;
108 int maxFrameCount() const;
109 bool isLiveProducer(Mlt::Producer *p = nullptr) const;
110 bool isClip() const;
111 bool isClosedClip(Producer *producer = nullptr) const;
112 bool isSeekableClip();
113 bool isPlaylist() const;
114 bool isMultitrack() const;
115 bool isImageProducer(Service *service) const;
116 bool isFileProducer(Service *service) const;
117 static bool isProjectProducer(Service *service);
118 void rewind(bool forceChangeDirection);
119 void fastForward(bool forceChangeDirection);
120 void previous(int currentPosition);
121 void next(int currentPosition);
122 void setIn(int);
123 void setOut(int);
124 void fixLengthProperties(Service &service);
125 void reload(const QString &xml);
126 void resetURL();
127 QImage image(Frame *frame, int width, int height);
128 QImage image(Mlt::Producer &producer, int frameNumber, int width, int height);
129 void updateAvformatCaching(int trackCount);
130 bool isAudioFilter(const QString &name);
131 int realTime() const;
132 void setImageDurationFromDefault(Service *service) const;
133 void setDurationFromDefault(Producer *service) const;
134 void lockCreationTime(Producer *producer) const;
135 Producer *setupNewProducer(Producer *newProducer) const;
136 QUuid uuid(Mlt::Properties &properties) const;
137 void setUuid(Mlt::Properties &properties, QUuid uid) const;
138 QUuid ensureHasUuid(Mlt::Properties &properties) const;
139 static void copyFilters(Mlt::Producer &fromProducer,
140 Mlt::Producer &toProducer,
141 bool fromClipboard = false,
142 int filterIndex = FILTER_INDEX_ENABLED);
143 void copyFilters(Mlt::Producer *producer = nullptr, int filterIndex = FILTER_INDEX_ENABLED);
144 void pasteFilters(Mlt::Producer *producer = nullptr, Mlt::Producer *fromProducer = nullptr);
145 static void adjustFilters(Mlt::Producer &producer, int startIndex = 0);
146 static void adjustFilter(
147 Mlt::Filter *filter, int in, int out, int inDelta, int outDelta, int keyframeDelta);
148 static void adjustClipFilters(
149 Mlt::Producer &producer, int in, int out, int inDelta, int outDelta, int keyframeDelta);
150 bool hasFiltersOnClipboard() const
151 {
152 return m_filtersClipboard->is_valid() && m_filtersClipboard->filter_count() > 0;
153 }
154 QString filtersClipboardXML() { return XML(m_filtersClipboard.get()); }
155
156 int audioChannels() const { return m_audioChannels; }
157 ShotcutSettings::ProcessingMode processingMode() const { return m_processingMode; }
158 Mlt::Repository *repository() const { return m_repo; }
159 Mlt::Profile &profile() { return m_profile; }
160 Mlt::Profile &previewProfile() { return m_previewProfile; }
161 Mlt::Producer *producer() const { return m_producer.data(); }
162 Mlt::Consumer *consumer() const { return m_consumer.data(); }
163 const QString &URL() const { return m_url; }
164 const TransportControllable *transportControl() const { return &m_transportControl; }
165 Mlt::Producer *savedProducer() const { return m_savedProducer.data(); }
166 void setSavedProducer(Mlt::Producer *producer);
167 static Mlt::Filter *getFilter(const QString &name, Mlt::Service *service);
168 static Mlt::Link *getLink(const QString &name, Mlt::Service *service);
169 QString projectFolder() const { return m_projectFolder; }
170 void setProjectFolder(const QString &folderName);
171 QChar decimalPoint();
172 static void resetLocale();
173 static int filterIn(Mlt::Playlist &playlist, int clipIndex);
174 static int filterOut(Mlt::Playlist &playlist, int clipIndex);
175 void setPreviewScale(int scale);
176 void updatePreviewProfile();
177 static void purgeMemoryPool();
178 static bool fullRange(Mlt::Producer &producer);
179 static bool isMltXml(const QString &s) { return s.contains("<mlt "); }
180 static bool isTrackProducer(Mlt::Producer &producer);
181 static int checkFile(const QString &path);
182 bool blockRefresh(bool block);
183 void configureHardwareDecoder(bool enable);
184
185 class RefreshBlocker
186 {
187 public:
188 RefreshBlocker() { singleton().blockRefresh(true); }
189 ~RefreshBlocker() { singleton().blockRefresh(false); }
190 };
191
192protected:
193 Mlt::Repository *m_repo;
194 QScopedPointer<Mlt::Producer> m_producer;
195 QScopedPointer<Mlt::FilteredConsumer> m_consumer;
196
197private:
198 Mlt::Profile m_profile;
199 Mlt::Profile m_previewProfile;
200 int m_audioChannels{2};
201 ShotcutSettings::ProcessingMode m_processingMode{ShotcutSettings::Native8Cpu};
202 QScopedPointer<Mlt::Filter> m_jackFilter;
203 QString m_url;
204 double m_volume{1.0};
205 TransportControl m_transportControl;
206 QScopedPointer<Mlt::Producer> m_savedProducer;
207 QScopedPointer<Mlt::Producer> m_filtersClipboard;
208 unsigned m_skipJackEvents{0};
209 QString m_projectFolder;
210 QMutex m_saveXmlMutex;
211 bool m_blockRefresh;
212
213 static void on_jack_started(mlt_properties owner, void *object, mlt_event_data data);
214 void onJackStarted(int position);
215 static void on_jack_stopped(mlt_properties owner, void *object, mlt_event_data data);
216 void onJackStopped(int position);
217 void stopJack();
218 void initFiltersClipboard();
219};
220
221} // namespace Mlt
222
223#define MLT Mlt::Controller::singleton()
224
225#endif // MLTCONTROLLER_H