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