1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
|
/*
MIDI Sequencer C++ library
Copyright (C) 2006-2024, Pedro Lopez-Cabanillas <plcl@users.sf.net>
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "errorcheck.h"
#include <drumstick/alsaclient.h>
/**
* @file subscription.cpp
* Implementation of classes managing ALSA sequencer subscriptions
*/
/** @ingroup ALSAGroup */
namespace drumstick {
namespace ALSA {
/**
* @addtogroup ALSASubs
* @{
*
* Subscriptions are virtual MIDI cables between readable and writable ports.
*
* The ALSA sequencer readable ports are equivalent to the MIDI OUT ports in the
* real world. Similarly, the writable ports are equivalent to the MIDI IN ones.
* Subscriptions, like real MIDI cables, always involve a readable port (source)
* and a writable port (destination).
*
* Classes:
*
* Subscriber: This class is used to enumerate the subscribers of a given (root) port.
*
* Subscription: This class represents a connection between two ports.
*
* @see https://www.alsa-project.org/alsa-doc/alsa-lib/group___seq_subscribe.html
* @}
*/
/**
* Default constructor
*/
Subscriber::Subscriber()
{
snd_seq_query_subscribe_malloc(&m_Info);
}
/**
* Copy constructor
* @param other Existing Subscriber object reference
*/
Subscriber::Subscriber(const Subscriber& other)
{
snd_seq_query_subscribe_malloc(&m_Info);
snd_seq_query_subscribe_copy(m_Info, other.m_Info);
}
/**
* Constructor
* @param other Pointer to an ALSA query subscribe object
*/
Subscriber::Subscriber(snd_seq_query_subscribe_t* other)
{
snd_seq_query_subscribe_malloc(&m_Info);
snd_seq_query_subscribe_copy(m_Info, other);
}
/**
* Destructor
*/
Subscriber::~Subscriber()
{
snd_seq_query_subscribe_free(m_Info);
}
/**
* Copy the current object
* @return Pointer to the new object
*/
Subscriber* Subscriber::clone()
{
return new Subscriber(m_Info);
}
/**
* Assignment operator
* @param other Existing Subscriber object reference
* @return This object
*/
Subscriber& Subscriber::operator=(const Subscriber& other)
{
if (this == &other)
return *this;
snd_seq_query_subscribe_copy(m_Info, other.m_Info);
return *this;
}
/**
* Gets the subscriber's client number
* @return Client number
*/
int
Subscriber::getClient()
{
return snd_seq_query_subscribe_get_client(m_Info);
}
/**
* Gets the subscriober's port number
* @return Port number
*/
int
Subscriber::getPort()
{
return snd_seq_query_subscribe_get_port(m_Info);
}
/**
* Gets the subscriber's root address
* @return Pointer to the ALSA client/port address
*/
const snd_seq_addr_t*
Subscriber::getRoot()
{
return snd_seq_query_subscribe_get_root(m_Info);
}
/**
* Gets the subscription type (read or write).
* <ul>
* <li>SND_SEQ_QUERY_SUBS_READ: read subscriptions</li>
* <li>SND_SEQ_QUERY_SUBS_WRITE: write subscriptions</li>
* </ul>
* @return Subscription type
*/
snd_seq_query_subs_type_t
Subscriber::getType()
{
return snd_seq_query_subscribe_get_type(m_Info);
}
/**
* Gets the index of the subscriber container
* @return Index of the subscriber
*/
int
Subscriber::getIndex()
{
return snd_seq_query_subscribe_get_index(m_Info);
}
/**
* Gets the number of subscribers returned by a query operation
* @return Number of subscribers
*/
int
Subscriber::getNumSubs()
{
return snd_seq_query_subscribe_get_num_subs(m_Info);
}
/**
* Gets the subscriber's address
* @return Pointer to the ALSA address record
*/
const snd_seq_addr_t*
Subscriber::getAddr()
{
return snd_seq_query_subscribe_get_addr(m_Info);
}
/**
* Gets the subscriber's queue number
* @return Queue number
*/
int
Subscriber::getQueue()
{
return snd_seq_query_subscribe_get_queue(m_Info);
}
/**
* Gets the subscriber's exclusive flag
* @return Exclusive flag
*/
bool
Subscriber::getExclusive()
{
return (snd_seq_query_subscribe_get_exclusive(m_Info) != 0);
}
/**
* Gets the susbcriber's time-update flag
* @return Time update flag
*/
bool
Subscriber::getTimeUpdate()
{
return (snd_seq_query_subscribe_get_time_update(m_Info) != 0);
}
/**
* Gets the subscriber's time real time-stamp flag
* @return Time real flag
*/
bool
Subscriber::getTimeReal()
{
return (snd_seq_query_subscribe_get_time_real(m_Info) != 0);
}
/**
* Sets the subscriber's client number
* @param client Client number
*/
void
Subscriber::setClient(int client)
{
snd_seq_query_subscribe_set_client(m_Info, client);
}
/**
* Sets the subscriber's port number
* @param port Port number
*/
void
Subscriber::setPort(int port)
{
snd_seq_query_subscribe_set_port(m_Info, port);
}
/**
* Sets the subscriber's root address
* @param addr Pointer to the root ALSA address record
*/
void
Subscriber::setRoot(snd_seq_addr_t* addr)
{
snd_seq_query_subscribe_set_root(m_Info, addr);
}
/**
* Sets the subscription type
* <ul>
* <li>SND_SEQ_QUERY_SUBS_READ: read subscriptions</li>
* <li>SND_SEQ_QUERY_SUBS_WRITE: write subscriptions</li>
* </ul>
* @param type Subscription type
*/
void
Subscriber::setType(snd_seq_query_subs_type_t type)
{
snd_seq_query_subscribe_set_type(m_Info, type);
}
/**
* Sets the index of the subscriber
* @param index Subscriber index
*/
void
Subscriber::setIndex(int index)
{
snd_seq_query_subscribe_set_index(m_Info, index);
}
/**
* Gets the size of the ALSA query subscriber object
* @return Size of the ALSA object
*/
int
Subscriber::getSizeOfInfo() const
{
return snd_seq_query_subscribe_sizeof();
}
/**
* Default constructor
*/
Subscription::Subscription()
{
snd_seq_port_subscribe_malloc(&m_Info);
}
/**
* Copy constructor
* @param other Existing Subscription object reference
*/
Subscription::Subscription(const Subscription& other)
{
snd_seq_port_subscribe_malloc(&m_Info);
snd_seq_port_subscribe_copy(m_Info, other.m_Info);
}
/**
* Constructor
* @param other Pointer to an ALSA subscription object
*/
Subscription::Subscription(snd_seq_port_subscribe_t* other)
{
snd_seq_port_subscribe_malloc(&m_Info);
snd_seq_port_subscribe_copy(m_Info, other);
}
/**
* Constructor
* @param seq Pointer to a MIDI Client object
*/
Subscription::Subscription(MidiClient* seq)
{
snd_seq_port_subscribe_malloc(&m_Info);
DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_get_port_subscription(seq->getHandle(), m_Info));
}
/**
* Destructor
*/
Subscription::~Subscription()
{
snd_seq_port_subscribe_free(m_Info);
}
/**
* Copy the current object
* @return Pointer to the new object
*/
Subscription*
Subscription::clone()
{
return new Subscription(m_Info);
}
/**
* Assignment operator
* @param other Existing subscription object reference
* @return This object
*/
Subscription&
Subscription::operator=(const Subscription& other)
{
if (this == &other)
return *this;
snd_seq_port_subscribe_copy(m_Info, other.m_Info);
return *this;
}
/**
* Gets the sender address of the subscription (MIDI OUT port)
* @return Pointer to the sender ALSA address record
*/
const snd_seq_addr_t*
Subscription::getSender()
{
return snd_seq_port_subscribe_get_sender(m_Info);
}
/**
* Gets the destination address of the subscription (MIDI IN port)
* @return Pointer to the destination ALSA address record
*/
const snd_seq_addr_t*
Subscription::getDest()
{
return snd_seq_port_subscribe_get_dest(m_Info);
}
/**
* Gets the susbcription's queue number
* @return Queue number
*/
int
Subscription::getQueue()
{
return snd_seq_port_subscribe_get_queue(m_Info);
}
/**
* Gets the subscription's exclusive flag
* @return Exclusive flag
*/
bool
Subscription::getExclusive()
{
return (snd_seq_port_subscribe_get_exclusive(m_Info) != 0);
}
/**
* Gets the susbcription's time-update flag
* @return Time-update flag
*/
bool
Subscription::getTimeUpdate()
{
return (snd_seq_port_subscribe_get_time_update(m_Info) != 0);
}
/**
* Gets the susbcription's time-real (time-stamping) flag
* @return Time real flag
*/
bool
Subscription::getTimeReal()
{
return (snd_seq_port_subscribe_get_time_real(m_Info) != 0);
}
/**
* Sets the Subscription's sender (MIDI OUT) port
* @param addr Pointer to the sender ALSA address record
*/
void
Subscription::setSender(const snd_seq_addr_t* addr)
{
snd_seq_port_subscribe_set_sender(m_Info, addr);
}
/**
* Sets the Subscription's destination (MIDI IN) port
* @param addr Pointer to the destination ALSA address record
*/
void
Subscription::setDest(const snd_seq_addr_t* addr)
{
snd_seq_port_subscribe_set_dest(m_Info, addr);
}
/**
* Sets the Subscription's Queue number
* @param q Queue number
*/
void
Subscription::setQueue(int q)
{
snd_seq_port_subscribe_set_queue(m_Info, q);
}
/**
* Sets the subscription's exclusive flag
* @param val Exclusive flag
*/
void
Subscription::setExclusive(bool val)
{
snd_seq_port_subscribe_set_exclusive(m_Info, val?1:0);
}
/**
* Sets the susbcription's time-update flag
* @param val Time update flag
*/
void
Subscription::setTimeUpdate(bool val)
{
snd_seq_port_subscribe_set_time_update(m_Info, val?1:0);
}
/**
* Sets the subscription's time real (time-stamping) flag
* @param val Time real flag
*/
void
Subscription::setTimeReal(bool val)
{
snd_seq_port_subscribe_set_time_real(m_Info, val?1:0);
}
/**
* Sets the Subscription's sender (MIDI OUT) port
* @param client Client number
* @param port Port number
*/
void
Subscription::setSender(unsigned char client, unsigned char port)
{
snd_seq_addr_t addr;
addr.client = client;
addr.port = port;
setSender(&addr);
}
/**
* Sets the Subscription's destination (MIDI IN) port
* @param client Client number
* @param port Port number
*/
void
Subscription::setDest(unsigned char client, unsigned char port)
{
snd_seq_addr_t addr;
addr.client = client;
addr.port = port;
setDest(&addr);
}
/**
* Performs the subscription in the ALSA sequencer subsystem.
* Neither the sender nor the destination ports need to belong to the
* same MidiClient instance performing the subscription.
* @param seq MidiClient instance pointer
*/
void
Subscription::subscribe(MidiClient* seq)
{
if ((m_Info == nullptr) || (seq == nullptr) || !(seq->isOpened()))
{
return;
}
DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_subscribe_port(seq->getHandle(), m_Info));
}
/**
* Breaks the subscription in the ALSA sequencer subsystem.
* Neither the sender nor the destination ports need to belong to the
* same MidiClient instance breaking the subscription.
* @param seq MidiClient instance pointer
*/
void
Subscription::unsubscribe(MidiClient* seq)
{
if ((m_Info == nullptr) || (seq == nullptr) || !(seq->isOpened()))
{
return;
}
DRUMSTICK_ALSA_CHECK_WARNING(snd_seq_unsubscribe_port(seq->getHandle(), m_Info));
}
/**
* Gets the size of the ALSA subscription object
* @return Size of the ALSA object
*/
int
Subscription::getSizeOfInfo() const
{
return snd_seq_port_subscribe_sizeof();
}
} // namespace ALSA
} // namespace drumstick
|