drumstick 2.10.0
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:
205
206protected:
208 void freeSubscriptions();
209 void setMidiClient( MidiClient* seq );
210
211private:
212 MidiClient* m_MidiClient;
213 PortInfo m_Info;
214 bool m_Attached;
215 SubscriptionsList m_Subscriptions;
216};
217
221typedef QList<MidiPort*> MidiPortList;
222
224
225}} /* namespace drumstick::ALSA */
226
227#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:923
void freeSubscriptions()
Releases the lists of subscriptions.
Definition alsaport.cpp:616
void detached(drumstick::ALSA::MidiPort *port)
Signal emitted when the port is detached from a MidiClient.
MidiPort(QObject *parent=nullptr)
Constructor.
Definition alsaport.cpp:574
void subscribeTo(PortInfo *port)
Subscribe to another port destination.
Definition alsaport.cpp:684
void updateConnectionsTo(const PortInfoList &desired)
Update the write subscriptions.
void unsubscribeAll()
Unsubscribe all subscriptions.
Definition alsaport.cpp:892
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:733
void subscribe(Subscription *subs)
Subscribe a Subscription object.
Definition alsaport.cpp:641
void subscribeFrom(PortInfo *port)
Subscribe a source port.
Definition alsaport.cpp:784
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:933
unsigned int getPortType()
Gets the port type.
Definition alsaport.cpp:978
int getMidiVoices()
Gets the MIDI voices.
void unsubscribe(Subscription *subs)
Unsubscribe a Subscription object.
Definition alsaport.cpp:656
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:989
PortInfoList getReadSubscribers()
Gets the list of read subscribers.
int getMidiChannels()
Gets the MIDI channels.
void setCapability(unsigned int newValue)
Sets the port capabilities.
Definition alsaport.cpp:966
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:883
void setTimestamping(bool value)
Sets the timestamping mode.
void setMidiClient(MidiClient *seq)
Sets the MidiClient.
Definition alsaport.cpp:626
int getSynthVoices()
Gets the synth voices.
int getPortId()
Gets the port number.
Definition alsaport.cpp:944
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:833
PortInfo * getPortInfo()
Gets the PortInfo object pointer.
Definition alsaport.cpp:597
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:955
void setTimestampQueue(int queueId)
Sets the timestamp queue number.
SubscriptionsList getSubscriptions() const
Gets the list of susbcriptions.
Definition alsaport.cpp:607
void applyPortInfo()
Applies all the the delayed PortInfo changes to the MIDI port object.
Definition alsaport.cpp:909
Port information container.
Definition alsaport.h:52
void freeSubscribers()
Releases the subscribers lists.
Definition alsaport.cpp:477
int getSizeOfInfo() const
Gets the size of the ALSA info object.
Definition alsaport.cpp:498
void setCapability(unsigned int capability)
Sets the capability bitmap.
Definition alsaport.cpp:345
int getWriteUse()
Gets the number of write subscriptions.
Definition alsaport.cpp:268
int getPortSpecified()
Gets the port-specified mode.
Definition alsaport.cpp:279
QString getClientName() const
Gets the client name.
Definition alsaport.cpp:171
int getReadUse()
Get the number of read subscriptions.
Definition alsaport.cpp:258
unsigned int getType()
Gets the port type.
Definition alsaport.cpp:215
void setType(unsigned int type)
Sets the port type.
Definition alsaport.cpp:372
SubscribersList getReadSubscribers() const
Gets the list of read subscribers.
Definition alsaport.cpp:426
void readSubscribers(MidiClient *seq)
Obtains the port subscribers lists.
Definition alsaport.cpp:446
bool getTimestamping()
Gets the timestamping mode.
Definition alsaport.cpp:509
void setMidiVoices(int voices)
Sets the MIDI voices.
Definition alsaport.cpp:394
int getClient()
Gets the client number.
Definition alsaport.cpp:150
const snd_seq_addr_t * getAddr()
Gets the address record for this port.
Definition alsaport.cpp:182
int getPort()
Gets the port number.
Definition alsaport.cpp:161
int getMidiVoices()
Gets the MIDI voices.
Definition alsaport.cpp:237
int getTimestampQueue()
Gets the timestamping queue number.
Definition alsaport.cpp:531
int getMidiChannels()
Gets the MIDI channels.
Definition alsaport.cpp:226
bool getTimestampReal()
Gets the timestamping real mode.
Definition alsaport.cpp:520
PortInfo & operator=(const PortInfo &other)
Assignment operator.
Definition alsaport.cpp:133
void setTimestamping(bool value)
Sets the timestamping mode.
Definition alsaport.cpp:542
PortInfo()
Default constructor.
Definition alsaport.cpp:59
void setClient(int client)
Sets the client number.
Definition alsaport.cpp:290
int getSynthVoices()
Gets the synth voices.
Definition alsaport.cpp:248
QString getName()
Gets the port name.
Definition alsaport.cpp:193
void setPortSpecified(int val)
Sets the port-specified mode.
Definition alsaport.cpp:416
void setMidiChannels(int channels)
Set the MIDI channels.
Definition alsaport.cpp:383
void setName(QString const &name)
Sets the port name.
Definition alsaport.cpp:323
PortInfo * clone()
Copy the current object.
Definition alsaport.cpp:123
SubscribersList getWriteSubscribers() const
Gets the list of write subscribers.
Definition alsaport.cpp:436
void setTimestampReal(bool value)
Sets the timestamping real mode.
Definition alsaport.cpp:553
unsigned int getCapability()
Gets the capabilities bitmap.
Definition alsaport.cpp:204
void setClientName(QString name)
Sets the client name.
Definition alsaport.cpp:488
void setTimestampQueue(int queueId)
Sets the timestamp queue number.
Definition alsaport.cpp:564
void setPort(int port)
Set the port number.
Definition alsaport.cpp:301
void setSynthVoices(int voices)
Sets the synth voices.
Definition alsaport.cpp:405
void setAddr(const snd_seq_addr_t *addr)
Sets the address record.
Definition alsaport.cpp:312
Subscription management.
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition alsaport.h:221
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.