LMMS
Loading...
Searching...
No Matches
RemotePlugin.h
Go to the documentation of this file.
1/*
2 * RemotePlugin.h - base class providing RPC like mechanisms
3 *
4 * Copyright (c) 2008-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
5 *
6 * This file is part of LMMS - https://lmms.io
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program (see COPYING); if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301 USA.
22 *
23 */
24
25#ifndef LMMS_REMOTE_PLUGIN_H
26#define LMMS_REMOTE_PLUGIN_H
27
28#include <QThread>
29#include <QProcess>
30#include <QRecursiveMutex>
31
32#include "RemotePluginBase.h"
33#include "SharedMemory.h"
34#include "LmmsTypes.h"
35
36namespace lmms
37{
38
39class MidiEvent;
40class RemotePlugin;
41class SampleFrame;
42
43class ProcessWatcher : public QThread
44{
45 Q_OBJECT
46public:
48 ~ProcessWatcher() override = default;
49
50 void stop()
51 {
52 m_quit = true;
53 quit();
54 }
55
56 void reset()
57 {
58 m_quit = false;
59 }
60
61private:
62 void run() override;
63
65 volatile bool m_quit;
66
67} ;
68
69
70class LMMS_EXPORT RemotePlugin : public QObject, public RemotePluginBase
71{
72 Q_OBJECT
73public:
75 ~RemotePlugin() override;
76
77 inline bool isRunning()
78 {
79#ifdef DEBUG_REMOTE_PLUGIN
80 return true;
81#else
82 return m_process.state() != QProcess::NotRunning;
83#endif // DEBUG_REMOTE_PLUGIN
84 }
85
86 bool init( const QString &pluginExecutable, bool waitForInitDoneMsg, QStringList extraArgs = {} );
87
93
94 inline void waitForInitDone( bool _busyWaiting = true )
95 {
96 m_failed = waitForMessage( IdInitDone, _busyWaiting ).id != IdInitDone;
97 }
98
99 bool processMessage( const message & _m ) override;
100
101 bool process( const SampleFrame* _in_buf, SampleFrame* _out_buf );
102
103 void processMidiEvent( const MidiEvent&, const f_cnt_t _offset );
104
106 {
107 lock();
108 sendMessage( message( IdSampleRateInformation ).addInt( _sr ) );
110 unlock();
111 }
112
113
114 virtual void toggleUI()
115 {
116 lock();
118 unlock();
119 }
120
122 {
123 lock();
125 unlock();
127 return m.id != IdIsUIVisible ? -1 : m.getInt() ? 1 : 0;
128 }
129
130 inline bool failed() const
131 {
132 return m_failed;
133 }
134
135 inline void lock()
136 {
137 m_commMutex.lock();
138 }
139
140 inline void unlock()
141 {
142 m_commMutex.unlock();
143 }
144
145public slots:
146 virtual void showUI();
147 virtual void hideUI();
148
149protected:
150 inline void setSplittedChannels( bool _on )
151 {
152 m_splitChannels = _on;
153 }
154
155
157private:
159
160
161 QProcess m_process;
163
164 QString m_exec;
165 QStringList m_args;
166
167 QRecursiveMutex m_commMutex;
169
171 std::size_t m_audioBufferSize;
172
175
176#ifndef SYNC_WITH_SHM_FIFO
179#endif // not SYNC_WITH_SHM_FIFO
180
181 friend class ProcessWatcher;
182
183
184private slots:
185 void processFinished( int exitCode, QProcess::ExitStatus exitStatus );
186 void processErrored(QProcess::ProcessError err );
187} ;
188
189inline std::string QSTR_TO_STDSTR(QString const& qstr)
190{
191 return qstr.toStdString();
192}
193
194} // namespace lmms
195
196#endif // LMMS_REMOTE_PLUGIN_H
static void message(int level, const char *fmt,...)
Definition adplugdb.cpp:120
void process(Alg_seq_ptr seq, bool tempo_flag, double tempo, bool flatten_flag)
Definition allegroconvert.cpp:42
Definition MidiEvent.h:37
ProcessWatcher(RemotePlugin *)
Definition RemotePlugin.cpp:80
RemotePlugin * m_plugin
Definition RemotePlugin.h:64
void run() override
Definition RemotePlugin.cpp:88
volatile bool m_quit
Definition RemotePlugin.h:65
~ProcessWatcher() override=default
void reset()
Definition RemotePlugin.h:56
void stop()
Definition RemotePlugin.h:50
int sendMessage(const message &_m)
message waitForMessage(const message &_m, bool _busy_waiting=false)
Definition RemotePlugin.h:71
bool isRunning()
Definition RemotePlugin.h:77
void waitForHostInfoGotten()
Definition RemotePlugin.h:88
QStringList m_args
Definition RemotePlugin.h:165
virtual void toggleUI()
Definition RemotePlugin.h:114
QString m_socketFile
Definition RemotePlugin.h:178
void lock()
Definition RemotePlugin.h:135
void waitForInitDone(bool _busyWaiting=true)
Definition RemotePlugin.h:94
void processFinished(int exitCode, QProcess::ExitStatus exitStatus)
Definition RemotePlugin.cpp:500
void unlock()
Definition RemotePlugin.h:140
QProcess m_process
Definition RemotePlugin.h:161
int m_inputCount
Definition RemotePlugin.h:173
SharedMemory< float[]> m_audioBuffer
Definition RemotePlugin.h:170
int m_server
Definition RemotePlugin.h:177
bool failed() const
Definition RemotePlugin.h:130
void processErrored(QProcess::ProcessError err)
Definition RemotePlugin.cpp:516
friend class ProcessWatcher
Definition RemotePlugin.h:181
ProcessWatcher m_watcher
Definition RemotePlugin.h:162
std::size_t m_audioBufferSize
Definition RemotePlugin.h:171
QRecursiveMutex m_commMutex
Definition RemotePlugin.h:167
bool m_failed
Definition RemotePlugin.h:156
bool m_splitChannels
Definition RemotePlugin.h:168
void resizeSharedProcessingMemory()
Definition RemotePlugin.cpp:480
void setSplittedChannels(bool _on)
Definition RemotePlugin.h:150
void updateSampleRate(sample_rate_t _sr)
Definition RemotePlugin.h:105
RemotePlugin()
Definition RemotePlugin.cpp:133
int isUIVisible()
Definition RemotePlugin.h:121
int m_outputCount
Definition RemotePlugin.h:174
QString m_exec
Definition RemotePlugin.h:164
Definition SampleFrame.h:41
Definition SharedMemory.h:147
unsigned * m
Definition inflate.c:1559
Definition AudioAlsa.cpp:35
std::uint32_t sample_rate_t
Definition LmmsTypes.h:42
std::uint64_t f_cnt_t
Definition LmmsTypes.h:43
std::string QSTR_TO_STDSTR(QString const &qstr)
Definition RemotePlugin.h:189
@ IdInitDone
Definition RemotePluginBase.h:324
@ IdToggleUI
Definition RemotePluginBase.h:339
@ IdHostInfoGotten
Definition RemotePluginBase.h:323
@ IdIsUIVisible
Definition RemotePluginBase.h:340
@ IdInformationUpdated
Definition RemotePluginBase.h:329
@ IdSampleRateInformation
Definition RemotePluginBase.h:327
Definition RemotePluginBase.h:358
ZCONST uch * init
Definition extract.c:2392