20 #include <QCoreApplication> 22 #include <QReadLocker> 23 #include <QRegularExpression> 25 #include <QWriteLocker> 30 #if defined(RTKIT_SUPPORT) 31 #include <QDBusConnection> 32 #include <QDBusInterface> 33 #include <sys/resource.h> 34 #include <sys/syscall.h> 35 #include <sys/types.h> 40 #define RLIMIT_RTTIME 15 43 #ifndef SCHED_RESET_ON_FORK 44 #define SCHED_RESET_ON_FORK 0x40000000 47 #ifndef DEFAULT_INPUT_TIMEOUT 48 #define DEFAULT_INPUT_TIMEOUT 500 200 void setRealtimePriority();
206 QReadWriteLock m_mutex;
209 class MidiClient::MidiClientPrivate
212 MidiClientPrivate() :
213 m_eventsEnabled(false),
215 m_NeedRefreshClientList(true),
216 m_OpenMode(SND_SEQ_OPEN_DUPLEX),
217 m_DeviceName(
"default"),
218 m_SeqHandle(nullptr),
224 bool m_eventsEnabled;
226 bool m_NeedRefreshClientList;
228 QString m_DeviceName;
229 snd_seq_t* m_SeqHandle;
230 QPointer<SequencerInputThread> m_Thread;
231 QPointer<MidiQueue> m_Queue;
239 QObjectList m_listeners;
260 d(new MidiClientPrivate)
262 qRegisterMetaType<drumstick::ALSA::SequencerEvent>();
263 qRegisterMetaType<drumstick::ALSA::SequencerEvent*>();
288 return d->m_SeqHandle;
297 return !d.isNull() && (d->m_SeqHandle !=
nullptr);
306 return d->m_DeviceName;
315 return d->m_OpenMode;
324 return d->m_BlockMode;
333 return d->m_eventsEnabled;
342 d->m_handler = handler;
356 if (d->m_Thread ==
nullptr) {
358 d->m_Thread->m_RealTime = enable;
369 if (d->m_Thread ==
nullptr)
371 return d->m_Thread->m_RealTime;
397 const bool blockMode)
400 openMode, blockMode ? 0 : SND_SEQ_NONBLOCK ) );
402 d->m_DeviceName = deviceName;
403 d->m_OpenMode = openMode;
404 d->m_BlockMode = blockMode;
429 const QString deviceName,
431 const bool blockMode )
434 deviceName.toLocal8Bit().data(),
436 blockMode ? 0 : SND_SEQ_NONBLOCK,
439 d->m_DeviceName = deviceName;
440 d->m_OpenMode = openMode;
441 d->m_BlockMode = blockMode;
454 if (d->m_SeqHandle !=
nullptr) {
457 d->m_SeqHandle =
nullptr;
472 return snd_seq_get_output_buffer_size(d->m_SeqHandle);
502 return snd_seq_get_input_buffer_size(d->m_SeqHandle);
533 if (d->m_BlockMode != newValue)
535 d->m_BlockMode = newValue;
536 if (d->m_SeqHandle !=
nullptr)
564 return snd_seq_type(d->m_SeqHandle);
592 snd_seq_event_t* evp =
nullptr;
594 err = snd_seq_event_input(d->m_SeqHandle, &evp);
595 if ((err >= 0) && (evp !=
nullptr)) {
598 case SND_SEQ_EVENT_NOTE:
602 case SND_SEQ_EVENT_NOTEON:
606 case SND_SEQ_EVENT_NOTEOFF:
610 case SND_SEQ_EVENT_KEYPRESS:
614 case SND_SEQ_EVENT_CONTROLLER:
615 case SND_SEQ_EVENT_CONTROL14:
616 case SND_SEQ_EVENT_REGPARAM:
617 case SND_SEQ_EVENT_NONREGPARAM:
621 case SND_SEQ_EVENT_PGMCHANGE:
625 case SND_SEQ_EVENT_CHANPRESS:
629 case SND_SEQ_EVENT_PITCHBEND:
633 case SND_SEQ_EVENT_SYSEX:
637 case SND_SEQ_EVENT_PORT_SUBSCRIBED:
638 case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
642 case SND_SEQ_EVENT_PORT_CHANGE:
643 case SND_SEQ_EVENT_PORT_EXIT:
644 case SND_SEQ_EVENT_PORT_START:
646 d->m_NeedRefreshClientList =
true;
649 case SND_SEQ_EVENT_CLIENT_CHANGE:
650 case SND_SEQ_EVENT_CLIENT_EXIT:
651 case SND_SEQ_EVENT_CLIENT_START:
653 d->m_NeedRefreshClientList =
true;
656 case SND_SEQ_EVENT_SONGPOS:
657 case SND_SEQ_EVENT_SONGSEL:
658 case SND_SEQ_EVENT_QFRAME:
659 case SND_SEQ_EVENT_TIMESIGN:
660 case SND_SEQ_EVENT_KEYSIGN:
664 case SND_SEQ_EVENT_SETPOS_TICK:
665 case SND_SEQ_EVENT_SETPOS_TIME:
666 case SND_SEQ_EVENT_QUEUE_SKEW:
670 case SND_SEQ_EVENT_TEMPO:
679 if (d->m_handler !=
nullptr) {
680 d->m_handler->handleSequencerEvent(event->clone());
683 if (d->m_eventsEnabled) {
684 QObjectList::Iterator it;
685 for(it=d->m_listeners.begin(); it!=d->m_listeners.end(); ++it) {
687 QCoreApplication::postEvent(sub, event->clone());
697 while (snd_seq_event_input_pending(d->m_SeqHandle, 0) > 0);
706 if (d->m_Thread ==
nullptr) {
709 d->m_Thread->start( d->m_Thread->m_RealTime ?
710 QThread::TimeCriticalPriority : QThread::InheritPriority );
720 if (d->m_Thread !=
nullptr) {
721 if (d->m_Thread->isRunning()) {
723 while (!d->m_Thread->wait(500) && (counter < 10)) {
726 if (!d->m_Thread->isFinished()) {
727 d->m_Thread->terminate();
743 while (snd_seq_query_next_client(d->m_SeqHandle, cInfo.m_Info) >= 0) {
745 d->m_ClientList.append(cInfo);
747 d->m_NeedRefreshClientList =
false;
756 d->m_ClientList.clear();
766 if (d->m_NeedRefreshClientList)
779 snd_seq_get_client_info(d->m_SeqHandle, d->m_Info.m_Info);
794 snd_seq_set_client_info(d->m_SeqHandle, d->m_Info.m_Info);
803 if (d->m_SeqHandle !=
nullptr) {
804 snd_seq_set_client_info(d->m_SeqHandle, d->m_Info.m_Info);
815 return d->m_Info.getName();
826 ClientInfoList::Iterator it;
827 if (d->m_NeedRefreshClientList)
829 for (it = d->m_ClientList.begin(); it != d->m_ClientList.end(); ++it) {
830 if ((*it).getClientId() == clientId) {
831 return (*it).getName();
844 if (newName != d->m_Info.getName()) {
845 d->m_Info.setName(newName);
879 if (d->m_SeqHandle !=
nullptr) {
881 d->m_Ports.push_back(port);
892 if (d->m_SeqHandle !=
nullptr) {
900 MidiPortList::iterator it;
901 for(it = d->m_Ports.begin(); it != d->m_Ports.end(); ++it)
905 d->m_Ports.erase(it);
917 if (d->m_SeqHandle !=
nullptr) {
918 QMutableListIterator<MidiPort*> it(d->m_Ports);
919 while (it.hasNext()) {
935 snd_seq_set_client_event_filter(d->m_SeqHandle, evtype);
946 return d->m_Info.getBroadcastFilter();
957 d->m_Info.setBroadcastFilter(newValue);
969 return d->m_Info.getErrorBounce();
980 d->m_Info.setErrorBounce(newValue);
998 pollfd* pfds =
nullptr;
1002 int npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1003 pfds = (pollfd*) calloc(npfds,
sizeof(pollfd));
1004 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1005 while (snd_seq_event_output(d->m_SeqHandle, ev->
getHandle()) < 0)
1007 poll(pfds, npfds, timeout);
1029 int npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1030 pollfd* pfds = (pollfd*) calloc(npfds,
sizeof(pollfd));
1031 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1032 while (snd_seq_event_output_direct(d->m_SeqHandle, ev->
getHandle()) < 0)
1034 poll(pfds, npfds, timeout);
1070 int npfds = snd_seq_poll_descriptors_count(d->m_SeqHandle, POLLOUT);
1071 pollfd* pfds = (pollfd*) calloc(npfds,
sizeof(pollfd));
1072 snd_seq_poll_descriptors(d->m_SeqHandle, pfds, npfds, POLLOUT);
1073 while (snd_seq_drain_output(d->m_SeqHandle) < 0)
1075 poll(pfds, npfds, timeout);
1089 snd_seq_sync_output_queue(d->m_SeqHandle);
1100 if (d->m_Queue ==
nullptr) {
1113 if (d->m_Queue !=
nullptr) {
1129 if (d->m_Queue !=
nullptr) {
1132 d->m_Queue =
new MidiQueue(
this, queueName,
this);
1146 if (d->m_Queue !=
nullptr) {
1149 d->m_Queue =
new MidiQueue(
this, queue_id,
this);
1163 if (d->m_Queue !=
nullptr) {
1167 if ( queue_id >= 0) {
1168 d->m_Queue =
new MidiQueue(
this, queue_id,
this);
1182 if (d->m_Queue !=
nullptr) {
1185 queue->setParent(
this);
1199 snd_seq_queue_info_t* qinfo;
1200 snd_seq_queue_info_alloca(&qinfo);
1202 for ( q = 0; q < max; ++q ) {
1203 err = snd_seq_get_queue_info(d->m_SeqHandle, q, qinfo);
1222 ClientInfoList::ConstIterator itc;
1223 PortInfoList::ConstIterator itp;
1225 if (d->m_NeedRefreshClientList)
1228 for (itc = d->m_ClientList.constBegin(); itc != d->m_ClientList.constEnd(); ++itc) {
1230 if ((ci.
getClientId() == SND_SEQ_CLIENT_SYSTEM) ||
1234 for(itp = lstPorts.constBegin(); itp != lstPorts.constEnd(); ++itp) {
1237 if ( ((filter & cap) != 0) &&
1238 ((SND_SEQ_PORT_CAP_NO_EXPORT & cap) == 0) ) {
1252 d->m_InputsAvail.clear();
1253 d->m_OutputsAvail.clear();
1254 d->m_InputsAvail =
filterPorts( SND_SEQ_PORT_CAP_READ |
1255 SND_SEQ_PORT_CAP_SUBS_READ );
1256 d->m_OutputsAvail =
filterPorts( SND_SEQ_PORT_CAP_WRITE |
1257 SND_SEQ_PORT_CAP_SUBS_WRITE );
1267 d->m_NeedRefreshClientList =
true;
1269 return d->m_InputsAvail;
1279 d->m_NeedRefreshClientList =
true;
1281 return d->m_OutputsAvail;
1293 d->m_listeners.append(listener);
1304 d->m_listeners.removeAll(listener);
1316 if (bEnabled != d->m_eventsEnabled) {
1317 d->m_eventsEnabled = bEnabled;
1328 snd_seq_system_info(d->m_SeqHandle, d->m_sysInfo.m_Info);
1329 return d->m_sysInfo;
1339 snd_seq_get_client_pool(d->m_SeqHandle, d->m_poolInfo.m_Info);
1340 return d->m_poolInfo;
1350 d->m_poolInfo = info;
1469 snd_seq_event_t* ev;
1484 return snd_seq_event_output_pending(d->m_SeqHandle);
1503 return snd_seq_event_input_pending(d->m_SeqHandle, fetch ? 1 : 0);
1515 return snd_seq_query_named_queue(d->m_SeqHandle, name.toLocal8Bit().data());
1526 return snd_seq_poll_descriptors_count(d->m_SeqHandle, events);
1546 return snd_seq_poll_descriptors(d->m_SeqHandle, pfds, space, events);
1558 unsigned short revents;
1572 return snd_seq_name(d->m_SeqHandle);
1598 name, caps, type ));
1674 QString testClient, testPort;
1675 ClientInfoList::ConstIterator cit;
1676 int pos = straddr.indexOf(
':');
1678 testClient = straddr.left(pos);
1679 testPort = straddr.mid(pos+1);
1681 testClient = straddr;
1684 addr.client = testClient.toInt(&ok);
1686 addr.port = testPort.toInt(&ok);
1688 if (d->m_NeedRefreshClientList)
1690 for ( cit = d->m_ClientList.constBegin();
1691 cit != d->m_ClientList.constEnd(); ++cit ) {
1693 if (testClient.compare(ci.
getName(), Qt::CaseInsensitive) == 0) {
1695 addr.port = testPort.toInt(&ok);
1710 QReadLocker locker(&m_mutex);
1720 QWriteLocker locker(&m_mutex);
1724 #if defined(RTKIT_SUPPORT) 1725 static pid_t _gettid() {
1726 return (pid_t) ::syscall(SYS_gettid);
1731 MidiClient::SequencerInputThread::setRealtimePriority()
1733 struct sched_param p;
1734 int rt, policy = SCHED_RR | SCHED_RESET_ON_FORK;
1735 quint32 priority = 6;
1736 #if defined(RTKIT_SUPPORT) 1740 struct rlimit old_limit, new_limit;
1741 long long max_rttime;
1744 ::memset(&p, 0,
sizeof(p));
1745 p.sched_priority = priority;
1746 rt = ::pthread_setschedparam(::pthread_self(), policy, &p);
1748 #if defined(RTKIT_SUPPORT) 1749 const QString rtkit_service =
1750 QStringLiteral(
"org.freedesktop.RealtimeKit1");
1751 const QString rtkit_path =
1752 QStringLiteral(
"/org/freedesktop/RealtimeKit1");
1753 const QString rtkit_iface = rtkit_service;
1755 QDBusConnection bus = QDBusConnection::systemBus();
1756 QDBusInterface realtimeKit(rtkit_service, rtkit_path, rtkit_iface, bus);
1757 QVariant maxRTPrio = realtimeKit.property(
"MaxRealtimePriority");
1758 max_prio = maxRTPrio.toUInt(&ok);
1760 qWarning() <<
"invalid property RealtimeKit.MaxRealtimePriority";
1763 if (priority > max_prio)
1764 priority = max_prio;
1765 QVariant maxRTNSec = realtimeKit.property(
"RTTimeNSecMax");
1766 max_rttime = maxRTNSec.toLongLong(&ok);
1767 if (!ok || max_rttime < 0) {
1768 qWarning() <<
"invalid property RealtimeKit.RTTimeNSecMax";
1771 new_limit.rlim_cur = new_limit.rlim_max = max_rttime;
1772 rt = ::getrlimit(RLIMIT_RTTIME, &old_limit);
1774 qWarning() <<
"getrlimit() failed. err=" << rt << ::strerror(rt);
1777 rt = ::setrlimit(RLIMIT_RTTIME, &new_limit);
1779 qWarning() <<
"setrlimit() failed, err=" << rt << ::strerror(rt);
1782 QDBusMessage reply = realtimeKit.call(
"MakeThreadRealtime", thread, priority);
1783 if (reply.type() == QDBusMessage::ErrorMessage )
1784 qWarning() <<
"error returned by RealtimeKit.MakeThreadRealtime:" 1785 << reply.errorMessage();
1788 qWarning() <<
"pthread_setschedparam() failed, err=" 1789 << rt << ::strerror(rt);
1799 if ( priority() == TimeCriticalPriority ) {
1800 setRealtimePriority();
1802 if (m_MidiClient !=
nullptr) {
1803 int npfd = snd_seq_poll_descriptors_count(m_MidiClient->getHandle(), POLLIN);
1804 pollfd* pfd = (pollfd *) calloc(npfd,
sizeof(pollfd));
1807 snd_seq_poll_descriptors(m_MidiClient->getHandle(), pfd, npfd, POLLIN);
1808 while (!stopped() && (m_MidiClient !=
nullptr))
1810 int rt = poll(pfd, npfd, m_Wait);
1812 m_MidiClient->doEvents();
1818 qWarning() <<
"exception in input thread";
1829 snd_seq_client_info_malloc(&m_Info);
1838 snd_seq_client_info_malloc(&m_Info);
1839 snd_seq_client_info_copy(m_Info, other.m_Info);
1840 m_Ports = other.m_Ports;
1849 snd_seq_client_info_malloc(&m_Info);
1850 snd_seq_client_info_copy(m_Info, other);
1860 snd_seq_client_info_malloc(&m_Info);
1861 snd_seq_get_any_client_info(seq->
getHandle(), id, m_Info);
1870 snd_seq_client_info_free(m_Info);
1893 snd_seq_client_info_copy(m_Info, other.m_Info);
1894 m_Ports = other.m_Ports;
1905 return snd_seq_client_info_get_client(m_Info);
1912 snd_seq_client_type_t
1915 return snd_seq_client_info_get_type(m_Info);
1925 return QString(snd_seq_client_info_get_name(m_Info));
1935 return (snd_seq_client_info_get_broadcast_filter(m_Info) != 0);
1945 return (snd_seq_client_info_get_error_bounce(m_Info) != 0);
1953 const unsigned char*
1956 return snd_seq_client_info_get_event_filter(m_Info);
1966 return snd_seq_client_info_get_num_ports(m_Info);
1976 return snd_seq_client_info_get_event_lost(m_Info);
1986 snd_seq_client_info_set_client(m_Info, client);
1996 snd_seq_client_info_set_name(m_Info, name.toLocal8Bit().data());
2006 snd_seq_client_info_set_broadcast_filter(m_Info, val ? 1 : 0);
2016 snd_seq_client_info_set_error_bounce(m_Info, val ? 1 : 0);
2027 snd_seq_client_info_set_event_filter(m_Info, filter);
2042 while (snd_seq_query_next_port(seq->
getHandle(), info.m_Info) >= 0) {
2044 m_Ports.append(info);
2075 return snd_seq_client_info_sizeof();
2078 #if SND_LIB_VERSION > 0x010010 2085 ClientInfo::addFilter(
int eventType)
2087 snd_seq_client_info_event_filter_add(m_Info, eventType);
2096 ClientInfo::isFiltered(
int eventType)
2098 return (snd_seq_client_info_event_filter_check(m_Info, eventType) != 0);
2105 ClientInfo::clearFilter()
2107 snd_seq_client_info_event_filter_clear(m_Info);
2115 ClientInfo::removeFilter(
int eventType)
2117 snd_seq_client_info_event_filter_del(m_Info, eventType);
2126 snd_seq_system_info_malloc(&m_Info);
2135 snd_seq_system_info_malloc(&m_Info);
2136 snd_seq_system_info_copy(m_Info, other.m_Info);
2145 snd_seq_system_info_malloc(&m_Info);
2146 snd_seq_system_info_copy(m_Info, other);
2155 snd_seq_system_info_malloc(&m_Info);
2156 snd_seq_system_info(seq->
getHandle(), m_Info);
2164 snd_seq_system_info_free(m_Info);
2187 snd_seq_system_info_copy(m_Info, other.m_Info);
2197 return snd_seq_system_info_get_clients(m_Info);
2206 return snd_seq_system_info_get_ports(m_Info);
2215 return snd_seq_system_info_get_queues(m_Info);
2224 return snd_seq_system_info_get_channels(m_Info);
2233 return snd_seq_system_info_get_cur_queues(m_Info);
2242 return snd_seq_system_info_get_cur_clients(m_Info);
2251 return snd_seq_system_info_sizeof();
2259 snd_seq_client_pool_malloc(&m_Info);
2268 snd_seq_client_pool_malloc(&m_Info);
2269 snd_seq_client_pool_copy(m_Info, other.m_Info);
2278 snd_seq_client_pool_malloc(&m_Info);
2279 snd_seq_client_pool_copy(m_Info, other);
2288 snd_seq_client_pool_malloc(&m_Info);
2289 snd_seq_get_client_pool(seq->
getHandle(), m_Info);
2297 snd_seq_client_pool_free(m_Info);
2320 snd_seq_client_pool_copy(m_Info, other.m_Info);
2331 return snd_seq_client_pool_get_client(m_Info);
2341 return snd_seq_client_pool_get_input_free(m_Info);
2351 return snd_seq_client_pool_get_input_pool(m_Info);
2361 return snd_seq_client_pool_get_output_free(m_Info);
2371 return snd_seq_client_pool_get_output_pool(m_Info);
2382 return snd_seq_client_pool_get_output_room(m_Info);
2392 snd_seq_client_pool_set_input_pool(m_Info, size);
2402 snd_seq_client_pool_set_output_pool(m_Info, size);
2414 snd_seq_client_pool_set_output_room(m_Info, size);
2424 return snd_seq_client_pool_sizeof();
2427 #if SND_LIB_VERSION > 0x010004 2434 getRuntimeALSALibraryVersion()
2436 return QString(snd_asoundlib_version());
2445 getRuntimeALSALibraryNumber()
2447 QRegularExpression rx(
"(\\d+)");
2448 QString str = getRuntimeALSALibraryVersion();
2450 int result = 0, j = 0;
2451 QRegularExpressionMatchIterator i = rx.globalMatch(str);
2452 while (i.hasNext() && (j < 3)) {
2453 QRegularExpressionMatch m = i.next();
2454 int v = m.captured(1).toInt(&ok);
2463 #endif // SND_LIB_VERSION > 0x010004 2473 QRegularExpression rx(
"([\\d\\.]+)");
2475 QFile f(
"/proc/asound/version");
2476 if (f.open(QFile::ReadOnly)) {
2477 QTextStream str(&f);
2478 QString sub = str.readLine().trimmed();
2479 QRegularExpressionMatch m = rx.match(sub);
2495 QRegularExpression rx(
"(\\d+)");
2498 int result = 0, j = 0;
2499 QRegularExpressionMatchIterator i = rx.globalMatch(str);
2500 while (i.hasNext() && (j < 3)) {
2501 QRegularExpressionMatch m = i.next();
2502 int v = m.captured(1).toInt(&ok);
2522 return QStringLiteral(SND_LIB_VERSION_STR);
2531 return QStringLiteral(QT_STRINGIFY(VERSION));
SystemInfo()
Default constructor.
MidiPortList getMidiPorts() const
Gets the list of MidiPort instances belonging to this client.
Sequencer Pool information.
bool getBroadcastFilter()
Gets the broadcast filter usage of the client.
void portDetach(MidiPort *port)
Detach a MidiPort instance from this client.
int getOutputFree()
Gets the available size on output pool.
void setBlockMode(bool newValue)
Change the blocking mode of the client.
ClientInfo & getThisClientInfo()
Gets the ClientInfo object holding data about this client.
MidiQueue * getQueue()
Get the MidiQueue instance associated to this client.
void removeListener(QObject *listener)
Removes a QObject listener from the listeners list.
Error checking functions and macros.
MidiQueue * createQueue()
Create and return a new MidiQueue associated to this client.
PoolInfo & getPoolInfo()
Gets a PoolInfo instance with an updated state of the client memory pool.
int getMaxPorts()
Get the system's maximum number of ports.
void setHandler(SequencerEventHandler *handler)
Sets a sequencer event handler enabling the callback delivery mode.
MidiClient(QObject *parent=nullptr)
Constructor.
void setClient(int client)
Sets the client number.
int getQueueId(const QString &name)
Gets the queue's numeric identifier corresponding to the provided name.
QList< MidiPort * > MidiPortList
List of Ports instances.
int inputPending(bool fetch)
Gets the size of the events on the input buffer.
Classes managing ALSA Sequencer clients.
bool stopped()
Returns true or false depending on the input thread state.
void readClients()
Reads the ALSA sequencer's clients list.
void setRealTimeInput(bool enabled)
Enables real-time priority for the MIDI input thread.
int outputPending()
Returns the size of pending events on the output buffer.
void resetPoolOutput()
Resets the client output pool.
void setPort(int port)
Set the port number.
Q_DECL_DEPRECATED void setEventFilter(unsigned char *filter)
Sets the event filter.
SystemInfo & getSystemInfo()
Gets a SystemInfo instance with the updated state of the system.
int getMaxChannels()
Get the system's maximum number of channels.
MidiQueue * useQueue(int queue_id)
Create a new MidiQueue instance using a queue already existing in the system, associating it to the c...
size_t getOutputBufferSize()
Gets the size of the library output buffer for the ALSA client.
void setInputBufferSize(size_t newSize)
Sets the size of the library input buffer for the ALSA client.
int getOpenMode()
Returns the last open mode used in open()
Event representing a MIDI bender, or pitch wheel event.
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
int getNumPorts()
Gets the client's port count.
ClientInfo & operator=(const ClientInfo &other)
Assignment operator.
Q_DECL_DEPRECATED const unsigned char * getEventFilter()
Gets the client's event filter.
#define DRUMSTICK_ALSA_CHECK_WARNING(x)
This macro calls the check warning function.
void applyClientInfo()
This internal method applies the ClientInfo data to the ALSA sequencer client.
Event representing a note-off MIDI event.
int getPort()
Gets the port number.
void setInputPool(int size)
Set the input pool size.
void setErrorBounce(bool val)
Sets the error bounce.
void updateAvailablePorts()
Update the internal lists of user ports.
PoolInfo()
Default constructor.
Event representing a MIDI system exclusive event.
snd_seq_client_type_t getClientType()
Gets the client's type.
The QObject class is the base class of all Qt objects.
void detachAllPorts()
Detach all the ports belonging to this client.
void setClient(int client)
Sets the client identifier number.
Generic event having a value property.
unsigned short pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds)
Gets the number of returned events from poll descriptors.
void setOutputBufferSize(size_t newSize)
Sets the size of the library output buffer for the ALSA client.
void setPoolInfo(const PoolInfo &info)
Applies (updates) the client's PoolInfo data into the system.
int getMaxQueues()
Get the system's maximum number of queues.
QString getRuntimeALSADriverVersion()
Gets the runtime ALSA drivers version string.
void setBroadcastFilter(bool val)
Sets the broadcast filter.
QList< PortInfo > PortInfoList
List of port information objects.
void setName(QString name)
Sets the client name.
size_t getInputBufferSize()
Gets the size of the library input buffer for the ALSA client.
QString getName()
Gets the client's name.
snd_seq_event_t * getHandle()
Gets the handle of the event.
void startSequencerInput()
Starts reading events from the ALSA sequencer.
void dropInput()
Clears the client's input buffer and and remove events in sequencer queue.
Port information container.
int getCurrentClients()
Get the system's current number of clients.
int getSizeOfInfo() const
Gets the size of the internal object.
ClientInfo * clone()
Clone the client info object.
virtual ~PoolInfo()
Destructor.
void freePorts()
Release the ports list.
Event representing a MIDI channel pressure or after-touch event.
int getInputFree()
Gets the available size on input pool.
PortInfoList getAvailableOutputs()
Gets the available user output ports in the system.
void deleteSimplePort(int port)
Remove an ALSA sequencer port.
QString getDrumstickLibraryVersion()
getDrumstickLibraryVersion provides the Drumstick version as an edited QString
void open(const QString deviceName="default", const int openMode=SND_SEQ_OPEN_DUPLEX, const bool blockMode=false)
Open the sequencer device.
int getOutputPool()
Gets the output pool size.
void setBroadcastFilter(bool newValue)
Sets the broadcast filter usage of the client.
void synchronizeOutput()
Wait until all sent events are processed.
void dropInputBuffer()
Remove all events on user-space input buffer.
void run() override
Main input thread process loop.
void disconnectFrom(int myport, int client, int port)
Unsubscribe one port from another arbitrary sequencer client:port.
void portAttach(MidiPort *port)
Attach a MidiPort instance to this client.
Class representing a note event with duration.
QString getDeviceName()
Returns the name of the sequencer device.
void resetPoolInput()
Resets the client input pool.
Base class for the event's hierarchy.
QList< ClientInfo > ClientInfoList
List of sequencer client information.
bool parseAddress(const QString &straddr, snd_seq_addr &result)
Parse a text address representation, returning an ALSA address record.
void doEvents()
Dispatch the events received from the Sequencer.
void stop()
Stops the input thread.
void dropOutputBuffer()
Removes all events on the library output buffer.
void addEventFilter(int evtype)
Add an event filter to the client.
void setEventsEnabled(const bool bEnabled)
Enables the notification of received SequencerEvent instances to the listeners registered with addLis...
PortInfoList filterPorts(unsigned int filter)
Gets a list of the available user ports in the system, filtered by the given bitmap of desired capabi...
int pollDescriptors(struct pollfd *pfds, unsigned int space, short events)
Get poll descriptors.
Auxiliary class to remove events from an ALSA queue.
void setClientName(QString const &newName)
Changes the public name of the ALSA sequencer client.
PortInfoList getAvailableInputs()
Gets the available user input ports in the system.
SystemInfo & operator=(const SystemInfo &other)
Assignment operator.
int getCurrentQueues()
Get the system's current number of queues.
void removeEvents(const RemoveEvents *spec)
Removes events on input/output buffers and pools.
const char * _getDeviceName()
Gets the internal sequencer device name.
SequencerEvent * extractOutput()
Extracts (and removes) the first event in the output buffer.
ALSA Event representing a tempo change for an ALSA queue.
bool getErrorBounce()
Get the error-bounce usage of the client.
bool getEventsEnabled() const
Returns true if the events mode of delivery has been enabled.
ALSA Event representing a queue control command.
void freeClients()
Releases the list of ALSA sequencer's clients.
Sequencer events handler.
void connectFrom(int myport, int client, int port)
Subscribe one port from another arbitrary sequencer client:port.
virtual ~SystemInfo()
Destructor.
void setPoolOutputRoom(int size)
Sets the room size of the client's output pool.
Event representing a MIDI program change event.
void close()
Close the sequencer device.
void addListener(QObject *listener)
Adds a QObject to the listeners list.
void outputDirect(SequencerEvent *ev, bool async=false, int timeout=-1)
Output an event directly to the sequencer.
void setErrorBounce(bool newValue)
Sets the error-bounce usage of the client.
bool isOpened()
Returns true if the sequencer is opened.
void readSubscribers(MidiClient *seq)
Obtains the port subscribers lists.
void setClientName(QString name)
Sets the client name.
int getClientId()
Gets the client ID.
void readPorts(MidiClient *seq)
Read the client ports.
ClientInfoList getAvailableClients()
Gets the list of clients from the ALSA sequencer.
snd_seq_type_t getSequencerType()
Returns the type snd_seq_type_t of the given sequencer handle.
bool realTimeInputEnabled()
Return the real-time priority setting for the MIDI input thread.
ClientInfo()
Default constructor.
virtual ~ClientInfo()
Destructor.
QString getCompiledALSALibraryVersion()
ALSA library version at build time.
bool getBlockMode()
Returns the last block mode used in open()
int getInputPool()
Gets the input pool size.
void drainOutput(bool async=false, int timeout=-1)
Drain the library output buffer.
Event representing a MIDI key pressure, or polyphonic after-touch event.
SystemInfo * clone()
Clone the system info object.
int getMaxClients()
Get the system's maximum number of clients.
void _setClientName(const char *name)
Sets the client name.
PortInfo * getPortInfo()
Gets the PortInfo object pointer.
void stopSequencerInput()
Stops reading events from the ALSA sequencer.
QList< int > getAvailableQueues()
Get a list of the existing queues.
virtual ~MidiClient()
Destructor.
void setPoolOutput(int size)
Sets the size of the client's output pool.
int getClient()
Gets the client number.
PoolInfo & operator=(const PoolInfo &other)
Assignment operator.
int getEventLost()
Gets the number of lost events.
void outputBuffer(SequencerEvent *ev)
Output an event using the library output buffer, without draining the buffer.
int getRuntimeALSADriverNumber()
Gets the runtime ALSA drivers version number.
void dropOutput()
Clears the client's output buffer and and remove events in sequencer queue.
void disconnectTo(int myport, int client, int port)
Unsubscribe one port to another arbitrary sequencer client:port.
Event representing a note-on MIDI event.
void connectTo(int myport, int client, int port)
Subscribe one port to another arbitrary sequencer client:port.
unsigned int getCapability()
Gets the capabilities bitmap.
Classes managing ALSA Sequencer queues.
int getPollDescriptorsCount(short events)
Returns the number of poll descriptors.
void setOutputRoom(int size)
Sets the output room size.
void setOutputPool(int size)
Sets the output pool size.
void setThisClientInfo(const ClientInfo &val)
Sets the data supplied by the ClientInfo object into the ALSA sequencer client.
int getOutputRoom()
Gets the output room size.
ALSA Event representing a change on some ALSA sequencer client on the system.
The QThread class provides platform-independent threads.
Classes managing ALSA Sequencer events.
int createSimplePort(const char *name, unsigned int caps, unsigned int type)
Create an ALSA sequencer port, without using MidiPort.
void attach(MidiClient *seq)
Attach the port to a MidiClient instance.
QString getClientName()
Gets the client's public name.
void setPoolInput(int size)
Sets the size of the client's input pool.
PoolInfo * clone()
Clone the pool info obeject.
void setMidiClient(MidiClient *seq)
Sets the MidiClient.
MidiPort * createPort()
Create and attach a new MidiPort instance to this client.
void output(SequencerEvent *ev, bool async=false, int timeout=-1)
Output an event using the library output buffer.
Event representing a MIDI control change event.
ALSA Event representing a subscription between two ALSA clients and ports.
ALSA Event representing a change on some ALSA sequencer port on the system.
void eventReceived(drumstick::ALSA::SequencerEvent *ev)
Signal emitted when an event is received.
PortInfoList getPorts() const
Gets the ports list.
#define DRUMSTICK_ALSA_CHECK_ERROR(x)
This macro calls the check error function.