drumstick 1.1.3
alsaevent.h
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#ifndef DRUMSTICK_ALSAEVENT_H
20#define DRUMSTICK_ALSAEVENT_H
21
22#include "drumstickcommon.h"
23#include <QEvent>
24
33namespace drumstick {
34
39const QEvent::Type SequencerEventType = QEvent::Type(QEvent::User + 4154); // :-)
40
44#define CLONE_EVENT_DECLARATION(T) virtual T* clone() { return new T(&m_event); }
45
52class DRUMSTICK_EXPORT SequencerEvent : public QEvent
53{
54public:
56 SequencerEvent(const SequencerEvent& other);
57 SequencerEvent(snd_seq_event_t* event);
59 virtual ~SequencerEvent() {}
60
61 SequencerEvent& operator=(const SequencerEvent& other);
62 void setSequencerType(const snd_seq_event_type_t eventType);
68 snd_seq_event_type_t getSequencerType() const { return m_event.type; }
69 void setDestination(const unsigned char client, const unsigned char port);
70 void setSource(const unsigned char port);
76 unsigned char getSourceClient() const { return m_event.source.client; }
82 unsigned char getSourcePort() const { return m_event.source.port; }
88 snd_seq_tick_time_t getTick() const { return m_event.time.tick; }
94 unsigned int getRealTimeSecs() const { return m_event.time.time.tv_sec; }
100 unsigned int getRealTimeNanos() const { return m_event.time.time.tv_nsec; }
101 void setSubscribers();
102 void setBroadcast();
103 void setDirect();
104 void scheduleTick(const int queue, const int tick, const bool relative);
105 void scheduleReal(const int queue, const ulong secs, const ulong nanos, const bool relative);
106 void setPriority(const bool high);
112 unsigned char getTag() const { return m_event.tag; }
113 void setTag(const unsigned char aTag);
114 unsigned int getRaw32(const unsigned int n) const;
115 void setRaw32(const unsigned int n, const unsigned int value);
116 unsigned char getRaw8(const unsigned int n) const;
117 void setRaw8(const unsigned int n, const unsigned char value);
122 snd_seq_event_t* getHandle() { return &m_event; }
123 int getEncodedLength();
124
125 static bool isSubscription(const SequencerEvent* event);
126 static bool isPort(const SequencerEvent* event);
127 static bool isClient(const SequencerEvent* event);
128 static bool isConnectionChange(const SequencerEvent* event);
129 static bool isChannel(const SequencerEvent* event);
130
133
134protected:
135 void free() __attribute__((deprecated));
136
141 snd_seq_event_t m_event;
142};
143
147class DRUMSTICK_EXPORT ChannelEvent : public SequencerEvent
148{
149public:
153 ChannelEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
159 void setChannel(const MidiByte c) { m_event.data.note.channel = (c & 0xf); }
165 int getChannel() const { return m_event.data.note.channel; }
166};
167
171class DRUMSTICK_EXPORT KeyEvent : public ChannelEvent
172{
173public:
177 KeyEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
183 int getKey() const { return m_event.data.note.note; }
189 void setKey(const MidiByte b) { m_event.data.note.note = b; }
195 int getVelocity() const { return m_event.data.note.velocity; }
201 void setVelocity(const MidiByte b) { m_event.data.note.velocity = b; }
202};
203
210class DRUMSTICK_EXPORT NoteEvent : public KeyEvent
211{
212public:
214 NoteEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTE; }
216 NoteEvent(snd_seq_event_t* event) : KeyEvent(event) {}
217 NoteEvent(const int ch, const int key, const int vel, const int dur);
223 ulong getDuration() const { return m_event.data.note.duration; }
229 void setDuration(const ulong d) { m_event.data.note.duration = d; }
232};
233
237class DRUMSTICK_EXPORT NoteOnEvent : public KeyEvent
238{
239public:
241 NoteOnEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTEON; }
243 NoteOnEvent(snd_seq_event_t* event) : KeyEvent(event) {}
244 NoteOnEvent(const int ch, const int key, const int vel);
247};
248
252class DRUMSTICK_EXPORT NoteOffEvent : public KeyEvent
253{
254public:
256 NoteOffEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTEOFF; }
258 NoteOffEvent(snd_seq_event_t* event) : KeyEvent(event) {}
259 NoteOffEvent(const int ch, const int key, const int vel);
262};
263
267class DRUMSTICK_EXPORT KeyPressEvent : public KeyEvent
268{
269public:
271 KeyPressEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_KEYPRESS; }
273 KeyPressEvent(snd_seq_event_t* event) : KeyEvent(event) {}
274 KeyPressEvent(const int ch, const int key, const int vel);
277};
278
282class DRUMSTICK_EXPORT ControllerEvent : public ChannelEvent
283{
284public:
288 ControllerEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
289 ControllerEvent(const int ch, const int cc, const int val);
295 uint getParam() const { return m_event.data.control.param; }
301 void setParam( const uint p ) { m_event.data.control.param = p; }
307 int getValue() const { return m_event.data.control.value; }
313 void setValue( const int v ) { m_event.data.control.value = v; }
316};
317
321class DRUMSTICK_EXPORT ProgramChangeEvent : public ChannelEvent
322{
323public:
325 ProgramChangeEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_PGMCHANGE; }
327 ProgramChangeEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
328 ProgramChangeEvent(const int ch, const int val);
330 int getValue() const { return m_event.data.control.value; }
332 void setValue( const int v ) { m_event.data.control.value = v; }
335};
336
340class DRUMSTICK_EXPORT PitchBendEvent : public ChannelEvent
341{
342public:
344 PitchBendEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_PITCHBEND; }
346 PitchBendEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
347 PitchBendEvent(const int ch, const int val);
349 int getValue() const { return m_event.data.control.value; }
351 void setValue( const int v ) { m_event.data.control.value = v; }
354};
355
359class DRUMSTICK_EXPORT ChanPressEvent : public ChannelEvent
360{
361public:
363 ChanPressEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_CHANPRESS; }
365 ChanPressEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
366 ChanPressEvent( const int ch, const int val);
368 int getValue() const { return m_event.data.control.value; }
370 void setValue( const int v ) { m_event.data.control.value = v; }
373};
374
378class DRUMSTICK_EXPORT VariableEvent : public SequencerEvent
379{
380public:
382 VariableEvent(snd_seq_event_t* event);
383 VariableEvent(const QByteArray& data);
384 VariableEvent(const VariableEvent& other);
385 VariableEvent(const unsigned int datalen, char* dataptr);
386 VariableEvent& operator=(const VariableEvent& other);
388 unsigned int getLength() const { return m_event.data.ext.len; }
390 const char* getData() const { return static_cast<const char*>(m_event.data.ext.ptr); }
393protected:
394 QByteArray m_data;
395};
396
400class DRUMSTICK_EXPORT SysExEvent : public VariableEvent
401{
402public:
403 SysExEvent();
404 SysExEvent(snd_seq_event_t* event);
405 SysExEvent(const QByteArray& data);
406 SysExEvent(const SysExEvent& other);
407 SysExEvent(const unsigned int datalen, char* dataptr);
410};
411
418class DRUMSTICK_EXPORT TextEvent : public VariableEvent
419{
420public:
421 TextEvent();
422 TextEvent(snd_seq_event_t* event);
423 explicit TextEvent(const QString& text, const int textType = 1);
424 TextEvent(const TextEvent& other);
425 TextEvent(const unsigned int datalen, char* dataptr);
426 QString getText() const;
427 int getTextType() const;
430protected:
432};
433
437class DRUMSTICK_EXPORT SystemEvent : public SequencerEvent
438{
439public:
443 SystemEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
444 SystemEvent(const snd_seq_event_type_t type);
447};
448
454class DRUMSTICK_EXPORT QueueControlEvent : public SequencerEvent
455{
456public:
460 QueueControlEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
461 QueueControlEvent(const snd_seq_event_type_t type, const int queue, const int value);
463 int getQueue() const { return m_event.data.queue.queue; }
465 void setQueue(const uchar q) { m_event.data.queue.queue = q; }
467 int getValue() const { return m_event.data.queue.param.value; }
469 void setValue(const int val) { m_event.data.queue.param.value = val; }
471 uint getPosition() const { return m_event.data.queue.param.position; }
473 void setPosition(const uint pos) { m_event.data.queue.param.position = pos; }
475 snd_seq_tick_time_t getTickTime() const { return m_event.data.queue.param.time.tick; }
477 void setTickTime(const snd_seq_tick_time_t t) { m_event.data.queue.param.time.tick = t; }
479 uint getSkewBase() const { return m_event.data.queue.param.skew.base; }
481 void setSkewBase(const uint base) { m_event.data.queue.param.skew.base = base; }
483 uint getSkewValue() const { return m_event.data.queue.param.skew.value; }
485 void setSkewValue(const uint val) {m_event.data.queue.param.skew.value = val; }
488};
489
493class DRUMSTICK_EXPORT ValueEvent : public SequencerEvent
494{
495public:
499 ValueEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
500 ValueEvent(const snd_seq_event_type_t type, const int val);
502 int getValue() const { return m_event.data.control.value; }
504 void setValue( const int v ) { m_event.data.control.value = v; }
507};
508
512class DRUMSTICK_EXPORT TempoEvent : public QueueControlEvent
513{
514public:
518 TempoEvent(snd_seq_event_t* event) : QueueControlEvent(event) {}
519 TempoEvent(const int queue, const int tempo);
522};
523
527class DRUMSTICK_EXPORT SubscriptionEvent : public SequencerEvent
528{
529public:
533 SubscriptionEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
535 bool subscribed() const { return (m_event.type == SND_SEQ_EVENT_PORT_SUBSCRIBED); }
537 bool unsubscribed() const { return (m_event.type == SND_SEQ_EVENT_PORT_UNSUBSCRIBED); }
539 int getSenderClient() const { return m_event.data.connect.sender.client; }
541 int getSenderPort() const { return m_event.data.connect.sender.port; }
543 int getDestClient() const { return m_event.data.connect.dest.client; }
545 int getDestPort() const { return m_event.data.connect.dest.port; }
548};
549
553class DRUMSTICK_EXPORT ClientEvent : public SequencerEvent
554{
555public:
559 ClientEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
560 int getClient() const { return m_event.data.addr.client; }
562 CLONE_EVENT_DECLARATION(ClientEvent)
563};
564
568class DRUMSTICK_EXPORT PortEvent : public ClientEvent
569{
570public:
574 PortEvent(snd_seq_event_t* event) : ClientEvent(event) {}
576 int getPort() const { return m_event.data.addr.port; }
579};
580
585class DRUMSTICK_EXPORT RemoveEvents
586{
587public:
588 friend class MidiClient;
589
590public:
592 RemoveEvents();
593 RemoveEvents(const RemoveEvents& other);
594 RemoveEvents(snd_seq_remove_events_t* other);
595 virtual ~RemoveEvents();
596 RemoveEvents* clone();
597 RemoveEvents& operator=(const RemoveEvents& other);
598 int getSizeOfInfo() const;
599
600 int getChannel();
601 unsigned int getCondition();
602 const snd_seq_addr_t* getDest();
603 int getEventType();
604 int getQueue();
605 int getTag();
606 const snd_seq_timestamp_t* getTime();
607 void setChannel(int chan);
608 void setCondition(unsigned int cond);
609 void setDest(const snd_seq_addr_t* dest);
610 void setEventType(int type);
611 void setQueue(int queue);
612 void setTag(int tag);
613 void setTime(const snd_seq_timestamp_t* time);
614
615private:
616 snd_seq_remove_events_t* m_Info;
617};
618
622class DRUMSTICK_EXPORT MidiCodec : public QObject
623{
624 Q_OBJECT
625public:
626 explicit MidiCodec(int bufsize, QObject* parent = 0);
627 ~MidiCodec();
628
629 void init();
630 long decode(unsigned char *buf,
631 long count,
632 const snd_seq_event_t *ev);
633 long encode(const unsigned char *buf,
634 long count,
635 snd_seq_event_t *ev);
636 long encode(int c,
637 snd_seq_event_t *ev);
638 void enableRunningStatus(bool enable);
639 void resetEncoder();
640 void resetDecoder();
641 void resizeBuffer(int bufsize);
642private:
643 snd_midi_event_t* m_Info;
644};
645
646} /* namespace drumstick */
647
650#endif //DRUMSTICK_ALSAEVENT_H
#define CLONE_EVENT_DECLARATION(T)
Macro to declare a virtual clone() method for SequencerEvent and derived classes.
Definition alsaevent.h:44
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.
Event representing a MIDI channel pressure or after-touch event.
Definition alsaevent.h:360
ChanPressEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:365
void setValue(const int v)
Sets the channel aftertouch value.
Definition alsaevent.h:370
int getValue() const
Gets the channel aftertouch value.
Definition alsaevent.h:368
ChanPressEvent()
Default constructor.
Definition alsaevent.h:363
Base class for the events having a Channel property.
Definition alsaevent.h:148
void setChannel(const MidiByte c)
Sets the channel of the event.
Definition alsaevent.h:159
ChannelEvent()
Default constructor.
Definition alsaevent.h:151
int getChannel() const
Gets the event's channel.
Definition alsaevent.h:165
ChannelEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:153
ALSA Event representing a change on some ALSA sequencer client on the system.
Definition alsaevent.h:554
ClientEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:559
ClientEvent()
Default constructor.
Definition alsaevent.h:557
Event representing a MIDI control change event.
Definition alsaevent.h:283
uint getParam() const
Gets the controller event's parameter.
Definition alsaevent.h:295
void setParam(const uint p)
Sets the controller event's parameter.
Definition alsaevent.h:301
ControllerEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:288
void setValue(const int v)
Sets the controller event's value.
Definition alsaevent.h:313
ControllerEvent()
Default constructor.
Definition alsaevent.h:286
int getValue() const
Gets the controller event's value.
Definition alsaevent.h:307
Base class for the events having Key and Velocity properties.
Definition alsaevent.h:172
int getKey() const
Gets the MIDI note of this event.
Definition alsaevent.h:183
KeyEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:177
void setKey(const MidiByte b)
Sets the MIDI note of this event.
Definition alsaevent.h:189
KeyEvent()
Default constructor.
Definition alsaevent.h:175
void setVelocity(const MidiByte b)
Sets the note velocity of this event.
Definition alsaevent.h:201
int getVelocity() const
Gets the note velocity of this event.
Definition alsaevent.h:195
Event representing a MIDI key pressure, or polyphonic after-touch event.
Definition alsaevent.h:268
KeyPressEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:273
KeyPressEvent()
Default constructor.
Definition alsaevent.h:271
Client management.
Definition alsaclient.h:198
Auxiliary class to translate between raw MIDI streams and ALSA events.
Definition alsaevent.h:623
Class representing a note event with duration.
Definition alsaevent.h:211
NoteEvent()
Default constructor.
Definition alsaevent.h:214
void setDuration(const ulong d)
Sets the note's duration.
Definition alsaevent.h:229
ulong getDuration() const
Gets the note's duration.
Definition alsaevent.h:223
NoteEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:216
Event representing a note-off MIDI event.
Definition alsaevent.h:253
NoteOffEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:258
NoteOffEvent()
Default constructor.
Definition alsaevent.h:256
Event representing a note-on MIDI event.
Definition alsaevent.h:238
NoteOnEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:243
NoteOnEvent()
Default constructor.
Definition alsaevent.h:241
Event representing a MIDI bender, or pitch wheel event.
Definition alsaevent.h:341
void setValue(const int v)
Sets the MIDI pitch bend value, zero centered from -8192 to 8191
Definition alsaevent.h:351
PitchBendEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:346
int getValue() const
Gets the MIDI pitch bend value, zero centered from -8192 to 8191.
Definition alsaevent.h:349
PitchBendEvent()
Default constructor.
Definition alsaevent.h:344
ALSA Event representing a change on some ALSA sequencer port on the system.
Definition alsaevent.h:569
PortEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:574
PortEvent()
Default constructor.
Definition alsaevent.h:572
int getPort() const
Gets the port number.
Definition alsaevent.h:576
Event representing a MIDI program change event.
Definition alsaevent.h:322
void setValue(const int v)
Sets the MIDI program number.
Definition alsaevent.h:332
ProgramChangeEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:327
ProgramChangeEvent()
Default constructor.
Definition alsaevent.h:325
int getValue() const
Gets the MIDI program number.
Definition alsaevent.h:330
ALSA Event representing a queue control command.
Definition alsaevent.h:455
void setSkewValue(const uint val)
Sets the skew value.
Definition alsaevent.h:485
void setTickTime(const snd_seq_tick_time_t t)
Sets the musical time in ticks.
Definition alsaevent.h:477
uint getPosition() const
Gets the queue position.
Definition alsaevent.h:471
uint getSkewBase() const
Gets the skew base.
Definition alsaevent.h:479
QueueControlEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:460
void setSkewBase(const uint base)
Sets the skew base, should be 65536.
Definition alsaevent.h:481
snd_seq_tick_time_t getTickTime() const
Gets the musical time in ticks.
Definition alsaevent.h:475
int getQueue() const
Gets the queue number.
Definition alsaevent.h:463
void setQueue(const uchar q)
Sets the queue number.
Definition alsaevent.h:465
uint getSkewValue() const
Gets the skew value.
Definition alsaevent.h:483
int getValue() const
Gets the event's value.
Definition alsaevent.h:467
void setPosition(const uint pos)
Sets the queue position.
Definition alsaevent.h:473
QueueControlEvent()
Default constructor.
Definition alsaevent.h:458
void setValue(const int val)
Sets the event's value.
Definition alsaevent.h:469
Auxiliary class to remove events from an ALSA queue.
Definition alsaevent.h:586
Base class for the event's hierarchy.
Definition alsaevent.h:53
CLONE_EVENT_DECLARATION(SequencerEvent)
Clone this object returning a pointer to the new object.
snd_seq_event_t * getHandle()
Gets the handle of the event.
Definition alsaevent.h:122
unsigned char getSourceClient() const
Gets the source client id.
Definition alsaevent.h:76
unsigned int getRealTimeSecs() const
Gets the seconds of the event's real time.
Definition alsaevent.h:94
unsigned char getTag() const
Gets the tag of the event.
Definition alsaevent.h:112
snd_seq_tick_time_t getTick() const
Gets the tick time of the event.
Definition alsaevent.h:88
unsigned char getSourcePort() const
Gets the source port id.
Definition alsaevent.h:82
virtual ~SequencerEvent()
Destructor.
Definition alsaevent.h:59
snd_seq_event_type_t getSequencerType() const
Gets the sequencer event type.
Definition alsaevent.h:68
unsigned int getRealTimeNanos() const
Gets the nanoseconds of the event's real time.
Definition alsaevent.h:100
ALSA Event representing a subscription between two ALSA clients and ports.
Definition alsaevent.h:528
bool subscribed() const
Returns true if the event was a subscribed port.
Definition alsaevent.h:535
SubscriptionEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:533
int getDestClient() const
Gets the destination client number.
Definition alsaevent.h:543
int getDestPort() const
Gets the destination port number.
Definition alsaevent.h:545
SubscriptionEvent()
Default constructor.
Definition alsaevent.h:531
int getSenderClient() const
Gets the sender client number.
Definition alsaevent.h:539
int getSenderPort() const
Gets the sender port number.
Definition alsaevent.h:541
bool unsubscribed() const
Returns true if the event was an unsubscribed port.
Definition alsaevent.h:537
Event representing a MIDI system exclusive event.
Definition alsaevent.h:401
Generic event.
Definition alsaevent.h:438
SystemEvent()
Default constructor.
Definition alsaevent.h:441
SystemEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:443
ALSA Event representing a tempo change for an ALSA queue.
Definition alsaevent.h:513
TempoEvent()
Default constructor.
Definition alsaevent.h:516
TempoEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:518
Event representing a SMF text event.
Definition alsaevent.h:419
int m_textType
Clone this object returning a pointer to the new object.
Definition alsaevent.h:431
Generic event having a value property.
Definition alsaevent.h:494
void setValue(const int v)
Sets the event's value.
Definition alsaevent.h:504
ValueEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:499
ValueEvent()
Default constructor.
Definition alsaevent.h:497
int getValue() const
Gets the event's value.
Definition alsaevent.h:502
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
unsigned int getLength() const
Gets the data length.
Definition alsaevent.h:388
const char * getData() const
Gets the data pointer.
Definition alsaevent.h:390
Common functionality.
quint8 MidiByte
8-bit unsigned number to be used as a MIDI message parameter