drumstick  1.1.2
subscription.cpp
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2018, 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
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #include "alsaclient.h"
20 
26 namespace drumstick {
27 
53 {
54  snd_seq_query_subscribe_malloc(&m_Info);
55 }
56 
62 {
63  snd_seq_query_subscribe_malloc(&m_Info);
64  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
65 }
66 
71 Subscriber::Subscriber(snd_seq_query_subscribe_t* other)
72 {
73  snd_seq_query_subscribe_malloc(&m_Info);
74  snd_seq_query_subscribe_copy(m_Info, other);
75 }
76 
81 {
82  snd_seq_query_subscribe_free(m_Info);
83 }
84 
90 {
91  return new Subscriber(m_Info);
92 }
93 
100 {
101  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
102  return *this;
103 }
104 
109 int
111 {
112  return snd_seq_query_subscribe_get_client(m_Info);
113 }
114 
119 int
121 {
122  return snd_seq_query_subscribe_get_port(m_Info);
123 }
124 
129 const snd_seq_addr_t*
131 {
132  return snd_seq_query_subscribe_get_root(m_Info);
133 }
134 
143 snd_seq_query_subs_type_t
145 {
146  return snd_seq_query_subscribe_get_type(m_Info);
147 }
148 
153 int
155 {
156  return snd_seq_query_subscribe_get_index(m_Info);
157 }
158 
163 int
165 {
166  return snd_seq_query_subscribe_get_num_subs(m_Info);
167 }
168 
173 const snd_seq_addr_t*
175 {
176  return snd_seq_query_subscribe_get_addr(m_Info);
177 }
178 
183 int
185 {
186  return snd_seq_query_subscribe_get_queue(m_Info);
187 }
188 
193 bool
195 {
196  return (snd_seq_query_subscribe_get_exclusive(m_Info) != 0);
197 }
198 
203 bool
205 {
206  return (snd_seq_query_subscribe_get_time_update(m_Info) != 0);
207 }
208 
213 bool
215 {
216  return (snd_seq_query_subscribe_get_time_real(m_Info) != 0);
217 }
218 
223 void
225 {
226  snd_seq_query_subscribe_set_client(m_Info, client);
227 }
228 
233 void
235 {
236  snd_seq_query_subscribe_set_port(m_Info, port);
237 }
238 
243 void
244 Subscriber::setRoot(snd_seq_addr_t* addr)
245 {
246  snd_seq_query_subscribe_set_root(m_Info, addr);
247 }
248 
257 void
258 Subscriber::setType(snd_seq_query_subs_type_t type)
259 {
260  snd_seq_query_subscribe_set_type(m_Info, type);
261 }
262 
267 void
269 {
270  snd_seq_query_subscribe_set_index(m_Info, index);
271 }
272 
277 int
279 {
280  return snd_seq_query_subscribe_sizeof();
281 }
282 
287 {
288  snd_seq_port_subscribe_malloc(&m_Info);
289 }
290 
296 {
297  snd_seq_port_subscribe_malloc(&m_Info);
298  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
299 }
300 
305 Subscription::Subscription(snd_seq_port_subscribe_t* other)
306 {
307  snd_seq_port_subscribe_malloc(&m_Info);
308  snd_seq_port_subscribe_copy(m_Info, other);
309 }
310 
316 {
317  snd_seq_port_subscribe_malloc(&m_Info);
318  CHECK_WARNING(snd_seq_get_port_subscription(seq->getHandle(), m_Info));
319 }
320 
326 {
327  snd_seq_port_subscribe_free(m_Info);
328 }
329 
336 {
337  return new Subscription(m_Info);
338 }
339 
347 {
348  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
349  return *this;
350 }
351 
356 const snd_seq_addr_t*
358 {
359  return snd_seq_port_subscribe_get_sender(m_Info);
360 }
361 
366 const snd_seq_addr_t*
368 {
369  return snd_seq_port_subscribe_get_dest(m_Info);
370 }
371 
376 int
378 {
379  return snd_seq_port_subscribe_get_queue(m_Info);
380 }
381 
386 bool
388 {
389  return (snd_seq_port_subscribe_get_exclusive(m_Info) != 0);
390 }
391 
396 bool
398 {
399  return (snd_seq_port_subscribe_get_time_update(m_Info) != 0);
400 }
401 
406 bool
408 {
409  return (snd_seq_port_subscribe_get_time_real(m_Info) != 0);
410 }
411 
416 void
417 Subscription::setSender(const snd_seq_addr_t* addr)
418 {
419  snd_seq_port_subscribe_set_sender(m_Info, addr);
420 }
421 
426 void
427 Subscription::setDest(const snd_seq_addr_t* addr)
428 {
429  snd_seq_port_subscribe_set_dest(m_Info, addr);
430 }
431 
436 void
438 {
439  snd_seq_port_subscribe_set_queue(m_Info, q);
440 }
441 
446 void
448 {
449  snd_seq_port_subscribe_set_exclusive(m_Info, val?1:0);
450 }
451 
456 void
458 {
459  snd_seq_port_subscribe_set_time_update(m_Info, val?1:0);
460 }
461 
466 void
468 {
469  snd_seq_port_subscribe_set_time_real(m_Info, val?1:0);
470 }
471 
477 void
478 Subscription::setSender(unsigned char client, unsigned char port)
479 {
480  snd_seq_addr_t addr;
481  addr.client = client;
482  addr.port = port;
483  setSender(&addr);
484 }
485 
491 void
492 Subscription::setDest(unsigned char client, unsigned char port)
493 {
494  snd_seq_addr_t addr;
495  addr.client = client;
496  addr.port = port;
497  setDest(&addr);
498 }
499 
506 void
508 {
509  if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
510  {
511  return;
512  }
513  CHECK_WARNING(snd_seq_subscribe_port(seq->getHandle(), m_Info));
514 }
515 
522 void
524 {
525  if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
526  {
527  return;
528  }
529  CHECK_WARNING(snd_seq_unsubscribe_port(seq->getHandle(), m_Info));
530 }
531 
536 int
538 {
539  return snd_seq_port_subscribe_sizeof();
540 }
541 
542 } /* namespace drumstick */
543 
const snd_seq_addr_t * getRoot()
Gets the subscriber's root address.
Subscriber * clone()
Copy the current object.
bool getTimeUpdate()
Gets the susbcriber's time-update flag.
const snd_seq_addr_t * getAddr()
Gets the subscriber's address.
Classes managing ALSA Sequencer clients.
void setQueue(int queue)
Sets the Subscription's Queue number.
bool getTimeUpdate()
Gets the susbcription's time-update flag.
bool isOpened()
Returns true if the sequencer is opened.
Definition: alsaclient.cpp:293
snd_seq_query_subs_type_t getType()
Gets the subscription type (read or write).
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
Definition: alsaclient.cpp:285
void setTimeUpdate(bool val)
Sets the susbcription's time-update flag.
const snd_seq_addr_t * getSender()
Gets the sender address of the subscription (MIDI OUT port)
int getQueue()
Gets the subscriber's queue number.
Subscription & operator=(const Subscription &other)
Assignment operator.
Subscription * clone()
Copy the current object.
Client management.
Definition: alsaclient.h:197
int getSizeOfInfo() const
Gets the size of the ALSA query subscriber object.
bool getExclusive()
Gets the subscriber's exclusive flag.
void unsubscribe(MidiClient *seq)
Breaks the subscription in the ALSA sequencer subsystem.
Subscriber()
Default constructor.
void setTimeReal(bool val)
Sets the subscription's time real (time-stamping) flag.
bool getTimeReal()
Gets the subscriber's time real time-stamp flag.
Subscriber & operator=(const Subscriber &other)
Assignment operator.
void setIndex(int index)
Sets the index of the subscriber.
void subscribe(MidiClient *seq)
Performs the subscription in the ALSA sequencer subsystem.
Subscription()
Default constructor.
virtual ~Subscription()
Destructor.
void setClient(int client)
Sets the subscriber's client number.
Subscription management.
Definition: subscription.h:81
void setRoot(snd_seq_addr_t *addr)
Sets the subscriber's root address.
int getSizeOfInfo() const
Gets the size of the ALSA subscription object.
bool getTimeReal()
Gets the susbcription's time-real (time-stamping) flag.
const snd_seq_addr_t * getDest()
Gets the destination address of the subscription (MIDI IN port)
int getNumSubs()
Gets the number of subscribers returned by a query operation.
void setType(snd_seq_query_subs_type_t type)
Sets the subscription type.
void setDest(unsigned char client, unsigned char port)
Sets the Subscription's destination (MIDI IN) port.
void setSender(unsigned char client, unsigned char port)
Sets the Subscription's sender (MIDI OUT) port.
void setExclusive(bool val)
Sets the subscription's exclusive flag.
bool getExclusive()
Gets the subscription's exclusive flag.
#define CHECK_WARNING(x)
This macro calls the check warning function.
virtual ~Subscriber()
Destructor.
Subscriber container class.
Definition: subscription.h:42
int getQueue()
Gets the susbcription's queue number.
int getClient()
Gets the subscriber's client number.
int getPort()
Gets the subscriober's port number.
int getIndex()
Gets the index of the subscriber container.
void setPort(int port)
Sets the subscriber's port number.