drumstick 1.1.3
alsaqueue.cpp
Go to the documentation of this file.
1/*
2 MIDI Sequencer C++ library
3 Copyright (C) 2006-2019, 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 2 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 <cmath>
20#include <drumstick/alsaqueue.h>
22#include <drumstick/alsaevent.h>
23#include <drumstick/alsatimer.h>
24
30namespace drumstick {
31
60{
61 snd_seq_queue_info_malloc(&m_Info);
62}
63
68QueueInfo::QueueInfo(snd_seq_queue_info_t* other)
69{
70 snd_seq_queue_info_malloc(&m_Info);
71 snd_seq_queue_info_copy(m_Info, other);
72}
73
79{
80 snd_seq_queue_info_malloc(&m_Info);
81 snd_seq_queue_info_copy(m_Info, other.m_Info);
82}
83
88{
89 snd_seq_queue_info_free(m_Info);
90}
91
97{
98 return new QueueInfo(m_Info);
99}
100
107{
108 snd_seq_queue_info_copy(m_Info, other.m_Info);
109 return *this;
110}
111
117{
118 return snd_seq_queue_info_get_queue(m_Info);
119}
120
126{
127 return QString(snd_seq_queue_info_get_name(m_Info));
128}
129
135{
136 return snd_seq_queue_info_get_owner(m_Info);
137}
138
144{
145 return (snd_seq_queue_info_get_locked(m_Info) != 0);
146}
147
153{
154 return snd_seq_queue_info_get_flags(m_Info);
155}
156
161void QueueInfo::setName(QString value)
162{
163 snd_seq_queue_info_set_name(m_Info, value.toLocal8Bit().data());
164}
165
170void QueueInfo::setOwner(int value)
171{
172 snd_seq_queue_info_set_owner(m_Info, value);
173}
174
179void QueueInfo::setFlags(unsigned int value)
180{
181 snd_seq_queue_info_set_flags(m_Info, value);
182}
183
188void QueueInfo::setLocked(bool locked)
189{
190 snd_seq_queue_info_set_locked(m_Info, locked ? 1 : 0);
191}
192
198{
199 return snd_seq_queue_info_sizeof();
200}
201
202
207{
208 snd_seq_queue_status_malloc(&m_Info);
209}
210
215QueueStatus::QueueStatus(snd_seq_queue_status_t* other)
216{
217 snd_seq_queue_status_malloc(&m_Info);
218 snd_seq_queue_status_copy(m_Info, other);
219}
220
226{
227 snd_seq_queue_status_malloc(&m_Info);
228 snd_seq_queue_status_copy(m_Info, other.m_Info);
229}
230
235{
236 snd_seq_queue_status_free(m_Info);
237}
238
244{
245 return new QueueStatus(m_Info);
246}
247
254{
255 snd_seq_queue_status_copy(m_Info, other.m_Info);
256 return *this;
257}
258
264{
265 return snd_seq_queue_status_get_queue(m_Info);
266}
267
273{
274 return snd_seq_queue_status_get_events(m_Info);
275}
276
281const snd_seq_real_time_t* QueueStatus::getRealtime()
282{
283 return snd_seq_queue_status_get_real_time(m_Info);
284}
285
291{
292 return snd_seq_queue_status_get_status(m_Info);
293}
294
299snd_seq_tick_time_t QueueStatus::getTickTime()
300{
301 return snd_seq_queue_status_get_tick_time(m_Info);
302}
303
309{
310 return snd_seq_queue_status_sizeof();
311}
312
318{
319 return (snd_seq_queue_status_get_status(m_Info) != 0);
320}
321
327{
328 const snd_seq_real_time_t* time = snd_seq_queue_status_get_real_time(m_Info);
329 return (time->tv_sec * 1.0) + (time->tv_nsec * 1.0e-9);
330}
331
336{
337 snd_seq_queue_tempo_malloc(&m_Info);
338}
339
344QueueTempo::QueueTempo(snd_seq_queue_tempo_t* other)
345{
346 snd_seq_queue_tempo_malloc(&m_Info);
347 snd_seq_queue_tempo_copy(m_Info, other);
348}
349
355{
356 snd_seq_queue_tempo_malloc(&m_Info);
357 snd_seq_queue_tempo_copy(m_Info, other.m_Info);
358}
359
364{
365 snd_seq_queue_tempo_free(m_Info);
366}
367
373{
374 return new QueueTempo(m_Info);
375}
376
383{
384 snd_seq_queue_tempo_copy(m_Info, other.m_Info);
385 return *this;
386}
387
393{
394 return snd_seq_queue_tempo_get_queue(m_Info);
395}
396
402{
403 return snd_seq_queue_tempo_get_ppq(m_Info);
404}
405
413{
414 return snd_seq_queue_tempo_get_skew(m_Info);
415}
416
424{
425 return snd_seq_queue_tempo_get_skew_base(m_Info);
426}
427
433{
434 return snd_seq_queue_tempo_get_tempo(m_Info);
435}
436
441void QueueTempo::setPPQ(int value)
442{
443 snd_seq_queue_tempo_set_ppq(m_Info, value);
444}
445
452void QueueTempo::setSkewValue(unsigned int value)
453{
454 snd_seq_queue_tempo_set_skew(m_Info, value);
455}
456
464void QueueTempo::setSkewBase(unsigned int value)
465{
466 snd_seq_queue_tempo_set_skew_base(m_Info, value);
467}
468
473void QueueTempo::setTempo(unsigned int value)
474{
475 snd_seq_queue_tempo_set_tempo(m_Info, value);
476}
477
483{
484 int itempo = getTempo();
485 if (itempo != 0)
486 return 6.0e7f / itempo;
487 return 0.0f;
488}
489
496{
497 float tempo = getNominalBPM();
498 return tempo * getSkewValue() / SKEW_BASE;
499}
500
506{
507 setSkewValue(floor(SKEW_BASE * value));
509}
510
516{
517 setTempo(floor(6.0e7f / value));
518}
519
525{
526 return snd_seq_queue_tempo_sizeof();
527}
528
533{
534 snd_seq_queue_timer_malloc(&m_Info);
535}
536
541QueueTimer::QueueTimer(snd_seq_queue_timer_t* other)
542{
543 snd_seq_queue_timer_malloc(&m_Info);
544 snd_seq_queue_timer_copy(m_Info, other);
545}
546
552{
553 snd_seq_queue_timer_malloc(&m_Info);
554 snd_seq_queue_timer_copy(m_Info, other.m_Info);
555}
556
561{
562 snd_seq_queue_timer_free(m_Info);
563}
564
570{
571 return new QueueTimer(m_Info);
572}
573
580{
581 snd_seq_queue_timer_copy(m_Info, other.m_Info);
582 return *this;
583}
584
590{
591 return snd_seq_queue_timer_get_queue(m_Info);
592}
593
606snd_seq_queue_timer_type_t QueueTimer::getType()
607{
608 return snd_seq_queue_timer_get_type(m_Info);
609}
610
615const snd_timer_id_t* QueueTimer::getId()
616{
617 return snd_seq_queue_timer_get_id(m_Info);
618}
619
625{
626 return snd_seq_queue_timer_get_resolution(m_Info);
627}
628
640void QueueTimer::setType(snd_seq_queue_timer_type_t value)
641{
642 snd_seq_queue_timer_set_type(m_Info, value);
643}
644
649void QueueTimer::setId(snd_timer_id_t* value)
650{
651 snd_seq_queue_timer_set_id(m_Info, value);
652}
653
660{
661 setId(id.m_Info);
662}
663
668void QueueTimer::setResolution(unsigned int value)
669{
670 snd_seq_queue_timer_set_resolution(m_Info, value);
671}
672
678{
679 return snd_seq_queue_timer_sizeof();
680}
681
688 : QObject(parent)
689{
690 m_MidiClient = seq;
691 m_Id = CHECK_ERROR(snd_seq_alloc_queue(m_MidiClient->getHandle()));
692 m_allocated = !(m_Id < 0);
693}
694
702 : QObject(parent)
703{
704 m_MidiClient = seq;
705 m_Info = info;
706 m_Id = CHECK_ERROR(snd_seq_create_queue(m_MidiClient->getHandle(), m_Info.m_Info));
707 m_allocated = !(m_Id < 0);
708}
709
716MidiQueue::MidiQueue(MidiClient* seq, const QString name, QObject* parent)
717 : QObject(parent)
718{
719 m_MidiClient = seq;
720 m_Id = CHECK_ERROR(snd_seq_alloc_named_queue(m_MidiClient->getHandle(), name.toLocal8Bit().data()));
721 m_allocated = !(m_Id < 0);
722}
723
732MidiQueue::MidiQueue(MidiClient* seq, const int queue_id, QObject* parent)
733 : QObject(parent)
734{
735 m_MidiClient = seq;
736 m_Id = queue_id;
737 m_allocated = false;
738}
739
744{
745 if ( m_allocated && (m_MidiClient->getHandle() != NULL) )
746 {
747 CHECK_ERROR(snd_seq_free_queue(m_MidiClient->getHandle(), m_Id));
748 }
749}
750
756{
757 CHECK_WARNING(snd_seq_get_queue_info(m_MidiClient->getHandle(), m_Id, m_Info.m_Info));
758 return m_Info;
759}
760
766{
767 CHECK_WARNING(snd_seq_get_queue_status(m_MidiClient->getHandle(), m_Id, m_Status.m_Info));
768 return m_Status;
769}
770
776{
777 CHECK_WARNING(snd_seq_get_queue_tempo(m_MidiClient->getHandle(), m_Id, m_Tempo.m_Info));
778 return m_Tempo;
779}
780
786{
787 CHECK_WARNING(snd_seq_get_queue_timer(m_MidiClient->getHandle(), m_Id, m_Timer.m_Info));
788 return m_Timer;
789}
790
796{
797 m_Info = value;
798 CHECK_WARNING(snd_seq_set_queue_info(m_MidiClient->getHandle(), m_Id, m_Info.m_Info));
799}
800
806{
807 m_Tempo = value;
808 CHECK_WARNING(snd_seq_set_queue_tempo(m_MidiClient->getHandle(), m_Id, m_Tempo.m_Info));
809}
810
816{
817 m_Timer = value;
818 CHECK_WARNING(snd_seq_set_queue_timer(m_MidiClient->getHandle(), m_Id, m_Timer.m_Info));
819}
820
827{
828 return CHECK_WARNING(snd_seq_get_queue_usage(m_MidiClient->getHandle(), m_Id));
829}
830
837{
838 CHECK_WARNING(snd_seq_set_queue_usage(m_MidiClient->getHandle(), m_Id, used));
839}
840
847{
848 CHECK_WARNING(snd_seq_start_queue(m_MidiClient->getHandle(), m_Id, NULL));
849 CHECK_WARNING(snd_seq_drain_output(m_MidiClient->getHandle()));
850}
851
858{
859 if (m_MidiClient != NULL && m_MidiClient->getHandle() != NULL) {
860 CHECK_WARNING(snd_seq_stop_queue(m_MidiClient->getHandle(), m_Id, NULL));
861 CHECK_WARNING(snd_seq_drain_output(m_MidiClient->getHandle()));
862 }
863}
864
871{
872 CHECK_WARNING(snd_seq_continue_queue(m_MidiClient->getHandle(), m_Id, NULL));
873 CHECK_WARNING(snd_seq_drain_output(m_MidiClient->getHandle()));
874}
875
880{
881 if (m_MidiClient != NULL && m_MidiClient->getHandle() != NULL)
882 snd_seq_drop_output(m_MidiClient->getHandle());
883}
884
889void MidiQueue::setTickPosition(snd_seq_tick_time_t pos)
890{
891 SystemEvent event(SND_SEQ_EVENT_SETPOS_TICK);
892 snd_seq_ev_set_queue_pos_tick(event.getHandle(), m_Id, pos);
893 event.setDirect();
894 m_MidiClient->outputDirect(&event);
895}
896
901void MidiQueue::setRealTimePosition(snd_seq_real_time_t* pos)
902{
903 SystemEvent event(SND_SEQ_EVENT_SETPOS_TIME);
904 snd_seq_ev_set_queue_pos_real(event.getHandle(), m_Id, pos);
905 event.setDirect();
906 m_MidiClient->outputDirect(&event);
907}
908
909} /* namespace drumstick */
Classes managing ALSA Sequencer clients.
Classes managing ALSA Sequencer events.
Classes managing ALSA Sequencer queues.
#define SKEW_BASE
This is the value for the base skew used in ALSA.
Definition alsaqueue.h:36
Classes managing ALSA Timers.
The QObject class is the base class of all Qt objects.
Client management.
Definition alsaclient.h:198
snd_seq_t * getHandle()
Returns the sequencer handler managed by ALSA.
void outputDirect(SequencerEvent *ev, bool async=false, int timeout=-1)
Output an event directly to the sequencer.
void setTimer(const QueueTimer &value)
Applies q QueueTimer object to the queue.
void setInfo(const QueueInfo &value)
Applies a QueueInfo object to the queue.
int getUsage()
Gets the queue usage flag.
void setTickPosition(snd_seq_tick_time_t pos)
Sets the queue position in musical time (ticks).
void continueRunning()
Start the queue without resetting the last position.
QueueTimer & getTimer()
Gets a QueueTimer object reference.
QueueStatus & getStatus()
Gets a QueueStatus object reference.
void start()
Start the queue.
void stop()
Stop the queue.
void setRealTimePosition(snd_seq_real_time_t *pos)
Sets the queue position in real time (clock) units: seconds and nanoseconds.
void clear()
Clear the queue, dropping any scheduled events.
MidiQueue(MidiClient *seq, QObject *parent=0)
Constructor.
QueueInfo & getInfo()
Gets a QueueInfo object reference.
virtual ~MidiQueue()
Destructor.
QueueTempo & getTempo()
Gets a QueueTempo object reference.
void setUsage(int used)
Sets the queue usage flag.
void setTempo(const QueueTempo &value)
Applies a QueueTempo object to the queue.
Queue information container.
Definition alsaqueue.h:47
bool isLocked()
Returns the locking status of the queue.
int getInfoSize() const
Gets the size of the ALSA queue info object.
unsigned int getFlags()
Gets the flags of the queue.
void setLocked(bool locked)
Sets the locked status of the queue.
int getOwner()
Gets the owner's client id of the queue.
virtual ~QueueInfo()
Destructor.
Definition alsaqueue.cpp:87
QueueInfo()
Default constructor.
Definition alsaqueue.cpp:59
int getId()
Gets the queue's numeric identifier.
QueueInfo * clone()
Copy the current object and return the copy.
Definition alsaqueue.cpp:96
void setFlags(unsigned int value)
Sets the bit flags of the queue.
QString getName()
Gets the queue name.
void setName(QString value)
Sets the queue name.
QueueInfo & operator=(const QueueInfo &other)
Assignment operator.
void setOwner(int value)
Sets the client ID of the owner.
Queue status container.
Definition alsaqueue.h:80
int getInfoSize() const
Gets the size of the ALSA status object.
bool isRunning()
Gets the queue's running state.
int getEvents()
Gets the number of queued events.
int getId()
Gets the queue's numeric identifier.
QueueStatus * clone()
Copy the current object and return the copy.
const snd_seq_real_time_t * getRealtime()
Gets the real time (secods and nanoseconds) of the queue.
QueueStatus()
Default constructor.
snd_seq_tick_time_t getTickTime()
Gets the musical time (ticks) of the queue.
double getClockTime()
Gets the clock time in seconds of the queue.
QueueStatus & operator=(const QueueStatus &other)
Assignment operator.
virtual ~QueueStatus()
Destructor.
unsigned int getStatusBits()
Gets the running status bits.
Queue tempo container.
Definition alsaqueue.h:117
int getInfoSize() const
Gets the size of the ALSA queue tempo object.
void setSkewValue(unsigned int value)
Sets the tempo skew numerator.
int getId()
Gets the queue's numeric identifier.
void setPPQ(int value)
Sets the queue resolution in parts per quarter note.
unsigned int getTempo()
Gets the queue's tempo in microseconds per beat.
QueueTempo()
Default constructor.
void setTempo(unsigned int value)
Sets the queue tempo in microseconds per beat.
float getRealBPM()
Gets the queue's real BPM tempo in beats per minute.
unsigned int getSkewValue()
Gets the tempo skew numerator.
float getNominalBPM()
Gets the queue's nominal BPM tempo (in beats per minute)
unsigned int getSkewBase()
Gets the tempo skew base.
QueueTempo * clone()
Copy the current object returning the copied object.
void setSkewBase(unsigned int value)
Sets the tempo skew base.
void setNominalBPM(float value)
Sets the queue's nominal tempo in BPM (beats per minute).
virtual ~QueueTempo()
Destructor.
int getPPQ()
Gets the PPQ (parts per quarter note) resolution of the queue.
QueueTempo & operator=(const QueueTempo &other)
Assignment operator.
void setTempoFactor(float value)
Sets the queue's tempo skew factor.
Queue timer container.
Definition alsaqueue.h:157
int getInfoSize() const
Gets the size of the ALSA queue timer object.
snd_seq_queue_timer_type_t getType()
Gets the timer type.
const snd_timer_id_t * getId()
Gets the timer identifier record.
QueueTimer()
Default constructor.
QueueTimer & operator=(const QueueTimer &other)
Assignment operator.
void setResolution(unsigned int value)
Sets the timer resolution.
QueueTimer * clone()
Copy the current object and return the copy.
unsigned int getResolution()
Gets the timer resolution.
int getQueueId()
The queue's numeric identifier.
void setId(snd_timer_id_t *value)
Sets the timer identifier record.
void setType(snd_seq_queue_timer_type_t value)
Sets the timer type.
virtual ~QueueTimer()
Destructor.
snd_seq_event_t * getHandle()
Gets the handle of the event.
Definition alsaevent.h:122
Generic event.
Definition alsaevent.h:438
ALSA Timer identifier container.
Definition alsatimer.h:79
#define CHECK_ERROR(x)
This macro calls the check error function.
#define CHECK_WARNING(x)
This macro calls the check warning function.