drumstick 1.1.3
alsaevent.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 <drumstick/alsaevent.h>
20
32namespace drumstick {
33
100{
101 snd_seq_ev_clear( &m_event );
102}
103
109{
110 snd_seq_ev_clear( &m_event );
111 m_event = *event;
112}
113
119{
120 snd_seq_ev_clear( &m_event );
121 m_event = other.m_event;
122}
123
131{
132 m_event = other.m_event;
133 return *this;
134}
135
141bool
143{
144 snd_seq_event_type_t te = event->getSequencerType();
145 return ( te == SND_SEQ_EVENT_PORT_SUBSCRIBED ||
146 te == SND_SEQ_EVENT_PORT_UNSUBSCRIBED );
147}
148
154bool
156{
157 snd_seq_event_type_t te = event->getSequencerType();
158 return ( te == SND_SEQ_EVENT_PORT_START ||
159 te == SND_SEQ_EVENT_PORT_EXIT ||
160 te == SND_SEQ_EVENT_PORT_CHANGE );
161}
162
168bool
170{
171 snd_seq_event_type_t te = event->getSequencerType();
172 return ( te == SND_SEQ_EVENT_CLIENT_START ||
173 te == SND_SEQ_EVENT_CLIENT_EXIT ||
174 te == SND_SEQ_EVENT_CLIENT_CHANGE );
175}
176
182bool
184{
185 snd_seq_event_type_t te = event->getSequencerType();
186 return ( te == SND_SEQ_EVENT_PORT_START ||
187 te == SND_SEQ_EVENT_PORT_EXIT ||
188 te == SND_SEQ_EVENT_PORT_CHANGE ||
189 te == SND_SEQ_EVENT_CLIENT_START ||
190 te == SND_SEQ_EVENT_CLIENT_EXIT ||
191 te == SND_SEQ_EVENT_CLIENT_CHANGE ||
192 te == SND_SEQ_EVENT_PORT_SUBSCRIBED ||
193 te == SND_SEQ_EVENT_PORT_UNSUBSCRIBED );
194}
195
202bool
204{
205 snd_seq_event_type_t te = event->getSequencerType();
206 return ( te == SND_SEQ_EVENT_NOTEOFF ||
207 te == SND_SEQ_EVENT_NOTEON ||
208 te == SND_SEQ_EVENT_NOTE ||
209 te == SND_SEQ_EVENT_KEYPRESS ||
210 te == SND_SEQ_EVENT_CONTROLLER ||
211 te == SND_SEQ_EVENT_CONTROL14 ||
212 te == SND_SEQ_EVENT_PGMCHANGE ||
213 te == SND_SEQ_EVENT_CHANPRESS ||
214 te == SND_SEQ_EVENT_PITCHBEND );
215}
216
221void SequencerEvent::setSequencerType(const snd_seq_event_type_t eventType)
222{
223 m_event.type = eventType;
224}
225
232void SequencerEvent::setDestination(const unsigned char client, const unsigned char port)
233{
234 snd_seq_ev_set_dest(&m_event, client, port);
235}
236
242void SequencerEvent::setSource(const unsigned char port)
243{
244 snd_seq_ev_set_source(&m_event, port);
245}
246
251{
252 snd_seq_ev_set_subs(&m_event);
253}
254
259{
260 snd_seq_ev_set_broadcast(&m_event);
261}
262
268{
269 snd_seq_ev_set_direct(&m_event);
270}
271
278void SequencerEvent::scheduleTick(int queue, int tick, bool relative)
279{
280 snd_seq_ev_schedule_tick(&m_event, queue, relative, tick);
281}
282
290void SequencerEvent::scheduleReal(int queue, ulong secs, ulong nanos, bool relative)
291{
292 snd_seq_real_time_t rtime;
293 rtime.tv_sec = secs;
294 rtime.tv_nsec = nanos;
295 snd_seq_ev_schedule_real(&m_event, queue, relative, &rtime);
296}
297
304void SequencerEvent::setPriority(const bool high)
305{
306 snd_seq_ev_set_priority(&m_event, high);
307}
308
314void SequencerEvent::setTag(const unsigned char aTag)
315{
316#if SND_LIB_VERSION > 0x010008
317 snd_seq_ev_set_tag(&m_event, aTag);
318#else
319 m_event.tag = aTag;
320#endif
321}
322
329unsigned int SequencerEvent::getRaw32(const unsigned int n) const
330{
331 if (n < 3) return m_event.data.raw32.d[n];
332 return 0;
333}
334
340void SequencerEvent::setRaw32(const unsigned int n, const unsigned int value)
341{
342 if (n < 3) m_event.data.raw32.d[n] = value;
343}
344
351unsigned char SequencerEvent::getRaw8(const unsigned int n) const
352{
353 if (n < 12) return m_event.data.raw8.d[n];
354 return 0;
355}
356
362void SequencerEvent::setRaw8(const unsigned int n, const unsigned char value)
363{
364 if (n < 12) m_event.data.raw8.d[n] = value;
365}
366
372{
373 snd_seq_free_event(&m_event);
374}
375
381{
382 return snd_seq_event_length(&m_event);
383}
384
392NoteEvent::NoteEvent(int ch, int key, int vel, int dur) : KeyEvent()
393{
394 snd_seq_ev_set_note(&m_event, ch, key, vel, dur);
395}
396
403NoteOnEvent::NoteOnEvent(int ch, int key, int vel) : KeyEvent()
404{
405 snd_seq_ev_set_noteon(&m_event, ch, key, vel);
406}
407
414NoteOffEvent::NoteOffEvent(int ch, int key, int vel) : KeyEvent()
415{
416 snd_seq_ev_set_noteoff(&m_event, ch, key, vel);
417}
418
425KeyPressEvent::KeyPressEvent(int ch, int key, int vel) : KeyEvent()
426{
427 snd_seq_ev_set_keypress(&m_event, ch, key, vel);
428}
429
437{
438 snd_seq_ev_set_controller(&m_event, ch, cc, val);
439}
440
447{
448 snd_seq_ev_set_pgmchange(&m_event, ch, val);
449}
450
457{
458 snd_seq_ev_set_pitchbend(&m_event, ch, val);
459}
460
467{
468 snd_seq_ev_set_chanpress(&m_event, ch, val);
469}
470
476{
477 m_data.clear();
478 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
479}
480
485VariableEvent::VariableEvent(snd_seq_event_t* event)
486 : SequencerEvent(event)
487{
488 m_data = QByteArray((char *) event->data.ext.ptr,
489 event->data.ext.len);
490 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
491}
492
497VariableEvent::VariableEvent(const QByteArray& data)
499{
500 m_data = data;
501 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
502}
503
510{
511 m_data = other.m_data;
512 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
513}
514
520VariableEvent::VariableEvent(const unsigned int datalen, char* dataptr)
522{
523 m_data = QByteArray(dataptr, datalen);
524 snd_seq_ev_set_variable( &m_event, m_data.size(), m_data.data() );
525}
526
533{
534 m_event = other.m_event;
535 m_data = other.m_data;
536 snd_seq_ev_set_variable ( &m_event, m_data.size(), m_data.data() );
537 return *this;
538}
539
544 : VariableEvent()
545{
546 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
547}
548
553SysExEvent::SysExEvent(snd_seq_event_t* event)
554 : VariableEvent(event)
555{
556 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
557}
558
563SysExEvent::SysExEvent(const QByteArray& data)
564 : VariableEvent(data)
565{
566 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
567}
568
574 : VariableEvent(other)
575{
576 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
577}
578
584SysExEvent::SysExEvent(const unsigned int datalen, char* dataptr)
585 : VariableEvent( datalen, dataptr )
586{
587 snd_seq_ev_set_sysex( &m_event, m_data.size(), m_data.data() );
588}
589
594 : VariableEvent(), m_textType(1)
595{
596 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
597}
598
603TextEvent::TextEvent(snd_seq_event_t* event)
604 : VariableEvent(event), m_textType(1)
605{
606 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
607}
608
614TextEvent::TextEvent(const QString& text, const int textType)
615 : VariableEvent(text.toUtf8()), m_textType(textType)
616{
617 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
618}
619
625 : VariableEvent(other)
626{
627 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
628 m_textType = other.getTextType();
629}
630
636TextEvent::TextEvent(const unsigned int datalen, char* dataptr)
637 : VariableEvent(datalen, dataptr), m_textType(1)
638{
639 setSequencerType(SND_SEQ_EVENT_USR_VAR0);
640}
641
646QString TextEvent::getText() const
647{
648 return QString::fromUtf8(m_data.data(), m_data.size());
649}
650
656{
657 return m_textType;
658}
659
664SystemEvent::SystemEvent(const snd_seq_event_type_t type) : SequencerEvent()
665{
666 snd_seq_ev_set_fixed(&m_event);
667 setSequencerType(type);
668}
669
676QueueControlEvent::QueueControlEvent(snd_seq_event_type_t type, int queue, int value)
678{
679 snd_seq_ev_set_queue_control(&m_event, type, queue, value);
680}
681
687ValueEvent::ValueEvent(const snd_seq_event_type_t type, int val) : SequencerEvent()
688{
689 snd_seq_ev_set_fixed(&m_event);
690 setSequencerType(type);
691 setValue(val);
692}
693
700{
701 snd_seq_ev_set_queue_tempo(&m_event, queue, tempo);
702}
703
708{
709 snd_seq_remove_events_malloc(&m_Info);
710}
711
717{
718 snd_seq_remove_events_malloc(&m_Info);
719 snd_seq_remove_events_copy(m_Info, other.m_Info);
720}
721
726RemoveEvents::RemoveEvents(snd_seq_remove_events_t* other)
727{
728 snd_seq_remove_events_malloc(&m_Info);
729 snd_seq_remove_events_copy(m_Info, other);
730}
731
736{
737 snd_seq_remove_events_free(m_Info);
738}
739
746{
747 return new RemoveEvents(m_Info);
748}
749
757{
758 snd_seq_remove_events_copy(m_Info, other.m_Info);
759 return *this;
760}
761
766int
768{
769 return snd_seq_remove_events_sizeof();
770}
771
777int
779{
780 return snd_seq_remove_events_get_channel(m_Info);
781}
782
788unsigned int
790{
791 return snd_seq_remove_events_get_condition(m_Info);
792}
793
799const snd_seq_addr_t*
801{
802 return snd_seq_remove_events_get_dest(m_Info);
803}
804
810int
812{
813 return snd_seq_remove_events_get_event_type(m_Info);
814}
815
821int
823{
824 return snd_seq_remove_events_get_queue(m_Info);
825}
826
832int
834{
835 return snd_seq_remove_events_get_tag(m_Info);
836}
837
843const snd_seq_timestamp_t*
845{
846 return snd_seq_remove_events_get_time(m_Info);
847}
848
854void
856{
857 snd_seq_remove_events_set_channel(m_Info, chan);
858}
859
878void
880{
881 snd_seq_remove_events_set_condition(m_Info, cond);
882}
883
889void
890RemoveEvents::setDest(const snd_seq_addr_t* dest)
891{
892 snd_seq_remove_events_set_dest(m_Info, dest);
893}
894
900void
902{
903 snd_seq_remove_events_set_event_type(m_Info, type);
904}
905
911void
913{
914 snd_seq_remove_events_set_queue(m_Info, queue);
915}
916
922void
924{
925 snd_seq_remove_events_set_tag(m_Info, tag);
926}
927
933void
934RemoveEvents::setTime(const snd_seq_timestamp_t* time)
935{
936 snd_seq_remove_events_set_time(m_Info, time);
937}
938
944MidiCodec::MidiCodec( int bufsize, QObject* parent ) : QObject(parent)
945{
946 CHECK_ERROR(snd_midi_event_new(bufsize, &m_Info));
947}
948
953{
954 snd_midi_event_free(m_Info);
955}
956
960void
962{
963 snd_midi_event_init(m_Info);
964}
965
973long
974MidiCodec::decode(unsigned char *buf,
975 long count,
976 const snd_seq_event_t *ev)
977{
978 return CHECK_WARNING(snd_midi_event_decode(m_Info, buf, count, ev));
979}
980
988long
989MidiCodec::encode(const unsigned char *buf,
990 long count,
991 snd_seq_event_t *ev)
992{
993 return CHECK_WARNING(snd_midi_event_encode(m_Info, buf, count, ev));
994}
995
1002long
1004 snd_seq_event_t *ev)
1005{
1006 return CHECK_WARNING(snd_midi_event_encode_byte(m_Info, c, ev));
1007}
1008
1013void
1015{
1016 snd_midi_event_no_status(m_Info, enable ? 0 : 1);
1017}
1018
1022void
1024{
1025 snd_midi_event_reset_decode(m_Info);
1026}
1027
1031void
1033{
1034 snd_midi_event_reset_encode(m_Info);
1035}
1036
1041void
1043{
1044 CHECK_WARNING(snd_midi_event_resize_buffer(m_Info, bufsize));
1045}
1046
1047} /* 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:39
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:363
Base class for the events having a Channel property.
Definition alsaevent.h:148
ControllerEvent()
Default constructor.
Definition alsaevent.h:286
Base class for the events having Key and Velocity properties.
Definition alsaevent.h:172
KeyPressEvent()
Default constructor.
Definition alsaevent.h:271
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:214
NoteOffEvent()
Default constructor.
Definition alsaevent.h:256
NoteOnEvent()
Default constructor.
Definition alsaevent.h:241
PitchBendEvent()
Default constructor.
Definition alsaevent.h:344
ProgramChangeEvent()
Default constructor.
Definition alsaevent.h:325
ALSA Event representing a queue control command.
Definition alsaevent.h:455
QueueControlEvent()
Default constructor.
Definition alsaevent.h:458
Auxiliary class to remove events from an ALSA queue.
Definition alsaevent.h:586
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:53
snd_seq_event_t m_event
ALSA sequencer event record.
Definition alsaevent.h:141
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.
Definition alsaevent.cpp:99
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:401
SysExEvent()
Default constructor.
SystemEvent()
Default constructor.
Definition alsaevent.h:441
TempoEvent()
Default constructor.
Definition alsaevent.h:516
Event representing a SMF text event.
Definition alsaevent.h:419
TextEvent()
Default constructor.
int m_textType
Clone this object returning a pointer to the new object.
Definition alsaevent.h:431
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:504
ValueEvent()
Default constructor.
Definition alsaevent.h:497
Base class for variable length events.
Definition alsaevent.h:379
QByteArray m_data
Clone this object returning a pointer to the new object.
Definition alsaevent.h:394
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.