drumstick 0.5.0
alsaclient.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2010, 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 2 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 along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18*/
19
20#ifndef DRUMSTICK_ALSACLIENT_H
21#define DRUMSTICK_ALSACLIENT_H
22
23#include "alsaport.h"
24#include <QPointer>
25#include <QThread>
26#include <QReadWriteLock>
27
36namespace drumstick {
37
38class MidiQueue;
39class MidiClient;
40class SequencerEvent;
41class SequencerInputThread;
42class RemoveEvents;
43
50class DRUMSTICK_EXPORT ClientInfo
51{
52 friend class MidiClient;
53
54public:
55 ClientInfo();
56 ClientInfo(const ClientInfo& other);
57 ClientInfo(snd_seq_client_info_t* other);
58 ClientInfo(MidiClient* seq, int id);
59 virtual ~ClientInfo();
60 ClientInfo* clone();
61 ClientInfo& operator=(const ClientInfo& other);
62 int getSizeOfInfo() const;
63
64 int getClientId();
65 snd_seq_client_type_t getClientType();
66 QString getName();
67 bool getBroadcastFilter();
68 bool getErrorBounce();
69 int getNumPorts();
70 int getEventLost();
71 void setClient(int client);
72 void setName(QString name);
73 void setBroadcastFilter(bool val);
74 void setErrorBounce(bool val);
75 PortInfoList getPorts() const;
76
77#if SND_LIB_VERSION > 0x010010
78 void addFilter(int eventType);
79 bool isFiltered(int eventType);
80 void clearFilter();
81 void removeFilter(int eventType);
82#endif
83
84protected:
85 void readPorts(MidiClient* seq);
86 void freePorts();
87
88 const unsigned char* getEventFilter() __attribute__((deprecated));
89 void setEventFilter(unsigned char* filter) __attribute__((deprecated));
90
91private:
92 snd_seq_client_info_t* m_Info;
93 PortInfoList m_Ports;
94};
95
99typedef QList<ClientInfo> ClientInfoList;
100
107class DRUMSTICK_EXPORT SystemInfo
108{
109 friend class MidiClient;
110
111public:
112 SystemInfo();
113 SystemInfo(const SystemInfo& other);
114 SystemInfo(snd_seq_system_info_t* other);
116 virtual ~SystemInfo();
117 SystemInfo* clone();
118 SystemInfo& operator=(const SystemInfo& other);
119 int getSizeOfInfo() const;
120
121 int getMaxClients();
122 int getMaxPorts();
123 int getMaxQueues();
124 int getMaxChannels();
125 int getCurrentQueues();
126 int getCurrentClients();
127
128private:
129 snd_seq_system_info_t* m_Info;
130};
131
138class DRUMSTICK_EXPORT PoolInfo
139{
140 friend class MidiClient;
141
142public:
143 PoolInfo();
144 PoolInfo(const PoolInfo& other);
145 PoolInfo(snd_seq_client_pool_t* other);
146 PoolInfo(MidiClient* seq);
147 virtual ~PoolInfo();
148 PoolInfo* clone();
149 PoolInfo& operator=(const PoolInfo& other);
150 int getSizeOfInfo() const;
151
152 int getClientId();
153 int getInputFree();
154 int getInputPool();
155 int getOutputFree();
156 int getOutputPool();
157 int getOutputRoom();
158 void setInputPool(int size);
159 void setOutputPool(int size);
160 void setOutputRoom(int size);
161
162private:
163 snd_seq_client_pool_t* m_Info;
164};
165
175class DRUMSTICK_EXPORT SequencerEventHandler
176{
177public:
180
191};
192
198class DRUMSTICK_EXPORT MidiClient : public QObject
199{
200 Q_OBJECT
201public:
202 MidiClient( QObject* parent = 0 );
203 virtual ~MidiClient();
204
205 void open( const QString deviceName = "default",
206 const int openMode = SND_SEQ_OPEN_DUPLEX,
207 const bool blockMode = false );
208 void open( snd_config_t* conf,
209 const QString deviceName = "default",
210 const int openMode = SND_SEQ_OPEN_DUPLEX,
211 const bool blockMode = false );
212 void close();
213 void startSequencerInput();
214 void stopSequencerInput();
215 MidiPort* createPort();
216 MidiQueue* createQueue();
217 MidiQueue* createQueue(QString const& name);
218 MidiQueue* getQueue();
219 MidiQueue* useQueue(int queue_id);
220 MidiQueue* useQueue(const QString& name);
221 MidiQueue* useQueue(MidiQueue* queue);
222 void portAttach(MidiPort* port);
223 void portDetach(MidiPort* port);
224 void detachAllPorts();
225 void addEventFilter(int evtype);
226 void output(SequencerEvent* ev, bool async = false, int timeout = -1);
227 void outputDirect(SequencerEvent* ev, bool async = false, int timeout = -1);
228 void outputBuffer(SequencerEvent* ev);
229 void drainOutput(bool async = false, int timeout = -1);
230 void synchronizeOutput();
231
232 int getClientId();
233 snd_seq_type_t getSequencerType();
235 snd_seq_t* getHandle() { return m_SeqHandle; }
237 bool isOpened() { return (m_SeqHandle != NULL); }
238
239 size_t getOutputBufferSize();
240 void setOutputBufferSize(size_t newSize);
241 size_t getInputBufferSize();
242 void setInputBufferSize(size_t newSize);
244 QString getDeviceName() { return m_DeviceName; }
246 int getOpenMode() { return m_OpenMode; }
248 bool getBlockMode() { return m_BlockMode; }
249 void setBlockMode(bool newValue);
250 QString getClientName();
251 QString getClientName(const int clientId);
252 void setClientName(QString const& newName);
253 bool getBroadcastFilter();
254 void setBroadcastFilter(bool newValue);
255 bool getErrorBounce();
256 void setErrorBounce(bool newValue);
257
258 ClientInfo& getThisClientInfo();
259 void setThisClientInfo(const ClientInfo& val);
260 MidiPortList getMidiPorts() const;
261 ClientInfoList getAvailableClients();
262 PortInfoList getAvailableInputs();
263 PortInfoList getAvailableOutputs();
264 SystemInfo& getSystemInfo();
265 QList<int> getAvailableQueues();
266
267 PoolInfo& getPoolInfo();
268 void setPoolInfo(const PoolInfo& info);
269 void setPoolInput(int size);
270 void setPoolOutput(int size);
271 void setPoolOutputRoom(int size);
272 void resetPoolInput();
273 void resetPoolOutput();
274 void dropInput();
275 void dropInputBuffer();
276 void dropOutput();
277 void dropOutputBuffer();
278 void removeEvents(const RemoveEvents* spec);
279 SequencerEvent* extractOutput();
280 int outputPending();
281 int inputPending(bool fetch);
282 int getQueueId(const QString& name);
283
284 void addListener(QObject* listener);
285 void removeListener(QObject* listener);
286 void setEventsEnabled(const bool bEnabled);
288 bool getEventsEnabled() const { return m_eventsEnabled; }
290 void setHandler(SequencerEventHandler* handler) { m_handler = handler; }
291 bool parseAddress( const QString& straddr, snd_seq_addr& result );
292 void setRealTimeInput(bool enabled);
293 bool realTimeInputEnabled();
294
295signals:
298
299protected:
300 void doEvents();
301 void applyClientInfo();
302 void readClients();
303 void freeClients();
304 void updateAvailablePorts();
305 PortInfoList filterPorts(unsigned int filter);
306
307 /* low level public functions */
308 const char * _getDeviceName();
309 int getPollDescriptorsCount(short events);
310 int pollDescriptors(struct pollfd *pfds, unsigned int space, short events);
311 unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds);
312
313 /* mid level functions */
314 void _setClientName( const char *name );
315 int createSimplePort( const char *name,
316 unsigned int caps,
317 unsigned int type );
318 void deleteSimplePort( int port );
319 void connectFrom(int myport, int client, int port);
320 void connectTo(int myport, int client, int port);
321 void disconnectFrom(int myport, int client, int port);
322 void disconnectTo(int myport, int client, int port);
323
324private:
326 bool m_eventsEnabled;
327 bool m_BlockMode;
328 bool m_NeedRefreshClientList;
329 int m_OpenMode;
330 QString m_DeviceName;
331 snd_seq_t* m_SeqHandle;
332 QPointer<SequencerInputThread> m_Thread;
333 QPointer<MidiQueue> m_Queue;
334 SequencerEventHandler* m_handler;
335
336 ClientInfo m_Info;
337 ClientInfoList m_ClientList;
338 MidiPortList m_Ports;
339 PortInfoList m_OutputsAvail;
340 PortInfoList m_InputsAvail;
341 QObjectList m_listeners;
342 SystemInfo m_sysInfo;
343 PoolInfo m_poolInfo;
344};
345
346#if SND_LIB_VERSION > 0x010004
347DRUMSTICK_EXPORT QString getRuntimeALSALibraryVersion();
348DRUMSTICK_EXPORT int getRuntimeALSALibraryNumber();
349#endif
350DRUMSTICK_EXPORT QString getRuntimeALSADriverVersion();
351DRUMSTICK_EXPORT int getRuntimeALSADriverNumber();
352
353} /* namespace drumstick */
354
357#endif // DRUMSTICK_ALSACLIENT_H
QList< ClientInfo > ClientInfoList
List of sequencer client information.
Definition: alsaclient.h:99
DRUMSTICK_EXPORT QString getRuntimeALSADriverVersion()
Gets the runtime ALSA drivers version string.
DRUMSTICK_EXPORT int getRuntimeALSADriverNumber()
Gets the runtime ALSA drivers version number.
Classes managing ALSA Sequencer ports.
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition: alsaport.h:215
QList< PortInfo > PortInfoList
List of port information objects.
Definition: alsaport.h:112
The QObject class is the base class of all Qt objects.
Client information.
Definition: alsaclient.h:51
This class manages event input from the ALSA sequencer.
Definition: alsaclient.cpp:330
Client management.
Definition: alsaclient.h:199
QString getDeviceName()
Returns the name of the sequencer device.
Definition: alsaclient.h:244
bool getEventsEnabled() const
Returns true if the events mode of delivery has been enabled.
Definition: alsaclient.h:288
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
Definition: alsaclient.h:235
int getOpenMode()
Returns the last open mode used in open()
Definition: alsaclient.h:246
void setHandler(SequencerEventHandler *handler)
Sets a sequencer event handler enabling the callback delivery mode.
Definition: alsaclient.h:290
void eventReceived(SequencerEvent *ev)
Signal emitted when an event is received.
bool getBlockMode()
Returns the last block mode used in open()
Definition: alsaclient.h:248
bool isOpened()
Returns true if the sequencer is opened.
Definition: alsaclient.h:237
Port management.
Definition: alsaport.h:120
Queue management.
Definition: alsaqueue.h:189
Sequencer Pool information.
Definition: alsaclient.h:139
Auxiliary class to remove events from an ALSA queue.
Definition: alsaevent.h:587
Sequencer events handler.
Definition: alsaclient.h:176
virtual ~SequencerEventHandler()
Destructor.
Definition: alsaclient.h:179
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:54
System information.
Definition: alsaclient.h:108