drumstick 2.9.1
C++ MIDI libraries using Qt objects, idioms, and style.
alsaport.h
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2024, 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_ALSAPORT_H
20#define DRUMSTICK_ALSAPORT_H
21
22#include "subscription.h"
23#include <QObject>
24
25namespace drumstick { namespace ALSA {
26
31
32#if defined(DRUMSTICK_STATIC)
33#define DRUMSTICK_ALSA_EXPORT
34#else
35#if defined(drumstick_alsa_EXPORTS)
36#define DRUMSTICK_ALSA_EXPORT Q_DECL_EXPORT
37#else
38#define DRUMSTICK_ALSA_EXPORT Q_DECL_IMPORT
39#endif
40#endif
41
42class MidiClient;
43
51class DRUMSTICK_ALSA_EXPORT PortInfo
52{
53 friend class MidiPort;
54 friend class ClientInfo;
55 friend class MidiClient;
56
57public:
58 PortInfo();
59 PortInfo(const PortInfo& other);
60 explicit PortInfo(snd_seq_port_info_t* other);
61 PortInfo(MidiClient* seq, const int client, const int port);
62 PortInfo(MidiClient* seq, const int port);
63 virtual ~PortInfo();
64 PortInfo* clone();
65 PortInfo& operator=(const PortInfo& other);
66 int getSizeOfInfo() const;
67
68 int getClient();
69 int getPort();
70 QString getClientName() const;
71 const snd_seq_addr_t* getAddr();
72 QString getName();
73 unsigned int getCapability();
74 unsigned int getType();
75 int getMidiChannels();
76 int getMidiVoices();
77 int getSynthVoices();
78 int getReadUse();
79 int getWriteUse();
80 int getPortSpecified();
81 void setClient(int client);
82 void setPort(int port);
83 void setAddr(const snd_seq_addr_t* addr);
84 void setName( QString const& name );
85 void setCapability(unsigned int capability);
86 void setType(unsigned int type);
87 void setMidiChannels(int channels);
88 void setMidiVoices(int voices);
89 void setSynthVoices(int voices);
90 void setPortSpecified(int val);
93
94 bool getTimestamping();
95 bool getTimestampReal();
97 void setTimestamping(bool value);
98 void setTimestampReal(bool value);
99 void setTimestampQueue(int queueId);
100
101protected:
102 void readSubscribers(MidiClient* seq);
103 void freeSubscribers();
104 void setClientName(QString name);
105
106private:
107 snd_seq_port_info_t* m_Info;
108 QString m_ClientName;
109 SubscribersList m_ReadSubscribers;
110 SubscribersList m_WriteSubscribers;
111};
112
113
117typedef QList<PortInfo> PortInfoList;
118
124class DRUMSTICK_ALSA_EXPORT MidiPort : public QObject
125{
126 Q_OBJECT
127 friend class MidiClient;
128
129public:
130 explicit MidiPort( QObject* parent = nullptr );
131 virtual ~MidiPort();
132
133 void attach( MidiClient* seq );
134 void detach();
135 void subscribe( Subscription* subs );
136 void unsubscribe( Subscription* subs );
137 void unsubscribeAll();
138 void unsubscribeTo( QString const& name );
139 void unsubscribeTo( PortInfo* port );
140 void unsubscribeTo( const snd_seq_addr_t* addr );
141 void unsubscribeFrom( QString const& name );
142 void unsubscribeFrom( PortInfo* port );
143 void unsubscribeFrom( const snd_seq_addr_t* addr );
144 void subscribeTo( PortInfo* port);
145 void subscribeTo( int client, int port );
146 void subscribeTo( QString const& name );
147 void subscribeFrom( PortInfo* port );
148 void subscribeFrom( int client, int port );
149 void subscribeFrom( QString const& name );
151 void updateSubscribers();
155 void updateConnectionsTo(const PortInfoList& desired);
156 void updateConnectionsFrom(const PortInfoList& desired);
157
158 static bool containsAddress(const snd_seq_addr_t* addr, const PortInfoList& lst);
159
160 void applyPortInfo();
161 QString getPortName();
162 void setPortName( QString const& newName);
163 int getPortId();
164 unsigned int getCapability();
165 void setCapability( unsigned int newValue);
166 unsigned int getPortType();
167 void setPortType( unsigned int newValue);
168 int getMidiChannels();
169 void setMidiChannels(int newValue);
170 int getMidiVoices();
171 void setMidiVoices(int newValue);
172 int getSynthVoices();
173 void setSynthVoices(int newValue);
174 bool getTimestamping();
175 bool getTimestampReal();
176 int getTimestampQueue();
177 void setTimestamping(bool value);
178 void setTimestampReal(bool value);
179 void setTimestampQueue(int queueId);
180
181Q_SIGNALS:
204
205protected:
207 void freeSubscriptions();
208 void setMidiClient( MidiClient* seq );
209
210private:
211 MidiClient* m_MidiClient;
212 PortInfo m_Info;
213 bool m_Attached;
214 SubscriptionsList m_Subscriptions;
215};
216
220typedef QList<MidiPort*> MidiPortList;
221
223
224}} /* namespace drumstick::ALSA */
225
226#endif //DRUMSTICK_ALSAPORT_H
The QObject class is the base class of all Qt objects.
Client management.
Definition alsaclient.h:219
Port management.
Definition alsaport.h:125
QString getPortName()
Gets the port name.
Definition alsaport.cpp:918
void freeSubscriptions()
Releases the lists of subscriptions.
Definition alsaport.cpp:614
void detached(drumstick::ALSA::MidiPort *port)
Signal emitted when the port is detached from a MidiClient.
MidiPort(QObject *parent=nullptr)
Constructor.
Definition alsaport.cpp:572
void subscribeTo(PortInfo *port)
Subscribe to another port destination.
Definition alsaport.cpp:679
void updateConnectionsTo(const PortInfoList &desired)
Update the write subscriptions.
void unsubscribeAll()
Unsubscribe all subscriptions.
Definition alsaport.cpp:887
void attached(drumstick::ALSA::MidiPort *port)
Signal emitted when the port is attached to a MidiClient.
void unsubscribeTo(QString const &name)
Unsubscribe a destination port.
Definition alsaport.cpp:728
void subscribe(Subscription *subs)
Subscribe a Subscription object.
Definition alsaport.cpp:639
void subscribeFrom(PortInfo *port)
Subscribe a source port.
Definition alsaport.cpp:779
PortInfoList getWriteSubscribers()
Gets the list of write subscribers.
bool getTimestamping()
Gets the timestamping mode.
void updateConnectionsFrom(const PortInfoList &desired)
Update the read susbcriptions.
void setPortName(QString const &newName)
Sets the port name.
Definition alsaport.cpp:928
unsigned int getPortType()
Gets the port type.
Definition alsaport.cpp:973
int getMidiVoices()
Gets the MIDI voices.
void unsubscribe(Subscription *subs)
Unsubscribe a Subscription object.
Definition alsaport.cpp:651
int getTimestampQueue()
Gets the timestamp queue number.
void attach(MidiClient *seq)
Attach the port to a MidiClient instance.
void setPortType(unsigned int newValue)
Sets the port type bitmap.
Definition alsaport.cpp:984
PortInfoList getReadSubscribers()
Gets the list of read subscribers.
int getMidiChannels()
Gets the MIDI channels.
Definition alsaport.cpp:995
void setCapability(unsigned int newValue)
Sets the port capabilities.
Definition alsaport.cpp:961
bool getTimestampReal()
Gets the timestamp real mode.
static bool containsAddress(const snd_seq_addr_t *addr, const PortInfoList &lst)
Checks if the provided address is included in the port list.
void subscribeFromAnnounce()
Subscribe from the System:announce port.
Definition alsaport.cpp:878
void setTimestamping(bool value)
Sets the timestamping mode.
void setMidiClient(MidiClient *seq)
Sets the MidiClient.
Definition alsaport.cpp:624
int getSynthVoices()
Gets the synth voices.
int getPortId()
Gets the port number.
Definition alsaport.cpp:939
void setMidiVoices(int newValue)
Sets the MIDI voices.
void setMidiChannels(int newValue)
Sets the MIDI channels.
void updateSubscribers()
Update the subscribers list in the PortInfo member.
void detach()
Detach the port from any MidiClient instance previously attached.
void setSynthVoices(int newValue)
Sets the synth voices.
void subscribed(drumstick::ALSA::MidiPort *port, drumstick::ALSA::Subscription *subs)
Signal emitted when an internal subscription is done.
void unsubscribeFrom(QString const &name)
Unsubscribe a source port.
Definition alsaport.cpp:828
PortInfo * getPortInfo()
Gets the PortInfo object pointer.
Definition alsaport.cpp:595
void midiClientChanged(drumstick::ALSA::MidiPort *port, drumstick::ALSA::MidiClient *seq)
Signal emitted when the MidiClient has changed.
void setTimestampReal(bool value)
Sets the timestamp real mode.
unsigned int getCapability()
Gets the port capabilities.
Definition alsaport.cpp:950
void setTimestampQueue(int queueId)
Sets the timestamp queue number.
SubscriptionsList getSubscriptions() const
Gets the list of susbcriptions.
Definition alsaport.cpp:605
void applyPortInfo()
Applies all the the delayed PortInfo changes to the MIDI port object.
Definition alsaport.cpp:904
Port information container.
Definition alsaport.h:52
void freeSubscribers()
Releases the subscribers lists.
Definition alsaport.cpp:475
int getSizeOfInfo() const
Gets the size of the ALSA info object.
Definition alsaport.cpp:496
void setCapability(unsigned int capability)
Sets the capability bitmap.
Definition alsaport.cpp:343
int getWriteUse()
Gets the number of write subscriptions.
Definition alsaport.cpp:266
int getPortSpecified()
Gets the port-specified mode.
Definition alsaport.cpp:277
QString getClientName() const
Gets the client name.
Definition alsaport.cpp:169
int getReadUse()
Get the number of read subscriptions.
Definition alsaport.cpp:256
unsigned int getType()
Gets the port type.
Definition alsaport.cpp:213
void setType(unsigned int type)
Sets the port type.
Definition alsaport.cpp:370
SubscribersList getReadSubscribers() const
Gets the list of read subscribers.
Definition alsaport.cpp:424
void readSubscribers(MidiClient *seq)
Obtains the port subscribers lists.
Definition alsaport.cpp:444
bool getTimestamping()
Gets the timestamping mode.
Definition alsaport.cpp:507
void setMidiVoices(int voices)
Sets the MIDI voices.
Definition alsaport.cpp:392
int getClient()
Gets the client number.
Definition alsaport.cpp:148
const snd_seq_addr_t * getAddr()
Gets the address record for this port.
Definition alsaport.cpp:180
int getPort()
Gets the port number.
Definition alsaport.cpp:159
int getMidiVoices()
Gets the MIDI voices.
Definition alsaport.cpp:235
int getTimestampQueue()
Gets the timestamping queue number.
Definition alsaport.cpp:529
int getMidiChannels()
Gets the MIDI channels.
Definition alsaport.cpp:224
bool getTimestampReal()
Gets the timestamping real mode.
Definition alsaport.cpp:518
PortInfo & operator=(const PortInfo &other)
Assignment operator.
Definition alsaport.cpp:131
void setTimestamping(bool value)
Sets the timestamping mode.
Definition alsaport.cpp:540
PortInfo()
Default constructor.
Definition alsaport.cpp:57
void setClient(int client)
Sets the client number.
Definition alsaport.cpp:288
int getSynthVoices()
Gets the synth voices.
Definition alsaport.cpp:246
QString getName()
Gets the port name.
Definition alsaport.cpp:191
void setPortSpecified(int val)
Sets the port-specified mode.
Definition alsaport.cpp:414
void setMidiChannels(int channels)
Set the MIDI channels.
Definition alsaport.cpp:381
void setName(QString const &name)
Sets the port name.
Definition alsaport.cpp:321
PortInfo * clone()
Copy the current object.
Definition alsaport.cpp:121
SubscribersList getWriteSubscribers() const
Gets the list of write subscribers.
Definition alsaport.cpp:434
void setTimestampReal(bool value)
Sets the timestamping real mode.
Definition alsaport.cpp:551
unsigned int getCapability()
Gets the capabilities bitmap.
Definition alsaport.cpp:202
void setClientName(QString name)
Sets the client name.
Definition alsaport.cpp:486
void setTimestampQueue(int queueId)
Sets the timestamp queue number.
Definition alsaport.cpp:562
void setPort(int port)
Set the port number.
Definition alsaport.cpp:299
void setSynthVoices(int voices)
Sets the synth voices.
Definition alsaport.cpp:403
void setAddr(const snd_seq_addr_t *addr)
Sets the address record.
Definition alsaport.cpp:310
Subscription management.
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition alsaport.h:220
QList< PortInfo > PortInfoList
List of port information objects.
Definition alsaport.h:117
QList< Subscription > SubscriptionsList
List of subscriptions.
QList< Subscriber > SubscribersList
List of subscribers.
Drumstick ALSA library wrapper.
Drumstick common.
Classes managing ALSA sequencer subscriptions.