drumstick  2.0.0
subscription.cpp
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2020, 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 #include "errorcheck.h"
20 #include <drumstick/alsaclient.h>
27 namespace drumstick {
28 namespace ALSA {
29 
55 {
56  snd_seq_query_subscribe_malloc(&m_Info);
57 }
58 
64 {
65  snd_seq_query_subscribe_malloc(&m_Info);
66  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
67 }
68 
73 Subscriber::Subscriber(snd_seq_query_subscribe_t* other)
74 {
75  snd_seq_query_subscribe_malloc(&m_Info);
76  snd_seq_query_subscribe_copy(m_Info, other);
77 }
78 
83 {
84  snd_seq_query_subscribe_free(m_Info);
85 }
86 
92 {
93  return new Subscriber(m_Info);
94 }
95 
102 {
103  if (this == &other)
104  return *this;
105  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
106  return *this;
107 }
108 
113 int
115 {
116  return snd_seq_query_subscribe_get_client(m_Info);
117 }
118 
123 int
125 {
126  return snd_seq_query_subscribe_get_port(m_Info);
127 }
128 
133 const snd_seq_addr_t*
135 {
136  return snd_seq_query_subscribe_get_root(m_Info);
137 }
138 
147 snd_seq_query_subs_type_t
149 {
150  return snd_seq_query_subscribe_get_type(m_Info);
151 }
152 
157 int
159 {
160  return snd_seq_query_subscribe_get_index(m_Info);
161 }
162 
167 int
169 {
170  return snd_seq_query_subscribe_get_num_subs(m_Info);
171 }
172 
177 const snd_seq_addr_t*
179 {
180  return snd_seq_query_subscribe_get_addr(m_Info);
181 }
182 
187 int
189 {
190  return snd_seq_query_subscribe_get_queue(m_Info);
191 }
192 
197 bool
199 {
200  return (snd_seq_query_subscribe_get_exclusive(m_Info) != 0);
201 }
202 
207 bool
209 {
210  return (snd_seq_query_subscribe_get_time_update(m_Info) != 0);
211 }
212 
217 bool
219 {
220  return (snd_seq_query_subscribe_get_time_real(m_Info) != 0);
221 }
222 
227 void
229 {
230  snd_seq_query_subscribe_set_client(m_Info, client);
231 }
232 
237 void
239 {
240  snd_seq_query_subscribe_set_port(m_Info, port);
241 }
242 
247 void
248 Subscriber::setRoot(snd_seq_addr_t* addr)
249 {
250  snd_seq_query_subscribe_set_root(m_Info, addr);
251 }
252 
261 void
262 Subscriber::setType(snd_seq_query_subs_type_t type)
263 {
264  snd_seq_query_subscribe_set_type(m_Info, type);
265 }
266 
271 void
273 {
274  snd_seq_query_subscribe_set_index(m_Info, index);
275 }
276 
281 int
283 {
284  return snd_seq_query_subscribe_sizeof();
285 }
286 
291 {
292  snd_seq_port_subscribe_malloc(&m_Info);
293 }
294 
300 {
301  snd_seq_port_subscribe_malloc(&m_Info);
302  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
303 }
304 
309 Subscription::Subscription(snd_seq_port_subscribe_t* other)
310 {
311  snd_seq_port_subscribe_malloc(&m_Info);
312  snd_seq_port_subscribe_copy(m_Info, other);
313 }
314 
320 {
321  snd_seq_port_subscribe_malloc(&m_Info);
322  DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_get_port_subscription(seq->getHandle(), m_Info));
323 }
324 
330 {
331  snd_seq_port_subscribe_free(m_Info);
332 }
333 
340 {
341  return new Subscription(m_Info);
342 }
343 
351 {
352  if (this == &other)
353  return *this;
354  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
355  return *this;
356 }
357 
362 const snd_seq_addr_t*
364 {
365  return snd_seq_port_subscribe_get_sender(m_Info);
366 }
367 
372 const snd_seq_addr_t*
374 {
375  return snd_seq_port_subscribe_get_dest(m_Info);
376 }
377 
382 int
384 {
385  return snd_seq_port_subscribe_get_queue(m_Info);
386 }
387 
392 bool
394 {
395  return (snd_seq_port_subscribe_get_exclusive(m_Info) != 0);
396 }
397 
402 bool
404 {
405  return (snd_seq_port_subscribe_get_time_update(m_Info) != 0);
406 }
407 
412 bool
414 {
415  return (snd_seq_port_subscribe_get_time_real(m_Info) != 0);
416 }
417 
422 void
423 Subscription::setSender(const snd_seq_addr_t* addr)
424 {
425  snd_seq_port_subscribe_set_sender(m_Info, addr);
426 }
427 
432 void
433 Subscription::setDest(const snd_seq_addr_t* addr)
434 {
435  snd_seq_port_subscribe_set_dest(m_Info, addr);
436 }
437 
442 void
444 {
445  snd_seq_port_subscribe_set_queue(m_Info, q);
446 }
447 
452 void
454 {
455  snd_seq_port_subscribe_set_exclusive(m_Info, val?1:0);
456 }
457 
462 void
464 {
465  snd_seq_port_subscribe_set_time_update(m_Info, val?1:0);
466 }
467 
472 void
474 {
475  snd_seq_port_subscribe_set_time_real(m_Info, val?1:0);
476 }
477 
483 void
484 Subscription::setSender(unsigned char client, unsigned char port)
485 {
486  snd_seq_addr_t addr;
487  addr.client = client;
488  addr.port = port;
489  setSender(&addr);
490 }
491 
497 void
498 Subscription::setDest(unsigned char client, unsigned char port)
499 {
500  snd_seq_addr_t addr;
501  addr.client = client;
502  addr.port = port;
503  setDest(&addr);
504 }
505 
512 void
514 {
515  if ((m_Info == nullptr) || (seq == nullptr) || !(seq->isOpened()))
516  {
517  return;
518  }
519  DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_subscribe_port(seq->getHandle(), m_Info));
520 }
521 
528 void
530 {
531  if ((m_Info == nullptr) || (seq == nullptr) || !(seq->isOpened()))
532  {
533  return;
534  }
535  DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_unsubscribe_port(seq->getHandle(), m_Info));
536 }
537 
542 int
544 {
545  return snd_seq_port_subscribe_sizeof();
546 }
547 
548 } // namespace ALSA
549 } // namespace drumstick
550 
Error checking functions and macros.
void setDest(unsigned char client, unsigned char port)
Sets the Subscription&#39;s destination (MIDI IN) port.
Classes managing ALSA Sequencer clients.
Subscription management.
Definition: subscription.h:86
Subscriber()
Default constructor.
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
Definition: alsaclient.cpp:284
#define DRUMSTICK_ALSA_CHECK_WARNING(x)
This macro calls the check warning function.
Definition: errorcheck.h:86
Subscriber container class.
Definition: subscription.h:47
void setType(snd_seq_query_subs_type_t type)
Sets the subscription type.
bool getExclusive()
Gets the subscription&#39;s exclusive flag.
void setPort(int port)
Sets the subscriber&#39;s port number.
snd_seq_query_subs_type_t getType()
Gets the subscription type (read or write).
void setTimeReal(bool val)
Sets the subscription&#39;s time real (time-stamping) flag.
bool getTimeUpdate()
Gets the susbcription&#39;s time-update flag.
void unsubscribe(MidiClient *seq)
Breaks the subscription in the ALSA sequencer subsystem.
const snd_seq_addr_t * getAddr()
Gets the subscriber&#39;s address.
int getSizeOfInfo() const
Gets the size of the ALSA query subscriber object.
int getNumSubs()
Gets the number of subscribers returned by a query operation.
int getQueue()
Gets the subscriber&#39;s queue number.
int getIndex()
Gets the index of the subscriber container.
Drumstick common.
Definition: alsaclient.cpp:68
int getPort()
Gets the subscriober&#39;s port number.
void setSender(unsigned char client, unsigned char port)
Sets the Subscription&#39;s sender (MIDI OUT) port.
Subscription & operator=(const Subscription &other)
Assignment operator.
virtual ~Subscription()
Destructor.
int getQueue()
Gets the susbcription&#39;s queue number.
void setQueue(int queue)
Sets the Subscription&#39;s Queue number.
Subscriber * clone()
Copy the current object.
Subscriber & operator=(const Subscriber &other)
Assignment operator.
bool getTimeReal()
Gets the subscriber&#39;s time real time-stamp flag.
int getSizeOfInfo() const
Gets the size of the ALSA subscription object.
void subscribe(MidiClient *seq)
Performs the subscription in the ALSA sequencer subsystem.
Subscription()
Default constructor.
bool isOpened()
Returns true if the sequencer is opened.
Definition: alsaclient.cpp:293
void setExclusive(bool val)
Sets the subscription&#39;s exclusive flag.
void setIndex(int index)
Sets the index of the subscriber.
Subscription * clone()
Copy the current object.
const snd_seq_addr_t * getDest()
Gets the destination address of the subscription (MIDI IN port)
const snd_seq_addr_t * getRoot()
Gets the subscriber&#39;s root address.
bool getTimeUpdate()
Gets the susbcriber&#39;s time-update flag.
bool getExclusive()
Gets the subscriber&#39;s exclusive flag.
virtual ~Subscriber()
Destructor.
bool getTimeReal()
Gets the susbcription&#39;s time-real (time-stamping) flag.
void setClient(int client)
Sets the subscriber&#39;s client number.
const snd_seq_addr_t * getSender()
Gets the sender address of the subscription (MIDI OUT port)
int getClient()
Gets the subscriber&#39;s client number.
Client management.
Definition: alsaclient.h:208
void setRoot(snd_seq_addr_t *addr)
Sets the subscriber&#39;s root address.
void setTimeUpdate(bool val)
Sets the susbcription&#39;s time-update flag.