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