drumstick 2.7.2
alsaclient.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2022, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4
5 This library is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#ifndef DRUMSTICK_ALSACLIENT_H
20#define DRUMSTICK_ALSACLIENT_H
21
22#include <QObject>
23#include <QPointer>
24#include <QScopedPointer>
25#include <QThread>
26#include <QReadWriteLock>
27#include "macros.h"
28#include "alsaport.h"
29
38namespace drumstick {
43namespace ALSA {
44
45class MidiQueue;
46class MidiClient;
47class SequencerEvent;
48class RemoveEvents;
49
60class DRUMSTICK_EXPORT ClientInfo
61{
62 friend class MidiClient;
63
64public:
65 ClientInfo();
66 ClientInfo(const ClientInfo &other);
67 explicit ClientInfo(snd_seq_client_info_t *other);
68 ClientInfo(MidiClient* seq, int id);
69 virtual ~ClientInfo();
70 ClientInfo* clone();
71 ClientInfo& operator=(const ClientInfo &other);
72 int getSizeOfInfo() const;
73
74 int getClientId();
75 snd_seq_client_type_t getClientType();
76 QString getName();
77 bool getBroadcastFilter();
78 bool getErrorBounce();
79 int getNumPorts();
80 int getEventLost();
81 void setClient(int client);
82 void setName(QString name);
83 void setBroadcastFilter(bool val);
84 void setErrorBounce(bool val);
85 PortInfoList getPorts() const;
86
87#if SND_LIB_VERSION > 0x010010
88 void addFilter(int eventType);
89 bool isFiltered(int eventType);
90 void clearFilter();
91 void removeFilter(int eventType);
92#endif
93
94protected:
95 void readPorts(MidiClient* seq);
96 void freePorts();
97
98 Q_DECL_DEPRECATED const unsigned char* getEventFilter();
99 Q_DECL_DEPRECATED void setEventFilter(unsigned char* filter);
100
101private:
102 snd_seq_client_info_t* m_Info;
103 PortInfoList m_Ports;
104};
105
109typedef QList<ClientInfo> ClientInfoList;
110
117class DRUMSTICK_EXPORT SystemInfo
118{
119 friend class MidiClient;
120
121public:
122 SystemInfo();
123 SystemInfo(const SystemInfo& other);
124 explicit SystemInfo(snd_seq_system_info_t* other);
125 explicit SystemInfo(MidiClient* seq);
126 virtual ~SystemInfo();
127 SystemInfo* clone();
128 SystemInfo& operator=(const SystemInfo& other);
129 int getSizeOfInfo() const;
130
131 int getMaxClients();
132 int getMaxPorts();
133 int getMaxQueues();
134 int getMaxChannels();
135 int getCurrentQueues();
136 int getCurrentClients();
137
138private:
139 snd_seq_system_info_t* m_Info;
140};
141
148class DRUMSTICK_EXPORT PoolInfo
149{
150 friend class MidiClient;
151
152public:
153 PoolInfo();
154 PoolInfo(const PoolInfo& other);
155 explicit PoolInfo(snd_seq_client_pool_t* other);
156 explicit PoolInfo(MidiClient* seq);
157 virtual ~PoolInfo();
158 PoolInfo* clone();
159 PoolInfo& operator=(const PoolInfo& other);
160 int getSizeOfInfo() const;
161
162 int getClientId();
163 int getInputFree();
164 int getInputPool();
165 int getOutputFree();
166 int getOutputPool();
167 int getOutputRoom();
168 void setInputPool(int size);
169 void setOutputPool(int size);
170 void setOutputRoom(int size);
171
172private:
173 snd_seq_client_pool_t* m_Info;
174};
175
185class DRUMSTICK_EXPORT SequencerEventHandler
186{
187public:
189 virtual ~SequencerEventHandler() = default;
190
201};
202
208class DRUMSTICK_EXPORT MidiClient : public QObject
209{
210 Q_OBJECT
211public:
212 explicit MidiClient( QObject* parent = nullptr );
213 virtual ~MidiClient();
214
215 void open( const QString deviceName = "default",
216 const int openMode = SND_SEQ_OPEN_DUPLEX,
217 const bool blockMode = false );
218 void open( snd_config_t* conf,
219 const QString deviceName = "default",
220 const int openMode = SND_SEQ_OPEN_DUPLEX,
221 const bool blockMode = false );
222 void close();
223 void startSequencerInput();
224 void stopSequencerInput();
225 MidiPort* createPort();
226 MidiQueue* createQueue();
227 MidiQueue* createQueue(QString const& name);
228 MidiQueue* getQueue();
229 MidiQueue* useQueue(int queue_id);
230 MidiQueue* useQueue(const QString& name);
231 MidiQueue* useQueue(MidiQueue* queue);
232 void portAttach(MidiPort* port);
233 void portDetach(MidiPort* port);
234 void detachAllPorts();
235 void addEventFilter(int evtype);
236 void output(SequencerEvent* ev, bool async = false, int timeout = -1);
237 void outputDirect(SequencerEvent* ev, bool async = false, int timeout = -1);
238 void outputBuffer(SequencerEvent* ev);
239 void drainOutput(bool async = false, int timeout = -1);
240 void synchronizeOutput();
241
242 int getClientId();
243 snd_seq_type_t getSequencerType();
244 snd_seq_t* getHandle();
245 bool isOpened();
246
247 size_t getOutputBufferSize();
248 void setOutputBufferSize(size_t newSize);
249 size_t getInputBufferSize();
250 void setInputBufferSize(size_t newSize);
251 QString getDeviceName();
252 int getOpenMode();
253 bool getBlockMode();
254 void setBlockMode(bool newValue);
255 QString getClientName();
256 QString getClientName(const int clientId);
257 void setClientName(QString const& newName);
258 bool getBroadcastFilter();
259 void setBroadcastFilter(bool newValue);
260 bool getErrorBounce();
261 void setErrorBounce(bool newValue);
262
263 ClientInfo& getThisClientInfo();
264 void setThisClientInfo(const ClientInfo& val);
265 MidiPortList getMidiPorts() const;
266 ClientInfoList getAvailableClients();
267 PortInfoList getAvailableInputs();
268 PortInfoList getAvailableOutputs();
269 SystemInfo& getSystemInfo();
270 QList<int> getAvailableQueues();
271
272 PoolInfo& getPoolInfo();
273 void setPoolInfo(const PoolInfo& info);
274 void setPoolInput(int size);
275 void setPoolOutput(int size);
276 void setPoolOutputRoom(int size);
277 void resetPoolInput();
278 void resetPoolOutput();
279 void dropInput();
280 void dropInputBuffer();
281 void dropOutput();
282 void dropOutputBuffer();
283 void removeEvents(const RemoveEvents* spec);
284 SequencerEvent* extractOutput();
285 int outputPending();
286 int inputPending(bool fetch);
287 int getQueueId(const QString& name);
288
289 void addListener(QObject* listener);
290 void removeListener(QObject* listener);
291 void setEventsEnabled(const bool bEnabled);
292 bool getEventsEnabled() const;
293 void setHandler(SequencerEventHandler* handler);
294 bool parseAddress( const QString& straddr, snd_seq_addr& result );
295 void setRealTimeInput(bool enabled);
296 bool realTimeInputEnabled();
297
298signals:
303
304protected:
305 void doEvents();
306 void applyClientInfo();
307 void readClients();
308 void freeClients();
309 void updateAvailablePorts();
310 PortInfoList filterPorts(unsigned int filter);
311
312 /* low level public functions */
313 const char * _getDeviceName();
314 int getPollDescriptorsCount(short events);
315 int pollDescriptors(struct pollfd *pfds, unsigned int space, short events);
316 unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds);
317
318 /* mid level functions */
319 void _setClientName( const char *name );
320 int createSimplePort( const char *name,
321 unsigned int caps,
322 unsigned int type );
323 void deleteSimplePort( int port );
324 void connectFrom(int myport, int client, int port);
325 void connectTo(int myport, int client, int port);
326 void disconnectFrom(int myport, int client, int port);
327 void disconnectTo(int myport, int client, int port);
328
329private:
331 class MidiClientPrivate;
332 QScopedPointer<MidiClientPrivate> d;
333};
334
335#if SND_LIB_VERSION > 0x010004
336DRUMSTICK_EXPORT QString getRuntimeALSALibraryVersion();
337DRUMSTICK_EXPORT int getRuntimeALSALibraryNumber();
338#endif
339DRUMSTICK_EXPORT QString getRuntimeALSADriverVersion();
340DRUMSTICK_EXPORT int getRuntimeALSADriverNumber();
341DRUMSTICK_EXPORT QString getCompiledALSALibraryVersion();
342DRUMSTICK_EXPORT QString getDrumstickLibraryVersion();
343
346}} /* namespace drumstick::ALSA */
347
348#endif // DRUMSTICK_ALSACLIENT_H
Classes managing ALSA Sequencer ports.
The QObject class is the base class of all Qt objects.
Client information.
Definition: alsaclient.h:61
This class manages event input from the ALSA sequencer.
Definition: alsaclient.cpp:188
Client management.
Definition: alsaclient.h:209
void eventReceived(drumstick::ALSA::SequencerEvent *ev)
Signal emitted when an event is received.
Port management.
Definition: alsaport.h:115
Queue management.
Definition: alsaqueue.h:191
Sequencer Pool information.
Definition: alsaclient.h:149
Auxiliary class to remove events from an ALSA queue.
Definition: alsaevent.h:740
Sequencer events handler.
Definition: alsaclient.h:186
virtual ~SequencerEventHandler()=default
Destructor.
virtual void handleSequencerEvent(SequencerEvent *ev)=0
Callback function to be implemented by the derived class.
Base class for the event's hierarchy.
Definition: alsaevent.h:58
System information.
Definition: alsaclient.h:118
int getRuntimeALSADriverNumber()
Gets the runtime ALSA drivers version number.
QString getRuntimeALSADriverVersion()
Gets the runtime ALSA drivers version string.
QList< ClientInfo > ClientInfoList
List of sequencer client information.
Definition: alsaclient.h:109
QString getDrumstickLibraryVersion()
getDrumstickLibraryVersion provides the Drumstick version as an edited QString
QString getCompiledALSALibraryVersion()
ALSA library version at build time.
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition: alsaport.h:210
QList< PortInfo > PortInfoList
List of port information objects.
Definition: alsaport.h:107
Drumstick visibility macros.
Drumstick common.
Definition: alsaclient.cpp:68