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