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