drumstick 0.5.0
alsaevent.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 "alsaevent.h"
21
33namespace drumstick {
34
101{
102 snd_seq_ev_clear( &m_event );
103}
104
110{
111 snd_seq_ev_clear( &m_event );
112 m_event = *event;
113}
114
120{
121 snd_seq_ev_clear( &m_event );
122 m_event = other.m_event;
123}
124
132{
133 m_event = other.m_event;
134 return *this;
135}
136
142bool
144{
145 snd_seq_event_type_t te = event->getSequencerType();
146 return ( te == SND_SEQ_EVENT_PORT_SUBSCRIBED ||
147 te == SND_SEQ_EVENT_PORT_UNSUBSCRIBED );
148}
149
155bool
157{
158 snd_seq_event_type_t te = event->getSequencerType();
159 return ( te == SND_SEQ_EVENT_PORT_START ||
160 te == SND_SEQ_EVENT_PORT_EXIT ||
161 te == SND_SEQ_EVENT_PORT_CHANGE );
162}
163
169bool
171{
172 snd_seq_event_type_t te = event->getSequencerType();
173 return ( te == SND_SEQ_EVENT_CLIENT_START ||
174 te == SND_SEQ_EVENT_CLIENT_EXIT ||
175 te == SND_SEQ_EVENT_CLIENT_CHANGE );
176}
177
183bool
185{
186 snd_seq_event_type_t te = event->getSequencerType();
187 return ( te == SND_SEQ_EVENT_PORT_START ||
188 te == SND_SEQ_EVENT_PORT_EXIT ||
189 te == SND_SEQ_EVENT_PORT_CHANGE ||
190 te == SND_SEQ_EVENT_CLIENT_START ||
191 te == SND_SEQ_EVENT_CLIENT_EXIT ||
192 te == SND_SEQ_EVENT_CLIENT_CHANGE ||
193 te == SND_SEQ_EVENT_PORT_SUBSCRIBED ||
194 te == SND_SEQ_EVENT_PORT_UNSUBSCRIBED );
195}
196
203bool
205{
206 snd_seq_event_type_t te = event->getSequencerType();
207 return ( te == SND_SEQ_EVENT_NOTEOFF ||
208 te == SND_SEQ_EVENT_NOTEON ||
209 te == SND_SEQ_EVENT_NOTE ||
210 te == SND_SEQ_EVENT_KEYPRESS ||
211 te == SND_SEQ_EVENT_CONTROLLER ||
212 te == SND_SEQ_EVENT_CONTROL14 ||
213 te == SND_SEQ_EVENT_PGMCHANGE ||
214 te == SND_SEQ_EVENT_CHANPRESS ||
215 te == SND_SEQ_EVENT_PITCHBEND );
216}
217
222void SequencerEvent::setSequencerType(const snd_seq_event_type_t eventType)
223{
224 m_event.type = eventType;
225}
226
233void SequencerEvent::setDestination(const unsigned char client, const unsigned char port)
234{
235 snd_seq_ev_set_dest(&m_event, client, port);
236}
237
243void SequencerEvent::setSource(const unsigned char port)
244{
245 snd_seq_ev_set_source(&m_event, port);
246}
247
252{
253 snd_seq_ev_set_subs(&m_event);
254}
255
260{
261 snd_seq_ev_set_broadcast(&m_event);
262}
263
269{
270 snd_seq_ev_set_direct(&m_event);
271}
272
279void SequencerEvent::scheduleTick(int queue, int tick, bool relative)
280{
281 snd_seq_ev_schedule_tick(&m_event, queue, relative, tick);
282}
283
291void SequencerEvent::scheduleReal(int queue, ulong secs, ulong nanos, bool relative)
292{
293 snd_seq_real_time_t rtime;
294 rtime.tv_sec = secs;
295 rtime.tv_nsec = nanos;
296 snd_seq_ev_schedule_real(&m_event, queue, relative, &rtime);
297}
298
305void SequencerEvent::setPriority(const bool high)
306{
307 snd_seq_ev_set_priority(&m_event, high);
308}
309
315void SequencerEvent::setTag(const unsigned char aTag)
316{
317#if SND_LIB_VERSION > 0x010008
318 snd_seq_ev_set_tag(&m_event, aTag);
319#else
320 m_event.tag = aTag;
321#endif
322}
323
330unsigned int SequencerEvent::getRaw32(const unsigned int n) const
331{
332 if (n < 3) return m_event.data.raw32.d[n];
333 return 0;
334}
335
341void SequencerEvent::setRaw32(const unsigned int n, const unsigned int value)
342{
343 if (n < 3) m_event.data.raw32.d[n] = value;
344}
345
352unsigned char SequencerEvent::getRaw8(const unsigned int n) const
353{
354 if (n < 12) return m_event.data.raw8.d[n];
355 return 0;
356}
357
363void SequencerEvent::setRaw8(const unsigned int n, const unsigned char value)
364{
365 if (n < 12) m_event.data.raw8.d[n] = value;
366}
367
373{
374 snd_seq_free_event(&m_event);
375}
376
382{
383 return snd_seq_event_length(&m_event);
384}
385
393NoteEvent::NoteEvent(int ch, int key, int vel, int dur) : KeyEvent()
394{
395 snd_seq_ev_set_note(&m_event, ch, key, vel, dur);
396}
397
404NoteOnEvent::NoteOnEvent(int ch, int key, int vel) : KeyEvent()
405{
406 snd_seq_ev_set_noteon(&m_event, ch, key, vel);
407}
408
415NoteOffEvent::NoteOffEvent(int ch, int key, int vel) : KeyEvent()
416{
417 snd_seq_ev_set_noteoff(&m_event, ch, key, vel);
418}
419
426KeyPressEvent::KeyPressEvent(int ch, int key, int vel) : KeyEvent()
427{
428 snd_seq_ev_set_keypress(&m_event, ch, key, vel);
429}
430
438{
439 snd_seq_ev_set_controller(&m_event, ch, cc, val);
440}
441
448{
449 snd_seq_ev_set_pgmchange(&m_event, ch, val);
450}
451
458{
459 snd_seq_ev_set_pitchbend(&m_event, ch, val);
460}
461
468{
469 snd_seq_ev_set_chanpress(&m_event, ch, val);
470}
471
477{
478 m_data.clear();
479 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
480}
481
486VariableEvent::VariableEvent(snd_seq_event_t* event)
487 : SequencerEvent(event)
488{
489 m_data = QByteArray((char *) event->data.ext.ptr,
490 event->data.ext.len);
491 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
492}
493
498VariableEvent::VariableEvent(const QByteArray& data)
500{
501 m_data = data;
502 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
503}
504
511{
512 m_data = other.m_data;
513 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
514}
515
521VariableEvent::VariableEvent(const unsigned int datalen, char* dataptr)
523{
524 m_data = QByteArray(dataptr, datalen);
525 snd_seq_ev_set_variable( &m_event, m_data.size(), m_data.data() );
526}
527
534{
535 m_event = other.m_event;
536 m_data = other.m_data;
537 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
538 return *this;
539}
540
545 : VariableEvent()
546{
547 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
548}
549
554SysExEvent::SysExEvent(snd_seq_event_t* event)
555 : VariableEvent(event)
556{
557 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
558}
559
564SysExEvent::SysExEvent(const QByteArray& data)
565 : VariableEvent(data)
566{
567 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
568}
569
575 : VariableEvent(other)
576{
577 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
578}
579
585SysExEvent::SysExEvent(const unsigned int datalen, char* dataptr)
586 : VariableEvent( datalen, dataptr )
587{
588 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
589}
590
595 : VariableEvent(), m_textType(1)
596{
597 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
598}
599
604TextEvent::TextEvent(snd_seq_event_t* event)
605 : VariableEvent(event), m_textType(1)
606{
607 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
608}
609
615TextEvent::TextEvent(const QString& text, const int textType)
616 : VariableEvent(text.toUtf8()), m_textType(textType)
617{
618 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
619}
620
626 : VariableEvent(other)
627{
628 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
629 m_textType = other.getTextType();
630}
631
637TextEvent::TextEvent(const unsigned int datalen, char* dataptr)
638 : VariableEvent(datalen, dataptr), m_textType(1)
639{
640 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
641}
642
647QString TextEvent::getText() const
648{
649 return QString::fromUtf8(m_data.data(), m_data.size());
650}
651
657{
658 return m_textType;
659}
660
665SystemEvent::SystemEvent(const snd_seq_event_type_t type) : SequencerEvent()
666{
667 snd_seq_ev_set_fixed(&m_event);
668 setSequencerType(type);
669}
670
677QueueControlEvent::QueueControlEvent(snd_seq_event_type_t type, int queue, int value)
679{
680 snd_seq_ev_set_queue_control(&m_event, type, queue, value);
681}
682
688ValueEvent::ValueEvent(const snd_seq_event_type_t type, int val) : SequencerEvent()
689{
690 snd_seq_ev_set_fixed(&m_event);
691 setSequencerType(type);
692 setValue(val);
693}
694
701{
702 snd_seq_ev_set_queue_tempo(&m_event, queue, tempo);
703}
704
709{
710 snd_seq_remove_events_malloc(&m_Info);
711}
712
718{
719 snd_seq_remove_events_malloc(&m_Info);
720 snd_seq_remove_events_copy(m_Info, other.m_Info);
721}
722
727RemoveEvents::RemoveEvents(snd_seq_remove_events_t* other)
728{
729 snd_seq_remove_events_malloc(&m_Info);
730 snd_seq_remove_events_copy(m_Info, other);
731}
732
737{
738 snd_seq_remove_events_free(m_Info);
739}
740
747{
748 return new RemoveEvents(m_Info);
749}
750
758{
759 snd_seq_remove_events_copy(m_Info, other.m_Info);
760 return *this;
761}
762
767int
769{
770 return snd_seq_remove_events_sizeof();
771}
772
778int
780{
781 return snd_seq_remove_events_get_channel(m_Info);
782}
783
789unsigned int
791{
792 return snd_seq_remove_events_get_condition(m_Info);
793}
794
800const snd_seq_addr_t*
802{
803 return snd_seq_remove_events_get_dest(m_Info);
804}
805
811int
813{
814 return snd_seq_remove_events_get_event_type(m_Info);
815}
816
822int
824{
825 return snd_seq_remove_events_get_queue(m_Info);
826}
827
833int
835{
836 return snd_seq_remove_events_get_tag(m_Info);
837}
838
844const snd_seq_timestamp_t*
846{
847 return snd_seq_remove_events_get_time(m_Info);
848}
849
855void
857{
858 snd_seq_remove_events_set_channel(m_Info, chan);
859}
860
879void
881{
882 snd_seq_remove_events_set_condition(m_Info, cond);
883}
884
890void
891RemoveEvents::setDest(const snd_seq_addr_t* dest)
892{
893 snd_seq_remove_events_set_dest(m_Info, dest);
894}
895
901void
903{
904 snd_seq_remove_events_set_event_type(m_Info, type);
905}
906
912void
914{
915 snd_seq_remove_events_set_queue(m_Info, queue);
916}
917
923void
925{
926 snd_seq_remove_events_set_tag(m_Info, tag);
927}
928
934void
935RemoveEvents::setTime(const snd_seq_timestamp_t* time)
936{
937 snd_seq_remove_events_set_time(m_Info, time);
938}
939
945MidiCodec::MidiCodec( int bufsize, QObject* parent ) : QObject(parent)
946{
947 CHECK_ERROR(snd_midi_event_new(bufsize, &m_Info));
948}
949
954{
955 snd_midi_event_free(m_Info);
956}
957
961void
963{
964 snd_midi_event_init(m_Info);
965}
966
974long
975MidiCodec::decode(unsigned char *buf,
976 long count,
977 const snd_seq_event_t *ev)
978{
979 return CHECK_WARNING(snd_midi_event_decode(m_Info, buf, count, ev));
980}
981
989long
990MidiCodec::encode(const unsigned char *buf,
991 long count,
992 snd_seq_event_t *ev)
993{
994 return CHECK_WARNING(snd_midi_event_encode(m_Info, buf, count, ev));
995}
996
1003long
1005 snd_seq_event_t *ev)
1006{
1007 return CHECK_WARNING(snd_midi_event_encode_byte(m_Info, c, ev));
1008}
1009
1014void
1016{
1017 snd_midi_event_no_status(m_Info, enable ? 0 : 1);
1018}
1019
1023void
1025{
1026 snd_midi_event_reset_decode(m_Info);
1027}
1028
1032void
1034{
1035 snd_midi_event_reset_encode(m_Info);
1036}
1037
1042void
1044{
1045 CHECK_WARNING(snd_midi_event_resize_buffer(m_Info, bufsize));
1046}
1047
1048} /* namespace drumstick */
Classes managing ALSA Sequencer events.
const QEvent::Type SequencerEventType
Constant SequencerEventType is the QEvent::type() of any SequencerEvent object to be used to check th...
Definition alsaevent.h:40
The QEvent class is the base class of all event classes.
The QObject class is the base class of all Qt objects.
ChanPressEvent()
Default constructor.
Definition alsaevent.h:364
Base class for the events having a Channel property.
Definition alsaevent.h:149
ControllerEvent()
Default constructor.
Definition alsaevent.h:287
Base class for the events having Key and Velocity properties.
Definition alsaevent.h:173
KeyPressEvent()
Default constructor.
Definition alsaevent.h:272
void init()
CODEC initialization.
long encode(const unsigned char *buf, long count, snd_seq_event_t *ev)
Encode from byte stream.
~MidiCodec()
Destructor.
void resetEncoder()
Reset MIDI encode parser.
void resizeBuffer(int bufsize)
Resize the CODEC buffer.
MidiCodec(int bufsize, QObject *parent=0)
MidiCodec constructor.
void enableRunningStatus(bool enable)
Enable MIDI running status (command merge)
long decode(unsigned char *buf, long count, const snd_seq_event_t *ev)
Decode from event to bytes.
void resetDecoder()
Reset MIDI decode parser.
NoteEvent()
Default constructor.
Definition alsaevent.h:215
NoteOffEvent()
Default constructor.
Definition alsaevent.h:257
NoteOnEvent()
Default constructor.
Definition alsaevent.h:242
PitchBendEvent()
Default constructor.
Definition alsaevent.h:345
ProgramChangeEvent()
Default constructor.
Definition alsaevent.h:326
ALSA Event representing a queue control command.
Definition alsaevent.h:456
QueueControlEvent()
Default constructor.
Definition alsaevent.h:459
Auxiliary class to remove events from an ALSA queue.
Definition alsaevent.h:587
virtual ~RemoveEvents()
Destructor.
int getSizeOfInfo() const
Gets the allocated size of the ALSA remove events object.
void setEventType(int type)
Sets the event type.
void setTag(int tag)
Sets the numeric tag.
RemoveEvents & operator=(const RemoveEvents &other)
Assignment operator.
const snd_seq_timestamp_t * getTime()
Gets the timestamp.
RemoveEvents()
Default constructor.
int getQueue()
Gets the queue number.
void setCondition(unsigned int cond)
Sets the flags of the conditional event's removal.
void setQueue(int queue)
Sets the queue number.
void setTime(const snd_seq_timestamp_t *time)
Sets the timestamp.
void setChannel(int chan)
Gets the MIDI channel.
int getEventType()
Gets the event type.
RemoveEvents * clone()
Create a new object copied from this object and return a pointer to the copy.
void setDest(const snd_seq_addr_t *dest)
Set the destination address.
int getTag()
Gets the numeric tag.
const snd_seq_addr_t * getDest()
Gets the destination.
int getChannel()
Gets the MIDI channel.
unsigned int getCondition()
Gets the condition.
Base class for the event's hierarchy.
Definition alsaevent.h:54
snd_seq_event_t m_event
ALSA sequencer event record.
Definition alsaevent.h:142
static bool isConnectionChange(const SequencerEvent *event)
Checks if the event's type is of type connection change.
void setSequencerType(const snd_seq_event_type_t eventType)
Sets the event's ALSA sequencer type.
int getEncodedLength()
Gets the encoded length of the event record.
static bool isChannel(const SequencerEvent *event)
Checks if the event's type is a Channel Voice message.
void scheduleTick(const int queue, const int tick, const bool relative)
Sets the event to be scheduled in musical time (ticks) units.
void setDirect()
Sets the event to be immediately delivered, not queued/scheduled.
unsigned char getRaw8(const unsigned int n) const
Gets an event's raw 8 bits parameter.
void free() __attribute__((deprecated))
Releases the event record.
void setRaw32(const unsigned int n, const unsigned int value)
Sets an event's raw 32 bits parameter.
void scheduleReal(const int queue, const ulong secs, const ulong nanos, const bool relative)
Sets the event to be scheduled in real (clock) time units.
SequencerEvent()
Default constructor.
unsigned int getRaw32(const unsigned int n) const
Gets an event's raw 32 bits parameter.
void setRaw8(const unsigned int n, const unsigned char value)
Sets an event's raw 8 bits parameter.
static bool isSubscription(const SequencerEvent *event)
Checks if the event's type is a subscription.
void setSubscribers()
Sets the event's destination to be all the subscribers of the source port.
void setDestination(const unsigned char client, const unsigned char port)
Sets the client:port destination of the event.
static bool isPort(const SequencerEvent *event)
Checks if the event's type is of type port.
void setSource(const unsigned char port)
Sets the event's source port ID.
static bool isClient(const SequencerEvent *event)
Checks if the event's type is of type client.
void setTag(const unsigned char aTag)
Sets the event's tag.
void setPriority(const bool high)
Sets the priority of the event.
SequencerEvent & operator=(const SequencerEvent &other)
Assignment operator.
void setBroadcast()
Sets the event's destination to be all queues/clients/ports/channels.
Event representing a MIDI system exclusive event.
Definition alsaevent.h:402
SysExEvent()
Default constructor.
SystemEvent()
Default constructor.
Definition alsaevent.h:442
TempoEvent()
Default constructor.
Definition alsaevent.h:517
Event representing a SMF text event.
Definition alsaevent.h:420
TextEvent()
Default constructor.
int m_textType
Clone this object returning a pointer to the new object.
Definition alsaevent.h:432
QString getText() const
Gets the event's text content.
int getTextType() const
Gets the event's SMF text type.
void setValue(const int v)
Sets the event's value.
Definition alsaevent.h:505
ValueEvent()
Default constructor.
Definition alsaevent.h:498
Base class for variable length events.
Definition alsaevent.h:380
QByteArray m_data
Clone this object returning a pointer to the new object.
Definition alsaevent.h:395
VariableEvent & operator=(const VariableEvent &other)
Assignment operator.
VariableEvent()
Default constructor.
#define CHECK_ERROR(x)
This macro calls the check error function.
#define CHECK_WARNING(x)
This macro calls the check warning function.