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