drumstick  2.1.0
alsaport.h
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2021, 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 
25 namespace drumstick { namespace ALSA {
26 
32 class MidiClient;
33 
41 class DRUMSTICK_EXPORT PortInfo
42 {
43  friend class MidiPort;
44  friend class ClientInfo;
45  friend class MidiClient;
46 
47 public:
48  PortInfo();
49  PortInfo(const PortInfo& other);
50  explicit PortInfo(snd_seq_port_info_t* other);
51  PortInfo(MidiClient* seq, const int client, const int port);
52  PortInfo(MidiClient* seq, const int port);
53  virtual ~PortInfo();
54  PortInfo* clone();
55  PortInfo& operator=(const PortInfo& other);
56  int getSizeOfInfo() const;
57 
58  int getClient();
59  int getPort();
60  QString getClientName() const;
61  const snd_seq_addr_t* getAddr();
62  QString getName();
63  unsigned int getCapability();
64  unsigned int getType();
65  int getMidiChannels();
66  int getMidiVoices();
67  int getSynthVoices();
68  int getReadUse();
69  int getWriteUse();
70  int getPortSpecified();
71  void setClient(int client);
72  void setPort(int port);
73  void setAddr(const snd_seq_addr_t* addr);
74  void setName( QString const& name );
75  void setCapability(unsigned int capability);
76  void setType(unsigned int type);
77  void setMidiChannels(int channels);
78  void setMidiVoices(int voices);
79  void setSynthVoices(int voices);
80  void setPortSpecified(int val);
81  SubscribersList getReadSubscribers() const;
82  SubscribersList getWriteSubscribers() const;
83 
84  bool getTimestamping();
85  bool getTimestampReal();
86  int getTimestampQueue();
87  void setTimestamping(bool value);
88  void setTimestampReal(bool value);
89  void setTimestampQueue(int queueId);
90 
91 protected:
92  void readSubscribers(MidiClient* seq);
93  void freeSubscribers();
94  void setClientName(QString name);
95 
96 private:
97  snd_seq_port_info_t* m_Info;
98  QString m_ClientName;
99  SubscribersList m_ReadSubscribers;
100  SubscribersList m_WriteSubscribers;
101 };
102 
103 
107 typedef QList<PortInfo> PortInfoList;
108 
114 class DRUMSTICK_EXPORT MidiPort : public QObject
115 {
116  Q_OBJECT
117  friend class MidiClient;
118 
119 public:
120  explicit MidiPort( QObject* parent = nullptr );
121  virtual ~MidiPort();
122 
123  void attach( MidiClient* seq );
124  void detach();
125  void subscribe( Subscription* subs );
126  void unsubscribe( Subscription* subs );
127  void unsubscribeAll();
128  void unsubscribeTo( QString const& name );
129  void unsubscribeTo( PortInfo* port );
130  void unsubscribeTo( const snd_seq_addr_t* addr );
131  void unsubscribeFrom( QString const& name );
132  void unsubscribeFrom( PortInfo* port );
133  void unsubscribeFrom( const snd_seq_addr_t* addr );
134  void subscribeTo( PortInfo* port);
135  void subscribeTo( int client, int port );
136  void subscribeTo( QString const& name );
137  void subscribeFrom( PortInfo* port );
138  void subscribeFrom( int client, int port );
139  void subscribeFrom( QString const& name );
140  void subscribeFromAnnounce();
141  void updateSubscribers();
142  SubscriptionsList getSubscriptions() const;
143  PortInfoList getReadSubscribers();
144  PortInfoList getWriteSubscribers();
145  void updateConnectionsTo(const PortInfoList& desired);
146  void updateConnectionsFrom(const PortInfoList& desired);
147 
148  static bool containsAddress(const snd_seq_addr_t* addr, const PortInfoList& lst);
149 
150  void applyPortInfo();
151  QString getPortName();
152  void setPortName( QString const& newName);
153  int getPortId();
154  unsigned int getCapability();
155  void setCapability( unsigned int newValue);
156  unsigned int getPortType();
157  void setPortType( unsigned int newValue);
158  int getMidiChannels();
159  void setMidiChannels(int newValue);
160  int getMidiVoices();
161  void setMidiVoices(int newValue);
162  int getSynthVoices();
163  void setSynthVoices(int newValue);
164  bool getTimestamping();
165  bool getTimestampReal();
166  int getTimestampQueue();
167  void setTimestamping(bool value);
168  void setTimestampReal(bool value);
169  void setTimestampQueue(int queueId);
170 
171 signals:
194 
195 protected:
196  PortInfo* getPortInfo();
197  void freeSubscriptions();
198  void setMidiClient( MidiClient* seq );
199 
200 private:
201  MidiClient* m_MidiClient;
202  PortInfo m_Info;
203  bool m_Attached;
204  SubscriptionsList m_Subscriptions;
205 };
206 
210 typedef QList<MidiPort*> MidiPortList;
211 
214 }} /* namespace drumstick::ALSA */
215 
216 #endif //DRUMSTICK_ALSAPORT_H
The QObject class is the base class of all Qt objects.
Client information.
Definition: alsaclient.h:61
Client management.
Definition: alsaclient.h:209
Port management.
Definition: alsaport.h:115
void detached(drumstick::ALSA::MidiPort *port)
Signal emitted when the port is detached from a MidiClient.
void attached(drumstick::ALSA::MidiPort *port)
Signal emitted when the port is attached to a MidiClient.
void subscribed(drumstick::ALSA::MidiPort *port, drumstick::ALSA::Subscription *subs)
Signal emitted when an internal subscription is done.
void midiClientChanged(drumstick::ALSA::MidiPort *port, drumstick::ALSA::MidiClient *seq)
Signal emitted when the MidiClient has changed.
Port information container.
Definition: alsaport.h:42
Subscription management.
Definition: subscription.h:87
QList< MidiPort * > MidiPortList
List of Ports instances.
Definition: alsaport.h:210
QList< PortInfo > PortInfoList
List of port information objects.
Definition: alsaport.h:107
QList< Subscription > SubscriptionsList
List of subscriptions.
Definition: subscription.h:123
QList< Subscriber > SubscribersList
List of subscribers.
Definition: subscription.h:128
Drumstick common.
Definition: alsaclient.cpp:68
Classes managing ALSA sequencer subscriptions.