drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
alsatimer.cpp
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2023, 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 3 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
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include "errorcheck.h"
20#include <QReadLocker>
21#include <QWriteLocker>
22#include <cmath>
23#include <cstdio>
24#include <drumstick/alsatimer.h>
30namespace drumstick {
31namespace ALSA {
32
89{
90 snd_timer_info_malloc(&m_Info);
91}
92
97TimerInfo::TimerInfo(const snd_timer_info_t *other)
98{
99 snd_timer_info_malloc(&m_Info);
100 snd_timer_info_copy(m_Info, other);
101}
102
108{
109 snd_timer_info_malloc(&m_Info);
110 snd_timer_info_copy(m_Info, other.m_Info);
111}
112
117{
118 snd_timer_info_free(m_Info);
119}
120
127{
128 return new TimerInfo(m_Info);
129}
130
138{
139 if (this == &other)
140 return *this;
141 snd_timer_info_copy(m_Info, other.m_Info);
142 return *this;
143}
144
149bool
151{
152 return (snd_timer_info_is_slave(m_Info) != 0);
153}
154
159int
161{
162 return snd_timer_info_get_card(m_Info);
163}
164
169QString
171{
172 return QString(snd_timer_info_get_id(m_Info));
173}
174
179QString
181{
182 return QString(snd_timer_info_get_name(m_Info));
183}
184
189long
191{
192 return snd_timer_info_get_resolution(m_Info);
193}
194
199long
201{
202 long res = getResolution();
203 if (res > 0)
204 {
205 return 1000000000L / res;
206 }
207 return 0;
208}
209
214int
216{
217 return snd_timer_info_sizeof();
218}
219
225long
227{
228 return snd_timer_info_get_ticks(m_Info);
229}
230
235{
236 snd_timer_id_malloc(&m_Info);
237}
238
243TimerId::TimerId(const snd_timer_id_t *other)
244{
245 snd_timer_id_malloc(&m_Info);
246 snd_timer_id_copy(m_Info, other);
247 if (getCard() < 0)
248 setCard(0);
249 if (getDevice() < 0)
250 setDevice(0);
251 if (getSubdevice() < 0)
252 setSubdevice(0);
253}
254
260{
261 snd_timer_id_malloc(&m_Info);
262 snd_timer_id_copy(m_Info, other.m_Info);
263 if (getCard() < 0)
264 setCard(0);
265 if (getDevice() < 0)
266 setDevice(0);
267 if (getSubdevice() < 0)
268 setSubdevice(0);
269}
270
279TimerId::TimerId(int cls, int scls, int card, int dev, int sdev)
280{
281 snd_timer_id_malloc(&m_Info);
282 setClass(cls);
283 setSlaveClass(scls);
284 setCard(card);
285 setDevice(dev);
286 setSubdevice(sdev);
287}
288
293{
294 snd_timer_id_free(m_Info);
295}
296
301TimerId*
303{
304 return new TimerId(m_Info);
305}
306
312TimerId&
314{
315 if (this == &other)
316 return *this;
317 snd_timer_id_copy(m_Info, other.m_Info);
318 if (getCard() < 0)
319 setCard(0);
320 if (getDevice() < 0)
321 setDevice(0);
322 if (getSubdevice() < 0)
323 setSubdevice(0);
324 return *this;
325}
326
337void
338TimerId::setClass(int devclass)
339{
340 snd_timer_id_set_class(m_Info, devclass);
341}
342
348int
350{
351 return snd_timer_id_get_class(m_Info);
352}
353
358void
360{
361 snd_timer_id_set_sclass(m_Info, devsclass);
362}
363
368int
370{
371 return snd_timer_id_get_sclass(m_Info);
372}
373
378void
380{
381 snd_timer_id_set_card(m_Info, card);
382}
383
388int
390{
391 return snd_timer_id_get_card(m_Info);
392}
393
398void
400{
401 snd_timer_id_set_device(m_Info, device);
402}
403
408int
410{
411 return snd_timer_id_get_device(m_Info);
412}
413
418void
420{
421 snd_timer_id_set_subdevice (m_Info, subdevice);
422}
423
428int
430{
431 return snd_timer_id_get_subdevice(m_Info);
432}
433
438int
440{
441 return snd_timer_id_sizeof();
442}
443
449TimerQuery::TimerQuery(const QString& deviceName, int openMode)
450{
451 DRUMSTICK_ALSA_CHECK_WARNING( snd_timer_query_open( &m_Info,
452 deviceName.toLocal8Bit().data(),
453 openMode ));
454 readTimers();
455}
456
463TimerQuery::TimerQuery( const QString& deviceName, int openMode,
464 snd_config_t* conf )
465{
466 DRUMSTICK_ALSA_CHECK_WARNING( snd_timer_query_open_lconf( &m_Info,
467 deviceName.toLocal8Bit().data(),
468 openMode, conf ));
469 readTimers();
470}
471
476{
477 freeTimers();
478 snd_timer_query_close(m_Info);
479}
480
484void
486{
487 TimerId tid;
488 snd_timer_id_set_class(tid.m_Info, SND_TIMER_CLASS_NONE);
489 for(;;)
490 {
491 int rc = snd_timer_query_next_device(m_Info, tid.m_Info);
492 if ((rc < 0) || (tid.getClass() < 0)) {
493 break;
494 }
495 m_timers.append(tid);
496 }
497}
498
502void
504{
505 m_timers.clear();
506}
507
514{
515 snd_timer_query_info(m_Info, m_GlobalInfo.m_Info);
516 return m_GlobalInfo;
517}
518
523void
524TimerQuery::setGlobalParams(snd_timer_gparams_t* params)
525{
526 snd_timer_query_params(m_Info, params);
527}
528
533void
534TimerQuery::getGlobalParams(snd_timer_gparams_t* params)
535{
536 snd_timer_query_params(m_Info, params);
537}
538
543void
544TimerQuery::getGlobalStatus(snd_timer_gstatus_t *status)
545{
546 snd_timer_query_status(m_Info, status);
547}
548
553{
554 snd_timer_ginfo_malloc(&m_Info);
555}
556
561TimerGlobalInfo::TimerGlobalInfo(const snd_timer_ginfo_t* other)
562{
563 snd_timer_ginfo_malloc(&m_Info);
564 snd_timer_ginfo_copy(m_Info, other);
565}
566
572{
573 snd_timer_ginfo_malloc(&m_Info);
574 snd_timer_ginfo_copy(m_Info, other.m_Info);
575}
576
581{
582 snd_timer_ginfo_free(m_Info);
583}
584
591{
592 return new TimerGlobalInfo(m_Info);
593}
594
602{
603 if (this == &other)
604 return *this;
605 snd_timer_ginfo_copy(m_Info, other.m_Info);
606 return *this;
607}
608
613void
615{
616 m_Id = tid;
617 snd_timer_ginfo_set_tid (m_Info, m_Id.m_Info);
618}
619
624TimerId&
626{
627 m_Id = TimerId(snd_timer_ginfo_get_tid (m_Info));
628 return m_Id;
629}
630
635unsigned int
637{
638 return snd_timer_ginfo_get_flags (m_Info);
639}
640
645int
647{
648 return snd_timer_ginfo_get_card (m_Info);
649}
650
655QString
657{
658 return QString(snd_timer_ginfo_get_id (m_Info));
659}
660
665QString
667{
668 return QString(snd_timer_ginfo_get_name (m_Info));
669}
670
675unsigned long
677{
678 return snd_timer_ginfo_get_resolution (m_Info);
679}
680
685unsigned long
687{
688 return snd_timer_ginfo_get_resolution_min (m_Info);
689}
690
695unsigned long
697{
698 return snd_timer_ginfo_get_resolution_max(m_Info);
699}
700
705unsigned int
707{
708 return snd_timer_ginfo_get_clients(m_Info);
709}
710
715int
717{
718 return snd_timer_ginfo_sizeof();
719}
720
725{
726 snd_timer_params_malloc (&m_Info);
727}
728
733TimerParams::TimerParams(const snd_timer_params_t *other)
734{
735 snd_timer_params_malloc (&m_Info);
736 snd_timer_params_copy (m_Info, other);
737}
738
744{
745 snd_timer_params_malloc (&m_Info);
746 snd_timer_params_copy (m_Info, other.m_Info);
747}
748
753{
754 snd_timer_params_free (m_Info);
755}
756
763{
764 return new TimerParams(m_Info);
765}
766
774{
775 if (this == &other)
776 return *this;
777 snd_timer_params_copy (m_Info, other.m_Info);
778 return *this;
779}
780
785void
787{
788 snd_timer_params_set_auto_start (m_Info, auto_start ? 1 : 0);
789}
790
795bool
797{
798 return (snd_timer_params_get_auto_start (m_Info) != 0);
799}
800
805void
807{
808 snd_timer_params_set_exclusive (m_Info, exclusive ? 1 : 0);
809}
810
815bool
817{
818 return (snd_timer_params_get_exclusive (m_Info) != 0);
819}
820
825void
827{
828 snd_timer_params_set_early_event (m_Info, early_event ? 1 : 0);
829}
830
835bool
837{
838 return (snd_timer_params_get_early_event (m_Info) != 0);
839}
840
845void
847{
848 snd_timer_params_set_ticks (m_Info, ticks);
849}
850
855long
857{
858 return snd_timer_params_get_ticks (m_Info);
859}
860
865void
867{
868 snd_timer_params_set_queue_size (m_Info, queue_size);
869}
870
875long
877{
878 return snd_timer_params_get_queue_size (m_Info);
879}
880
885void
886TimerParams::setFilter(unsigned int filter)
887{
888 snd_timer_params_set_filter (m_Info, filter);
889}
890
895unsigned int
897{
898 return snd_timer_params_get_filter (m_Info);
899}
900
905int
907{
908 return snd_timer_params_sizeof();
909}
910
915{
916 snd_timer_status_malloc (&m_Info);
917}
918
923TimerStatus::TimerStatus(const snd_timer_status_t *other)
924{
925 snd_timer_status_malloc (&m_Info);
926 snd_timer_status_copy (m_Info, other);
927}
928
934{
935 snd_timer_status_malloc (&m_Info);
936 snd_timer_status_copy (m_Info, other.m_Info);
937}
938
943{
944 snd_timer_status_free (m_Info);
945}
946
953{
954 return new TimerStatus(m_Info);
955}
956
964{
965 if (this == &other)
966 return *this;
967 snd_timer_status_copy (m_Info, other.m_Info);
968 return *this;
969}
970
975snd_htimestamp_t
977{
978 return snd_timer_status_get_timestamp (m_Info);
979}
980
985long
987{
988 return snd_timer_status_get_resolution (m_Info);
989}
990
995long
997{
998 return snd_timer_status_get_lost (m_Info);
999}
1000
1005long
1007{
1008 return snd_timer_status_get_overrun (m_Info);
1009}
1010
1015long
1017{
1018 return snd_timer_status_get_queue (m_Info);
1019}
1020
1025int
1027{
1028 return snd_timer_status_sizeof();
1029}
1030
1042Timer::Timer( const QString& deviceName, int openMode, QObject* parent )
1043 : QObject(parent),
1044 m_asyncHandler(nullptr),
1045 m_handler(nullptr),
1046 m_thread(nullptr),
1047 m_deviceName(deviceName)
1048{
1049 DRUMSTICK_ALSA_CHECK_ERROR( snd_timer_open( &m_Info, m_deviceName.toLocal8Bit().data(),
1050 openMode ));
1051}
1052
1065Timer::Timer( const QString& deviceName, int openMode, snd_config_t* conf,
1066 QObject* parent )
1067 : QObject(parent),
1068 m_asyncHandler(nullptr),
1069 m_handler(nullptr),
1070 m_thread(nullptr),
1071 m_deviceName(deviceName)
1072{
1073 DRUMSTICK_ALSA_CHECK_ERROR( snd_timer_open_lconf( &m_Info,
1074 m_deviceName.toLocal8Bit().data(),
1075 openMode, conf ));
1076}
1077
1089Timer::Timer( TimerId& id, int openMode, QObject* parent )
1090 : QObject(parent),
1091 m_asyncHandler(nullptr),
1092 m_handler(nullptr),
1093 m_thread(nullptr)
1094{
1095 m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1096 .arg(id.getClass())
1097 .arg(id.getSlaveClass())
1098 .arg(id.getCard())
1099 .arg(id.getDevice())
1100 .arg(id.getSubdevice());
1101 DRUMSTICK_ALSA_CHECK_ERROR( snd_timer_open( &m_Info,
1102 m_deviceName.toLocal8Bit().data(),
1103 openMode ));
1104}
1105
1121Timer::Timer( int cls, int scls, int card, int dev, int sdev,
1122 int openMode, QObject* parent )
1123 : QObject(parent),
1124 m_asyncHandler(nullptr),
1125 m_handler(nullptr),
1126 m_thread(nullptr)
1127{
1128 m_deviceName = QString("hw:CLASS=%1,SCLASS=%2,CARD=%3,DEV=%4,SUBDEV=%5")
1129 .arg(cls)
1130 .arg(scls)
1131 .arg(card)
1132 .arg(dev)
1133 .arg(sdev);
1134 DRUMSTICK_ALSA_CHECK_ERROR( snd_timer_open( &m_Info,
1135 m_deviceName.toLocal8Bit().data(),
1136 openMode ));
1137}
1138
1143{
1144 stopEvents();
1145 if (m_thread != nullptr)
1146 delete m_thread;
1147 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_close(m_Info));
1148}
1149
1155void
1156Timer::addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
1157{
1158 DRUMSTICK_ALSA_CHECK_WARNING(snd_async_add_timer_handler(&m_asyncHandler, m_Info, callback, private_data));
1159}
1160
1165snd_timer_t*
1167{
1168 return snd_async_handler_get_timer(m_asyncHandler);
1169}
1170
1175int
1177{
1178 return snd_timer_poll_descriptors_count(m_Info);
1179}
1180
1186void
1187Timer::pollDescriptors(struct pollfd *pfds, unsigned int space)
1188{
1189 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_poll_descriptors(m_Info, pfds, space));
1190}
1191
1198void
1199Timer::pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
1200{
1201 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_poll_descriptors_revents(m_Info, pfds, nfds, revents));
1202}
1203
1208TimerInfo&
1210{
1211 snd_timer_info (m_Info, m_TimerInfo.m_Info);
1212 return m_TimerInfo;
1213}
1214
1219void
1221{
1222 DRUMSTICK_ALSA_CHECK_WARNING( snd_timer_params(m_Info, params.m_Info) );
1223}
1224
1231{
1232 DRUMSTICK_ALSA_CHECK_WARNING( snd_timer_status(m_Info, m_TimerStatus.m_Info) );
1233 return m_TimerStatus;
1234}
1235
1239void
1241{
1242 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_start(m_Info));
1243}
1244
1248void
1250{
1251 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_stop(m_Info));
1252}
1253
1257void
1259{
1260 DRUMSTICK_ALSA_CHECK_WARNING(snd_timer_continue(m_Info));
1261}
1262
1269ssize_t
1270Timer::read(void *buffer, size_t size)
1271{
1272 return snd_timer_read(m_Info, buffer, size);
1273}
1274
1283void
1285{
1286 snd_timer_tread_t tr;
1287 while ( read(&tr, sizeof(tr)) == sizeof(tr) ) {
1288 int msecs = ((tr.tstamp.tv_sec - m_last_time.tv_sec) * 1000) +
1289 round((tr.tstamp.tv_nsec - m_last_time.tv_nsec) / 1000000.0);
1290 m_last_time = tr.tstamp;
1291 if ( m_handler != nullptr )
1292 m_handler->handleTimerEvent(tr.val, msecs);
1293 else
1294 Q_EMIT timerExpired(tr.val, msecs);
1295 }
1296}
1297
1302{
1303 m_last_time = getTimerStatus().getTimestamp();
1304 if (m_thread == nullptr) {
1305 m_thread = new TimerInputThread(this, 500);
1306 m_thread->start();
1307 }
1308}
1309
1314{
1315 int counter = 0;
1316 if (m_thread != nullptr) {
1317 m_thread->stop();
1318 while (!m_thread->wait(500) && (counter < 10)) {
1319 counter++;
1320 }
1321 if (!m_thread->isFinished()) {
1322 m_thread->terminate();
1323 }
1324 delete m_thread;
1325 }
1326}
1327
1334TimerId
1336{
1337 TimerId id;
1338 snd_timer_t* timer;
1339 snd_timer_info_t* info;
1340 long res, best_res = LONG_MAX;
1341 char timername[64];
1342 int test_devs[] = {
1343 SND_TIMER_GLOBAL_SYSTEM
1344 , SND_TIMER_GLOBAL_RTC
1345#ifdef SND_TIMER_GLOBAL_HPET
1346 , SND_TIMER_GLOBAL_HPET
1347#endif
1348#ifdef SND_TIMER_GLOBAL_HRTIMER
1349 , SND_TIMER_GLOBAL_HRTIMER
1350#endif
1351 };
1352 int max_global_timers = sizeof(test_devs)/sizeof(int);
1353 int clas = SND_TIMER_CLASS_GLOBAL;
1354 int scls = SND_TIMER_SCLASS_NONE;
1355 int card = 0;
1356 int dev = SND_TIMER_GLOBAL_SYSTEM;
1357 int sdev = 0;
1358 int err = 0;
1359 int is_slave = 0;
1360 int i;
1361 snd_timer_info_alloca(&info);
1362 // default system timer
1363 id.setClass(clas);
1364 id.setSlaveClass(scls);
1365 id.setCard(card);
1366 id.setDevice(dev);
1367 id.setSubdevice(sdev);
1368 // select a non slave timer with the lowest resolution value
1369 for( i = 0; i < max_global_timers; ++i )
1370 {
1371 dev = test_devs[i];
1372 sprintf( timername, "hw:CLASS=%i,SCLASS=%i,CARD=%i,DEV=%i,SUBDEV=%i",
1373 clas, scls, card, dev, sdev );
1374 err = snd_timer_open(&timer, timername, SND_TIMER_OPEN_NONBLOCK);
1375 if (err < 0) continue;
1376 err = snd_timer_info(timer, info);
1377 if (err == 0) {
1378 is_slave = snd_timer_info_is_slave(info);
1379 res = snd_timer_info_get_resolution(info);
1380 if ((is_slave == 0) && (best_res > res)) {
1381 best_res = res;
1382 id.setDevice(dev);
1383 }
1384 }
1385 snd_timer_close(timer);
1386 }
1387 return id;
1388}
1389
1397Timer*
1398Timer::bestGlobalTimer(int openMode, QObject* parent)
1399{
1401 return new Timer(id, openMode, parent);
1402}
1403
1407void
1408Timer::TimerInputThread::run()
1409{
1410 int err, count;
1411 struct pollfd *fds;
1412 if (m_timer == nullptr) return;
1413
1414 count = m_timer->getPollDescriptorsCount();
1415 fds = (pollfd *) calloc(count, sizeof(struct pollfd));
1416 if (fds == nullptr) {
1417 qWarning() << "allocation error!";
1418 return;
1419 }
1420 fds->events = POLLIN;
1421 fds->revents = 0;
1422
1423 try {
1424 while (!stopped() && (m_timer != nullptr)) {
1425 m_timer->pollDescriptors(fds, count);
1426 if ((err = poll(fds, count, m_Wait)) < 0) {
1427 qWarning() << "poll error " << err << "(" << strerror(err) << ")";
1428 free(fds);
1429 return;
1430 }
1431 if (err == 0) {
1432 qWarning() << "timer time out";
1433 free(fds);
1434 return;
1435 }
1436 m_timer->doEvents();
1437 }
1438 } catch (...) {
1439 qWarning() << "exception in input thread";
1440 }
1441 free(fds);
1442}
1443
1448bool
1449Timer::TimerInputThread::stopped()
1450{
1451 QReadLocker locker(&m_mutex);
1452 return m_Stopped;
1453}
1454
1458void
1459Timer::TimerInputThread::stop()
1460{
1461 QWriteLocker locker(&m_mutex);
1462 m_Stopped = true;
1463}
1464
1465} // namespace ALSA
1466} // namespace drumstick
1467
Classes managing ALSA Timers.
The QObject class is the base class of all Qt objects.
virtual void handleTimerEvent(int ticks, int msecs)=0
Timer event handler.
Global timer information container.
Definition: alsatimer.h:137
unsigned int getFlags()
Gets the flags.
Definition: alsatimer.cpp:636
TimerGlobalInfo()
Default constructor.
Definition: alsatimer.cpp:552
unsigned int getClients()
Gets current timer clients.
Definition: alsatimer.cpp:706
int getSizeOfInfo() const
Gets the size of the ALSA timer global info object.
Definition: alsatimer.cpp:716
TimerGlobalInfo & operator=(const TimerGlobalInfo &other)
Assignment operator.
Definition: alsatimer.cpp:601
QString getId()
Gets the timer ID string.
Definition: alsatimer.cpp:656
unsigned long getMinResolution()
Gets timer minimal resolution in ns.
Definition: alsatimer.cpp:686
void setTimerId(const TimerId &tid)
Sets the timer identifier.
Definition: alsatimer.cpp:614
TimerGlobalInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:590
virtual ~TimerGlobalInfo()
Destructor.
Definition: alsatimer.cpp:580
TimerId & getTimerId()
Gets the timer identifier.
Definition: alsatimer.cpp:625
unsigned long getMaxResolution()
Gets timer maximal resolution in ns.
Definition: alsatimer.cpp:696
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:666
int getCard()
Gets the card number.
Definition: alsatimer.cpp:646
unsigned long getResolution()
Gets the timer resolution in ns.
Definition: alsatimer.cpp:676
ALSA Timer identifier container.
Definition: alsatimer.h:96
int getDevice()
Gets the device number.
Definition: alsatimer.cpp:409
int getSlaveClass()
Gets the slave class.
Definition: alsatimer.cpp:369
int getSizeOfInfo() const
Gets the size of the ALSA timer ID object.
Definition: alsatimer.cpp:439
void setSubdevice(int subdevice)
Sets the subdevice number.
Definition: alsatimer.cpp:419
TimerId * clone()
Copy the object.
Definition: alsatimer.cpp:302
void setCard(int card)
Sets the card number.
Definition: alsatimer.cpp:379
int getClass()
Gets the class identifier.
Definition: alsatimer.cpp:349
TimerId & operator=(const TimerId &other)
Assignment operator.
Definition: alsatimer.cpp:313
int getSubdevice()
Gets the subdevice number.
Definition: alsatimer.cpp:429
void setClass(int devclass)
Set the class identifier.
Definition: alsatimer.cpp:338
void setSlaveClass(int devsclass)
Sets the Slave class.
Definition: alsatimer.cpp:359
int getCard()
Gets the card number.
Definition: alsatimer.cpp:389
virtual ~TimerId()
Destructor.
Definition: alsatimer.cpp:292
void setDevice(int device)
Sets the device number.
Definition: alsatimer.cpp:399
ALSA Timer information container.
Definition: alsatimer.h:64
int getSizeOfInfo() const
Gets the size of the ALSA timer info object.
Definition: alsatimer.cpp:215
bool isSlave()
Check if the timer is slave (depends on another device)
Definition: alsatimer.cpp:150
virtual ~TimerInfo()
Destructor.
Definition: alsatimer.cpp:116
QString getId()
Gets the string identifier.
Definition: alsatimer.cpp:170
long getResolution()
Gets the timer resolution (timer period in nanoseconds)
Definition: alsatimer.cpp:190
QString getName()
Gets the timer name.
Definition: alsatimer.cpp:180
Q_DECL_DEPRECATED long getTicks()
Gets the maximum timer ticks.
Definition: alsatimer.cpp:226
TimerInfo & operator=(const TimerInfo &other)
Assignment operator.
Definition: alsatimer.cpp:137
int getCard()
Gets the card number.
Definition: alsatimer.cpp:160
long getFrequency()
Gets the timer frequency in Hz.
Definition: alsatimer.cpp:200
TimerInfo * clone()
Copy the current object.
Definition: alsatimer.cpp:126
ALSA Timer parameters container.
Definition: alsatimer.h:202
void setFilter(unsigned int filter)
Sets the event filter.
Definition: alsatimer.cpp:886
void setEarlyEvent(bool early_event)
Sets the timer early event.
Definition: alsatimer.cpp:826
virtual ~TimerParams()
Destructor.
Definition: alsatimer.cpp:752
int getSizeOfInfo() const
Gets the size of the ALSA timer parameters object.
Definition: alsatimer.cpp:906
TimerParams & operator=(const TimerParams &other)
Assignment operator.
Definition: alsatimer.cpp:773
void setAutoStart(bool auto_start)
Sets the automatic start flag.
Definition: alsatimer.cpp:786
bool getExclusive()
Gets the timer's exclusive flag.
Definition: alsatimer.cpp:816
long getQueueSize()
Gets the queue size.
Definition: alsatimer.cpp:876
TimerParams()
Default constructor.
Definition: alsatimer.cpp:724
bool getEarlyEvent()
Gets the timer early event.
Definition: alsatimer.cpp:836
void setExclusive(bool exclusive)
Sets the exclusive flag.
Definition: alsatimer.cpp:806
bool getAutoStart()
Gets the automatic start flag.
Definition: alsatimer.cpp:796
void setTicks(long ticks)
Sets the timer ticks.
Definition: alsatimer.cpp:846
long getTicks()
Gets the timer ticks.
Definition: alsatimer.cpp:856
TimerParams * clone()
Copy the current object.
Definition: alsatimer.cpp:762
unsigned int getFilter()
Gets the event filter.
Definition: alsatimer.cpp:896
void setQueueSize(long queue_size)
Sets the queue size (32-1024)
Definition: alsatimer.cpp:866
void getGlobalStatus(snd_timer_gstatus_t *status)
Gets the global timer status.
Definition: alsatimer.cpp:544
virtual ~TimerQuery()
Destructor.
Definition: alsatimer.cpp:475
void readTimers()
Enumerate the available timers storing the results into an internal list.
Definition: alsatimer.cpp:485
TimerQuery(const QString &deviceName, int openMode)
Constructor.
Definition: alsatimer.cpp:449
void freeTimers()
Release the internal list of timers.
Definition: alsatimer.cpp:503
TimerGlobalInfo & getGlobalInfo()
Get a TimerGlobalInfo object.
Definition: alsatimer.cpp:513
void setGlobalParams(snd_timer_gparams_t *params)
Sets the global parameters.
Definition: alsatimer.cpp:524
void getGlobalParams(snd_timer_gparams_t *params)
Gets the global timer parameters.
Definition: alsatimer.cpp:534
ALSA Timer status container.
Definition: alsatimer.h:237
long getLost()
Gets the master tick lost count.
Definition: alsatimer.cpp:996
virtual ~TimerStatus()
Destructor.
Definition: alsatimer.cpp:942
TimerStatus()
Default constructor.
Definition: alsatimer.cpp:914
int getSizeOfInfo() const
Gets the size of the ALSA timer status object.
Definition: alsatimer.cpp:1026
long getOverrun()
Gets the overrun count.
Definition: alsatimer.cpp:1006
long getResolution()
Gets the resolution in us.
Definition: alsatimer.cpp:986
TimerStatus & operator=(const TimerStatus &other)
Assignment operator.
Definition: alsatimer.cpp:963
TimerStatus * clone()
Copy the current object.
Definition: alsatimer.cpp:952
snd_htimestamp_t getTimestamp()
Gets the high resolution time-stamp.
Definition: alsatimer.cpp:976
long getQueue()
Gets the count of used queue elements.
Definition: alsatimer.cpp:1016
ALSA Timer management.
Definition: alsatimer.h:284
void stopEvents()
Stops the events dispatching thread.
Definition: alsatimer.cpp:1313
Timer(int cls, int scls, int card, int dev, int sdev, int openMode, QObject *parent=nullptr)
Constructor.
Definition: alsatimer.cpp:1121
static TimerId bestGlobalTimerId()
Check and return the best available global TimerId in the system, meaning the timer with higher frequ...
Definition: alsatimer.cpp:1335
int getPollDescriptorsCount()
Gets the count of poll descriptors.
Definition: alsatimer.cpp:1176
void continueRunning()
Continue rolling the timer.
Definition: alsatimer.cpp:1258
TimerStatus & getTimerStatus()
Gets the timer status.
Definition: alsatimer.cpp:1230
void timerExpired(int ticks, int msecs)
This signal is emitted when the timer has expired, if there is not an event hander installed.
static Timer * bestGlobalTimer(int openMode, QObject *parent=nullptr)
Check and return the best available global Timer in the system, meaning the timer with higher frequen...
Definition: alsatimer.cpp:1398
virtual ~Timer()
Destructor.
Definition: alsatimer.cpp:1142
snd_timer_t * getTimerHandle()
Gets the ALSA timer handle.
Definition: alsatimer.cpp:1166
void start()
Start rolling the timer.
Definition: alsatimer.cpp:1240
void setTimerParams(const TimerParams &params)
Sets the timer parameters.
Definition: alsatimer.cpp:1220
void stop()
Stop rolling the timer.
Definition: alsatimer.cpp:1249
void addAsyncTimerHandler(snd_async_callback_t callback, void *private_data)
Adds an asynchronous timer handler function.
Definition: alsatimer.cpp:1156
ssize_t read(void *buffer, size_t size)
Read bytes from the timer handle.
Definition: alsatimer.cpp:1270
TimerInfo & getTimerInfo()
Gets the timer info object.
Definition: alsatimer.cpp:1209
void doEvents()
Internal function to deliver the timer events using one of the two available methods:
Definition: alsatimer.cpp:1284
void startEvents()
Starts the events dispatching thread.
Definition: alsatimer.cpp:1301
void pollDescriptorsRevents(struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
Gets returned events from poll descriptors.
Definition: alsatimer.cpp:1199
void pollDescriptors(struct pollfd *pfds, unsigned int space)
Gets poll descriptors.
Definition: alsatimer.cpp:1187
Error checking functions and macros.
#define DRUMSTICK_ALSA_CHECK_WARNING(x)
This macro calls the check warning function.
Definition: errorcheck.h:86
#define DRUMSTICK_ALSA_CHECK_ERROR(x)
This macro calls the check error function.
Definition: errorcheck.h:80
Drumstick common.
Definition: alsaclient.cpp:68