Home | History | Annotate | Download | only in alsa
      1 /**
      2  * \file include/seq_event.h
      3  * \brief Application interface library for the ALSA driver
      4  * \author Jaroslav Kysela <perex (at) perex.cz>
      5  * \author Abramo Bagnara <abramo (at) alsa-project.org>
      6  * \author Takashi Iwai <tiwai (at) suse.de>
      7  * \date 1998-2001
      8  *
      9  * Application interface library for the ALSA driver
     10  */
     11 /*
     12  *   This library is free software; you can redistribute it and/or modify
     13  *   it under the terms of the GNU Lesser General Public License as
     14  *   published by the Free Software Foundation; either version 2.1 of
     15  *   the License, or (at your option) any later version.
     16  *
     17  *   This program is distributed in the hope that it will be useful,
     18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     20  *   GNU Lesser General Public License for more details.
     21  *
     22  *   You should have received a copy of the GNU Lesser General Public
     23  *   License along with this library; if not, write to the Free Software
     24  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     25  *
     26  */
     27 
     28 #ifndef __ALSA_SEQ_EVENT_H
     29 #define __ALSA_SEQ_EVENT_H
     30 
     31 /**
     32  *  \defgroup SeqEvents Sequencer Event Definitions
     33  *  Sequencer Event Definitions
     34  *  \ingroup Sequencer
     35  *  \{
     36  */
     37 
     38 /**
     39  * Sequencer event data type
     40  */
     41 typedef unsigned char snd_seq_event_type_t;
     42 
     43 /** Sequencer event type */
     44 enum snd_seq_event_type {
     45 	/** system status; event data type = #snd_seq_result_t */
     46 	SND_SEQ_EVENT_SYSTEM = 0,
     47 	/** returned result status; event data type = #snd_seq_result_t */
     48 	SND_SEQ_EVENT_RESULT,
     49 
     50 	/** note on and off with duration; event data type = #snd_seq_ev_note_t */
     51 	SND_SEQ_EVENT_NOTE = 5,
     52 	/** note on; event data type = #snd_seq_ev_note_t */
     53 	SND_SEQ_EVENT_NOTEON,
     54 	/** note off; event data type = #snd_seq_ev_note_t */
     55 	SND_SEQ_EVENT_NOTEOFF,
     56 	/** key pressure change (aftertouch); event data type = #snd_seq_ev_note_t */
     57 	SND_SEQ_EVENT_KEYPRESS,
     58 
     59 	/** controller; event data type = #snd_seq_ev_ctrl_t */
     60 	SND_SEQ_EVENT_CONTROLLER = 10,
     61 	/** program change; event data type = #snd_seq_ev_ctrl_t */
     62 	SND_SEQ_EVENT_PGMCHANGE,
     63 	/** channel pressure; event data type = #snd_seq_ev_ctrl_t */
     64 	SND_SEQ_EVENT_CHANPRESS,
     65 	/** pitchwheel; event data type = #snd_seq_ev_ctrl_t; data is from -8192 to 8191) */
     66 	SND_SEQ_EVENT_PITCHBEND,
     67 	/** 14 bit controller value; event data type = #snd_seq_ev_ctrl_t */
     68 	SND_SEQ_EVENT_CONTROL14,
     69 	/** 14 bit NRPN;  event data type = #snd_seq_ev_ctrl_t */
     70 	SND_SEQ_EVENT_NONREGPARAM,
     71 	/** 14 bit RPN; event data type = #snd_seq_ev_ctrl_t */
     72 	SND_SEQ_EVENT_REGPARAM,
     73 
     74 	/** SPP with LSB and MSB values; event data type = #snd_seq_ev_ctrl_t */
     75 	SND_SEQ_EVENT_SONGPOS = 20,
     76 	/** Song Select with song ID number; event data type = #snd_seq_ev_ctrl_t */
     77 	SND_SEQ_EVENT_SONGSEL,
     78 	/** midi time code quarter frame; event data type = #snd_seq_ev_ctrl_t */
     79 	SND_SEQ_EVENT_QFRAME,
     80 	/** SMF Time Signature event; event data type = #snd_seq_ev_ctrl_t */
     81 	SND_SEQ_EVENT_TIMESIGN,
     82 	/** SMF Key Signature event; event data type = #snd_seq_ev_ctrl_t */
     83 	SND_SEQ_EVENT_KEYSIGN,
     84 
     85 	/** MIDI Real Time Start message; event data type = #snd_seq_ev_queue_control_t */
     86 	SND_SEQ_EVENT_START = 30,
     87 	/** MIDI Real Time Continue message; event data type = #snd_seq_ev_queue_control_t */
     88 	SND_SEQ_EVENT_CONTINUE,
     89 	/** MIDI Real Time Stop message; event data type = #snd_seq_ev_queue_control_t */
     90 	SND_SEQ_EVENT_STOP,
     91 	/** Set tick queue position; event data type = #snd_seq_ev_queue_control_t */
     92 	SND_SEQ_EVENT_SETPOS_TICK,
     93 	/** Set real-time queue position; event data type = #snd_seq_ev_queue_control_t */
     94 	SND_SEQ_EVENT_SETPOS_TIME,
     95 	/** (SMF) Tempo event; event data type = #snd_seq_ev_queue_control_t */
     96 	SND_SEQ_EVENT_TEMPO,
     97 	/** MIDI Real Time Clock message; event data type = #snd_seq_ev_queue_control_t */
     98 	SND_SEQ_EVENT_CLOCK,
     99 	/** MIDI Real Time Tick message; event data type = #snd_seq_ev_queue_control_t */
    100 	SND_SEQ_EVENT_TICK,
    101 	/** Queue timer skew; event data type = #snd_seq_ev_queue_control_t */
    102 	SND_SEQ_EVENT_QUEUE_SKEW,
    103 	/** Sync position changed; event data type = #snd_seq_ev_queue_control_t */
    104 	SND_SEQ_EVENT_SYNC_POS,
    105 
    106 	/** Tune request; event data type = none */
    107 	SND_SEQ_EVENT_TUNE_REQUEST = 40,
    108 	/** Reset to power-on state; event data type = none */
    109 	SND_SEQ_EVENT_RESET,
    110 	/** Active sensing event; event data type = none */
    111 	SND_SEQ_EVENT_SENSING,
    112 
    113 	/** Echo-back event; event data type = any type */
    114 	SND_SEQ_EVENT_ECHO = 50,
    115 	/** OSS emulation raw event; event data type = any type */
    116 	SND_SEQ_EVENT_OSS,
    117 
    118 	/** New client has connected; event data type = #snd_seq_addr_t */
    119 	SND_SEQ_EVENT_CLIENT_START = 60,
    120 	/** Client has left the system; event data type = #snd_seq_addr_t */
    121 	SND_SEQ_EVENT_CLIENT_EXIT,
    122 	/** Client status/info has changed; event data type = #snd_seq_addr_t */
    123 	SND_SEQ_EVENT_CLIENT_CHANGE,
    124 	/** New port was created; event data type = #snd_seq_addr_t */
    125 	SND_SEQ_EVENT_PORT_START,
    126 	/** Port was deleted from system; event data type = #snd_seq_addr_t */
    127 	SND_SEQ_EVENT_PORT_EXIT,
    128 	/** Port status/info has changed; event data type = #snd_seq_addr_t */
    129 	SND_SEQ_EVENT_PORT_CHANGE,
    130 
    131 	/** Ports connected; event data type = #snd_seq_connect_t */
    132 	SND_SEQ_EVENT_PORT_SUBSCRIBED,
    133 	/** Ports disconnected; event data type = #snd_seq_connect_t */
    134 	SND_SEQ_EVENT_PORT_UNSUBSCRIBED,
    135 
    136 	/** Sample select; event data type = #snd_seq_ev_sample_control_t */
    137 	SND_SEQ_EVENT_SAMPLE = 70,
    138 	/** Sample cluster select; event data type = #snd_seq_ev_sample_control_t */
    139 	SND_SEQ_EVENT_SAMPLE_CLUSTER,
    140 	/** voice start */
    141 	SND_SEQ_EVENT_SAMPLE_START,
    142 	/** voice stop */
    143 	SND_SEQ_EVENT_SAMPLE_STOP,
    144 	/** playback frequency */
    145 	SND_SEQ_EVENT_SAMPLE_FREQ,
    146 	/** volume and balance */
    147 	SND_SEQ_EVENT_SAMPLE_VOLUME,
    148 	/** sample loop */
    149 	SND_SEQ_EVENT_SAMPLE_LOOP,
    150 	/** sample position */
    151 	SND_SEQ_EVENT_SAMPLE_POSITION,
    152 	/** private (hardware dependent) event */
    153 	SND_SEQ_EVENT_SAMPLE_PRIVATE1,
    154 
    155 	/** user-defined event; event data type = any (fixed size) */
    156 	SND_SEQ_EVENT_USR0 = 90,
    157 	/** user-defined event; event data type = any (fixed size) */
    158 	SND_SEQ_EVENT_USR1,
    159 	/** user-defined event; event data type = any (fixed size) */
    160 	SND_SEQ_EVENT_USR2,
    161 	/** user-defined event; event data type = any (fixed size) */
    162 	SND_SEQ_EVENT_USR3,
    163 	/** user-defined event; event data type = any (fixed size) */
    164 	SND_SEQ_EVENT_USR4,
    165 	/** user-defined event; event data type = any (fixed size) */
    166 	SND_SEQ_EVENT_USR5,
    167 	/** user-defined event; event data type = any (fixed size) */
    168 	SND_SEQ_EVENT_USR6,
    169 	/** user-defined event; event data type = any (fixed size) */
    170 	SND_SEQ_EVENT_USR7,
    171 	/** user-defined event; event data type = any (fixed size) */
    172 	SND_SEQ_EVENT_USR8,
    173 	/** user-defined event; event data type = any (fixed size) */
    174 	SND_SEQ_EVENT_USR9,
    175 
    176 	/** begin of instrument management */
    177 	SND_SEQ_EVENT_INSTR_BEGIN = 100,
    178 	/** end of instrument management */
    179 	SND_SEQ_EVENT_INSTR_END,
    180 	/** query instrument interface info */
    181 	SND_SEQ_EVENT_INSTR_INFO,
    182 	/** result of instrument interface info */
    183 	SND_SEQ_EVENT_INSTR_INFO_RESULT,
    184 	/** query instrument format info */
    185 	SND_SEQ_EVENT_INSTR_FINFO,
    186 	/** result of instrument format info */
    187 	SND_SEQ_EVENT_INSTR_FINFO_RESULT,
    188 	/** reset instrument instrument memory */
    189 	SND_SEQ_EVENT_INSTR_RESET,
    190 	/** get instrument interface status */
    191 	SND_SEQ_EVENT_INSTR_STATUS,
    192 	/** result of instrument interface status */
    193 	SND_SEQ_EVENT_INSTR_STATUS_RESULT,
    194 	/** put an instrument to port */
    195 	SND_SEQ_EVENT_INSTR_PUT,
    196 	/** get an instrument from port */
    197 	SND_SEQ_EVENT_INSTR_GET,
    198 	/** result of instrument query */
    199 	SND_SEQ_EVENT_INSTR_GET_RESULT,
    200 	/** free instrument(s) */
    201 	SND_SEQ_EVENT_INSTR_FREE,
    202 	/** get instrument list */
    203 	SND_SEQ_EVENT_INSTR_LIST,
    204 	/** result of instrument list */
    205 	SND_SEQ_EVENT_INSTR_LIST_RESULT,
    206 	/** set cluster parameters */
    207 	SND_SEQ_EVENT_INSTR_CLUSTER,
    208 	/** get cluster parameters */
    209 	SND_SEQ_EVENT_INSTR_CLUSTER_GET,
    210 	/** result of cluster parameters */
    211 	SND_SEQ_EVENT_INSTR_CLUSTER_RESULT,
    212 	/** instrument change */
    213 	SND_SEQ_EVENT_INSTR_CHANGE,
    214 
    215 	/** system exclusive data (variable length);  event data type = #snd_seq_ev_ext_t */
    216 	SND_SEQ_EVENT_SYSEX = 130,
    217 	/** error event;  event data type = #snd_seq_ev_ext_t */
    218 	SND_SEQ_EVENT_BOUNCE,
    219 	/** reserved for user apps;  event data type = #snd_seq_ev_ext_t */
    220 	SND_SEQ_EVENT_USR_VAR0 = 135,
    221 	/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
    222 	SND_SEQ_EVENT_USR_VAR1,
    223 	/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
    224 	SND_SEQ_EVENT_USR_VAR2,
    225 	/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
    226 	SND_SEQ_EVENT_USR_VAR3,
    227 	/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
    228 	SND_SEQ_EVENT_USR_VAR4,
    229 
    230 	/** NOP; ignored in any case */
    231 	SND_SEQ_EVENT_NONE = 255
    232 };
    233 
    234 
    235 /** Sequencer event address */
    236 typedef struct snd_seq_addr {
    237 	unsigned char client;	/**< Client id */
    238 	unsigned char port;	/**< Port id */
    239 } snd_seq_addr_t;
    240 
    241 /** Connection (subscription) between ports */
    242 typedef struct snd_seq_connect {
    243 	snd_seq_addr_t sender;	/**< sender address */
    244 	snd_seq_addr_t dest;	/**< destination address */
    245 } snd_seq_connect_t;
    246 
    247 
    248 /** Real-time data record */
    249 typedef struct snd_seq_real_time {
    250 	unsigned int tv_sec;		/**< seconds */
    251 	unsigned int tv_nsec;		/**< nanoseconds */
    252 } snd_seq_real_time_t;
    253 
    254 /** (MIDI) Tick-time data record */
    255 typedef unsigned int snd_seq_tick_time_t;
    256 
    257 /** unioned time stamp */
    258 typedef union snd_seq_timestamp {
    259 	snd_seq_tick_time_t tick;	/**< tick-time */
    260 	struct snd_seq_real_time time;	/**< real-time */
    261 } snd_seq_timestamp_t;
    262 
    263 
    264 /**
    265  * Event mode flags
    266  *
    267  * NOTE: only 8 bits available!
    268  */
    269 #define SND_SEQ_TIME_STAMP_TICK		(0<<0)	/**< timestamp in clock ticks */
    270 #define SND_SEQ_TIME_STAMP_REAL		(1<<0)	/**< timestamp in real time */
    271 #define SND_SEQ_TIME_STAMP_MASK		(1<<0)	/**< mask for timestamp bits */
    272 
    273 #define SND_SEQ_TIME_MODE_ABS		(0<<1)	/**< absolute timestamp */
    274 #define SND_SEQ_TIME_MODE_REL		(1<<1)	/**< relative to current time */
    275 #define SND_SEQ_TIME_MODE_MASK		(1<<1)	/**< mask for time mode bits */
    276 
    277 #define SND_SEQ_EVENT_LENGTH_FIXED	(0<<2)	/**< fixed event size */
    278 #define SND_SEQ_EVENT_LENGTH_VARIABLE	(1<<2)	/**< variable event size */
    279 #define SND_SEQ_EVENT_LENGTH_VARUSR	(2<<2)	/**< variable event size - user memory space */
    280 #define SND_SEQ_EVENT_LENGTH_MASK	(3<<2)	/**< mask for event length bits */
    281 
    282 #define SND_SEQ_PRIORITY_NORMAL		(0<<4)	/**< normal priority */
    283 #define SND_SEQ_PRIORITY_HIGH		(1<<4)	/**< event should be processed before others */
    284 #define SND_SEQ_PRIORITY_MASK		(1<<4)	/**< mask for priority bits */
    285 
    286 
    287 /** Note event */
    288 typedef struct snd_seq_ev_note {
    289 	unsigned char channel;		/**< channel number */
    290 	unsigned char note;		/**< note */
    291 	unsigned char velocity;		/**< velocity */
    292 	unsigned char off_velocity;	/**< note-off velocity; only for #SND_SEQ_EVENT_NOTE */
    293 	unsigned int duration;		/**< duration until note-off; only for #SND_SEQ_EVENT_NOTE */
    294 } snd_seq_ev_note_t;
    295 
    296 /** Controller event */
    297 typedef struct snd_seq_ev_ctrl {
    298 	unsigned char channel;		/**< channel number */
    299 	unsigned char unused[3];	/**< reserved */
    300 	unsigned int param;		/**< control parameter */
    301 	signed int value;		/**< control value */
    302 } snd_seq_ev_ctrl_t;
    303 
    304 /** generic set of bytes (12x8 bit) */
    305 typedef struct snd_seq_ev_raw8 {
    306 	unsigned char d[12];		/**< 8 bit value */
    307 } snd_seq_ev_raw8_t;
    308 
    309 /** generic set of integers (3x32 bit) */
    310 typedef struct snd_seq_ev_raw32 {
    311 	unsigned int d[3];		/**< 32 bit value */
    312 } snd_seq_ev_raw32_t;
    313 
    314 /** external stored data */
    315 typedef struct snd_seq_ev_ext {
    316 	unsigned int len;		/**< length of data */
    317 	void *ptr;			/**< pointer to data (note: can be 64-bit) */
    318 } __attribute__((packed)) snd_seq_ev_ext_t;
    319 
    320 /** Instrument cluster type */
    321 typedef unsigned int snd_seq_instr_cluster_t;
    322 
    323 /** Instrument type */
    324 typedef struct snd_seq_instr {
    325 	snd_seq_instr_cluster_t cluster;	/**< cluster id */
    326 	unsigned int std;	/**< instrument standard id; the upper byte means a private instrument (owner - client id) */
    327 	unsigned short bank;	/**< instrument bank id */
    328 	unsigned short prg;	/**< instrument program id */
    329 } snd_seq_instr_t;
    330 
    331 /** sample number */
    332 typedef struct snd_seq_ev_sample {
    333 	unsigned int std;	/**< sample standard id */
    334 	unsigned short bank;	/**< sample bank id */
    335 	unsigned short prg;	/**< sample program id */
    336 } snd_seq_ev_sample_t;
    337 
    338 /** sample cluster */
    339 typedef struct snd_seq_ev_cluster {
    340 	snd_seq_instr_cluster_t cluster;	/**< cluster id */
    341 } snd_seq_ev_cluster_t;
    342 
    343 /** sample position */
    344 typedef unsigned int snd_seq_position_t; /**< playback position (in samples) * 16 */
    345 
    346 /** sample stop mode */
    347 typedef enum snd_seq_stop_mode {
    348 	SND_SEQ_SAMPLE_STOP_IMMEDIATELY = 0,	/**< terminate playing immediately */
    349 	SND_SEQ_SAMPLE_STOP_VENVELOPE = 1,	/**< finish volume envelope */
    350 	SND_SEQ_SAMPLE_STOP_LOOP = 2		/**< terminate loop and finish wave */
    351 } snd_seq_stop_mode_t;
    352 
    353 /** sample frequency */
    354 typedef int snd_seq_frequency_t; /**< playback frequency in HZ * 16 */
    355 
    356 /** sample volume control; if any value is set to -1 == do not change */
    357 typedef struct snd_seq_ev_volume {
    358 	signed short volume;	/**< range: 0-16383 */
    359 	signed short lr;	/**< left-right balance; range: 0-16383 */
    360 	signed short fr;	/**< front-rear balance; range: 0-16383 */
    361 	signed short du;	/**< down-up balance; range: 0-16383 */
    362 } snd_seq_ev_volume_t;
    363 
    364 /** simple loop redefinition */
    365 typedef struct snd_seq_ev_loop {
    366 	unsigned int start;	/**< loop start (in samples) * 16 */
    367 	unsigned int end;	/**< loop end (in samples) * 16 */
    368 } snd_seq_ev_loop_t;
    369 
    370 /** Sample control events */
    371 typedef struct snd_seq_ev_sample_control {
    372 	unsigned char channel;		/**< channel */
    373 	unsigned char unused[3];	/**< reserved */
    374 	union {
    375 		snd_seq_ev_sample_t sample;	/**< sample number */
    376 		snd_seq_ev_cluster_t cluster;	/**< cluster number */
    377 		snd_seq_position_t position;	/**< position */
    378 		snd_seq_stop_mode_t stop_mode;	/**< stop mode */
    379 		snd_seq_frequency_t frequency;	/**< frequency */
    380 		snd_seq_ev_volume_t volume;	/**< volume */
    381 		snd_seq_ev_loop_t loop;		/**< loop control */
    382 		unsigned char raw8[8];		/**< raw 8-bit */
    383 	} param;		/**< control parameters */
    384 } snd_seq_ev_sample_control_t;
    385 
    386 
    387 
    388 /** INSTR_BEGIN event */
    389 typedef struct snd_seq_ev_instr_begin {
    390 	int timeout;		/**< zero = forever, otherwise timeout in ms */
    391 } snd_seq_ev_instr_begin_t;
    392 
    393 /** Result events */
    394 typedef struct snd_seq_result {
    395 	int event;		/**< processed event type */
    396 	int result;		/**< status */
    397 } snd_seq_result_t;
    398 
    399 /** Queue skew values */
    400 typedef struct snd_seq_queue_skew {
    401 	unsigned int value;	/**< skew value */
    402 	unsigned int base;	/**< skew base */
    403 } snd_seq_queue_skew_t;
    404 
    405 /** queue timer control */
    406 typedef struct snd_seq_ev_queue_control {
    407 	unsigned char queue;			/**< affected queue */
    408 	unsigned char unused[3];		/**< reserved */
    409 	union {
    410 		signed int value;		/**< affected value (e.g. tempo) */
    411 		snd_seq_timestamp_t time;	/**< time */
    412 		unsigned int position;		/**< sync position */
    413 		snd_seq_queue_skew_t skew;	/**< queue skew */
    414 		unsigned int d32[2];		/**< any data */
    415 		unsigned char d8[8];		/**< any data */
    416 	} param;				/**< data value union */
    417 } snd_seq_ev_queue_control_t;
    418 
    419 
    420 /** Sequencer event */
    421 typedef struct snd_seq_event {
    422 	snd_seq_event_type_t type;	/**< event type */
    423 	unsigned char flags;		/**< event flags */
    424 	unsigned char tag;		/**< tag */
    425 
    426 	unsigned char queue;		/**< schedule queue */
    427 	snd_seq_timestamp_t time;	/**< schedule time */
    428 
    429 	snd_seq_addr_t source;		/**< source address */
    430 	snd_seq_addr_t dest;		/**< destination address */
    431 
    432 	union {
    433 		snd_seq_ev_note_t note;		/**< note information */
    434 		snd_seq_ev_ctrl_t control;	/**< MIDI control information */
    435 		snd_seq_ev_raw8_t raw8;		/**< raw8 data */
    436 		snd_seq_ev_raw32_t raw32;	/**< raw32 data */
    437 		snd_seq_ev_ext_t ext;		/**< external data */
    438 		snd_seq_ev_queue_control_t queue; /**< queue control */
    439 		snd_seq_timestamp_t time;	/**< timestamp */
    440 		snd_seq_addr_t addr;		/**< address */
    441 		snd_seq_connect_t connect;	/**< connect information */
    442 		snd_seq_result_t result;	/**< operation result code */
    443 		snd_seq_ev_instr_begin_t instr_begin; /**< instrument */
    444 		snd_seq_ev_sample_control_t sample; /**< sample control */
    445 	} data;				/**< event data... */
    446 } snd_seq_event_t;
    447 
    448 
    449 /** \} */
    450 
    451 #endif /* __ALSA_SEQ_EVENT_H */
    452 
    453