Home | History | Annotate | Download | only in alsa
      1 /**
      2  * \file include/seq.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 /*
     10  * Application interface library for the ALSA driver
     11  *
     12  *
     13  *   This library is free software; you can redistribute it and/or modify
     14  *   it under the terms of the GNU Lesser General Public License as
     15  *   published by the Free Software Foundation; either version 2.1 of
     16  *   the License, or (at your option) any later version.
     17  *
     18  *   This program is distributed in the hope that it will be useful,
     19  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
     20  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21  *   GNU Lesser General Public License for more details.
     22  *
     23  *   You should have received a copy of the GNU Lesser General Public
     24  *   License along with this library; if not, write to the Free Software
     25  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
     26  *
     27  */
     28 
     29 #ifndef __ALSA_SEQ_H
     30 #define __ALSA_SEQ_H
     31 
     32 #ifdef __cplusplus
     33 extern "C" {
     34 #endif
     35 
     36 /**
     37  *  \defgroup Sequencer MIDI Sequencer
     38  *  MIDI Sequencer Interface.
     39  *  See \ref seq page for more details.
     40  *  \{
     41  */
     42 
     43 /** dlsym version for interface entry callback */
     44 #define SND_SEQ_DLSYM_VERSION		_dlsym_seq_001
     45 
     46 /** Sequencer handle */
     47 typedef struct _snd_seq snd_seq_t;
     48 
     49 #ifndef DOC_HIDDEN
     50 #define SND_ALLOCA(type,ptr) \
     51 do {\
     52 	assert(ptr);\
     53 	*ptr = (type##_t *)alloca(type##_sizeof());\
     54 	memset(*ptr, 0, type##_sizeof());\
     55 } while (0)
     56 #endif
     57 
     58 /**
     59  * sequencer opening stream types
     60  */
     61 #define SND_SEQ_OPEN_OUTPUT	1	/**< open for output (write) */
     62 #define SND_SEQ_OPEN_INPUT	2	/**< open for input (read) */
     63 #define SND_SEQ_OPEN_DUPLEX	(SND_SEQ_OPEN_OUTPUT|SND_SEQ_OPEN_INPUT)	/**< open for both input and output (read/write) */
     64 
     65 /**
     66  * sequencer opening mode
     67  */
     68 #define SND_SEQ_NONBLOCK	0x0001	/**< non-blocking mode (flag to open mode) */
     69 
     70 /** sequencer handle type */
     71 typedef enum _snd_seq_type {
     72 	SND_SEQ_TYPE_HW,		/**< hardware */
     73 	SND_SEQ_TYPE_SHM,		/**< shared memory (NYI) */
     74 	SND_SEQ_TYPE_INET		/**< network (NYI) */
     75 } snd_seq_type_t;
     76 
     77 /** special client (port) ids */
     78 #define SND_SEQ_ADDRESS_UNKNOWN		253	/**< unknown source */
     79 #define SND_SEQ_ADDRESS_SUBSCRIBERS	254	/**< send event to all subscribed ports */
     80 #define SND_SEQ_ADDRESS_BROADCAST	255	/**< send event to all queues/clients/ports/channels */
     81 
     82 /** known client numbers */
     83 #define SND_SEQ_CLIENT_SYSTEM		0	/**< system client */
     84 
     85 /*
     86  */
     87 int snd_seq_open(snd_seq_t **handle, const char *name, int streams, int mode);
     88 int snd_seq_open_lconf(snd_seq_t **handle, const char *name, int streams, int mode, snd_config_t *lconf);
     89 const char *snd_seq_name(snd_seq_t *seq);
     90 snd_seq_type_t snd_seq_type(snd_seq_t *seq);
     91 int snd_seq_close(snd_seq_t *handle);
     92 int snd_seq_poll_descriptors_count(snd_seq_t *handle, short events);
     93 int snd_seq_poll_descriptors(snd_seq_t *handle, struct pollfd *pfds, unsigned int space, short events);
     94 int snd_seq_poll_descriptors_revents(snd_seq_t *seq, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
     95 int snd_seq_nonblock(snd_seq_t *handle, int nonblock);
     96 int snd_seq_client_id(snd_seq_t *handle);
     97 
     98 size_t snd_seq_get_output_buffer_size(snd_seq_t *handle);
     99 size_t snd_seq_get_input_buffer_size(snd_seq_t *handle);
    100 int snd_seq_set_output_buffer_size(snd_seq_t *handle, size_t size);
    101 int snd_seq_set_input_buffer_size(snd_seq_t *handle, size_t size);
    102 
    103 /** system information container */
    104 typedef struct _snd_seq_system_info snd_seq_system_info_t;
    105 
    106 size_t snd_seq_system_info_sizeof(void);
    107 /** allocate a #snd_seq_system_info_t container on stack */
    108 #define snd_seq_system_info_alloca(ptr) \
    109 	SND_ALLOCA(snd_seq_system_info, ptr)
    110 int snd_seq_system_info_malloc(snd_seq_system_info_t **ptr);
    111 void snd_seq_system_info_free(snd_seq_system_info_t *ptr);
    112 void snd_seq_system_info_copy(snd_seq_system_info_t *dst, const snd_seq_system_info_t *src);
    113 
    114 int snd_seq_system_info_get_queues(const snd_seq_system_info_t *info);
    115 int snd_seq_system_info_get_clients(const snd_seq_system_info_t *info);
    116 int snd_seq_system_info_get_ports(const snd_seq_system_info_t *info);
    117 int snd_seq_system_info_get_channels(const snd_seq_system_info_t *info);
    118 int snd_seq_system_info_get_cur_clients(const snd_seq_system_info_t *info);
    119 int snd_seq_system_info_get_cur_queues(const snd_seq_system_info_t *info);
    120 
    121 int snd_seq_system_info(snd_seq_t *handle, snd_seq_system_info_t *info);
    122 
    123 /** \} */
    124 
    125 
    126 /**
    127  *  \defgroup SeqClient Sequencer Client Interface
    128  *  Sequencer Client Interface
    129  *  \ingroup Sequencer
    130  *  \{
    131  */
    132 
    133 /** client information container */
    134 typedef struct _snd_seq_client_info snd_seq_client_info_t;
    135 
    136 /** client types */
    137 typedef enum snd_seq_client_type {
    138 	SND_SEQ_USER_CLIENT     = 1,	/**< user client */
    139 	SND_SEQ_KERNEL_CLIENT   = 2	/**< kernel client */
    140 } snd_seq_client_type_t;
    141 
    142 size_t snd_seq_client_info_sizeof(void);
    143 /** allocate a #snd_seq_client_info_t container on stack */
    144 #define snd_seq_client_info_alloca(ptr) \
    145 	SND_ALLOCA(snd_seq_client_info, ptr)
    146 int snd_seq_client_info_malloc(snd_seq_client_info_t **ptr);
    147 void snd_seq_client_info_free(snd_seq_client_info_t *ptr);
    148 void snd_seq_client_info_copy(snd_seq_client_info_t *dst, const snd_seq_client_info_t *src);
    149 
    150 int snd_seq_client_info_get_client(const snd_seq_client_info_t *info);
    151 snd_seq_client_type_t snd_seq_client_info_get_type(const snd_seq_client_info_t *info);
    152 const char *snd_seq_client_info_get_name(snd_seq_client_info_t *info);
    153 int snd_seq_client_info_get_broadcast_filter(const snd_seq_client_info_t *info);
    154 int snd_seq_client_info_get_error_bounce(const snd_seq_client_info_t *info);
    155 const unsigned char *snd_seq_client_info_get_event_filter(const snd_seq_client_info_t *info);
    156 int snd_seq_client_info_get_num_ports(const snd_seq_client_info_t *info);
    157 int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info);
    158 
    159 void snd_seq_client_info_set_client(snd_seq_client_info_t *info, int client);
    160 void snd_seq_client_info_set_name(snd_seq_client_info_t *info, const char *name);
    161 void snd_seq_client_info_set_broadcast_filter(snd_seq_client_info_t *info, int val);
    162 void snd_seq_client_info_set_error_bounce(snd_seq_client_info_t *info, int val);
    163 void snd_seq_client_info_set_event_filter(snd_seq_client_info_t *info, unsigned char *filter);
    164 
    165 int snd_seq_get_client_info(snd_seq_t *handle, snd_seq_client_info_t *info);
    166 int snd_seq_get_any_client_info(snd_seq_t *handle, int client, snd_seq_client_info_t *info);
    167 int snd_seq_set_client_info(snd_seq_t *handle, snd_seq_client_info_t *info);
    168 int snd_seq_query_next_client(snd_seq_t *handle, snd_seq_client_info_t *info);
    169 
    170 /*
    171  */
    172 
    173 /** client pool information container */
    174 typedef struct _snd_seq_client_pool snd_seq_client_pool_t;
    175 
    176 size_t snd_seq_client_pool_sizeof(void);
    177 /** allocate a #snd_seq_client_pool_t container on stack */
    178 #define snd_seq_client_pool_alloca(ptr) \
    179 	SND_ALLOCA(snd_seq_client_pool, ptr)
    180 int snd_seq_client_pool_malloc(snd_seq_client_pool_t **ptr);
    181 void snd_seq_client_pool_free(snd_seq_client_pool_t *ptr);
    182 void snd_seq_client_pool_copy(snd_seq_client_pool_t *dst, const snd_seq_client_pool_t *src);
    183 
    184 int snd_seq_client_pool_get_client(const snd_seq_client_pool_t *info);
    185 size_t snd_seq_client_pool_get_output_pool(const snd_seq_client_pool_t *info);
    186 size_t snd_seq_client_pool_get_input_pool(const snd_seq_client_pool_t *info);
    187 size_t snd_seq_client_pool_get_output_room(const snd_seq_client_pool_t *info);
    188 size_t snd_seq_client_pool_get_output_free(const snd_seq_client_pool_t *info);
    189 size_t snd_seq_client_pool_get_input_free(const snd_seq_client_pool_t *info);
    190 void snd_seq_client_pool_set_output_pool(snd_seq_client_pool_t *info, size_t size);
    191 void snd_seq_client_pool_set_input_pool(snd_seq_client_pool_t *info, size_t size);
    192 void snd_seq_client_pool_set_output_room(snd_seq_client_pool_t *info, size_t size);
    193 
    194 int snd_seq_get_client_pool(snd_seq_t *handle, snd_seq_client_pool_t *info);
    195 int snd_seq_set_client_pool(snd_seq_t *handle, snd_seq_client_pool_t *info);
    196 
    197 
    198 /** \} */
    199 
    200 
    201 /**
    202  *  \defgroup SeqPort Sequencer Port Interface
    203  *  Sequencer Port Interface
    204  *  \ingroup Sequencer
    205  *  \{
    206  */
    207 
    208 /** port information container */
    209 typedef struct _snd_seq_port_info snd_seq_port_info_t;
    210 
    211 /** known port numbers */
    212 #define SND_SEQ_PORT_SYSTEM_TIMER	0	/**< system timer port */
    213 #define SND_SEQ_PORT_SYSTEM_ANNOUNCE	1	/**< system announce port */
    214 
    215 /** port capabilities (32 bits) */
    216 #define SND_SEQ_PORT_CAP_READ		(1<<0)	/**< readable from this port */
    217 #define SND_SEQ_PORT_CAP_WRITE		(1<<1)	/**< writable to this port */
    218 
    219 #define SND_SEQ_PORT_CAP_SYNC_READ	(1<<2)	/**< allow read subscriptions */
    220 #define SND_SEQ_PORT_CAP_SYNC_WRITE	(1<<3)	/**< allow write subscriptions */
    221 
    222 #define SND_SEQ_PORT_CAP_DUPLEX		(1<<4)	/**< allow read/write duplex */
    223 
    224 #define SND_SEQ_PORT_CAP_SUBS_READ	(1<<5)	/**< allow read subscription */
    225 #define SND_SEQ_PORT_CAP_SUBS_WRITE	(1<<6)	/**< allow write subscription */
    226 #define SND_SEQ_PORT_CAP_NO_EXPORT	(1<<7)	/**< routing not allowed */
    227 
    228 /* port type */
    229 /** Messages sent from/to this port have device-specific semantics. */
    230 #define SND_SEQ_PORT_TYPE_SPECIFIC	(1<<0)
    231 /** This port understands MIDI messages. */
    232 #define SND_SEQ_PORT_TYPE_MIDI_GENERIC	(1<<1)
    233 /** This port is compatible with the General MIDI specification. */
    234 #define SND_SEQ_PORT_TYPE_MIDI_GM	(1<<2)
    235 /** This port is compatible with the Roland GS standard. */
    236 #define SND_SEQ_PORT_TYPE_MIDI_GS	(1<<3)
    237 /** This port is compatible with the Yamaha XG specification. */
    238 #define SND_SEQ_PORT_TYPE_MIDI_XG	(1<<4)
    239 /** This port is compatible with the Roland MT-32. */
    240 #define SND_SEQ_PORT_TYPE_MIDI_MT32	(1<<5)
    241 /** This port is compatible with the General MIDI 2 specification. */
    242 #define SND_SEQ_PORT_TYPE_MIDI_GM2	(1<<6)
    243 /** This port understands SND_SEQ_EVENT_SAMPLE_xxx messages
    244     (these are not MIDI messages). */
    245 #define SND_SEQ_PORT_TYPE_SYNTH		(1<<10)
    246 /** Instruments can be downloaded to this port
    247     (with SND_SEQ_EVENT_INSTR_xxx messages sent directly). */
    248 #define SND_SEQ_PORT_TYPE_DIRECT_SAMPLE (1<<11)
    249 /** Instruments can be downloaded to this port
    250     (with SND_SEQ_EVENT_INSTR_xxx messages sent directly or through a queue). */
    251 #define SND_SEQ_PORT_TYPE_SAMPLE	(1<<12)
    252 /** This port is implemented in hardware. */
    253 #define SND_SEQ_PORT_TYPE_HARDWARE	(1<<16)
    254 /** This port is implemented in software. */
    255 #define SND_SEQ_PORT_TYPE_SOFTWARE	(1<<17)
    256 /** Messages sent to this port will generate sounds. */
    257 #define SND_SEQ_PORT_TYPE_SYNTHESIZER	(1<<18)
    258 /** This port may connect to other devices
    259     (whose characteristics are not known). */
    260 #define SND_SEQ_PORT_TYPE_PORT		(1<<19)
    261 /** This port belongs to an application, such as a sequencer or editor. */
    262 #define SND_SEQ_PORT_TYPE_APPLICATION	(1<<20)
    263 
    264 
    265 size_t snd_seq_port_info_sizeof(void);
    266 /** allocate a #snd_seq_port_info_t container on stack */
    267 #define snd_seq_port_info_alloca(ptr) \
    268 	SND_ALLOCA(snd_seq_port_info, ptr)
    269 int snd_seq_port_info_malloc(snd_seq_port_info_t **ptr);
    270 void snd_seq_port_info_free(snd_seq_port_info_t *ptr);
    271 void snd_seq_port_info_copy(snd_seq_port_info_t *dst, const snd_seq_port_info_t *src);
    272 
    273 int snd_seq_port_info_get_client(const snd_seq_port_info_t *info);
    274 int snd_seq_port_info_get_port(const snd_seq_port_info_t *info);
    275 const snd_seq_addr_t *snd_seq_port_info_get_addr(const snd_seq_port_info_t *info);
    276 const char *snd_seq_port_info_get_name(const snd_seq_port_info_t *info);
    277 unsigned int snd_seq_port_info_get_capability(const snd_seq_port_info_t *info);
    278 unsigned int snd_seq_port_info_get_type(const snd_seq_port_info_t *info);
    279 int snd_seq_port_info_get_midi_channels(const snd_seq_port_info_t *info);
    280 int snd_seq_port_info_get_midi_voices(const snd_seq_port_info_t *info);
    281 int snd_seq_port_info_get_synth_voices(const snd_seq_port_info_t *info);
    282 int snd_seq_port_info_get_read_use(const snd_seq_port_info_t *info);
    283 int snd_seq_port_info_get_write_use(const snd_seq_port_info_t *info);
    284 int snd_seq_port_info_get_port_specified(const snd_seq_port_info_t *info);
    285 int snd_seq_port_info_get_timestamping(const snd_seq_port_info_t *info);
    286 int snd_seq_port_info_get_timestamp_real(const snd_seq_port_info_t *info);
    287 int snd_seq_port_info_get_timestamp_queue(const snd_seq_port_info_t *info);
    288 
    289 void snd_seq_port_info_set_client(snd_seq_port_info_t *info, int client);
    290 void snd_seq_port_info_set_port(snd_seq_port_info_t *info, int port);
    291 void snd_seq_port_info_set_addr(snd_seq_port_info_t *info, const snd_seq_addr_t *addr);
    292 void snd_seq_port_info_set_name(snd_seq_port_info_t *info, const char *name);
    293 void snd_seq_port_info_set_capability(snd_seq_port_info_t *info, unsigned int capability);
    294 void snd_seq_port_info_set_type(snd_seq_port_info_t *info, unsigned int type);
    295 void snd_seq_port_info_set_midi_channels(snd_seq_port_info_t *info, int channels);
    296 void snd_seq_port_info_set_midi_voices(snd_seq_port_info_t *info, int voices);
    297 void snd_seq_port_info_set_synth_voices(snd_seq_port_info_t *info, int voices);
    298 void snd_seq_port_info_set_port_specified(snd_seq_port_info_t *info, int val);
    299 void snd_seq_port_info_set_timestamping(snd_seq_port_info_t *info, int enable);
    300 void snd_seq_port_info_set_timestamp_real(snd_seq_port_info_t *info, int realtime);
    301 void snd_seq_port_info_set_timestamp_queue(snd_seq_port_info_t *info, int queue);
    302 
    303 int snd_seq_create_port(snd_seq_t *handle, snd_seq_port_info_t *info);
    304 int snd_seq_delete_port(snd_seq_t *handle, int port);
    305 int snd_seq_get_port_info(snd_seq_t *handle, int port, snd_seq_port_info_t *info);
    306 int snd_seq_get_any_port_info(snd_seq_t *handle, int client, int port, snd_seq_port_info_t *info);
    307 int snd_seq_set_port_info(snd_seq_t *handle, int port, snd_seq_port_info_t *info);
    308 int snd_seq_query_next_port(snd_seq_t *handle, snd_seq_port_info_t *info);
    309 
    310 /** \} */
    311 
    312 
    313 /**
    314  *  \defgroup SeqSubscribe Sequencer Port Subscription
    315  *  Sequencer Port Subscription
    316  *  \ingroup Sequencer
    317  *  \{
    318  */
    319 
    320 /** port subscription container */
    321 typedef struct _snd_seq_port_subscribe snd_seq_port_subscribe_t;
    322 
    323 size_t snd_seq_port_subscribe_sizeof(void);
    324 /** allocate a #snd_seq_port_subscribe_t container on stack */
    325 #define snd_seq_port_subscribe_alloca(ptr) \
    326 	SND_ALLOCA(snd_seq_port_subscribe, ptr)
    327 int snd_seq_port_subscribe_malloc(snd_seq_port_subscribe_t **ptr);
    328 void snd_seq_port_subscribe_free(snd_seq_port_subscribe_t *ptr);
    329 void snd_seq_port_subscribe_copy(snd_seq_port_subscribe_t *dst, const snd_seq_port_subscribe_t *src);
    330 
    331 const snd_seq_addr_t *snd_seq_port_subscribe_get_sender(const snd_seq_port_subscribe_t *info);
    332 const snd_seq_addr_t *snd_seq_port_subscribe_get_dest(const snd_seq_port_subscribe_t *info);
    333 int snd_seq_port_subscribe_get_queue(const snd_seq_port_subscribe_t *info);
    334 int snd_seq_port_subscribe_get_exclusive(const snd_seq_port_subscribe_t *info);
    335 int snd_seq_port_subscribe_get_time_update(const snd_seq_port_subscribe_t *info);
    336 int snd_seq_port_subscribe_get_time_real(const snd_seq_port_subscribe_t *info);
    337 
    338 void snd_seq_port_subscribe_set_sender(snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr);
    339 void snd_seq_port_subscribe_set_dest(snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr);
    340 void snd_seq_port_subscribe_set_queue(snd_seq_port_subscribe_t *info, int q);
    341 void snd_seq_port_subscribe_set_exclusive(snd_seq_port_subscribe_t *info, int val);
    342 void snd_seq_port_subscribe_set_time_update(snd_seq_port_subscribe_t *info, int val);
    343 void snd_seq_port_subscribe_set_time_real(snd_seq_port_subscribe_t *info, int val);
    344 
    345 int snd_seq_get_port_subscription(snd_seq_t *handle, snd_seq_port_subscribe_t *sub);
    346 int snd_seq_subscribe_port(snd_seq_t *handle, snd_seq_port_subscribe_t *sub);
    347 int snd_seq_unsubscribe_port(snd_seq_t *handle, snd_seq_port_subscribe_t *sub);
    348 
    349 /*
    350  */
    351 
    352 /** subscription query container */
    353 typedef struct _snd_seq_query_subscribe snd_seq_query_subscribe_t;
    354 
    355 /** type of query subscription */
    356 typedef enum {
    357 	SND_SEQ_QUERY_SUBS_READ,	/**< query read subscriptions */
    358 	SND_SEQ_QUERY_SUBS_WRITE	/**< query write subscriptions */
    359 } snd_seq_query_subs_type_t;
    360 
    361 size_t snd_seq_query_subscribe_sizeof(void);
    362 /** allocate a #snd_seq_query_subscribe_t container on stack */
    363 #define snd_seq_query_subscribe_alloca(ptr) \
    364 	SND_ALLOCA(snd_seq_query_subscribe, ptr)
    365 int snd_seq_query_subscribe_malloc(snd_seq_query_subscribe_t **ptr);
    366 void snd_seq_query_subscribe_free(snd_seq_query_subscribe_t *ptr);
    367 void snd_seq_query_subscribe_copy(snd_seq_query_subscribe_t *dst, const snd_seq_query_subscribe_t *src);
    368 
    369 int snd_seq_query_subscribe_get_client(const snd_seq_query_subscribe_t *info);
    370 int snd_seq_query_subscribe_get_port(const snd_seq_query_subscribe_t *info);
    371 const snd_seq_addr_t *snd_seq_query_subscribe_get_root(const snd_seq_query_subscribe_t *info);
    372 snd_seq_query_subs_type_t snd_seq_query_subscribe_get_type(const snd_seq_query_subscribe_t *info);
    373 int snd_seq_query_subscribe_get_index(const snd_seq_query_subscribe_t *info);
    374 int snd_seq_query_subscribe_get_num_subs(const snd_seq_query_subscribe_t *info);
    375 const snd_seq_addr_t *snd_seq_query_subscribe_get_addr(const snd_seq_query_subscribe_t *info);
    376 int snd_seq_query_subscribe_get_queue(const snd_seq_query_subscribe_t *info);
    377 int snd_seq_query_subscribe_get_exclusive(const snd_seq_query_subscribe_t *info);
    378 int snd_seq_query_subscribe_get_time_update(const snd_seq_query_subscribe_t *info);
    379 int snd_seq_query_subscribe_get_time_real(const snd_seq_query_subscribe_t *info);
    380 
    381 void snd_seq_query_subscribe_set_client(snd_seq_query_subscribe_t *info, int client);
    382 void snd_seq_query_subscribe_set_port(snd_seq_query_subscribe_t *info, int port);
    383 void snd_seq_query_subscribe_set_root(snd_seq_query_subscribe_t *info, const snd_seq_addr_t *addr);
    384 void snd_seq_query_subscribe_set_type(snd_seq_query_subscribe_t *info, snd_seq_query_subs_type_t type);
    385 void snd_seq_query_subscribe_set_index(snd_seq_query_subscribe_t *info, int _index);
    386 
    387 int snd_seq_query_port_subscribers(snd_seq_t *seq, snd_seq_query_subscribe_t * subs);
    388 
    389 /** \} */
    390 
    391 
    392 /**
    393  *  \defgroup SeqQueue Sequencer Queue Interface
    394  *  Sequencer Queue Interface
    395  *  \ingroup Sequencer
    396  *  \{
    397  */
    398 
    399 /** queue information container */
    400 typedef struct _snd_seq_queue_info snd_seq_queue_info_t;
    401 /** queue status container */
    402 typedef struct _snd_seq_queue_status snd_seq_queue_status_t;
    403 /** queue tempo container */
    404 typedef struct _snd_seq_queue_tempo snd_seq_queue_tempo_t;
    405 /** queue timer information container */
    406 typedef struct _snd_seq_queue_timer snd_seq_queue_timer_t;
    407 
    408 /** special queue ids */
    409 #define SND_SEQ_QUEUE_DIRECT		253	/**< direct dispatch */
    410 
    411 size_t snd_seq_queue_info_sizeof(void);
    412 /** allocate a #snd_seq_queue_info_t container on stack */
    413 #define snd_seq_queue_info_alloca(ptr) \
    414 	SND_ALLOCA(snd_seq_queue_info, ptr)
    415 int snd_seq_queue_info_malloc(snd_seq_queue_info_t **ptr);
    416 void snd_seq_queue_info_free(snd_seq_queue_info_t *ptr);
    417 void snd_seq_queue_info_copy(snd_seq_queue_info_t *dst, const snd_seq_queue_info_t *src);
    418 
    419 int snd_seq_queue_info_get_queue(const snd_seq_queue_info_t *info);
    420 const char *snd_seq_queue_info_get_name(const snd_seq_queue_info_t *info);
    421 int snd_seq_queue_info_get_owner(const snd_seq_queue_info_t *info);
    422 int snd_seq_queue_info_get_locked(const snd_seq_queue_info_t *info);
    423 unsigned int snd_seq_queue_info_get_flags(const snd_seq_queue_info_t *info);
    424 
    425 void snd_seq_queue_info_set_name(snd_seq_queue_info_t *info, const char *name);
    426 void snd_seq_queue_info_set_owner(snd_seq_queue_info_t *info, int owner);
    427 void snd_seq_queue_info_set_locked(snd_seq_queue_info_t *info, int locked);
    428 void snd_seq_queue_info_set_flags(snd_seq_queue_info_t *info, unsigned int flags);
    429 
    430 int snd_seq_create_queue(snd_seq_t *seq, snd_seq_queue_info_t *info);
    431 int snd_seq_alloc_named_queue(snd_seq_t *seq, const char *name);
    432 int snd_seq_alloc_queue(snd_seq_t *handle);
    433 int snd_seq_free_queue(snd_seq_t *handle, int q);
    434 int snd_seq_get_queue_info(snd_seq_t *seq, int q, snd_seq_queue_info_t *info);
    435 int snd_seq_set_queue_info(snd_seq_t *seq, int q, snd_seq_queue_info_t *info);
    436 int snd_seq_query_named_queue(snd_seq_t *seq, const char *name);
    437 
    438 int snd_seq_get_queue_usage(snd_seq_t *handle, int q);
    439 int snd_seq_set_queue_usage(snd_seq_t *handle, int q, int used);
    440 
    441 /*
    442  */
    443 size_t snd_seq_queue_status_sizeof(void);
    444 /** allocate a #snd_seq_queue_status_t container on stack */
    445 #define snd_seq_queue_status_alloca(ptr) \
    446 	SND_ALLOCA(snd_seq_queue_status, ptr)
    447 int snd_seq_queue_status_malloc(snd_seq_queue_status_t **ptr);
    448 void snd_seq_queue_status_free(snd_seq_queue_status_t *ptr);
    449 void snd_seq_queue_status_copy(snd_seq_queue_status_t *dst, const snd_seq_queue_status_t *src);
    450 
    451 int snd_seq_queue_status_get_queue(const snd_seq_queue_status_t *info);
    452 int snd_seq_queue_status_get_events(const snd_seq_queue_status_t *info);
    453 snd_seq_tick_time_t snd_seq_queue_status_get_tick_time(const snd_seq_queue_status_t *info);
    454 const snd_seq_real_time_t *snd_seq_queue_status_get_real_time(const snd_seq_queue_status_t *info);
    455 unsigned int snd_seq_queue_status_get_status(const snd_seq_queue_status_t *info);
    456 
    457 int snd_seq_get_queue_status(snd_seq_t *handle, int q, snd_seq_queue_status_t *status);
    458 
    459 /*
    460  */
    461 size_t snd_seq_queue_tempo_sizeof(void);
    462 /** allocate a #snd_seq_queue_tempo_t container on stack */
    463 #define snd_seq_queue_tempo_alloca(ptr) \
    464 	SND_ALLOCA(snd_seq_queue_tempo, ptr)
    465 int snd_seq_queue_tempo_malloc(snd_seq_queue_tempo_t **ptr);
    466 void snd_seq_queue_tempo_free(snd_seq_queue_tempo_t *ptr);
    467 void snd_seq_queue_tempo_copy(snd_seq_queue_tempo_t *dst, const snd_seq_queue_tempo_t *src);
    468 
    469 int snd_seq_queue_tempo_get_queue(const snd_seq_queue_tempo_t *info);
    470 unsigned int snd_seq_queue_tempo_get_tempo(const snd_seq_queue_tempo_t *info);
    471 int snd_seq_queue_tempo_get_ppq(const snd_seq_queue_tempo_t *info);
    472 unsigned int snd_seq_queue_tempo_get_skew(const snd_seq_queue_tempo_t *info);
    473 unsigned int snd_seq_queue_tempo_get_skew_base(const snd_seq_queue_tempo_t *info);
    474 void snd_seq_queue_tempo_set_tempo(snd_seq_queue_tempo_t *info, unsigned int tempo);
    475 void snd_seq_queue_tempo_set_ppq(snd_seq_queue_tempo_t *info, int ppq);
    476 void snd_seq_queue_tempo_set_skew(snd_seq_queue_tempo_t *info, unsigned int skew);
    477 void snd_seq_queue_tempo_set_skew_base(snd_seq_queue_tempo_t *info, unsigned int base);
    478 
    479 int snd_seq_get_queue_tempo(snd_seq_t *handle, int q, snd_seq_queue_tempo_t *tempo);
    480 int snd_seq_set_queue_tempo(snd_seq_t *handle, int q, snd_seq_queue_tempo_t *tempo);
    481 
    482 /*
    483  */
    484 
    485 /** sequencer timer sources */
    486 typedef enum {
    487 	SND_SEQ_TIMER_ALSA = 0,		/* ALSA timer */
    488 	SND_SEQ_TIMER_MIDI_CLOCK = 1,	/* Midi Clock (CLOCK event) */
    489 	SND_SEQ_TIMER_MIDI_TICK = 2	/* Midi Timer Tick (TICK event */
    490 } snd_seq_queue_timer_type_t;
    491 
    492 size_t snd_seq_queue_timer_sizeof(void);
    493 /** allocate a #snd_seq_queue_timer_t container on stack */
    494 #define snd_seq_queue_timer_alloca(ptr) \
    495 	SND_ALLOCA(snd_seq_queue_timer, ptr)
    496 int snd_seq_queue_timer_malloc(snd_seq_queue_timer_t **ptr);
    497 void snd_seq_queue_timer_free(snd_seq_queue_timer_t *ptr);
    498 void snd_seq_queue_timer_copy(snd_seq_queue_timer_t *dst, const snd_seq_queue_timer_t *src);
    499 
    500 int snd_seq_queue_timer_get_queue(const snd_seq_queue_timer_t *info);
    501 snd_seq_queue_timer_type_t snd_seq_queue_timer_get_type(const snd_seq_queue_timer_t *info);
    502 const snd_timer_id_t *snd_seq_queue_timer_get_id(const snd_seq_queue_timer_t *info);
    503 unsigned int snd_seq_queue_timer_get_resolution(const snd_seq_queue_timer_t *info);
    504 
    505 void snd_seq_queue_timer_set_type(snd_seq_queue_timer_t *info, snd_seq_queue_timer_type_t type);
    506 void snd_seq_queue_timer_set_id(snd_seq_queue_timer_t *info, const snd_timer_id_t *id);
    507 void snd_seq_queue_timer_set_resolution(snd_seq_queue_timer_t *info, unsigned int resolution);
    508 
    509 int snd_seq_get_queue_timer(snd_seq_t *handle, int q, snd_seq_queue_timer_t *timer);
    510 int snd_seq_set_queue_timer(snd_seq_t *handle, int q, snd_seq_queue_timer_t *timer);
    511 
    512 /** \} */
    513 
    514 /**
    515  *  \defgroup SeqEvent Sequencer Event API
    516  *  Sequencer Event API
    517  *  \ingroup Sequencer
    518  *  \{
    519  */
    520 
    521 int snd_seq_free_event(snd_seq_event_t *ev);
    522 ssize_t snd_seq_event_length(snd_seq_event_t *ev);
    523 int snd_seq_event_output(snd_seq_t *handle, snd_seq_event_t *ev);
    524 int snd_seq_event_output_buffer(snd_seq_t *handle, snd_seq_event_t *ev);
    525 int snd_seq_event_output_direct(snd_seq_t *handle, snd_seq_event_t *ev);
    526 int snd_seq_event_input(snd_seq_t *handle, snd_seq_event_t **ev);
    527 int snd_seq_event_input_pending(snd_seq_t *seq, int fetch_sequencer);
    528 int snd_seq_drain_output(snd_seq_t *handle);
    529 int snd_seq_event_output_pending(snd_seq_t *seq);
    530 int snd_seq_extract_output(snd_seq_t *handle, snd_seq_event_t **ev);
    531 int snd_seq_drop_output(snd_seq_t *handle);
    532 int snd_seq_drop_output_buffer(snd_seq_t *handle);
    533 int snd_seq_drop_input(snd_seq_t *handle);
    534 int snd_seq_drop_input_buffer(snd_seq_t *handle);
    535 
    536 /** event removal conditionals */
    537 typedef struct _snd_seq_remove_events snd_seq_remove_events_t;
    538 
    539 /** Remove conditional flags */
    540 #define SND_SEQ_REMOVE_INPUT		(1<<0)	/**< Flush input queues */
    541 #define SND_SEQ_REMOVE_OUTPUT		(1<<1)	/**< Flush output queues */
    542 #define SND_SEQ_REMOVE_DEST		(1<<2)	/**< Restrict by destination q:client:port */
    543 #define SND_SEQ_REMOVE_DEST_CHANNEL	(1<<3)	/**< Restrict by channel */
    544 #define SND_SEQ_REMOVE_TIME_BEFORE	(1<<4)	/**< Restrict to before time */
    545 #define SND_SEQ_REMOVE_TIME_AFTER	(1<<5)	/**< Restrict to time or after */
    546 #define SND_SEQ_REMOVE_TIME_TICK	(1<<6)	/**< Time is in ticks */
    547 #define SND_SEQ_REMOVE_EVENT_TYPE	(1<<7)	/**< Restrict to event type */
    548 #define SND_SEQ_REMOVE_IGNORE_OFF 	(1<<8)	/**< Do not flush off events */
    549 #define SND_SEQ_REMOVE_TAG_MATCH 	(1<<9)	/**< Restrict to events with given tag */
    550 
    551 size_t snd_seq_remove_events_sizeof(void);
    552 /** allocate a #snd_seq_remove_events_t container on stack */
    553 #define snd_seq_remove_events_alloca(ptr) \
    554 	SND_ALLOCA(snd_seq_remove_events, ptr)
    555 int snd_seq_remove_events_malloc(snd_seq_remove_events_t **ptr);
    556 void snd_seq_remove_events_free(snd_seq_remove_events_t *ptr);
    557 void snd_seq_remove_events_copy(snd_seq_remove_events_t *dst, const snd_seq_remove_events_t *src);
    558 
    559 unsigned int snd_seq_remove_events_get_condition(const snd_seq_remove_events_t *info);
    560 int snd_seq_remove_events_get_queue(const snd_seq_remove_events_t *info);
    561 const snd_seq_timestamp_t *snd_seq_remove_events_get_time(const snd_seq_remove_events_t *info);
    562 const snd_seq_addr_t *snd_seq_remove_events_get_dest(const snd_seq_remove_events_t *info);
    563 int snd_seq_remove_events_get_channel(const snd_seq_remove_events_t *info);
    564 int snd_seq_remove_events_get_event_type(const snd_seq_remove_events_t *info);
    565 int snd_seq_remove_events_get_tag(const snd_seq_remove_events_t *info);
    566 
    567 void snd_seq_remove_events_set_condition(snd_seq_remove_events_t *info, unsigned int flags);
    568 void snd_seq_remove_events_set_queue(snd_seq_remove_events_t *info, int queue);
    569 void snd_seq_remove_events_set_time(snd_seq_remove_events_t *info, const snd_seq_timestamp_t *time);
    570 void snd_seq_remove_events_set_dest(snd_seq_remove_events_t *info, const snd_seq_addr_t *addr);
    571 void snd_seq_remove_events_set_channel(snd_seq_remove_events_t *info, int channel);
    572 void snd_seq_remove_events_set_event_type(snd_seq_remove_events_t *info, int type);
    573 void snd_seq_remove_events_set_tag(snd_seq_remove_events_t *info, int tag);
    574 
    575 int snd_seq_remove_events(snd_seq_t *handle, snd_seq_remove_events_t *info);
    576 
    577 /** \} */
    578 
    579 /**
    580  *  \defgroup SeqMisc Sequencer Miscellaneous
    581  *  Sequencer Miscellaneous
    582  *  \ingroup Sequencer
    583  *  \{
    584  */
    585 
    586 void snd_seq_set_bit(int nr, void *array);
    587 int snd_seq_change_bit(int nr, void *array);
    588 int snd_seq_get_bit(int nr, void *array);
    589 
    590 /** \} */
    591 
    592 
    593 /**
    594  *  \defgroup SeqEvType Sequencer Event Type Checks
    595  *  Sequencer Event Type Checks
    596  *  \ingroup Sequencer
    597  *  \{
    598  */
    599 
    600 /* event type macros */
    601 enum {
    602 	SND_SEQ_EVFLG_RESULT,
    603 	SND_SEQ_EVFLG_NOTE,
    604 	SND_SEQ_EVFLG_CONTROL,
    605 	SND_SEQ_EVFLG_QUEUE,
    606 	SND_SEQ_EVFLG_SYSTEM,
    607 	SND_SEQ_EVFLG_MESSAGE,
    608 	SND_SEQ_EVFLG_CONNECTION,
    609 	SND_SEQ_EVFLG_SAMPLE,
    610 	SND_SEQ_EVFLG_USERS,
    611 	SND_SEQ_EVFLG_INSTR,
    612 	SND_SEQ_EVFLG_QUOTE,
    613 	SND_SEQ_EVFLG_NONE,
    614 	SND_SEQ_EVFLG_RAW,
    615 	SND_SEQ_EVFLG_FIXED,
    616 	SND_SEQ_EVFLG_VARIABLE,
    617 	SND_SEQ_EVFLG_VARUSR
    618 };
    619 
    620 enum {
    621 	SND_SEQ_EVFLG_NOTE_ONEARG,
    622 	SND_SEQ_EVFLG_NOTE_TWOARG
    623 };
    624 
    625 enum {
    626 	SND_SEQ_EVFLG_QUEUE_NOARG,
    627 	SND_SEQ_EVFLG_QUEUE_TICK,
    628 	SND_SEQ_EVFLG_QUEUE_TIME,
    629 	SND_SEQ_EVFLG_QUEUE_VALUE
    630 };
    631 
    632 /**
    633  * Exported event type table
    634  *
    635  * This table is referred by snd_seq_ev_is_xxx.
    636  */
    637 extern const unsigned int snd_seq_event_types[];
    638 
    639 #define _SND_SEQ_TYPE(x)	(1<<(x))	/**< master type - 24bit */
    640 #define _SND_SEQ_TYPE_OPT(x)	((x)<<24)	/**< optional type - 8bit */
    641 
    642 /** check the event type */
    643 #define snd_seq_type_check(ev,x) (snd_seq_event_types[(ev)->type] & _SND_SEQ_TYPE(x))
    644 
    645 /** event type check: result events */
    646 #define snd_seq_ev_is_result_type(ev) \
    647 	snd_seq_type_check(ev, SND_SEQ_EVFLG_RESULT)
    648 /** event type check: note events */
    649 #define snd_seq_ev_is_note_type(ev) \
    650 	snd_seq_type_check(ev, SND_SEQ_EVFLG_NOTE)
    651 /** event type check: control events */
    652 #define snd_seq_ev_is_control_type(ev) \
    653 	snd_seq_type_check(ev, SND_SEQ_EVFLG_CONTROL)
    654 /** event type check: channel specific events */
    655 #define snd_seq_ev_is_channel_type(ev) \
    656 	(snd_seq_event_types[(ev)->type] & (_SND_SEQ_TYPE(SND_SEQ_EVFLG_NOTE) | _SND_SEQ_TYPE(SND_SEQ_EVFLG_CONTROL)))
    657 
    658 /** event type check: queue control events */
    659 #define snd_seq_ev_is_queue_type(ev) \
    660 	snd_seq_type_check(ev, SND_SEQ_EVFLG_QUEUE)
    661 /** event type check: system status messages */
    662 #define snd_seq_ev_is_message_type(ev) \
    663 	snd_seq_type_check(ev, SND_SEQ_EVFLG_MESSAGE)
    664 /** event type check: system status messages */
    665 #define snd_seq_ev_is_subscribe_type(ev) \
    666 	snd_seq_type_check(ev, SND_SEQ_EVFLG_CONNECTION)
    667 /** event type check: sample messages */
    668 #define snd_seq_ev_is_sample_type(ev) \
    669 	snd_seq_type_check(ev, SND_SEQ_EVFLG_SAMPLE)
    670 /** event type check: user-defined messages */
    671 #define snd_seq_ev_is_user_type(ev) \
    672 	snd_seq_type_check(ev, SND_SEQ_EVFLG_USERS)
    673 /** event type check: instrument layer events */
    674 #define snd_seq_ev_is_instr_type(ev) \
    675 	snd_seq_type_check(ev, SND_SEQ_EVFLG_INSTR)
    676 /** event type check: fixed length events */
    677 #define snd_seq_ev_is_fixed_type(ev) \
    678 	snd_seq_type_check(ev, SND_SEQ_EVFLG_FIXED)
    679 /** event type check: variable length events */
    680 #define snd_seq_ev_is_variable_type(ev)	\
    681 	snd_seq_type_check(ev, SND_SEQ_EVFLG_VARIABLE)
    682 /** event type check: user pointer events */
    683 #define snd_seq_ev_is_varusr_type(ev) \
    684 	snd_seq_type_check(ev, SND_SEQ_EVFLG_VARUSR)
    685 /** event type check: reserved for kernel */
    686 #define snd_seq_ev_is_reserved(ev) \
    687 	(! snd_seq_event_types[(ev)->type])
    688 
    689 /**
    690  * macros to check event flags
    691  */
    692 /** prior events */
    693 #define snd_seq_ev_is_prior(ev)	\
    694 	(((ev)->flags & SND_SEQ_PRIORITY_MASK) == SND_SEQ_PRIORITY_HIGH)
    695 
    696 /** get the data length type */
    697 #define snd_seq_ev_length_type(ev) \
    698 	((ev)->flags & SND_SEQ_EVENT_LENGTH_MASK)
    699 /** fixed length events */
    700 #define snd_seq_ev_is_fixed(ev)	\
    701 	(snd_seq_ev_length_type(ev) == SND_SEQ_EVENT_LENGTH_FIXED)
    702 /** variable length events */
    703 #define snd_seq_ev_is_variable(ev) \
    704 	(snd_seq_ev_length_type(ev) == SND_SEQ_EVENT_LENGTH_VARIABLE)
    705 /** variable length on user-space */
    706 #define snd_seq_ev_is_varusr(ev) \
    707 	(snd_seq_ev_length_type(ev) == SND_SEQ_EVENT_LENGTH_VARUSR)
    708 
    709 /** time-stamp type */
    710 #define snd_seq_ev_timestamp_type(ev) \
    711 	((ev)->flags & SND_SEQ_TIME_STAMP_MASK)
    712 /** event is in tick time */
    713 #define snd_seq_ev_is_tick(ev) \
    714 	(snd_seq_ev_timestamp_type(ev) == SND_SEQ_TIME_STAMP_TICK)
    715 /** event is in real-time */
    716 #define snd_seq_ev_is_real(ev) \
    717 	(snd_seq_ev_timestamp_type(ev) == SND_SEQ_TIME_STAMP_REAL)
    718 
    719 /** time-mode type */
    720 #define snd_seq_ev_timemode_type(ev) \
    721 	((ev)->flags & SND_SEQ_TIME_MODE_MASK)
    722 /** scheduled in absolute time */
    723 #define snd_seq_ev_is_abstime(ev) \
    724 	(snd_seq_ev_timemode_type(ev) == SND_SEQ_TIME_MODE_ABS)
    725 /** scheduled in relative time */
    726 #define snd_seq_ev_is_reltime(ev) \
    727 	(snd_seq_ev_timemode_type(ev) == SND_SEQ_TIME_MODE_REL)
    728 
    729 /** direct dispatched events */
    730 #define snd_seq_ev_is_direct(ev) \
    731 	((ev)->queue == SND_SEQ_QUEUE_DIRECT)
    732 
    733 /** \} */
    734 
    735 #ifdef __cplusplus
    736 }
    737 #endif
    738 
    739 #endif /* __ALSA_SEQ_H */
    740 
    741