drumstick  0.5.0
subscription.cpp
Go to the documentation of this file.
1 /*
2  MIDI Sequencer C++ library
3  Copyright (C) 2006-2010, 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 along
16  with this program; if not, write to the Free Software Foundation, Inc.,
17  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 
20 #include "alsaclient.h"
21 
27 namespace drumstick {
28 
54 {
55  snd_seq_query_subscribe_malloc(&m_Info);
56 }
57 
63 {
64  snd_seq_query_subscribe_malloc(&m_Info);
65  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
66 }
67 
72 Subscriber::Subscriber(snd_seq_query_subscribe_t* other)
73 {
74  snd_seq_query_subscribe_malloc(&m_Info);
75  snd_seq_query_subscribe_copy(m_Info, other);
76 }
77 
82 {
83  snd_seq_query_subscribe_free(m_Info);
84 }
85 
91 {
92  return new Subscriber(m_Info);
93 }
94 
101 {
102  snd_seq_query_subscribe_copy(m_Info, other.m_Info);
103  return *this;
104 }
105 
110 int
112 {
113  return snd_seq_query_subscribe_get_client(m_Info);
114 }
115 
120 int
122 {
123  return snd_seq_query_subscribe_get_port(m_Info);
124 }
125 
130 const snd_seq_addr_t*
132 {
133  return snd_seq_query_subscribe_get_root(m_Info);
134 }
135 
144 snd_seq_query_subs_type_t
146 {
147  return snd_seq_query_subscribe_get_type(m_Info);
148 }
149 
154 int
156 {
157  return snd_seq_query_subscribe_get_index(m_Info);
158 }
159 
164 int
166 {
167  return snd_seq_query_subscribe_get_num_subs(m_Info);
168 }
169 
174 const snd_seq_addr_t*
176 {
177  return snd_seq_query_subscribe_get_addr(m_Info);
178 }
179 
184 int
186 {
187  return snd_seq_query_subscribe_get_queue(m_Info);
188 }
189 
194 bool
196 {
197  return (snd_seq_query_subscribe_get_exclusive(m_Info) != 0);
198 }
199 
204 bool
206 {
207  return (snd_seq_query_subscribe_get_time_update(m_Info) != 0);
208 }
209 
214 bool
216 {
217  return (snd_seq_query_subscribe_get_time_real(m_Info) != 0);
218 }
219 
224 void
226 {
227  snd_seq_query_subscribe_set_client(m_Info, client);
228 }
229 
234 void
236 {
237  snd_seq_query_subscribe_set_port(m_Info, port);
238 }
239 
244 void
245 Subscriber::setRoot(snd_seq_addr_t* addr)
246 {
247  snd_seq_query_subscribe_set_root(m_Info, addr);
248 }
249 
258 void
259 Subscriber::setType(snd_seq_query_subs_type_t type)
260 {
261  snd_seq_query_subscribe_set_type(m_Info, type);
262 }
263 
268 void
270 {
271  snd_seq_query_subscribe_set_index(m_Info, index);
272 }
273 
278 int
280 {
281  return snd_seq_query_subscribe_sizeof();
282 }
283 
288 {
289  snd_seq_port_subscribe_malloc(&m_Info);
290 }
291 
297 {
298  snd_seq_port_subscribe_malloc(&m_Info);
299  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
300 }
301 
306 Subscription::Subscription(snd_seq_port_subscribe_t* other)
307 {
308  snd_seq_port_subscribe_malloc(&m_Info);
309  snd_seq_port_subscribe_copy(m_Info, other);
310 }
311 
317 {
318  snd_seq_port_subscribe_malloc(&m_Info);
319  CHECK_WARNING(snd_seq_get_port_subscription(seq->getHandle(), m_Info));
320 }
321 
327 {
328  snd_seq_port_subscribe_free(m_Info);
329 }
330 
337 {
338  return new Subscription(m_Info);
339 }
340 
348 {
349  snd_seq_port_subscribe_copy(m_Info, other.m_Info);
350  return *this;
351 }
352 
357 const snd_seq_addr_t*
359 {
360  return snd_seq_port_subscribe_get_sender(m_Info);
361 }
362 
367 const snd_seq_addr_t*
369 {
370  return snd_seq_port_subscribe_get_dest(m_Info);
371 }
372 
377 int
379 {
380  return snd_seq_port_subscribe_get_queue(m_Info);
381 }
382 
387 bool
389 {
390  return (snd_seq_port_subscribe_get_exclusive(m_Info) != 0);
391 }
392 
397 bool
399 {
400  return (snd_seq_port_subscribe_get_time_update(m_Info) != 0);
401 }
402 
407 bool
409 {
410  return (snd_seq_port_subscribe_get_time_real(m_Info) != 0);
411 }
412 
417 void
418 Subscription::setSender(const snd_seq_addr_t* addr)
419 {
420  snd_seq_port_subscribe_set_sender(m_Info, addr);
421 }
422 
427 void
428 Subscription::setDest(const snd_seq_addr_t* addr)
429 {
430  snd_seq_port_subscribe_set_dest(m_Info, addr);
431 }
432 
437 void
439 {
440  snd_seq_port_subscribe_set_queue(m_Info, q);
441 }
442 
447 void
449 {
450  snd_seq_port_subscribe_set_exclusive(m_Info, val?1:0);
451 }
452 
457 void
459 {
460  snd_seq_port_subscribe_set_time_update(m_Info, val?1:0);
461 }
462 
467 void
469 {
470  snd_seq_port_subscribe_set_time_real(m_Info, val?1:0);
471 }
472 
478 void
479 Subscription::setSender(unsigned char client, unsigned char port)
480 {
481  snd_seq_addr_t addr;
482  addr.client = client;
483  addr.port = port;
484  setSender(&addr);
485 }
486 
492 void
493 Subscription::setDest(unsigned char client, unsigned char port)
494 {
495  snd_seq_addr_t addr;
496  addr.client = client;
497  addr.port = port;
498  setDest(&addr);
499 }
500 
507 void
509 {
510  if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
511  {
512  return;
513  }
514  CHECK_WARNING(snd_seq_subscribe_port(seq->getHandle(), m_Info));
515 }
516 
523 void
525 {
526  if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
527  {
528  return;
529  }
530  CHECK_WARNING(snd_seq_unsubscribe_port(seq->getHandle(), m_Info));
531 }
532 
537 int
539 {
540  return snd_seq_port_subscribe_sizeof();
541 }
542 
543 } /* namespace drumstick */
544 
const snd_seq_addr_t * getRoot()
Gets the subscriber&#39;s root address.
Subscriber * clone()
Copy the current object.
bool getTimeUpdate()
Gets the susbcriber&#39;s time-update flag.
const snd_seq_addr_t * getAddr()
Gets the subscriber&#39;s address.
Classes managing ALSA Sequencer clients.
void setQueue(int queue)
Sets the Subscription&#39;s Queue number.
bool getTimeUpdate()
Gets the susbcription&#39;s time-update flag.
bool isOpened()
Returns true if the sequencer is opened.
Definition: alsaclient.h:237
snd_seq_query_subs_type_t getType()
Gets the subscription type (read or write).
void setTimeUpdate(bool val)
Sets the susbcription&#39;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&#39;s queue number.
Subscription & operator=(const Subscription &other)
Assignment operator.
Subscription * clone()
Copy the current object.
Client management.
Definition: alsaclient.h:198
int getSizeOfInfo() const
Gets the size of the ALSA query subscriber object.
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
Definition: alsaclient.h:235
bool getExclusive()
Gets the subscriber&#39;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&#39;s time real (time-stamping) flag.
bool getTimeReal()
Gets the subscriber&#39;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&#39;s client number.
Subscription management.
Definition: subscription.h:82
void setRoot(snd_seq_addr_t *addr)
Sets the subscriber&#39;s root address.
int getSizeOfInfo() const
Gets the size of the ALSA subscription object.
bool getTimeReal()
Gets the susbcription&#39;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&#39;s destination (MIDI IN) port.
void setSender(unsigned char client, unsigned char port)
Sets the Subscription&#39;s sender (MIDI OUT) port.
void setExclusive(bool val)
Sets the subscription&#39;s exclusive flag.
bool getExclusive()
Gets the subscription&#39;s exclusive flag.
#define CHECK_WARNING(x)
This macro calls the check warning function.
virtual ~Subscriber()
Destructor.
Subscriber container class.
Definition: subscription.h:43
int getQueue()
Gets the susbcription&#39;s queue number.
int getClient()
Gets the subscriber&#39;s client number.
int getPort()
Gets the subscriober&#39;s port number.
int getIndex()
Gets the index of the subscriber container.
void setPort(int port)
Sets the subscriber&#39;s port number.