drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
alsaclient.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2023, 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
35#if defined(DRUMSTICK_STATIC)
36#define DRUMSTICK_ALSA_EXPORT
37#else
38#if defined(drumstick_alsa_EXPORTS)
39#define DRUMSTICK_ALSA_EXPORT Q_DECL_EXPORT
40#else
41#define DRUMSTICK_ALSA_EXPORT Q_DECL_IMPORT
42#endif
43#endif
44
48namespace drumstick {
53namespace ALSA {
54
55class MidiQueue;
56class MidiClient;
57class SequencerEvent;
58class RemoveEvents;
59
70class DRUMSTICK_ALSA_EXPORT ClientInfo
71{
72 friend class MidiClient;
73
74public:
75 ClientInfo();
76 ClientInfo(const ClientInfo &other);
77 explicit ClientInfo(snd_seq_client_info_t *other);
78 ClientInfo(MidiClient* seq, int id);
79 virtual ~ClientInfo();
80 ClientInfo* clone();
81 ClientInfo& operator=(const ClientInfo &other);
82 int getSizeOfInfo() const;
83
84 int getClientId();
85 snd_seq_client_type_t getClientType();
86 QString getName();
87 bool getBroadcastFilter();
88 bool getErrorBounce();
89 int getNumPorts();
90 int getEventLost();
91 void setClient(int client);
92 void setName(QString name);
93 void setBroadcastFilter(bool val);
94 void setErrorBounce(bool val);
95 PortInfoList getPorts() const;
96
97#if SND_LIB_VERSION > 0x010010
98 void addFilter(int eventType);
99 bool isFiltered(int eventType);
100 void clearFilter();
101 void removeFilter(int eventType);
102#endif
103
104protected:
105 void readPorts(MidiClient* seq);
106 void freePorts();
107
108 Q_DECL_DEPRECATED const unsigned char* getEventFilter();
109 Q_DECL_DEPRECATED void setEventFilter(unsigned char* filter);
110
111private:
112 snd_seq_client_info_t* m_Info;
113 PortInfoList m_Ports;
114};
115
119typedef QList<ClientInfo> ClientInfoList;
120
127class DRUMSTICK_ALSA_EXPORT SystemInfo
128{
129 friend class MidiClient;
130
131public:
132 SystemInfo();
133 SystemInfo(const SystemInfo& other);
134 explicit SystemInfo(snd_seq_system_info_t* other);
135 explicit SystemInfo(MidiClient* seq);
136 virtual ~SystemInfo();
137 SystemInfo* clone();
138 SystemInfo& operator=(const SystemInfo& other);
139 int getSizeOfInfo() const;
140
141 int getMaxClients();
142 int getMaxPorts();
143 int getMaxQueues();
144 int getMaxChannels();
145 int getCurrentQueues();
146 int getCurrentClients();
147
148private:
149 snd_seq_system_info_t* m_Info;
150};
151
158class DRUMSTICK_ALSA_EXPORT PoolInfo
159{
160 friend class MidiClient;
161
162public:
163 PoolInfo();
164 PoolInfo(const PoolInfo& other);
165 explicit PoolInfo(snd_seq_client_pool_t* other);
166 explicit PoolInfo(MidiClient* seq);
167 virtual ~PoolInfo();
168 PoolInfo* clone();
169 PoolInfo& operator=(const PoolInfo& other);
170 int getSizeOfInfo() const;
171
172 int getClientId();
173 int getInputFree();
174 int getInputPool();
175 int getOutputFree();
176 int getOutputPool();
177 int getOutputRoom();
178 void setInputPool(int size);
179 void setOutputPool(int size);
180 void setOutputRoom(int size);
181
182private:
183 snd_seq_client_pool_t* m_Info;
184};
185
195class DRUMSTICK_ALSA_EXPORT SequencerEventHandler
196{
197public:
199 virtual ~SequencerEventHandler() = default;
200
211};
212
218class DRUMSTICK_ALSA_EXPORT MidiClient : public QObject
219{
220 Q_OBJECT
221public:
222 explicit MidiClient( QObject* parent = nullptr );
223 virtual ~MidiClient();
224
225 void open( const QString deviceName = "default",
226 const int openMode = SND_SEQ_OPEN_DUPLEX,
227 const bool blockMode = false );
228 void open( snd_config_t* conf,
229 const QString deviceName = "default",
230 const int openMode = SND_SEQ_OPEN_DUPLEX,
231 const bool blockMode = false );
232 void close();
233 void startSequencerInput();
234 void stopSequencerInput();
235 MidiPort* createPort();
236 MidiQueue* createQueue();
237 MidiQueue* createQueue(QString const& name);
238 MidiQueue* getQueue();
239 MidiQueue* useQueue(int queue_id);
240 MidiQueue* useQueue(const QString& name);
241 MidiQueue* useQueue(MidiQueue* queue);
242 void portAttach(MidiPort* port);
243 void portDetach(MidiPort* port);
244 void detachAllPorts();
245 void addEventFilter(int evtype);
246 void output(SequencerEvent* ev, bool async = false, int timeout = -1);
247 void outputDirect(SequencerEvent* ev, bool async = false, int timeout = -1);
248 void outputBuffer(SequencerEvent* ev);
249 void drainOutput(bool async = false, int timeout = -1);
250 void synchronizeOutput();
251
252 int getClientId();
253 snd_seq_type_t getSequencerType();
254 snd_seq_t* getHandle();
255 bool isOpened();
256
257 size_t getOutputBufferSize();
258 void setOutputBufferSize(size_t newSize);
259 size_t getInputBufferSize();
260 void setInputBufferSize(size_t newSize);
261 QString getDeviceName();
262 int getOpenMode();
263 bool getBlockMode();
264 void setBlockMode(bool newValue);
265 QString getClientName();
266 QString getClientName(const int clientId);
267 void setClientName(QString const& newName);
268 bool getBroadcastFilter();
269 void setBroadcastFilter(bool newValue);
270 bool getErrorBounce();
271 void setErrorBounce(bool newValue);
272
273 ClientInfo& getThisClientInfo();
274 void setThisClientInfo(const ClientInfo& val);
275 MidiPortList getMidiPorts() const;
276 ClientInfoList getAvailableClients();
277 PortInfoList getAvailableInputs();
278 PortInfoList getAvailableOutputs();
279 SystemInfo& getSystemInfo();
280 QList<int> getAvailableQueues();
281
282 PoolInfo& getPoolInfo();
283 void setPoolInfo(const PoolInfo& info);
284 void setPoolInput(int size);
285 void setPoolOutput(int size);
286 void setPoolOutputRoom(int size);
287 void resetPoolInput();
288 void resetPoolOutput();
289 void dropInput();
290 void dropInputBuffer();
291 void dropOutput();
292 void dropOutputBuffer();
293 void removeEvents(const RemoveEvents* spec);
294 SequencerEvent* extractOutput();
295 int outputPending();
296 int inputPending(bool fetch);
297 int getQueueId(const QString& name);
298
299 void addListener(QObject* listener);
300 void removeListener(QObject* listener);
301 void setEventsEnabled(const bool bEnabled);
302 bool getEventsEnabled() const;
303 void setHandler(SequencerEventHandler* handler);
304 bool parseAddress( const QString& straddr, snd_seq_addr& result );
305 void setRealTimeInput(bool enabled);
306 bool realTimeInputEnabled();
307
308Q_SIGNALS:
313
314protected:
315 void doEvents();
316 void applyClientInfo();
317 void readClients();
318 void freeClients();
319 void updateAvailablePorts();
320 PortInfoList filterPorts(unsigned int filter);
321
322 /* low level public functions */
323 const char * _getDeviceName();
324 int getPollDescriptorsCount(short events);
325 int pollDescriptors(struct pollfd *pfds, unsigned int space, short events);
326 unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds);
327
328 /* mid level functions */
329 void _setClientName( const char *name );
330 int createSimplePort( const char *name,
331 unsigned int caps,
332 unsigned int type );
333 void deleteSimplePort( int port );
334 void connectFrom(int myport, int client, int port);
335 void connectTo(int myport, int client, int port);
336 void disconnectFrom(int myport, int client, int port);
337 void disconnectTo(int myport, int client, int port);
338
339private:
341 class MidiClientPrivate;
342 QScopedPointer<MidiClientPrivate> d;
343};
344
345#if SND_LIB_VERSION > 0x010004
346DRUMSTICK_ALSA_EXPORT QString getRuntimeALSALibraryVersion();
347DRUMSTICK_ALSA_EXPORT int getRuntimeALSALibraryNumber();
348#endif
349DRUMSTICK_ALSA_EXPORT QString getRuntimeALSADriverVersion();
350DRUMSTICK_ALSA_EXPORT int getRuntimeALSADriverNumber();
351DRUMSTICK_ALSA_EXPORT QString getCompiledALSALibraryVersion();
352DRUMSTICK_ALSA_EXPORT QString getDrumstickLibraryVersion();
353
356}} /* namespace drumstick::ALSA */
357
358#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:71
This class manages event input from the ALSA sequencer.
Definition: alsaclient.cpp:188
Client management.
Definition: alsaclient.h:219
void eventReceived(drumstick::ALSA::SequencerEvent *ev)
Signal emitted when an event is received.
Port management.
Definition: alsaport.h:125
Queue management.
Definition: alsaqueue.h:201
Sequencer Pool information.
Definition: alsaclient.h:159
Auxiliary class to remove events from an ALSA queue.
Definition: alsaevent.h:752
Sequencer events handler.
Definition: alsaclient.h:196
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:68
System information.
Definition: alsaclient.h:128
QString getDrumstickLibraryVersion()
getDrumstickLibraryVersion provides the Drumstick version as an edited QString
int getRuntimeALSADriverNumber()
Gets the runtime ALSA drivers version number.
QList< ClientInfo > ClientInfoList
List of sequencer client information.
Definition: alsaclient.h:119
QString getRuntimeALSADriverVersion()
Gets the runtime ALSA drivers version string.
QString getCompiledALSALibraryVersion()
ALSA library version at build time.
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition: alsaport.h:220
QList< PortInfo > PortInfoList
List of port information objects.
Definition: alsaport.h:117
Drumstick common.
Definition: alsaclient.cpp:68