CuteLogger
Fast and simple logging solution for Qt based applications
glaxnimateproducerwidget.h
1 /*
2  * Copyright (c) 2022 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 GLAXNIMATEPRODUCERWIDGET_H
19 #define GLAXNIMATEPRODUCERWIDGET_H
20 
21 #include <QWidget>
22 #include <QPointer>
23 #include <QLocalSocket>
24 #include <QLocalServer>
25 #include <QDataStream>
26 #include <QSharedMemory>
27 
28 #include "abstractproducerwidget.h"
29 
30 class GlaxnimateIpcServer : public QObject
31 {
32  Q_OBJECT
33 
34  class ParentResources
35  {
36  public:
37  Mlt::Producer m_producer;
38  std::unique_ptr<Mlt::Profile> m_profile;
39  std::unique_ptr<Mlt::Producer> m_glaxnimateProducer;
40  int m_frameNum = -1;
41 
42  void setProducer(const Mlt::Producer &producer, bool hideCurrentTrack);
43  };
44 
45 public:
46  std::unique_ptr<ParentResources> parent;
47  std::unique_ptr<QLocalServer> m_server;
48  std::unique_ptr<QDataStream> m_stream;
49  bool m_isProtocolValid = false;
50  std::unique_ptr<QSharedMemory> m_sharedMemory;
51  QPointer<QLocalSocket> m_socket;
52 
53  static GlaxnimateIpcServer &instance();
54  static void newFile(const QString &filename, int duration);
55  void reset();
56  void launch(const Mlt::Producer &producer, QString filename = QString(),
57  bool hideCurrentTrack = true);
58 
59 private slots:
60  void onConnect();
61  void onReadyRead();
62  void onSocketError(QLocalSocket::LocalSocketError socketError);
63 
64 private:
65  int toMltFps(float frame) const;
66  bool copyToShared(const QImage &image);
67 };
68 
69 namespace Ui {
70 class GlaxnimateProducerWidget;
71 }
72 class QFileSystemWatcher;
73 class QLocalServer;
74 class QDataStream;
75 class QSharedMemory;
76 
77 class GlaxnimateProducerWidget : public QWidget, public AbstractProducerWidget
78 {
79  friend GlaxnimateIpcServer;
80 
81  Q_OBJECT
82 
83 public:
84  explicit GlaxnimateProducerWidget(QWidget *parent = 0);
85  ~GlaxnimateProducerWidget();
86 
87  // AbstractProducerWidget overrides
88  Mlt::Producer *newProducer(Mlt::Profile &);
89  virtual void setProducer(Mlt::Producer *);
90  Mlt::Properties getPreset() const;
91  void loadPreset(Mlt::Properties &);
92 
93 signals:
94  void producerChanged(Mlt::Producer *);
95  void modified();
96 
97 public slots:
98  void rename();
99 
100 private slots:
101  void on_colorButton_clicked();
102  void on_preset_selected(void *p);
103  void on_preset_saveClicked();
104  void on_lineEdit_editingFinished();
105  void on_notesTextEdit_textChanged();
106  void on_editButton_clicked();
107  void onFileChanged(const QString &path);
108  void on_reloadButton_clicked();
109  void on_durationSpinBox_editingFinished();
110 
111 private:
112  Ui::GlaxnimateProducerWidget *ui;
113  QString m_title;
114  std::unique_ptr<QFileSystemWatcher> m_watcher;
115 };
116 
117 #endif // GLAXNIMATEPRODUCERWIDGET_H