26 #include <QReadLocker> 27 #include <QWriteLocker> 28 #if defined(RTKIT_SUPPORT) 29 #include <QDBusConnection> 30 #include <QDBusInterface> 31 #include <sys/types.h> 32 #include <sys/syscall.h> 33 #include <sys/resource.h> 38 #define RLIMIT_RTTIME 15 41 #ifndef SCHED_RESET_ON_FORK 42 #define SCHED_RESET_ON_FORK 0x40000000 45 #ifndef DEFAULT_INPUT_TIMEOUT 46 #define DEFAULT_INPUT_TIMEOUT 500 342 void setRealtimePriority();
348 QReadWriteLock m_mutex;
351 class MidiClient::MidiClientPrivate
354 MidiClientPrivate() :
355 m_eventsEnabled(
false),
357 m_NeedRefreshClientList(
true),
358 m_OpenMode(SND_SEQ_OPEN_DUPLEX),
359 m_DeviceName(
"default"),
366 bool m_eventsEnabled;
368 bool m_NeedRefreshClientList;
370 QString m_DeviceName;
371 snd_seq_t* m_SeqHandle;
372 QPointer<SequencerInputThread> m_Thread;
373 QPointer<MidiQueue> m_Queue;
381 QObjectList m_listeners;
403 d(new MidiClientPrivate)
419 if (d->m_Thread != 0)
431 return d->m_SeqHandle;
439 return (d->m_SeqHandle != NULL);
447 return d->m_DeviceName;
455 return d->m_OpenMode;
463 return d->m_BlockMode;
471 return d->m_eventsEnabled;
479 d->m_handler = handler;
493 if (d->m_Thread == 0) {
495 d->m_Thread->m_RealTime = enable;
506 if (d->m_Thread == 0)
508 return d->m_Thread->m_RealTime;
534 const bool blockMode)
536 CHECK_ERROR( snd_seq_open( &d->m_SeqHandle, deviceName.toLocal8Bit().data(),
537 openMode, blockMode ? 0 : SND_SEQ_NONBLOCK ) );
538 CHECK_WARNING( snd_seq_get_client_info( d->m_SeqHandle, d->m_Info.m_Info ) );
539 d->m_DeviceName = deviceName;
540 d->m_OpenMode = openMode;
541 d->m_BlockMode = blockMode;
566 const QString deviceName,
568 const bool blockMode )
571 deviceName.toLocal8Bit().data(),
573 blockMode ? 0 : SND_SEQ_NONBLOCK,
575 CHECK_WARNING( snd_seq_get_client_info(d->m_SeqHandle, d->m_Info.m_Info));
576 d->m_DeviceName = deviceName;
577 d->m_OpenMode = openMode;
578 d->m_BlockMode = blockMode;
591 if (d->m_SeqHandle != NULL) {
594 d->m_SeqHandle = NULL;
609 return snd_seq_get_output_buffer_size(d->m_SeqHandle);
624 CHECK_WARNING(snd_seq_set_output_buffer_size(d->m_SeqHandle, newSize));
639 return snd_seq_get_input_buffer_size(d->m_SeqHandle);
654 CHECK_WARNING(snd_seq_set_input_buffer_size(d->m_SeqHandle, newSize));
670 if (d->m_BlockMode != newValue)
672 d->m_BlockMode = newValue;
673 if (d->m_SeqHandle != NULL)
675 CHECK_WARNING(snd_seq_nonblock(d->m_SeqHandle, d->m_BlockMode ? 0 : 1));
701 return snd_seq_type(d->m_SeqHandle);
729 snd_seq_event_t* evp = NULL;
731 err = snd_seq_event_input(d->m_SeqHandle, &evp);
732 if ((err >= 0) && (evp != NULL)) {
735 case SND_SEQ_EVENT_NOTE:
739 case SND_SEQ_EVENT_NOTEON:
743 case SND_SEQ_EVENT_NOTEOFF:
747 case SND_SEQ_EVENT_KEYPRESS:
751 case SND_SEQ_EVENT_CONTROLLER:
752 case SND_SEQ_EVENT_CONTROL14:
753 case SND_SEQ_EVENT_REGPARAM:
754 case SND_SEQ_EVENT_NONREGPARAM:
758 case SND_SEQ_EVENT_PGMCHANGE:
762 case SND_SEQ_EVENT_CHANPRESS:
766 case SND_SEQ_EVENT_PITCHBEND:
770 case SND_SEQ_EVENT_SYSEX:
774 case SND_SEQ_EVENT_PORT_SUBSCRIBED:
775 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
779 case SND_SEQ_EVENT_PORT_CHANGE:
780 case SND_SEQ_EVENT_PORT_EXIT:
781 case SND_SEQ_EVENT_PORT_START:
783 d->m_NeedRefreshClientList =
true;
786 case SND_SEQ_EVENT_CLIENT_CHANGE:
787 case SND_SEQ_EVENT_CLIENT_EXIT:
788 case SND_SEQ_EVENT_CLIENT_START:
790 d->m_NeedRefreshClientList =
true;
793 case SND_SEQ_EVENT_SONGPOS:
794 case SND_SEQ_EVENT_SONGSEL:
795 case SND_SEQ_EVENT_QFRAME:
796 case SND_SEQ_EVENT_TIMESIGN:
797 case SND_SEQ_EVENT_KEYSIGN:
801 case SND_SEQ_EVENT_SETPOS_TICK:
802 case SND_SEQ_EVENT_SETPOS_TIME:
803 case SND_SEQ_EVENT_QUEUE_SKEW:
807 case SND_SEQ_EVENT_TEMPO:
816 if (d->m_handler != NULL) {
817 d->m_handler->handleSequencerEvent(event->clone());
820 if (d->m_eventsEnabled) {
821 QObjectList::Iterator it;
822 for(it=d->m_listeners.begin(); it!=d->m_listeners.end(); ++it) {
824 QCoreApplication::postEvent(sub, event->clone());
834 while (snd_seq_event_input_pending(d->m_SeqHandle, 0) > 0);
843 if (d->m_Thread == 0) {
846 d->m_Thread->start( d->m_Thread->m_RealTime ?
847 QThread::TimeCriticalPriority : QThread::InheritPriority );
857 if (d->m_Thread != 0) {
858 if (d->m_Thread->isRunning()) {
860 while (!d->m_Thread->wait(500) && (counter < 10)) {
863 if (!d->m_Thread->isFinished()) {
864 d->m_Thread->terminate();
880 while (snd_seq_query_next_client(d->m_SeqHandle, cInfo.m_Info) >= 0) {
882 d->m_ClientList.append(cInfo);
884 d->m_NeedRefreshClientList =
false;
893 d->m_ClientList.clear();
903 if (d->m_NeedRefreshClientList)
916 snd_seq_get_client_info(d->m_SeqHandle, d->m_Info.m_Info);
931 snd_seq_set_client_info(d->m_SeqHandle, d->m_Info.m_Info);
940 if (d->m_SeqHandle != NULL) {
941 snd_seq_set_client_info(d->m_SeqHandle, d->m_Info.m_Info);
952 return d->m_Info.getName();
963 ClientInfoList::Iterator it;
964 if (d->m_NeedRefreshClientList)
966 for (it = d->m_ClientList.begin(); it != d->m_ClientList.end(); ++it) {
967 if ((*it).getClientId() == clientId) {
968 return (*it).getName();
981 if (newName != d->m_Info.getName()) {
982 d->m_Info.setName(newName);
1016 if (d->m_SeqHandle != NULL) {
1017 CHECK_ERROR(snd_seq_create_port(d->m_SeqHandle, port->m_Info.m_Info));
1018 d->m_Ports.push_back(port);
1029 if (d->m_SeqHandle != NULL) {
1037 MidiPortList::iterator it;
1038 for(it = d->m_Ports.begin(); it != d->m_Ports.end(); ++it)
1042 d->m_Ports.erase(it);
1054 if (d->m_SeqHandle != NULL) {
1055 MidiPortList::iterator it;
1056 for (it = d->m_Ports.begin(); it != d->m_Ports.end(); ++it) {
1057 CHECK_ERROR(snd_seq_delete_port(d->m_SeqHandle, (*it)->getPortInfo()->getPort()));
1058 (*it)->setMidiClient(NULL);
1059 d->m_Ports.erase(it);
1071 snd_seq_set_client_event_filter(d->m_SeqHandle, evtype);
1082 return d->m_Info.getBroadcastFilter();
1093 d->m_Info.setBroadcastFilter(newValue);
1105 return d->m_Info.getErrorBounce();
1116 d->m_Info.setErrorBounce(newValue);
1139 npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1140 pfds = (pollfd*) alloca(npfds *
sizeof(pollfd));
1141 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1142 while (snd_seq_event_output(d->m_SeqHandle, ev->
getHandle()) < 0)
1144 poll(pfds, npfds, timeout);
1167 npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1168 pfds = (pollfd*) alloca(npfds *
sizeof(pollfd));
1169 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1170 while (snd_seq_event_output_direct(d->m_SeqHandle, ev->
getHandle()) < 0)
1172 poll(pfds, npfds, timeout);
1209 npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1210 pfds = (pollfd*) alloca(npfds *
sizeof(pollfd));
1211 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1212 while (snd_seq_drain_output(d->m_SeqHandle) < 0)
1214 poll(pfds, npfds, timeout);
1227 snd_seq_sync_output_queue(d->m_SeqHandle);
1238 if (d->m_Queue == NULL) {
1251 if (d->m_Queue != NULL) {
1267 if (d->m_Queue != NULL) {
1270 d->m_Queue =
new MidiQueue(
this, queueName,
this);
1284 if (d->m_Queue != NULL) {
1287 d->m_Queue =
new MidiQueue(
this, queue_id,
this);
1301 if (d->m_Queue != NULL) {
1305 if ( queue_id >= 0) {
1306 d->m_Queue =
new MidiQueue(
this, queue_id,
this);
1320 if (d->m_Queue != NULL) {
1323 queue->setParent(
this);
1337 snd_seq_queue_info_t* qinfo;
1338 snd_seq_queue_info_alloca(&qinfo);
1340 for ( q = 0; q < max; ++q ) {
1341 err = snd_seq_get_queue_info(d->m_SeqHandle, q, qinfo);
1360 ClientInfoList::ConstIterator itc;
1361 PortInfoList::ConstIterator itp;
1363 if (d->m_NeedRefreshClientList)
1366 for (itc = d->m_ClientList.constBegin(); itc != d->m_ClientList.constEnd(); ++itc) {
1368 if ((ci.
getClientId() == SND_SEQ_CLIENT_SYSTEM) ||
1372 for(itp = lstPorts.constBegin(); itp != lstPorts.constEnd(); ++itp) {
1375 if ( ((filter & cap) != 0) &&
1376 ((SND_SEQ_PORT_CAP_NO_EXPORT & cap) == 0) ) {
1390 d->m_InputsAvail.clear();
1391 d->m_OutputsAvail.clear();
1392 d->m_InputsAvail =
filterPorts( SND_SEQ_PORT_CAP_READ |
1393 SND_SEQ_PORT_CAP_SUBS_READ );
1394 d->m_OutputsAvail =
filterPorts( SND_SEQ_PORT_CAP_WRITE |
1395 SND_SEQ_PORT_CAP_SUBS_WRITE );
1405 d->m_NeedRefreshClientList =
true;
1407 return d->m_InputsAvail;
1417 d->m_NeedRefreshClientList =
true;
1419 return d->m_OutputsAvail;
1431 d->m_listeners.append(listener);
1442 d->m_listeners.removeAll(listener);
1454 if (bEnabled != d->m_eventsEnabled) {
1455 d->m_eventsEnabled = bEnabled;
1466 snd_seq_system_info(d->m_SeqHandle, d->m_sysInfo.m_Info);
1467 return d->m_sysInfo;
1477 snd_seq_get_client_pool(d->m_SeqHandle, d->m_poolInfo.m_Info);
1478 return d->m_poolInfo;
1488 d->m_poolInfo = info;
1489 CHECK_WARNING(snd_seq_set_client_pool(d->m_SeqHandle, d->m_poolInfo.m_Info));
1519 CHECK_WARNING(snd_seq_set_client_pool_input(d->m_SeqHandle, size));
1529 CHECK_WARNING(snd_seq_set_client_pool_output(d->m_SeqHandle, size));
1539 CHECK_WARNING(snd_seq_set_client_pool_output_room(d->m_SeqHandle, size));
1597 CHECK_WARNING(snd_seq_remove_events(d->m_SeqHandle, spec->m_Info));
1607 snd_seq_event_t* ev;
1608 if (
CHECK_WARNING(snd_seq_extract_output(d->m_SeqHandle, &ev) == 0)) {
1622 return snd_seq_event_output_pending(d->m_SeqHandle);
1641 return snd_seq_event_input_pending(d->m_SeqHandle, fetch ? 1 : 0);
1653 return snd_seq_query_named_queue(d->m_SeqHandle, name.toLocal8Bit().data());
1664 return snd_seq_poll_descriptors_count(d->m_SeqHandle, events);
1684 return snd_seq_poll_descriptors(d->m_SeqHandle, pfds, space, events);
1696 unsigned short revents;
1697 CHECK_WARNING( snd_seq_poll_descriptors_revents( d->m_SeqHandle,
1710 return snd_seq_name(d->m_SeqHandle);
1720 CHECK_WARNING(snd_seq_set_client_name(d->m_SeqHandle, name));
1735 return CHECK_WARNING( snd_seq_create_simple_port( d->m_SeqHandle,
1736 name, caps, type ));
1746 CHECK_WARNING( snd_seq_delete_simple_port( d->m_SeqHandle, port ));
1758 CHECK_WARNING( snd_seq_connect_from(d->m_SeqHandle, myport, client, port ));
1770 CHECK_WARNING( snd_seq_connect_to(d->m_SeqHandle, myport, client, port ));
1782 CHECK_WARNING( snd_seq_disconnect_from(d->m_SeqHandle, myport, client, port ));
1794 CHECK_WARNING( snd_seq_disconnect_to(d->m_SeqHandle, myport, client, port ));
1812 QString testClient, testPort;
1813 ClientInfoList::ConstIterator cit;
1814 int pos = straddr.indexOf(
':');
1816 testClient = straddr.left(pos);
1817 testPort = straddr.mid(pos+1);
1819 testClient = straddr;
1822 addr.client = testClient.toInt(&ok);
1824 addr.port = testPort.toInt(&ok);
1826 if (d->m_NeedRefreshClientList)
1828 for ( cit = d->m_ClientList.constBegin();
1829 cit != d->m_ClientList.constEnd(); ++cit ) {
1831 if (testClient.compare(ci.
getName(), Qt::CaseInsensitive) == 0) {
1833 addr.port = testPort.toInt(&ok);
1848 QReadLocker locker(&m_mutex);
1858 QWriteLocker locker(&m_mutex);
1862 #if defined(RTKIT_SUPPORT) 1863 static pid_t _gettid(
void) {
1864 return (pid_t) ::syscall(SYS_gettid);
1869 MidiClient::SequencerInputThread::setRealtimePriority()
1871 struct sched_param p;
1872 int rt, policy = SCHED_RR | SCHED_RESET_ON_FORK;
1873 quint32 priority = 6;
1874 #if defined(RTKIT_SUPPORT) 1878 struct rlimit old_limit, new_limit;
1879 long long max_rttime;
1882 ::memset(&p, 0,
sizeof(p));
1883 p.sched_priority = priority;
1884 rt = ::pthread_setschedparam(::pthread_self(), policy, &p);
1886 #if defined(RTKIT_SUPPORT) 1887 const QString rtkit_service =
1888 QLatin1String(
"org.freedesktop.RealtimeKit1");
1889 const QString rtkit_path =
1890 QLatin1String(
"/org/freedesktop/RealtimeKit1");
1891 const QString rtkit_iface = rtkit_service;
1893 QDBusConnection bus = QDBusConnection::systemBus();
1894 QDBusInterface realtimeKit(rtkit_service, rtkit_path, rtkit_iface, bus);
1895 QVariant maxRTPrio = realtimeKit.property(
"MaxRealtimePriority");
1896 max_prio = maxRTPrio.toUInt(&ok);
1898 qWarning() <<
"invalid property RealtimeKit.MaxRealtimePriority";
1901 if (priority > max_prio)
1902 priority = max_prio;
1903 QVariant maxRTNSec = realtimeKit.property(
"RTTimeNSecMax");
1904 max_rttime = maxRTNSec.toLongLong(&ok);
1905 if (!ok || max_rttime < 0) {
1906 qWarning() <<
"invalid property RealtimeKit.RTTimeNSecMax";
1909 new_limit.rlim_cur = new_limit.rlim_max = max_rttime;
1910 rt = ::getrlimit(RLIMIT_RTTIME, &old_limit);
1912 qWarning() <<
"getrlimit() failed. err=" << rt << ::strerror(rt);
1915 rt = ::setrlimit(RLIMIT_RTTIME, &new_limit);
1917 qWarning() <<
"setrlimit() failed, err=" << rt << ::strerror(rt);
1920 QDBusMessage reply = realtimeKit.call(
"MakeThreadRealtime", thread, priority);
1921 if (reply.type() == QDBusMessage::ErrorMessage )
1922 qWarning() <<
"error returned by RealtimeKit.MakeThreadRealtime:" 1923 << reply.errorMessage();
1925 qWarning() <<
"pthread_setschedparam() failed, err=" 1926 << rt << ::strerror(rt);
1939 if ( priority() == TimeCriticalPriority )
1940 setRealtimePriority();
1942 if (m_MidiClient != NULL) {
1943 npfd = snd_seq_poll_descriptors_count(m_MidiClient->getHandle(), POLLIN);
1944 pfd = (pollfd *) alloca(npfd *
sizeof(pollfd));
1947 snd_seq_poll_descriptors(m_MidiClient->getHandle(), pfd, npfd, POLLIN);
1948 while (!stopped() && (m_MidiClient != NULL))
1950 int rt = poll(pfd, npfd, m_Wait);
1952 m_MidiClient->doEvents();
1958 qWarning() <<
"exception in input thread";
1968 snd_seq_client_info_malloc(&m_Info);
1977 snd_seq_client_info_malloc(&m_Info);
1978 snd_seq_client_info_copy(m_Info, other.m_Info);
1979 m_Ports = other.m_Ports;
1988 snd_seq_client_info_malloc(&m_Info);
1989 snd_seq_client_info_copy(m_Info, other);
1999 snd_seq_client_info_malloc(&m_Info);
2000 snd_seq_get_any_client_info(seq->
getHandle(), id, m_Info);
2009 snd_seq_client_info_free(m_Info);
2030 snd_seq_client_info_copy(m_Info, other.m_Info);
2031 m_Ports = other.m_Ports;
2042 return snd_seq_client_info_get_client(m_Info);
2049 snd_seq_client_type_t
2052 return snd_seq_client_info_get_type(m_Info);
2062 return QString(snd_seq_client_info_get_name(m_Info));
2072 return (snd_seq_client_info_get_broadcast_filter(m_Info) != 0);
2082 return (snd_seq_client_info_get_error_bounce(m_Info) != 0);
2090 const unsigned char*
2093 return snd_seq_client_info_get_event_filter(m_Info);
2103 return snd_seq_client_info_get_num_ports(m_Info);
2113 return snd_seq_client_info_get_event_lost(m_Info);
2123 snd_seq_client_info_set_client(m_Info, client);
2133 snd_seq_client_info_set_name(m_Info, name.toLocal8Bit().data());
2143 snd_seq_client_info_set_broadcast_filter(m_Info, val ? 1 : 0);
2153 snd_seq_client_info_set_error_bounce(m_Info, val ? 1 : 0);
2164 snd_seq_client_info_set_event_filter(m_Info, filter);
2179 while (snd_seq_query_next_port(seq->
getHandle(), info.m_Info) >= 0) {
2181 m_Ports.append(info);
2212 return snd_seq_client_info_sizeof();
2215 #if SND_LIB_VERSION > 0x010010 2222 ClientInfo::addFilter(
int eventType)
2224 snd_seq_client_info_event_filter_add(m_Info, eventType);
2233 ClientInfo::isFiltered(
int eventType)
2235 return (snd_seq_client_info_event_filter_check(m_Info, eventType) != 0);
2242 ClientInfo::clearFilter()
2244 snd_seq_client_info_event_filter_clear(m_Info);
2252 ClientInfo::removeFilter(
int eventType)
2254 snd_seq_client_info_event_filter_del(m_Info, eventType);
2263 snd_seq_system_info_malloc(&m_Info);
2272 snd_seq_system_info_malloc(&m_Info);
2273 snd_seq_system_info_copy(m_Info, other.m_Info);
2282 snd_seq_system_info_malloc(&m_Info);
2283 snd_seq_system_info_copy(m_Info, other);
2292 snd_seq_system_info_malloc(&m_Info);
2293 snd_seq_system_info(seq->
getHandle(), m_Info);
2301 snd_seq_system_info_free(m_Info);
2322 snd_seq_system_info_copy(m_Info, other.m_Info);
2332 return snd_seq_system_info_get_clients(m_Info);
2341 return snd_seq_system_info_get_ports(m_Info);
2350 return snd_seq_system_info_get_queues(m_Info);
2359 return snd_seq_system_info_get_channels(m_Info);
2368 return snd_seq_system_info_get_cur_queues(m_Info);
2377 return snd_seq_system_info_get_cur_clients(m_Info);
2386 return snd_seq_system_info_sizeof();
2394 snd_seq_client_pool_malloc(&m_Info);
2403 snd_seq_client_pool_malloc(&m_Info);
2404 snd_seq_client_pool_copy(m_Info, other.m_Info);
2413 snd_seq_client_pool_malloc(&m_Info);
2414 snd_seq_client_pool_copy(m_Info, other);
2423 snd_seq_client_pool_malloc(&m_Info);
2424 snd_seq_get_client_pool(seq->
getHandle(), m_Info);
2432 snd_seq_client_pool_free(m_Info);
2452 snd_seq_client_pool_copy(m_Info, other.m_Info);
2463 return snd_seq_client_pool_get_client(m_Info);
2473 return snd_seq_client_pool_get_input_free(m_Info);
2483 return snd_seq_client_pool_get_input_pool(m_Info);
2493 return snd_seq_client_pool_get_output_free(m_Info);
2503 return snd_seq_client_pool_get_output_pool(m_Info);
2514 return snd_seq_client_pool_get_output_room(m_Info);
2524 snd_seq_client_pool_set_input_pool(m_Info, size);
2534 snd_seq_client_pool_set_output_pool(m_Info, size);
2546 snd_seq_client_pool_set_output_room(m_Info, size);
2556 return snd_seq_client_pool_sizeof();
2559 #if SND_LIB_VERSION > 0x010004 2566 getRuntimeALSALibraryVersion()
2568 return QString(snd_asoundlib_version());
2577 getRuntimeALSALibraryNumber()
2579 QRegExp rx(
"(\\d+)");
2580 QString str = getRuntimeALSALibraryVersion();
2582 int pos = 0, result = 0, j = 0;
2583 while ((pos = rx.indexIn(str, pos)) != -1 && j < 3) {
2584 int v = rx.cap(1).toInt(&ok);
2589 pos += rx.matchedLength();
2594 #endif // SND_LIB_VERSION > 0x010004 2604 QRegExp rx(
".*Driver Version.*([\\d\\.]+).*");
2606 QFile f(
"/proc/asound/version");
2607 if (f.open(QFile::ReadOnly)) {
2608 QTextStream str(&f);
2609 if (rx.exactMatch(str.readLine().trimmed()))
2623 QRegExp rx(
"(\\d+)");
2626 int pos = 0, result = 0, j = 0;
2627 while ((pos = rx.indexIn(str, pos)) != -1 && j < 3) {
2628 int v = rx.cap(1).toInt(&ok);
2633 pos += rx.matchedLength();
void setClient(int client)
Sets the client number.
snd_seq_event_t * getHandle()
Gets the handle of the event.
MidiPort * createPort()
Create and attach a new MidiPort instance to this client.
void portAttach(MidiPort *port)
Attach a MidiPort instance to this client.
void setEventsEnabled(const bool bEnabled)
Enables the notification of received SequencerEvent instances to the listeners registered with addLis...
void setInputPool(int size)
Set the input pool size.
ALSA Event representing a queue control command.
int outputPending()
Returns the size of pending events on the output buffer.
void eventReceived(SequencerEvent *ev)
Signal emitted when an event is received.
QList< ClientInfo > ClientInfoList
List of sequencer client information.
void setBlockMode(bool newValue)
Change the blocking mode of the client.
void close()
Close the sequencer device.
void updateAvailablePorts()
Update the internal lists of user ports.
void portDetach(MidiPort *port)
Detach a MidiPort instance from this client.
void dropInputBuffer()
Remove all events on user-space input buffer.
Classes managing ALSA Sequencer clients.
void disconnectFrom(int myport, int client, int port)
Unsubscribe one port from another arbitrary sequencer client:port.
void setName(QString name)
Sets the client name.
bool parseAddress(const QString &straddr, snd_seq_addr &result)
Parse a text address representation, returning an ALSA address record.
void addListener(QObject *listener)
Adds a QObject to the listeners list.
int getMaxQueues()
Get the system's maximum number of queues.
void setErrorBounce(bool newValue)
Sets the error-bounce usage of the client.
virtual ~ClientInfo()
Destructor.
void setBroadcastFilter(bool val)
Sets the broadcast filter.
Generic event having a value property.
PoolInfo & getPoolInfo()
Gets a PoolInfo instance with an updated state of the client memory pool.
PoolInfo & operator=(const PoolInfo &other)
Assignment operator.
size_t getInputBufferSize()
Gets the size of the library input buffer for the ALSA client.
int getPollDescriptorsCount(short events)
Returns the number of poll descriptors.
bool isOpened()
Returns true if the sequencer is opened.
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
virtual ~MidiClient()
Destructor.
void setClientName(QString const &newName)
Changes the public name of the ALSA sequencer client.
virtual ~SystemInfo()
Destructor.
PortInfoList getAvailableOutputs()
Gets the available user output ports in the system.
void freeClients()
Releases the list of ALSA sequencer's clients.
void setClient(int client)
Sets the client identifier number.
void disconnectTo(int myport, int client, int port)
Unsubscribe one port to another arbitrary sequencer client:port.
void setOutputBufferSize(size_t newSize)
Sets the size of the library output buffer for the ALSA client.
const unsigned char * getEventFilter() __attribute__((deprecated))
Gets the client's event filter.
int createSimplePort(const char *name, unsigned int caps, unsigned int type)
Create an ALSA sequencer port, without using MidiPort.
void _setClientName(const char *name)
Sets the client name.
Event representing a MIDI control change event.
MidiQueue * createQueue()
Create and return a new MidiQueue associated to this client.
bool getBlockMode()
Returns the last block mode used in open()
void connectTo(int myport, int client, int port)
Subscribe one port to another arbitrary sequencer client:port.
MidiQueue * useQueue(int queue_id)
Create a new MidiQueue instance using a queue already existing in the system, associating it to the c...
SystemInfo()
Default constructor.
ALSA Event representing a change on some ALSA sequencer client on the system.
void setEventFilter(unsigned char *filter) __attribute__((deprecated))
Sets the event filter.
int getMaxPorts()
Get the system's maximum number of ports.
The QObject class is the base class of all Qt objects.
Base class for the event's hierarchy.
PortInfoList getPorts() const
Gets the ports list.
Event representing a MIDI system exclusive event.
int getInputFree()
Gets the available size on input pool.
void freePorts()
Release the ports list.
snd_seq_client_type_t getClientType()
Gets the client's type.
bool getBroadcastFilter()
Gets the broadcast filter usage of the client.
void setPoolOutputRoom(int size)
Sets the room size of the client's output pool.
void doEvents()
Dispatch the events received from the Sequencer.
void drainOutput(bool async=false, int timeout=-1)
Drain the library output buffer.
void stopSequencerInput()
Stops reading events from the ALSA sequencer.
void setRealTimeInput(bool enabled)
Enables real-time priority for the MIDI input thread.
void attach(MidiClient *seq)
Attach the port to a MidiClient instance.
virtual ~PoolInfo()
Destructor.
MidiPortList getMidiPorts() const
Gets the list of MidiPort instances belonging to this client.
#define CHECK_ERROR(x)
This macro calls the check error function.
int getClient()
Gets the client number.
QList< PortInfo > PortInfoList
List of port information objects.
void readPorts(MidiClient *seq)
Read the client ports.
int getEventLost()
Gets the number of lost events.
int getOutputRoom()
Gets the output room size.
int getMaxClients()
Get the system's maximum number of clients.
bool realTimeInputEnabled()
Return the real-time priority setting for the MIDI input thread.
void setHandler(SequencerEventHandler *handler)
Sets a sequencer event handler enabling the callback delivery mode.
void setClientName(QString name)
Sets the client name.
Sequencer Pool information.
void setMidiClient(MidiClient *seq)
Sets the MidiClient.
void setPoolOutput(int size)
Sets the size of the client's output pool.
void deleteSimplePort(int port)
Remove an ALSA sequencer port.
void setBroadcastFilter(bool newValue)
Sets the broadcast filter usage of the client.
void resetPoolInput()
Resets the client input pool.
void setPoolInfo(const PoolInfo &info)
Applies (updates) the client's PoolInfo data into the system.
bool getBroadcastFilter()
Gets the client's broadcast filter.
Sequencer events handler.
bool getErrorBounce()
Gets the client's error bounce.
void setThisClientInfo(const ClientInfo &val)
Sets the data supplied by the ClientInfo object into the ALSA sequencer client.
int getClientId()
Gets the client's numeric identifier.
int inputPending(bool fetch)
Gets the size of the events on the input buffer.
void connectFrom(int myport, int client, int port)
Subscribe one port from another arbitrary sequencer client:port.
ALSA Event representing a change on some ALSA sequencer port on the system.
Event representing a MIDI key pressure, or polyphonic after-touch event.
ALSA Event representing a tempo change for an ALSA queue.
Event representing a MIDI program change event.
int getCurrentClients()
Get the system's current number of clients.
ClientInfoList getAvailableClients()
Gets the list of clients from the ALSA sequencer.
QList< int > getAvailableQueues()
Get a list of the existing queues.
unsigned int getCapability()
Gets the capabilities bitmap.
void detachAllPorts()
Detach all the ports belonging to this client.
QString getClientName()
Gets the client's public name.
int getRuntimeALSADriverNumber()
Gets the runtime ALSA drivers version number.
int getCurrentQueues()
Get the system's current number of queues.
void setErrorBounce(bool val)
Sets the error bounce.
void resetPoolOutput()
Resets the client output pool.
MidiClient(QObject *parent=0)
Constructor.
void dropOutputBuffer()
Removes all events on the library output buffer.
void readSubscribers(MidiClient *seq)
Obtains the port subscribers lists.
void removeEvents(const RemoveEvents *spec)
Removes events on input/output buffers and pools.
int getClientId()
Gets the client ID for this object.
int pollDescriptors(struct pollfd *pfds, unsigned int space, short events)
Get poll descriptors.
Auxiliary class to remove events from an ALSA queue.
int getOpenMode()
Returns the last open mode used in open()
void readClients()
Reads the ALSA sequencer's clients list.
Class representing a note event with duration.
int getSizeOfInfo() const
Gets the size of the client pool object.
PortInfo * getPortInfo()
Gets the PortInfo object pointer.
bool getEventsEnabled() const
Returns true if the events mode of delivery has been enabled.
SystemInfo & operator=(const SystemInfo &other)
Assignment operator.
snd_seq_type_t getSequencerType()
Returns the type snd_seq_type_t of the given sequencer handle.
ClientInfo()
Default constructor.
unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds)
Gets the number of returned events from poll descriptors.
SystemInfo & getSystemInfo()
Gets a SystemInfo instance with the updated state of the system.
PoolInfo()
Default constructor.
ALSA Event representing a subscription between two ALSA clients and ports.
void dropOutput()
Clears the client's output buffer and and remove events in sequencer queue.
void startSequencerInput()
Starts reading events from the ALSA sequencer.
MidiQueue * getQueue()
Get the MidiQueue instance associated to this client.
int getSizeOfInfo() const
Get the system's info object size.
Event representing a MIDI bender, or pitch wheel event.
bool getErrorBounce()
Get the error-bounce usage of the client.
size_t getOutputBufferSize()
Gets the size of the library output buffer for the ALSA client.
void setOutputPool(int size)
Sets the output pool size.
Port information container.
void outputDirect(SequencerEvent *ev, bool async=false, int timeout=-1)
Output an event directly to the sequencer.
void applyClientInfo()
This internal method applies the ClientInfo data to the ALSA sequencer client.
Event representing a note-off MIDI event.
void dropInput()
Clears the client's input buffer and and remove events in sequencer queue.
QString getDeviceName()
Returns the name of the sequencer device.
const char * _getDeviceName()
Gets the internal sequencer device name.
Event representing a MIDI channel pressure or after-touch event.
void setPoolInput(int size)
Sets the size of the client's input pool.
Event representing a note-on MIDI event.
int getOutputPool()
Gets the output pool size.
void setOutputRoom(int size)
Sets the output room size.
void setInputBufferSize(size_t newSize)
Sets the size of the library input buffer for the ALSA client.
void output(SequencerEvent *ev, bool async=false, int timeout=-1)
Output an event using the library output buffer.
ClientInfo & operator=(const ClientInfo &other)
Assignment operator.
PoolInfo * clone()
Clone the pool info obeject.
int getPort()
Gets the port number.
#define CHECK_WARNING(x)
This macro calls the check warning function.
int getInputPool()
Gets the input pool size.
Classes managing ALSA Sequencer queues.
QString getName()
Gets the client's name.
int getClientId()
Gets the client ID.
QString getRuntimeALSADriverVersion()
Gets the runtime ALSA drivers version string.
int getNumPorts()
Gets the client's port count.
QList< MidiPort * > MidiPortList
List of Ports instances.
void outputBuffer(SequencerEvent *ev)
Output an event using the library output buffer, without draining the buffer.
int getMaxChannels()
Get the system's maximum number of channels.
void synchronizeOutput()
Wait until all sent events are processed.
The QThread class provides platform-independent threads.
int getOutputFree()
Gets the available size on output pool.
Classes managing ALSA Sequencer events.
int getQueueId(const QString &name)
Gets the queue's numeric identifier corresponding to the provided name.
void addEventFilter(int evtype)
Add an event filter to the client.
void removeListener(QObject *listener)
Removes a QObject listener from the listeners list.
SystemInfo * clone()
Clone the system info object.
ClientInfo * clone()
Clone the client info object.
void open(const QString deviceName="default", const int openMode=SND_SEQ_OPEN_DUPLEX, const bool blockMode=false)
Open the sequencer device.
PortInfoList filterPorts(unsigned int filter)
Gets a list of the available user ports in the system, filtered by the given bitmap of desired capabi...
PortInfoList getAvailableInputs()
Gets the available user input ports in the system.
SequencerEvent * extractOutput()
Extracts (and removes) the first event in the output buffer.
void setPort(int port)
Set the port number.
int getSizeOfInfo() const
Gets the size of the internal object.
ClientInfo & getThisClientInfo()
Gets the ClientInfo object holding data about this client.