drumstick 0.5.0
alsaevent.h
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#ifndef DRUMSTICK_ALSAEVENT_H
21#define DRUMSTICK_ALSAEVENT_H
22
23#include "drumstickcommon.h"
24#include <QEvent>
25
34namespace drumstick {
35
40const QEvent::Type SequencerEventType = QEvent::Type(QEvent::User + 4154); // :-)
41
45#define CLONE_EVENT_DECLARATION(T) virtual T* clone() { return new T(&m_event); }
46
53class DRUMSTICK_EXPORT SequencerEvent : public QEvent
54{
55public:
57 SequencerEvent(const SequencerEvent& other);
58 SequencerEvent(snd_seq_event_t* event);
60 virtual ~SequencerEvent() {}
61
62 SequencerEvent& operator=(const SequencerEvent& other);
63 void setSequencerType(const snd_seq_event_type_t eventType);
69 snd_seq_event_type_t getSequencerType() const { return m_event.type; }
70 void setDestination(const unsigned char client, const unsigned char port);
71 void setSource(const unsigned char port);
77 unsigned char getSourceClient() const { return m_event.source.client; }
83 unsigned char getSourcePort() const { return m_event.source.port; }
89 snd_seq_tick_time_t getTick() const { return m_event.time.tick; }
95 unsigned int getRealTimeSecs() const { return m_event.time.time.tv_sec; }
101 unsigned int getRealTimeNanos() const { return m_event.time.time.tv_nsec; }
102 void setSubscribers();
103 void setBroadcast();
104 void setDirect();
105 void scheduleTick(const int queue, const int tick, const bool relative);
106 void scheduleReal(const int queue, const ulong secs, const ulong nanos, const bool relative);
107 void setPriority(const bool high);
113 unsigned char getTag() const { return m_event.tag; }
114 void setTag(const unsigned char aTag);
115 unsigned int getRaw32(const unsigned int n) const;
116 void setRaw32(const unsigned int n, const unsigned int value);
117 unsigned char getRaw8(const unsigned int n) const;
118 void setRaw8(const unsigned int n, const unsigned char value);
123 snd_seq_event_t* getHandle() { return &m_event; }
124 int getEncodedLength();
125
126 static bool isSubscription(const SequencerEvent* event);
127 static bool isPort(const SequencerEvent* event);
128 static bool isClient(const SequencerEvent* event);
129 static bool isConnectionChange(const SequencerEvent* event);
130 static bool isChannel(const SequencerEvent* event);
131
134
135protected:
136 void free() __attribute__((deprecated));
137
142 snd_seq_event_t m_event;
143};
144
148class DRUMSTICK_EXPORT ChannelEvent : public SequencerEvent
149{
150public:
154 ChannelEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
160 void setChannel(const MidiByte c) { m_event.data.note.channel = (c & 0xf); }
166 int getChannel() const { return m_event.data.note.channel; }
167};
168
172class DRUMSTICK_EXPORT KeyEvent : public ChannelEvent
173{
174public:
178 KeyEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
184 int getKey() const { return m_event.data.note.note; }
190 void setKey(const MidiByte b) { m_event.data.note.note = b; }
196 int getVelocity() const { return m_event.data.note.velocity; }
202 void setVelocity(const MidiByte b) { m_event.data.note.velocity = b; }
203};
204
211class DRUMSTICK_EXPORT NoteEvent : public KeyEvent
212{
213public:
215 NoteEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTE; }
217 NoteEvent(snd_seq_event_t* event) : KeyEvent(event) {}
218 NoteEvent(const int ch, const int key, const int vel, const int dur);
224 ulong getDuration() const { return m_event.data.note.duration; }
230 void setDuration(const ulong d) { m_event.data.note.duration = d; }
233};
234
238class DRUMSTICK_EXPORT NoteOnEvent : public KeyEvent
239{
240public:
242 NoteOnEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTEON; }
244 NoteOnEvent(snd_seq_event_t* event) : KeyEvent(event) {}
245 NoteOnEvent(const int ch, const int key, const int vel);
248};
249
253class DRUMSTICK_EXPORT NoteOffEvent : public KeyEvent
254{
255public:
257 NoteOffEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_NOTEOFF; }
259 NoteOffEvent(snd_seq_event_t* event) : KeyEvent(event) {}
260 NoteOffEvent(const int ch, const int key, const int vel);
263};
264
268class DRUMSTICK_EXPORT KeyPressEvent : public KeyEvent
269{
270public:
272 KeyPressEvent() : KeyEvent() { m_event.type = SND_SEQ_EVENT_KEYPRESS; }
274 KeyPressEvent(snd_seq_event_t* event) : KeyEvent(event) {}
275 KeyPressEvent(const int ch, const int key, const int vel);
278};
279
283class DRUMSTICK_EXPORT ControllerEvent : public ChannelEvent
284{
285public:
289 ControllerEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
290 ControllerEvent(const int ch, const int cc, const int val);
296 uint getParam() const { return m_event.data.control.param; }
302 void setParam( const uint p ) { m_event.data.control.param = p; }
308 int getValue() const { return m_event.data.control.value; }
314 void setValue( const int v ) { m_event.data.control.value = v; }
317};
318
322class DRUMSTICK_EXPORT ProgramChangeEvent : public ChannelEvent
323{
324public:
326 ProgramChangeEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_PGMCHANGE; }
328 ProgramChangeEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
329 ProgramChangeEvent(const int ch, const int val);
331 int getValue() const { return m_event.data.control.value; }
333 void setValue( const int v ) { m_event.data.control.value = v; }
336};
337
341class DRUMSTICK_EXPORT PitchBendEvent : public ChannelEvent
342{
343public:
345 PitchBendEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_PITCHBEND; }
347 PitchBendEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
348 PitchBendEvent(const int ch, const int val);
350 int getValue() const { return m_event.data.control.value; }
352 void setValue( const int v ) { m_event.data.control.value = v; }
355};
356
360class DRUMSTICK_EXPORT ChanPressEvent : public ChannelEvent
361{
362public:
364 ChanPressEvent() : ChannelEvent() { m_event.type = SND_SEQ_EVENT_CHANPRESS; }
366 ChanPressEvent(snd_seq_event_t* event) : ChannelEvent(event) {}
367 ChanPressEvent( const int ch, const int val);
369 int getValue() const { return m_event.data.control.value; }
371 void setValue( const int v ) { m_event.data.control.value = v; }
374};
375
379class DRUMSTICK_EXPORT VariableEvent : public SequencerEvent
380{
381public:
383 VariableEvent(snd_seq_event_t* event);
384 VariableEvent(const QByteArray& data);
385 VariableEvent(const VariableEvent& other);
386 VariableEvent(const unsigned int datalen, char* dataptr);
387 VariableEvent& operator=(const VariableEvent& other);
389 unsigned int getLength() const { return m_event.data.ext.len; }
391 const char* getData() const { return static_cast<const char*>(m_event.data.ext.ptr); }
394protected:
395 QByteArray m_data;
396};
397
401class DRUMSTICK_EXPORT SysExEvent : public VariableEvent
402{
403public:
404 SysExEvent();
405 SysExEvent(snd_seq_event_t* event);
406 SysExEvent(const QByteArray& data);
407 SysExEvent(const SysExEvent& other);
408 SysExEvent(const unsigned int datalen, char* dataptr);
411};
412
419class DRUMSTICK_EXPORT TextEvent : public VariableEvent
420{
421public:
422 TextEvent();
423 TextEvent(snd_seq_event_t* event);
424 explicit TextEvent(const QString& text, const int textType = 1);
425 TextEvent(const TextEvent& other);
426 TextEvent(const unsigned int datalen, char* dataptr);
427 QString getText() const;
428 int getTextType() const;
431protected:
433};
434
438class DRUMSTICK_EXPORT SystemEvent : public SequencerEvent
439{
440public:
444 SystemEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
445 SystemEvent(const snd_seq_event_type_t type);
448};
449
455class DRUMSTICK_EXPORT QueueControlEvent : public SequencerEvent
456{
457public:
461 QueueControlEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
462 QueueControlEvent(const snd_seq_event_type_t type, const int queue, const int value);
464 int getQueue() const { return m_event.data.queue.queue; }
466 void setQueue(const uchar q) { m_event.data.queue.queue = q; }
468 int getValue() const { return m_event.data.queue.param.value; }
470 void setValue(const int val) { m_event.data.queue.param.value = val; }
472 uint getPosition() const { return m_event.data.queue.param.position; }
474 void setPosition(const uint pos) { m_event.data.queue.param.position = pos; }
476 snd_seq_tick_time_t getTickTime() const { return m_event.data.queue.param.time.tick; }
478 void setTickTime(const snd_seq_tick_time_t t) { m_event.data.queue.param.time.tick = t; }
480 uint getSkewBase() const { return m_event.data.queue.param.skew.base; }
482 void setSkewBase(const uint base) { m_event.data.queue.param.skew.base = base; }
484 uint getSkewValue() const { return m_event.data.queue.param.skew.value; }
486 void setSkewValue(const uint val) {m_event.data.queue.param.skew.value = val; }
489};
490
494class DRUMSTICK_EXPORT ValueEvent : public SequencerEvent
495{
496public:
500 ValueEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
501 ValueEvent(const snd_seq_event_type_t type, const int val);
503 int getValue() const { return m_event.data.control.value; }
505 void setValue( const int v ) { m_event.data.control.value = v; }
508};
509
513class DRUMSTICK_EXPORT TempoEvent : public QueueControlEvent
514{
515public:
519 TempoEvent(snd_seq_event_t* event) : QueueControlEvent(event) {}
520 TempoEvent(const int queue, const int tempo);
523};
524
528class DRUMSTICK_EXPORT SubscriptionEvent : public SequencerEvent
529{
530public:
534 SubscriptionEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
536 bool subscribed() const { return (m_event.type == SND_SEQ_EVENT_PORT_SUBSCRIBED); }
538 bool unsubscribed() const { return (m_event.type == SND_SEQ_EVENT_PORT_UNSUBSCRIBED); }
540 int getSenderClient() const { return m_event.data.connect.sender.client; }
542 int getSenderPort() const { return m_event.data.connect.sender.port; }
544 int getDestClient() const { return m_event.data.connect.dest.client; }
546 int getDestPort() const { return m_event.data.connect.dest.port; }
549};
550
554class DRUMSTICK_EXPORT ClientEvent : public SequencerEvent
555{
556public:
560 ClientEvent(snd_seq_event_t* event) : SequencerEvent(event) {}
561 int getClient() const { return m_event.data.addr.client; }
563 CLONE_EVENT_DECLARATION(ClientEvent)
564};
565
569class DRUMSTICK_EXPORT PortEvent : public ClientEvent
570{
571public:
575 PortEvent(snd_seq_event_t* event) : ClientEvent(event) {}
577 int getPort() const { return m_event.data.addr.port; }
580};
581
586class DRUMSTICK_EXPORT RemoveEvents
587{
588public:
589 friend class MidiClient;
590
591public:
593 RemoveEvents();
594 RemoveEvents(const RemoveEvents& other);
595 RemoveEvents(snd_seq_remove_events_t* other);
596 virtual ~RemoveEvents();
597 RemoveEvents* clone();
598 RemoveEvents& operator=(const RemoveEvents& other);
599 int getSizeOfInfo() const;
600
601 int getChannel();
602 unsigned int getCondition();
603 const snd_seq_addr_t* getDest();
604 int getEventType();
605 int getQueue();
606 int getTag();
607 const snd_seq_timestamp_t* getTime();
608 void setChannel(int chan);
609 void setCondition(unsigned int cond);
610 void setDest(const snd_seq_addr_t* dest);
611 void setEventType(int type);
612 void setQueue(int queue);
613 void setTag(int tag);
614 void setTime(const snd_seq_timestamp_t* time);
615
616private:
617 snd_seq_remove_events_t* m_Info;
618};
619
623class DRUMSTICK_EXPORT MidiCodec : public QObject
624{
625 Q_OBJECT
626public:
627 explicit MidiCodec(int bufsize, QObject* parent = 0);
628 ~MidiCodec();
629
630 void init();
631 long decode(unsigned char *buf,
632 long count,
633 const snd_seq_event_t *ev);
634 long encode(const unsigned char *buf,
635 long count,
636 snd_seq_event_t *ev);
637 long encode(int c,
638 snd_seq_event_t *ev);
639 void enableRunningStatus(bool enable);
640 void resetEncoder();
641 void resetDecoder();
642 void resizeBuffer(int bufsize);
643private:
644 snd_midi_event_t* m_Info;
645};
646
647} /* namespace drumstick */
648
651#endif //DRUMSTICK_ALSAEVENT_H
#define CLONE_EVENT_DECLARATION(T)
Macro to declare a virtual clone() method for SequencerEvent and derived classes.
Definition alsaevent.h:45
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.
Event representing a MIDI channel pressure or after-touch event.
Definition alsaevent.h:361
ChanPressEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:366
void setValue(const int v)
Sets the channel aftertouch value.
Definition alsaevent.h:371
int getValue() const
Gets the channel aftertouch value.
Definition alsaevent.h:369
ChanPressEvent()
Default constructor.
Definition alsaevent.h:364
Base class for the events having a Channel property.
Definition alsaevent.h:149
void setChannel(const MidiByte c)
Sets the channel of the event.
Definition alsaevent.h:160
ChannelEvent()
Default constructor.
Definition alsaevent.h:152
int getChannel() const
Gets the event's channel.
Definition alsaevent.h:166
ChannelEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:154
ALSA Event representing a change on some ALSA sequencer client on the system.
Definition alsaevent.h:555
ClientEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:560
ClientEvent()
Default constructor.
Definition alsaevent.h:558
Event representing a MIDI control change event.
Definition alsaevent.h:284
uint getParam() const
Gets the controller event's parameter.
Definition alsaevent.h:296
void setParam(const uint p)
Sets the controller event's parameter.
Definition alsaevent.h:302
ControllerEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:289
void setValue(const int v)
Sets the controller event's value.
Definition alsaevent.h:314
ControllerEvent()
Default constructor.
Definition alsaevent.h:287
int getValue() const
Gets the controller event's value.
Definition alsaevent.h:308
Base class for the events having Key and Velocity properties.
Definition alsaevent.h:173
int getKey() const
Gets the MIDI note of this event.
Definition alsaevent.h:184
KeyEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:178
void setKey(const MidiByte b)
Sets the MIDI note of this event.
Definition alsaevent.h:190
KeyEvent()
Default constructor.
Definition alsaevent.h:176
void setVelocity(const MidiByte b)
Sets the note velocity of this event.
Definition alsaevent.h:202
int getVelocity() const
Gets the note velocity of this event.
Definition alsaevent.h:196
Event representing a MIDI key pressure, or polyphonic after-touch event.
Definition alsaevent.h:269
KeyPressEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:274
KeyPressEvent()
Default constructor.
Definition alsaevent.h:272
Client management.
Definition alsaclient.h:199
Auxiliary class to translate between raw MIDI streams and ALSA events.
Definition alsaevent.h:624
Class representing a note event with duration.
Definition alsaevent.h:212
NoteEvent()
Default constructor.
Definition alsaevent.h:215
void setDuration(const ulong d)
Sets the note's duration.
Definition alsaevent.h:230
ulong getDuration() const
Gets the note's duration.
Definition alsaevent.h:224
NoteEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:217
Event representing a note-off MIDI event.
Definition alsaevent.h:254
NoteOffEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:259
NoteOffEvent()
Default constructor.
Definition alsaevent.h:257
Event representing a note-on MIDI event.
Definition alsaevent.h:239
NoteOnEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:244
NoteOnEvent()
Default constructor.
Definition alsaevent.h:242
Event representing a MIDI bender, or pitch wheel event.
Definition alsaevent.h:342
void setValue(const int v)
Sets the MIDI pitch bend value, zero centered from -8192 to 8191
Definition alsaevent.h:352
PitchBendEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:347
int getValue() const
Gets the MIDI pitch bend value, zero centered from -8192 to 8191.
Definition alsaevent.h:350
PitchBendEvent()
Default constructor.
Definition alsaevent.h:345
ALSA Event representing a change on some ALSA sequencer port on the system.
Definition alsaevent.h:570
PortEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:575
PortEvent()
Default constructor.
Definition alsaevent.h:573
int getPort() const
Gets the port number.
Definition alsaevent.h:577
Event representing a MIDI program change event.
Definition alsaevent.h:323
void setValue(const int v)
Sets the MIDI program number.
Definition alsaevent.h:333
ProgramChangeEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:328
ProgramChangeEvent()
Default constructor.
Definition alsaevent.h:326
int getValue() const
Gets the MIDI program number.
Definition alsaevent.h:331
ALSA Event representing a queue control command.
Definition alsaevent.h:456
void setSkewValue(const uint val)
Sets the skew value.
Definition alsaevent.h:486
void setTickTime(const snd_seq_tick_time_t t)
Sets the musical time in ticks.
Definition alsaevent.h:478
uint getPosition() const
Gets the queue position.
Definition alsaevent.h:472
uint getSkewBase() const
Gets the skew base.
Definition alsaevent.h:480
QueueControlEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:461
void setSkewBase(const uint base)
Sets the skew base, should be 65536.
Definition alsaevent.h:482
snd_seq_tick_time_t getTickTime() const
Gets the musical time in ticks.
Definition alsaevent.h:476
int getQueue() const
Gets the queue number.
Definition alsaevent.h:464
void setQueue(const uchar q)
Sets the queue number.
Definition alsaevent.h:466
uint getSkewValue() const
Gets the skew value.
Definition alsaevent.h:484
int getValue() const
Gets the event's value.
Definition alsaevent.h:468
void setPosition(const uint pos)
Sets the queue position.
Definition alsaevent.h:474
QueueControlEvent()
Default constructor.
Definition alsaevent.h:459
void setValue(const int val)
Sets the event's value.
Definition alsaevent.h:470
Auxiliary class to remove events from an ALSA queue.
Definition alsaevent.h:587
Base class for the event's hierarchy.
Definition alsaevent.h:54
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:123
unsigned char getSourceClient() const
Gets the source client id.
Definition alsaevent.h:77
unsigned int getRealTimeSecs() const
Gets the seconds of the event's real time.
Definition alsaevent.h:95
unsigned char getTag() const
Gets the tag of the event.
Definition alsaevent.h:113
snd_seq_tick_time_t getTick() const
Gets the tick time of the event.
Definition alsaevent.h:89
unsigned char getSourcePort() const
Gets the source port id.
Definition alsaevent.h:83
virtual ~SequencerEvent()
Destructor.
Definition alsaevent.h:60
snd_seq_event_type_t getSequencerType() const
Gets the sequencer event type.
Definition alsaevent.h:69
unsigned int getRealTimeNanos() const
Gets the nanoseconds of the event's real time.
Definition alsaevent.h:101
ALSA Event representing a subscription between two ALSA clients and ports.
Definition alsaevent.h:529
bool subscribed() const
Returns true if the event was a subscribed port.
Definition alsaevent.h:536
SubscriptionEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:534
int getDestClient() const
Gets the destination client number.
Definition alsaevent.h:544
int getDestPort() const
Gets the destination port number.
Definition alsaevent.h:546
SubscriptionEvent()
Default constructor.
Definition alsaevent.h:532
int getSenderClient() const
Gets the sender client number.
Definition alsaevent.h:540
int getSenderPort() const
Gets the sender port number.
Definition alsaevent.h:542
bool unsubscribed() const
Returns true if the event was an unsubscribed port.
Definition alsaevent.h:538
Event representing a MIDI system exclusive event.
Definition alsaevent.h:402
Generic event.
Definition alsaevent.h:439
SystemEvent()
Default constructor.
Definition alsaevent.h:442
SystemEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:444
ALSA Event representing a tempo change for an ALSA queue.
Definition alsaevent.h:514
TempoEvent()
Default constructor.
Definition alsaevent.h:517
TempoEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:519
Event representing a SMF text event.
Definition alsaevent.h:420
int m_textType
Clone this object returning a pointer to the new object.
Definition alsaevent.h:432
Generic event having a value property.
Definition alsaevent.h:495
void setValue(const int v)
Sets the event's value.
Definition alsaevent.h:505
ValueEvent(snd_seq_event_t *event)
Constructor from an ALSA event record.
Definition alsaevent.h:500
ValueEvent()
Default constructor.
Definition alsaevent.h:498
int getValue() const
Gets the event's value.
Definition alsaevent.h:503
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
unsigned int getLength() const
Gets the data length.
Definition alsaevent.h:389
const char * getData() const
Gets the data pointer.
Definition alsaevent.h:391
Common functionality.
quint8 MidiByte
8-bit unsigned number to be used as a MIDI message parameter