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