drumstick  1.0.2
subscription.cpp
Go to the documentation of this file.
00001 /*
00002     MIDI Sequencer C++ library 
00003     Copyright (C) 2006-2015, Pedro Lopez-Cabanillas <plcl@users.sf.net>
00004  
00005     This library is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009  
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014  
00015     You should have received a copy of the GNU General Public License along 
00016     with this program; if not, write to the Free Software Foundation, Inc., 
00017     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.    
00018 */
00019 
00020 #include "alsaclient.h"
00021 
00027 namespace drumstick {
00028 
00053 Subscriber::Subscriber()
00054 {
00055     snd_seq_query_subscribe_malloc(&m_Info);
00056 }
00057 
00062 Subscriber::Subscriber(const Subscriber& other)
00063 {
00064     snd_seq_query_subscribe_malloc(&m_Info);
00065     snd_seq_query_subscribe_copy(m_Info, other.m_Info);
00066 }
00067 
00072 Subscriber::Subscriber(snd_seq_query_subscribe_t* other)
00073 {
00074     snd_seq_query_subscribe_malloc(&m_Info);
00075     snd_seq_query_subscribe_copy(m_Info, other);
00076 }
00077 
00081 Subscriber::~Subscriber()
00082 {
00083     snd_seq_query_subscribe_free(m_Info);
00084 }
00085 
00090 Subscriber* Subscriber::clone()
00091 {
00092     return new Subscriber(m_Info);
00093 }
00094 
00100 Subscriber& Subscriber::operator=(const Subscriber& other)
00101 {
00102     snd_seq_query_subscribe_copy(m_Info, other.m_Info);
00103     return *this;
00104 }
00105 
00110 int
00111 Subscriber::getClient()
00112 {
00113     return snd_seq_query_subscribe_get_client(m_Info);
00114 }
00115 
00120 int
00121 Subscriber::getPort()
00122 {
00123     return snd_seq_query_subscribe_get_port(m_Info);
00124 }
00125 
00130 const snd_seq_addr_t*
00131 Subscriber::getRoot()
00132 {
00133     return snd_seq_query_subscribe_get_root(m_Info);
00134 }
00135 
00144 snd_seq_query_subs_type_t
00145 Subscriber::getType()
00146 {
00147     return snd_seq_query_subscribe_get_type(m_Info);
00148 }
00149 
00154 int
00155 Subscriber::getIndex()
00156 {
00157     return snd_seq_query_subscribe_get_index(m_Info);
00158 }
00159 
00164 int
00165 Subscriber::getNumSubs()
00166 {
00167     return snd_seq_query_subscribe_get_num_subs(m_Info);
00168 }
00169 
00174 const snd_seq_addr_t*
00175 Subscriber::getAddr()
00176 {
00177     return snd_seq_query_subscribe_get_addr(m_Info);
00178 }
00179 
00184 int
00185 Subscriber::getQueue()
00186 {
00187     return snd_seq_query_subscribe_get_queue(m_Info);
00188 }
00189 
00194 bool
00195 Subscriber::getExclusive()
00196 {
00197     return (snd_seq_query_subscribe_get_exclusive(m_Info) != 0);
00198 }
00199 
00204 bool
00205 Subscriber::getTimeUpdate()
00206 {
00207     return (snd_seq_query_subscribe_get_time_update(m_Info) != 0);
00208 }
00209 
00214 bool
00215 Subscriber::getTimeReal()
00216 {
00217     return (snd_seq_query_subscribe_get_time_real(m_Info) != 0);
00218 }
00219 
00224 void
00225 Subscriber::setClient(int client)
00226 {
00227     snd_seq_query_subscribe_set_client(m_Info, client);
00228 }
00229 
00234 void
00235 Subscriber::setPort(int port)
00236 {
00237     snd_seq_query_subscribe_set_port(m_Info, port);
00238 }
00239 
00244 void
00245 Subscriber::setRoot(snd_seq_addr_t* addr)
00246 {
00247     snd_seq_query_subscribe_set_root(m_Info, addr);
00248 }
00249 
00258 void
00259 Subscriber::setType(snd_seq_query_subs_type_t type)
00260 {
00261     snd_seq_query_subscribe_set_type(m_Info, type);
00262 }
00263 
00268 void
00269 Subscriber::setIndex(int index)
00270 {
00271     snd_seq_query_subscribe_set_index(m_Info, index);
00272 }
00273 
00278 int 
00279 Subscriber::getSizeOfInfo() const
00280 {
00281     return snd_seq_query_subscribe_sizeof();
00282 }
00283 
00287 Subscription::Subscription()
00288 {
00289     snd_seq_port_subscribe_malloc(&m_Info);
00290 }
00291 
00296 Subscription::Subscription(const Subscription& other)
00297 {
00298     snd_seq_port_subscribe_malloc(&m_Info);
00299     snd_seq_port_subscribe_copy(m_Info, other.m_Info);
00300 }
00301 
00306 Subscription::Subscription(snd_seq_port_subscribe_t* other)
00307 {
00308     snd_seq_port_subscribe_malloc(&m_Info);
00309     snd_seq_port_subscribe_copy(m_Info, other);
00310 }
00311 
00316 Subscription::Subscription(MidiClient* seq)
00317 {
00318     snd_seq_port_subscribe_malloc(&m_Info);
00319     CHECK_WARNING(snd_seq_get_port_subscription(seq->getHandle(), m_Info));
00320 }
00321 
00326 Subscription::~Subscription()
00327 {
00328     snd_seq_port_subscribe_free(m_Info);
00329 }
00330 
00335 Subscription*
00336 Subscription::clone()
00337 {
00338     return new Subscription(m_Info);
00339 }
00340 
00346 Subscription&
00347 Subscription::operator=(const Subscription& other)
00348 {
00349     snd_seq_port_subscribe_copy(m_Info, other.m_Info);
00350     return *this;
00351 }
00352 
00357 const snd_seq_addr_t*
00358 Subscription::getSender()
00359 {
00360     return snd_seq_port_subscribe_get_sender(m_Info);
00361 }
00362 
00367 const snd_seq_addr_t*
00368 Subscription::getDest()
00369 {
00370     return snd_seq_port_subscribe_get_dest(m_Info);
00371 }
00372 
00377 int
00378 Subscription::getQueue()
00379 {
00380     return snd_seq_port_subscribe_get_queue(m_Info);
00381 }
00382 
00387 bool
00388 Subscription::getExclusive()
00389 {
00390     return (snd_seq_port_subscribe_get_exclusive(m_Info) != 0);
00391 }
00392 
00397 bool
00398 Subscription::getTimeUpdate()
00399 {
00400     return (snd_seq_port_subscribe_get_time_update(m_Info) != 0);
00401 }
00402 
00407 bool
00408 Subscription::getTimeReal()
00409 {
00410     return (snd_seq_port_subscribe_get_time_real(m_Info) != 0);
00411 }
00412 
00417 void
00418 Subscription::setSender(const snd_seq_addr_t* addr)
00419 {
00420     snd_seq_port_subscribe_set_sender(m_Info, addr);
00421 }
00422 
00427 void
00428 Subscription::setDest(const snd_seq_addr_t* addr)
00429 {
00430     snd_seq_port_subscribe_set_dest(m_Info, addr);
00431 }
00432 
00437 void
00438 Subscription::setQueue(int q)
00439 {
00440     snd_seq_port_subscribe_set_queue(m_Info, q);
00441 }
00442 
00447 void
00448 Subscription::setExclusive(bool val)
00449 {
00450     snd_seq_port_subscribe_set_exclusive(m_Info, val?1:0);
00451 }
00452 
00457 void
00458 Subscription::setTimeUpdate(bool val)
00459 {
00460     snd_seq_port_subscribe_set_time_update(m_Info, val?1:0);
00461 }
00462 
00467 void
00468 Subscription::setTimeReal(bool val)
00469 {
00470     snd_seq_port_subscribe_set_time_real(m_Info, val?1:0);
00471 }
00472 
00478 void
00479 Subscription::setSender(unsigned char client, unsigned char port)
00480 {
00481     snd_seq_addr_t addr;
00482     addr.client = client;
00483     addr.port = port;
00484     setSender(&addr);
00485 }
00486 
00492 void
00493 Subscription::setDest(unsigned char client, unsigned char port)
00494 {
00495     snd_seq_addr_t addr;
00496     addr.client = client;
00497     addr.port = port;
00498     setDest(&addr);
00499 }
00500 
00507 void
00508 Subscription::subscribe(MidiClient* seq)
00509 {
00510     if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
00511     {
00512         return;
00513     }
00514     CHECK_WARNING(snd_seq_subscribe_port(seq->getHandle(), m_Info));
00515 }
00516 
00523 void
00524 Subscription::unsubscribe(MidiClient* seq)
00525 {
00526     if ((m_Info == NULL) || (seq == NULL) || !(seq->isOpened()))
00527     {
00528         return;
00529     }
00530     CHECK_WARNING(snd_seq_unsubscribe_port(seq->getHandle(), m_Info));
00531 }
00532 
00537 int 
00538 Subscription::getSizeOfInfo() const
00539 {
00540     return snd_seq_port_subscribe_sizeof();
00541 }
00542 
00543 } /* namespace drumstick */
00544