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
30
31namespace drumstick {
32
56
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
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:48
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:88
QueueInfo()
Default constructor.
Definition alsaqueue.cpp:60
int getId()
Gets the queue's numeric identifier.
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.
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:81
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:118
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:158
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: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.