3 * \brief Sequencer Interface
4 * \author Jaroslav Kysela <perex@suse.cz>
5 * \author Abramo Bagnara <abramo@alsa-project.org>
6 * \author Takashi Iwai <tiwai@suse.de>
9 * See \ref seq page for more details.
13 * Sequencer Interface - main file
15 * This library is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License as
17 * published by the Free Software Foundation; either version 2.1 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 /*! \page seq Sequencer interface
39 #include "seq_local.h"
41 /****************************************************************************
46 ****************************************************************************/
49 * \brief get identifier of sequencer handle
50 * \param seq sequencer handle
51 * \return ascii identifier of sequencer handle
53 * Returns the ASCII identifier of the given sequencer handle. It's the same
54 * identifier specified in snd_seq_open().
56 const char *snd_seq_name(snd_seq_t *seq)
63 * \brief get type of sequencer handle
64 * \param seq sequencer handle
65 * \return type of sequencer handle
67 * Returns the type #snd_seq_type_t of the given sequencer handle.
69 snd_seq_type_t snd_seq_type(snd_seq_t *seq)
75 static int snd_seq_open_conf(snd_seq_t **seqp, const char *name,
76 snd_config_t *seq_root, snd_config_t *seq_conf,
77 int streams, int mode)
82 snd_config_t *conf, *type_conf = NULL;
83 snd_config_iterator_t i, next;
85 const char *lib = NULL, *open_name = NULL;
86 int (*open_func)(snd_seq_t **, const char *,
87 snd_config_t *, snd_config_t *,
90 extern void *snd_seq_open_symbols(void);
93 if (snd_config_get_type(seq_conf) != SND_CONFIG_TYPE_COMPOUND) {
95 SNDERR("Invalid type for SEQ %s definition", name);
97 SNDERR("Invalid type for SEQ definition");
100 err = snd_config_search(seq_conf, "type", &conf);
102 SNDERR("type is not defined");
105 err = snd_config_get_id(conf, &id);
107 SNDERR("unable to get id");
110 err = snd_config_get_string(conf, &str);
112 SNDERR("Invalid type for %s", id);
115 err = snd_config_search_definition(seq_root, "seq_type", str, &type_conf);
117 if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
118 SNDERR("Invalid type for SEQ type %s definition", str);
121 snd_config_for_each(i, next, type_conf) {
122 snd_config_t *n = snd_config_iterator_entry(i);
124 if (snd_config_get_id(n, &id) < 0)
126 if (strcmp(id, "comment") == 0)
128 if (strcmp(id, "lib") == 0) {
129 err = snd_config_get_string(n, &lib);
131 SNDERR("Invalid type for %s", id);
136 if (strcmp(id, "open") == 0) {
137 err = snd_config_get_string(n, &open_name);
139 SNDERR("Invalid type for %s", id);
144 SNDERR("Unknown field %s", id);
151 snprintf(buf, sizeof(buf), "_snd_seq_%s_open", str);
154 snd_seq_open_symbols();
156 h = snd_dlopen(lib, RTLD_NOW);
158 open_func = snd_dlsym(h, open_name, SND_DLSYM_VERSION(SND_SEQ_DLSYM_VERSION));
161 SNDERR("Cannot open shared library %s", lib);
163 } else if (!open_func) {
164 SNDERR("symbol %s is not defined inside %s", open_name, lib);
170 snd_config_delete(type_conf);
171 return err >= 0 ? open_func(seqp, name, seq_root, seq_conf, streams, mode) : err;
174 static int snd_seq_open_noupdate(snd_seq_t **seqp, snd_config_t *root,
175 const char *name, int streams, int mode)
178 snd_config_t *seq_conf;
179 err = snd_config_search_definition(root, "seq", name, &seq_conf);
181 SNDERR("Unknown SEQ %s", name);
184 err = snd_seq_open_conf(seqp, name, root, seq_conf, streams, mode);
185 snd_config_delete(seq_conf);
191 * \brief Open the ALSA sequencer
193 * \param seqp Pointer to a snd_seq_t pointer. This pointer must be
194 * kept and passed to most of the other sequencer functions.
195 * \param name The sequencer's "name". This is \em not a name you make
196 * up for your own purposes; it has special significance to the ALSA
197 * library. Usually you need to pass \c "default" here.
198 * \param streams The read/write mode of the sequencer. Can be one of
200 * - #SND_SEQ_OPEN_OUTPUT - open the sequencer for output only
201 * - #SND_SEQ_OPEN_INPUT - open the sequencer for input only
202 * - #SND_SEQ_OPEN_DUPLEX - open the sequencer for output and input
203 * \note Internally, these are translated to \c O_WRONLY, \c O_RDONLY and
204 * \O_RDWR respectively and used as the second argument to the C library
206 * \param mode Optional modifier. Can be either 0, or
207 * #SND_SEQ_NONBLOCK, which will make read/write operations
208 * non-blocking. This can also be set later using #snd_seq_nonblock().
209 * \return 0 on success otherwise a negative error code
211 * Creates a new handle and opens a connection to the kernel
212 * sequencer interface.
213 * After a client is created successfully, an event
214 * with #SND_SEQ_EVENT_CLIENT_START is broadcast to announce port.
216 int snd_seq_open(snd_seq_t **seqp, const char *name,
217 int streams, int mode)
220 assert(seqp && name);
221 err = snd_config_update();
224 return snd_seq_open_noupdate(seqp, snd_config, name, streams, mode);
228 * \brief Open the ALSA sequencer using local configuration
230 * \param seqp Pointer to a snd_seq_t pointer.
231 * \param streams The read/write mode of the sequencer.
232 * \param mode Optional modifier
233 * \param lconf Local configuration
234 * \return 0 on success otherwise a negative error code
236 * See the snd_seq_open() function for further details. The extension
237 * is that the given configuration is used to resolve abstract name.
239 int snd_seq_open_lconf(snd_seq_t **seqp, const char *name,
240 int streams, int mode, snd_config_t *lconf)
242 assert(seqp && name && lconf);
243 return snd_seq_open_noupdate(seqp, lconf, name, streams, mode);
247 * \brief Close the sequencer
248 * \param handle Handle returned from #snd_seq_open()
249 * \return 0 on success otherwise a negative error code
251 * Closes the sequencer client and releases its resources.
252 * After a client is closed, an event with
253 * #SND_SEQ_EVENT_CLIENT_EXIT is broadcast to announce port.
254 * The connection between other clients are disconnected.
255 * Call this just before exiting your program.
257 int snd_seq_close(snd_seq_t *seq)
261 err = seq->ops->close(seq);
277 * \brief Returns the number of poll descriptors
278 * \param seq sequencer handle
279 * \param events the poll events to be checked (\c POLLIN and \c POLLOUT)
280 * \return the number of poll descriptors.
282 * Get the number of poll descriptors. The polling events to be checked
283 * can be specified by the second argument. When both input and output
284 * are checked, pass \c POLLIN|POLLOUT
286 int snd_seq_poll_descriptors_count(snd_seq_t *seq, short events)
290 if (events & POLLIN) {
291 assert(seq->streams & SND_SEQ_OPEN_INPUT);
294 if (events & POLLOUT) {
295 assert(seq->streams & SND_SEQ_OPEN_OUTPUT);
298 return result ? 1 : 0;
302 * \brief Get poll descriptors
303 * \param seq sequencer handle
304 * \param pfds array of poll descriptors
305 * \param space space in the poll descriptor array
306 * \param events polling events to be checked (\c POLLIN and \c POLLOUT)
307 * \return count of filled descriptors
309 * Get poll descriptors assigned to the sequencer handle.
311 int snd_seq_poll_descriptors(snd_seq_t *seq, struct pollfd *pfds, unsigned int space, short events)
316 if ((events & POLLIN) && space >= 1) {
317 assert(seq->streams & SND_SEQ_OPEN_INPUT);
318 revents |= POLLIN|POLLERR;
320 if ((events & POLLOUT) && space >= 1) {
321 assert(seq->streams & SND_SEQ_OPEN_INPUT);
322 revents |= POLLOUT|POLLERR;
326 pfds->fd = seq->poll_fd;
327 pfds->events = revents;
332 * \brief get returned events from poll descriptors
333 * \param seq sequencer handle
334 * \param pfds array of poll descriptors
335 * \param nfds count of poll descriptors
336 * \param revents returned events
337 * \return zero if success, otherwise a negative error code
339 int snd_seq_poll_descriptors_revents(snd_seq_t *seq, struct pollfd *pfds, unsigned int nfds, unsigned short *revents)
341 assert(seq && pfds && revents);
343 *revents = pfds->revents;
350 * \brief Set nonblock mode
351 * \param seq sequencer handle
352 * \param nonblock 0 = block, 1 = nonblock mode
353 * \return 0 on success otherwise a negative error code
355 * Change the blocking mode of the given client.
356 * In block mode, the client falls into sleep when it fills the
357 * output memory pool with full events. The client will be woken up
358 * after a certain amount of free space becomes available.
360 int snd_seq_nonblock(snd_seq_t *seq, int nonblock)
364 err = seq->ops->nonblock(seq, nonblock);
368 seq->mode |= SND_SEQ_NONBLOCK;
370 seq->mode &= ~SND_SEQ_NONBLOCK;
375 * \brief Get the client id
376 * \param seq sequencer handle
377 * \return the client id
379 * Returns the id of the specified client.
380 * If an error occurs, function returns the negative error code.
381 * A client id is necessary to inquiry or to set the client information.
382 * A user client is assigned from 128 to 191.
384 int snd_seq_client_id(snd_seq_t *seq)
391 * \brief Return the size of output buffer
392 * \param seq sequencer handle
393 * \return the size of output buffer in bytes
395 * Obtains the size of output buffer.
396 * This buffer is used to store decoded byte-stream of output events
397 * before transferring to sequencer.
399 size_t snd_seq_get_output_buffer_size(snd_seq_t *seq)
404 return seq->obufsize;
408 * \brief Return the size of input buffer
409 * \param seq sequencer handle
410 * \return the size of input buffer in bytes
412 * Obtains the size of input buffer.
413 * This buffer is used to read byte-stream of input events from sequencer.
415 size_t snd_seq_get_input_buffer_size(snd_seq_t *seq)
420 return seq->ibufsize * sizeof(snd_seq_event_t);
424 * \brief Change the size of output buffer
425 * \param seq sequencer handle
426 * \param size the size of output buffer to be changed in bytes
427 * \return 0 on success otherwise a negative error code
429 * Changes the size of output buffer.
431 int snd_seq_set_output_buffer_size(snd_seq_t *seq, size_t size)
433 assert(seq && seq->obuf);
434 assert(size >= sizeof(snd_seq_event_t));
435 snd_seq_drop_output(seq);
436 if (size != seq->obufsize) {
438 newbuf = calloc(1, size);
443 seq->obufsize = size;
449 * \brief Resize the input buffer
450 * \param seq sequencer handle
451 * \param size the size of input buffer to be changed in bytes
452 * \return 0 on success otherwise a negative error code
454 * Changes the size of input buffer.
456 int snd_seq_set_input_buffer_size(snd_seq_t *seq, size_t size)
458 assert(seq && seq->ibuf);
459 assert(size >= sizeof(snd_seq_event_t));
460 snd_seq_drop_input(seq);
461 size = (size + sizeof(snd_seq_event_t) - 1) / sizeof(snd_seq_event_t);
462 if (size != seq->ibufsize) {
463 snd_seq_event_t *newbuf;
464 newbuf = calloc(sizeof(snd_seq_event_t), size);
469 seq->ibufsize = size;
476 * \brief Get size of #snd_seq_system_info_t
477 * \return size in bytes
479 size_t snd_seq_system_info_sizeof()
481 return sizeof(snd_seq_system_info_t);
485 * \brief Allocate an empty #snd_seq_system_info_t using standard malloc
486 * \param ptr returned pointer
487 * \return 0 on success otherwise negative error code
489 int snd_seq_system_info_malloc(snd_seq_system_info_t **ptr)
492 *ptr = calloc(1, sizeof(snd_seq_system_info_t));
499 * \brief Frees a previously allocated #snd_seq_system_info_t
500 * \param pointer to object to free
502 void snd_seq_system_info_free(snd_seq_system_info_t *obj)
508 * \brief Copy one #snd_seq_system_info_t to another
509 * \param dst pointer to destination
510 * \param src pointer to source
512 void snd_seq_system_info_copy(snd_seq_system_info_t *dst, const snd_seq_system_info_t *src)
520 * \brief Get maximum number of queues
521 * \param info #snd_seq_system_info_t container
522 * \return maximum number of queues
524 int snd_seq_system_info_get_queues(const snd_seq_system_info_t *info)
531 * \brief Get maximum number of clients
532 * \param info #snd_seq_system_info_t container
533 * \return maximum number of clients
535 int snd_seq_system_info_get_clients(const snd_seq_system_info_t *info)
538 return info->clients;
542 * \brief Get maximum number of ports
543 * \param info #snd_seq_system_info_t container
544 * \return maximum number of ports
546 int snd_seq_system_info_get_ports(const snd_seq_system_info_t *info)
553 * \brief Get maximum number of channels
554 * \param info #snd_seq_system_info_t container
555 * \return maximum number of channels
557 int snd_seq_system_info_get_channels(const snd_seq_system_info_t *info)
560 return info->channels;
564 * \brief Get the current number of clients
565 * \param info #snd_seq_system_info_t container
566 * \return current number of clients
568 int snd_seq_system_info_get_cur_clients(const snd_seq_system_info_t *info)
571 return info->cur_clients;
575 * \brief Get the current number of queues
576 * \param info #snd_seq_system_info_t container
577 * \return current number of queues
579 int snd_seq_system_info_get_cur_queues(const snd_seq_system_info_t *info)
582 return info->cur_queues;
586 * \brief obtain the sequencer system information
587 * \param seq sequencer handle
588 * \param info the pointer to be stored
589 * \return 0 on success otherwise a negative error code
591 * Stores the global system information of ALSA sequencer system.
592 * The returned data contains
593 * the maximum available numbers of queues, clients, ports and channels.
595 int snd_seq_system_info(snd_seq_t *seq, snd_seq_system_info_t * info)
598 return seq->ops->system_info(seq, info);
602 /*----------------------------------------------------------------*/
605 * \brief get size of #snd_seq_client_info_t
606 * \return size in bytes
608 size_t snd_seq_client_info_sizeof()
610 return sizeof(snd_seq_client_info_t);
614 * \brief allocate an empty #snd_seq_client_info_t using standard malloc
615 * \param ptr returned pointer
616 * \return 0 on success otherwise negative error code
618 int snd_seq_client_info_malloc(snd_seq_client_info_t **ptr)
621 *ptr = calloc(1, sizeof(snd_seq_client_info_t));
628 * \brief frees a previously allocated #snd_seq_client_info_t
629 * \param pointer to object to free
631 void snd_seq_client_info_free(snd_seq_client_info_t *obj)
637 * \brief copy one #snd_seq_client_info_t to another
638 * \param dst pointer to destination
639 * \param src pointer to source
641 void snd_seq_client_info_copy(snd_seq_client_info_t *dst, const snd_seq_client_info_t *src)
649 * \brief Get client id of a client_info container
650 * \param info client_info container
653 int snd_seq_client_info_get_client(const snd_seq_client_info_t *info)
660 * \brief Get client type of a client_info container
661 * \param info client_info container
662 * \return client type
664 * The client type is either #SEQ_CLIENT_TYPE_KERNEL or #SEQ_CLIENT_TYPE_USER
665 * for kernel or user client respectively.
667 snd_seq_client_type_t snd_seq_client_info_get_type(const snd_seq_client_info_t *info)
674 * \brief Get the name of a client_info container
675 * \param info client_info container
676 * \return name string
678 const char *snd_seq_client_info_get_name(snd_seq_client_info_t *info)
685 * \brief Get the broadcast filter usage of a client_info container
686 * \param info client_info container
687 * \return 1 if broadcast is accepted
689 int snd_seq_client_info_get_broadcast_filter(const snd_seq_client_info_t *info)
692 return (info->filter & SNDRV_SEQ_FILTER_BROADCAST) ? 1 : 0;
696 * \brief Get the error-bounce usage of a client_info container
697 * \param info client_info container
698 * \return 1 if error-bounce is enabled
700 int snd_seq_client_info_get_error_bounce(const snd_seq_client_info_t *info)
703 return (info->filter & SNDRV_SEQ_FILTER_BOUNCE) ? 1 : 0;
707 * \brief Get the event filter bitmap of a client_info container
708 * \param info client_info container
709 * \return NULL if no event filter, or pointer to event filter bitmap
711 const unsigned char *snd_seq_client_info_get_event_filter(const snd_seq_client_info_t *info)
714 if (info->filter & SNDRV_SEQ_FILTER_USE_EVENT)
715 return info->event_filter;
721 * \brief Get the number of opened ports of a client_info container
722 * \param info client_info container
723 * \return number of opened ports
725 int snd_seq_client_info_get_num_ports(const snd_seq_client_info_t *info)
728 return info->num_ports;
732 * \brief Get the number of lost events of a client_info container
733 * \param info client_info container
734 * \return number of lost events
736 int snd_seq_client_info_get_event_lost(const snd_seq_client_info_t *info)
739 return info->event_lost;
743 * \brief Set the client id of a client_info container
744 * \param info client_info container
745 * \param client client id
747 void snd_seq_client_info_set_client(snd_seq_client_info_t *info, int client)
750 info->client = client;
754 * \brief Set the name of a client_info container
755 * \param info client_info container
756 * \param name name string
758 void snd_seq_client_info_set_name(snd_seq_client_info_t *info, const char *name)
760 assert(info && name);
761 strncpy(info->name, name, sizeof(info->name));
765 * \brief Set the broadcast filter usage of a client_info container
766 * \param info client_info container
767 * \param val non-zero if broadcast is accepted
769 void snd_seq_client_info_set_broadcast_filter(snd_seq_client_info_t *info, int val)
773 info->filter |= SNDRV_SEQ_FILTER_BROADCAST;
775 info->filter &= ~SNDRV_SEQ_FILTER_BROADCAST;
779 * \brief Set the error-bounce usage of a client_info container
780 * \param info client_info container
781 * \param val non-zero if error is bounced
783 void snd_seq_client_info_set_error_bounce(snd_seq_client_info_t *info, int val)
787 info->filter |= SNDRV_SEQ_FILTER_BOUNCE;
789 info->filter &= ~SNDRV_SEQ_FILTER_BOUNCE;
793 * \brief Set the event filter bitmap of a client_info container
794 * \param info client_info container
795 * \param filter event filter bitmap
797 void snd_seq_client_info_set_event_filter(snd_seq_client_info_t *info, unsigned char *filter)
801 info->filter &= ~SNDRV_SEQ_FILTER_USE_EVENT;
803 info->filter |= SNDRV_SEQ_FILTER_USE_EVENT;
804 memcpy(info->event_filter, filter, sizeof(info->event_filter));
810 * \brief obtain the information of the given client
811 * \param seq sequencer handle
812 * \param client client id
813 * \param info the pointer to be stored
814 * \return 0 on success otherwise a negative error code
816 * Obtains the information of the client with a client id specified by
818 * The obtained information is written on info parameter.
820 int snd_seq_get_any_client_info(snd_seq_t *seq, int client, snd_seq_client_info_t *info)
822 assert(seq && info && client >= 0);
823 memset(info, 0, sizeof(snd_seq_client_info_t));
824 info->client = client;
825 return seq->ops->get_client_info(seq, info);
829 * \brief obtain the current client information
830 * \param seq sequencer handle
831 * \param info the pointer to be stored
832 * \return 0 on success otherwise a negative error code
834 * Obtains the information of the current client stored on info.
835 * client and type fields are ignored.
837 int snd_seq_get_client_info(snd_seq_t *seq, snd_seq_client_info_t *info)
839 return snd_seq_get_any_client_info(seq, seq->client, info);
843 * \brief set the current client information
844 * \param seq sequencer handle
845 * \param info the client info data to set
846 * \return 0 on success otherwise a negative error code
848 * Obtains the information of the current client stored on info.
849 * client and type fields are ignored.
851 int snd_seq_set_client_info(snd_seq_t *seq, snd_seq_client_info_t *info)
854 info->client = seq->client;
855 info->type = USER_CLIENT;
856 return seq->ops->set_client_info(seq, info);
860 * \brief query the next matching client
861 * \param seq sequencer handle
862 * \param info query pattern and result
864 * Queries the next matching client with the given condition in
866 * The search begins at the client with an id one greater than
867 * client field in info.
868 * If name field in info is not empty, the client name is compared.
869 * If a matching client is found, its attributes are stored o
870 * info and returns zero.
871 * Otherwise returns a negative error code.
873 int snd_seq_query_next_client(snd_seq_t *seq, snd_seq_client_info_t *info)
876 return seq->ops->query_next_client(seq, info);
880 /*----------------------------------------------------------------*/
888 * \brief get size of #snd_seq_port_info_t
889 * \return size in bytes
891 size_t snd_seq_port_info_sizeof()
893 return sizeof(snd_seq_port_info_t);
897 * \brief allocate an empty #snd_seq_port_info_t using standard malloc
898 * \param ptr returned pointer
899 * \return 0 on success otherwise negative error code
901 int snd_seq_port_info_malloc(snd_seq_port_info_t **ptr)
904 *ptr = calloc(1, sizeof(snd_seq_port_info_t));
911 * \brief frees a previously allocated #snd_seq_port_info_t
912 * \param pointer to object to free
914 void snd_seq_port_info_free(snd_seq_port_info_t *obj)
920 * \brief copy one #snd_seq_port_info_t to another
921 * \param dst pointer to destination
922 * \param src pointer to source
924 void snd_seq_port_info_copy(snd_seq_port_info_t *dst, const snd_seq_port_info_t *src)
932 * \brief Get client id of a port_info container
933 * \param info port_info container
936 int snd_seq_port_info_get_client(const snd_seq_port_info_t *info)
939 return info->addr.client;
943 * \brief Get port id of a port_info container
944 * \param info port_info container
947 int snd_seq_port_info_get_port(const snd_seq_port_info_t *info)
950 return info->addr.port;
954 * \brief Get client/port address of a port_info container
955 * \param info port_info container
956 * \return client/port address pointer
958 const snd_seq_addr_t *snd_seq_port_info_get_addr(const snd_seq_port_info_t *info)
961 return (snd_seq_addr_t *)&info->addr;
965 * \brief Get the name of a port_info container
966 * \param info port_info container
967 * \return name string
969 const char *snd_seq_port_info_get_name(const snd_seq_port_info_t *info)
976 * \brief Get the capability bits of a port_info container
977 * \param info port_info container
978 * \return capability bits
980 unsigned int snd_seq_port_info_get_capability(const snd_seq_port_info_t *info)
983 return info->capability;
987 * \brief Get the type bits of a port_info container
988 * \param info port_info container
989 * \return port type bits
991 unsigned int snd_seq_port_info_get_type(const snd_seq_port_info_t *info)
998 * \brief Get the number of read subscriptions of a port_info container
999 * \param info port_info container
1000 * \return number of read subscriptions
1002 int snd_seq_port_info_get_read_use(const snd_seq_port_info_t *info)
1005 return info->read_use;
1009 * \brief Get the number of write subscriptions of a port_info container
1010 * \param info port_info container
1011 * \return number of write subscriptions
1013 int snd_seq_port_info_get_write_use(const snd_seq_port_info_t *info)
1016 return info->write_use;
1020 * \brief Get the midi channels of a port_info container
1021 * \param info port_info container
1022 * \return number of midi channels (default 0)
1024 int snd_seq_port_info_get_midi_channels(const snd_seq_port_info_t *info)
1027 return info->midi_channels;
1031 * \brief Get the midi voices of a port_info container
1032 * \param info port_info container
1033 * \return number of midi voices (default 0)
1035 int snd_seq_port_info_get_midi_voices(const snd_seq_port_info_t *info)
1038 return info->midi_voices;
1042 * \brief Get the synth voices of a port_info container
1043 * \param info port_info container
1044 * \return number of synth voices (default 0)
1046 int snd_seq_port_info_get_synth_voices(const snd_seq_port_info_t *info)
1049 return info->synth_voices;
1053 * \brief Get the port-specified mode of a port_info container
1054 * \param info port_info container
1055 * \return 1 if port id is specified at creation
1057 int snd_seq_port_info_get_port_specified(const snd_seq_port_info_t *info)
1060 return (info->flags & SNDRV_SEQ_PORT_FLG_GIVEN_PORT) ? 1 : 0;
1064 * \brief Set the client id of a port_info container
1065 * \param info port_info container
1066 * \param client client id
1068 void snd_seq_port_info_set_client(snd_seq_port_info_t *info, int client)
1071 info->addr.client = client;
1075 * \brief Set the port id of a port_info container
1076 * \param info port_info container
1077 * \param port port id
1079 void snd_seq_port_info_set_port(snd_seq_port_info_t *info, int port)
1082 info->addr.port = port;
1086 * \brief Set the client/port address of a port_info container
1087 * \param info port_info container
1088 * \param addr client/port address
1090 void snd_seq_port_info_set_addr(snd_seq_port_info_t *info, const snd_seq_addr_t *addr)
1093 info->addr = *(struct sndrv_seq_addr *)addr;
1097 * \brief Set the name of a port_info container
1098 * \param info port_info container
1099 * \param name name string
1101 void snd_seq_port_info_set_name(snd_seq_port_info_t *info, const char *name)
1103 assert(info && name);
1104 strncpy(info->name, name, sizeof(info->name));
1108 * \brief set the capability bits of a port_info container
1109 * \param info port_info container
1110 * \param capability capability bits
1112 void snd_seq_port_info_set_capability(snd_seq_port_info_t *info, unsigned int capability)
1115 info->capability = capability;
1119 * \brief Get the type bits of a port_info container
1120 * \param info port_info container
1121 * \return port type bits
1123 void snd_seq_port_info_set_type(snd_seq_port_info_t *info, unsigned int type)
1130 * \brief set the midi channels of a port_info container
1131 * \param info port_info container
1132 * \param channels midi channels (default 0)
1134 void snd_seq_port_info_set_midi_channels(snd_seq_port_info_t *info, int channels)
1137 info->midi_channels = channels;
1141 * \brief set the midi voices of a port_info container
1142 * \param info port_info container
1143 * \param voices midi voices (default 0)
1145 void snd_seq_port_info_set_midi_voices(snd_seq_port_info_t *info, int voices)
1148 info->midi_voices = voices;
1152 * \brief set the synth voices of a port_info container
1153 * \param info port_info container
1154 * \param voices synth voices (default 0)
1156 void snd_seq_port_info_set_synth_voices(snd_seq_port_info_t *info, int voices)
1159 info->synth_voices = voices;
1163 * \brief Set the port-specified mode of a port_info container
1164 * \param info port_info container
1165 * \param val non-zero if specifying the port id at creation
1167 void snd_seq_port_info_set_port_specified(snd_seq_port_info_t *info, int val)
1171 info->flags |= SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
1173 info->flags &= ~SNDRV_SEQ_PORT_FLG_GIVEN_PORT;
1178 * \brief create a sequencer port on the current client
1179 * \param seq sequencer handle
1180 * \param port port information for the new port
1181 * \return 0 on success otherwise a negative error code
1183 * Creates a sequencer port on the current client.
1184 * The attributes of created port is specified in \a info argument.
1186 * The client field in \a info argument is overwritten with the current client id.
1187 * The port id to be created can be specified via #snd_seq_port_info_set_port_specified.
1188 * You can get the created port id by reading the port pointer via #snd_seq_port_info_get_port.
1190 * Each port has the capability bit-masks to specify the access capability
1191 * of the port from other clients.
1192 * The capability bit flags are defined as follows:
1193 * - #SND_SEQ_PORT_CAP_READ Readable from this port
1194 * - #SND_SEQ_PORT_CAP_WRITE Writable to this port.
1195 * - #SND_SEQ_PORT_CAP_SYNC_READ For synchronization (not implemented)
1196 * - #SND_SEQ_PORT_CAP_SYNC_WRITE For synchronization (not implemented)
1197 * - #SND_SEQ_PORT_CAP_DUPLEX Read/write duplex access is supported
1198 * - #SND_SEQ_PORT_CAP_SUBS_READ Read subscription is allowed
1199 * - #SND_SEQ_PORT_CAP_SUBS_WRITE Write subscription is allowed
1200 * - #SND_SEQ_PORT_CAP_SUBS_NO_EXPORT Subscription management from 3rd client is disallowed
1202 * Each port has also the type bitmasks defined as follows:
1203 * - #SND_SEQ_PORT_TYPE_SPECIFIC Hardware specific port
1204 * - #SND_SEQ_PORT_TYPE_MIDI_GENERIC Generic MIDI device
1205 * - #SND_SEQ_PORT_TYPE_MIDI_GM General MIDI compatible device
1206 * - #SND_SEQ_PORT_TYPE_MIDI_GS GS compatible device
1207 * - #SND_SEQ_PORT_TYPE_MIDI_XG XG compatible device
1208 * - #SND_SEQ_PORT_TYPE_MIDI_MT32 MT-32 compatible device
1209 * - #SND_SEQ_PORT_TYPE_SYNTH Synth device
1210 * - #SND_SEQ_PORT_TYPE_DIRECT_SAMPLE Sampling device (supporting download)
1211 * - #SND_SEQ_PORT_TYPE_SAMPLE Sampling device (sample can be downloaded at any time)
1212 * - #SND_SEQ_PORT_TYPE_APPLICATION Application (sequencer/editor)
1214 * A port may contain specific midi channels, midi voices and synth voices.
1215 * These values could be zero as default.
1217 int snd_seq_create_port(snd_seq_t *seq, snd_seq_port_info_t * port)
1219 assert(seq && port);
1220 port->addr.client = seq->client;
1221 return seq->ops->create_port(seq, port);
1225 * \brief delete a sequencer port on the current client
1226 * \param seq sequencer handle
1227 * \param port port to be deleted
1228 * \return 0 on success otherwise a negative error code
1230 * Deletes the existing sequencer port on the current client.
1232 int snd_seq_delete_port(snd_seq_t *seq, int port)
1234 snd_seq_port_info_t pinfo;
1236 memset(&pinfo, 0, sizeof(pinfo));
1237 pinfo.addr.client = seq->client;
1238 pinfo.addr.port = port;
1239 return seq->ops->delete_port(seq, &pinfo);
1243 * \brief obtain the information of a port on an arbitrary client
1244 * \param seq sequencer handle
1245 * \param client client id to get
1246 * \param port port id to get
1247 * \param info pointer information returns
1248 * \return 0 on success otherwise a negative error code
1250 int snd_seq_get_any_port_info(snd_seq_t *seq, int client, int port, snd_seq_port_info_t * info)
1252 assert(seq && info && client >= 0 && port >= 0);
1253 memset(info, 0, sizeof(snd_seq_port_info_t));
1254 info->addr.client = client;
1255 info->addr.port = port;
1256 return seq->ops->get_port_info(seq, info);
1260 * \brief obtain the information of a port on the current client
1261 * \param seq sequencer handle
1262 * \param port port id to get
1263 * \param info pointer information returns
1264 * \return 0 on success otherwise a negative error code
1266 int snd_seq_get_port_info(snd_seq_t *seq, int port, snd_seq_port_info_t * info)
1268 return snd_seq_get_any_port_info(seq, seq->client, port, info);
1272 * \brief set the information of a port on the current client
1273 * \param seq sequencer handle
1274 * \param port port to be set
1275 * \param info port information to be set
1276 * \return 0 on success otherwise a negative error code
1278 int snd_seq_set_port_info(snd_seq_t *seq, int port, snd_seq_port_info_t * info)
1280 assert(seq && info && port >= 0);
1281 info->addr.client = seq->client;
1282 info->addr.port = port;
1283 return seq->ops->set_port_info(seq, info);
1287 * \brief query the next matching port
1288 * \param seq sequencer handle
1289 * \param info query pattern and result
1291 * Queries the next matching port on the client specified in
1293 * The search begins at the next port specified in
1294 * port field of \a info argument.
1295 * For finding the first port at a certain client, give -1.
1297 * If a matching port is found, its attributes are stored on
1298 * \a info and function returns zero.
1299 * Otherwise, a negative error code is returned.
1301 int snd_seq_query_next_port(snd_seq_t *seq, snd_seq_port_info_t *info)
1303 assert(seq && info);
1304 return seq->ops->query_next_port(seq, info);
1308 /*----------------------------------------------------------------*/
1316 * \brief get size of #snd_seq_port_subscribe_t
1317 * \return size in bytes
1319 size_t snd_seq_port_subscribe_sizeof()
1321 return sizeof(snd_seq_port_subscribe_t);
1325 * \brief allocate an empty #snd_seq_port_subscribe_t using standard malloc
1326 * \param ptr returned pointer
1327 * \return 0 on success otherwise negative error code
1329 int snd_seq_port_subscribe_malloc(snd_seq_port_subscribe_t **ptr)
1332 *ptr = calloc(1, sizeof(snd_seq_port_subscribe_t));
1339 * \brief frees a previously allocated #snd_seq_port_subscribe_t
1340 * \param pointer to object to free
1342 void snd_seq_port_subscribe_free(snd_seq_port_subscribe_t *obj)
1348 * \brief copy one #snd_seq_port_subscribe_t to another
1349 * \param dst pointer to destination
1350 * \param src pointer to source
1352 void snd_seq_port_subscribe_copy(snd_seq_port_subscribe_t *dst, const snd_seq_port_subscribe_t *src)
1360 * \brief Get sender address of a port_subscribe container
1361 * \param info port_subscribe container
1362 * \param addr sender address
1364 const snd_seq_addr_t *snd_seq_port_subscribe_get_sender(const snd_seq_port_subscribe_t *info)
1367 return (snd_seq_addr_t *)&info->sender;
1371 * \brief Get destination address of a port_subscribe container
1372 * \param info port_subscribe container
1373 * \param addr destination address
1375 const snd_seq_addr_t *snd_seq_port_subscribe_get_dest(const snd_seq_port_subscribe_t *info)
1378 return (snd_seq_addr_t *)&info->dest;
1382 * \brief Get the queue id of a port_subscribe container
1383 * \param info port_subscribe container
1386 int snd_seq_port_subscribe_get_queue(const snd_seq_port_subscribe_t *info)
1393 * \brief Get the exclusive mode of a port_subscribe container
1394 * \param info port_subscribe container
1395 * \return 1 if exclusive mode
1397 int snd_seq_port_subscribe_get_exclusive(const snd_seq_port_subscribe_t *info)
1400 return (info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE) ? 1 : 0;
1404 * \brief Get the time-update mode of a port_subscribe container
1405 * \param info port_subscribe container
1406 * \return 1 if update timestamp
1408 int snd_seq_port_subscribe_get_time_update(const snd_seq_port_subscribe_t *info)
1411 return (info->flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP) ? 1 : 0;
1415 * \brief Get the real-time update mode of a port_subscribe container
1416 * \param info port_subscribe container
1417 * \return 1 if real-time update mode
1419 int snd_seq_port_subscribe_get_time_real(const snd_seq_port_subscribe_t *info)
1422 return (info->flags & SNDRV_SEQ_PORT_SUBS_TIME_REAL) ? 1 : 0;
1426 * \brief Set sender address of a port_subscribe container
1427 * \param info port_subscribe container
1428 * \param addr sender address
1430 void snd_seq_port_subscribe_set_sender(snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr)
1433 memcpy(&info->sender, addr, sizeof(*addr));
1437 * \brief Set destination address of a port_subscribe container
1438 * \param info port_subscribe container
1439 * \param addr destination address
1441 void snd_seq_port_subscribe_set_dest(snd_seq_port_subscribe_t *info, const snd_seq_addr_t *addr)
1444 memcpy(&info->dest, addr, sizeof(*addr));
1448 * \brief Set the queue id of a port_subscribe container
1449 * \param info port_subscribe container
1452 void snd_seq_port_subscribe_set_queue(snd_seq_port_subscribe_t *info, int q)
1459 * \brief Set the voices of a port_subscribe container
1460 * \param info port_subscribe container
1461 * \param voices voices to be allocated (0 = don't care)
1463 void snd_seq_port_subscribe_set_voices(snd_seq_port_subscribe_t *info, unsigned int voices)
1466 info->voices = voices;
1470 * \brief Set the exclusive mode of a port_subscribe container
1471 * \param info port_subscribe container
1472 * \param val non-zero to enable
1474 void snd_seq_port_subscribe_set_exclusive(snd_seq_port_subscribe_t *info, int val)
1478 info->flags |= SNDRV_SEQ_PORT_SUBS_EXCLUSIVE;
1480 info->flags &= ~SNDRV_SEQ_PORT_SUBS_EXCLUSIVE;
1484 * \brief Set the time-update mode of a port_subscribe container
1485 * \param info port_subscribe container
1486 * \param val non-zero to enable
1488 void snd_seq_port_subscribe_set_time_update(snd_seq_port_subscribe_t *info, int val)
1492 info->flags |= SNDRV_SEQ_PORT_SUBS_TIMESTAMP;
1494 info->flags &= ~SNDRV_SEQ_PORT_SUBS_TIMESTAMP;
1498 * \brief Set the real-time mode of a port_subscribe container
1499 * \param info port_subscribe container
1500 * \param val non-zero to enable
1502 void snd_seq_port_subscribe_set_time_real(snd_seq_port_subscribe_t *info, int val)
1506 info->flags |= SNDRV_SEQ_PORT_SUBS_TIME_REAL;
1508 info->flags &= ~SNDRV_SEQ_PORT_SUBS_TIME_REAL;
1513 * \brief obtain subscription information
1514 * \param seq sequencer handle
1515 * \param sub pointer to return the subscription information
1516 * \return 0 on success otherwise a negative error code
1518 int snd_seq_get_port_subscription(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
1521 return seq->ops->get_port_subscription(seq, sub);
1525 * \brief subscribe a port connection
1526 * \param seq sequencer handle
1527 * \param sub subscription information
1528 * \return 0 on success otherwise a negative error code
1530 * Subscribes a connection between two ports.
1531 * The subscription information is stored in sub argument.
1533 int snd_seq_subscribe_port(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
1536 return seq->ops->subscribe_port(seq, sub);
1540 * \brief unsubscribe a connection between ports
1541 * \param seq sequencer handle
1542 * \param sub subscription information to disconnect
1543 * \return 0 on success otherwise a negative error code
1545 * Unsubscribes a connection between two ports,
1546 * described in sender and dest fields in sub argument.
1548 int snd_seq_unsubscribe_port(snd_seq_t *seq, snd_seq_port_subscribe_t * sub)
1551 return seq->ops->unsubscribe_port(seq, sub);
1556 * \brief get size of #snd_seq_query_subscribe_t
1557 * \return size in bytes
1559 size_t snd_seq_query_subscribe_sizeof()
1561 return sizeof(snd_seq_query_subscribe_t);
1565 * \brief allocate an empty #snd_seq_query_subscribe_t using standard malloc
1566 * \param ptr returned pointer
1567 * \return 0 on success otherwise negative error code
1569 int snd_seq_query_subscribe_malloc(snd_seq_query_subscribe_t **ptr)
1572 *ptr = calloc(1, sizeof(snd_seq_query_subscribe_t));
1579 * \brief frees a previously allocated #snd_seq_query_subscribe_t
1580 * \param pointer to object to free
1582 void snd_seq_query_subscribe_free(snd_seq_query_subscribe_t *obj)
1588 * \brief copy one #snd_seq_query_subscribe_t to another
1589 * \param dst pointer to destination
1590 * \param src pointer to source
1592 void snd_seq_query_subscribe_copy(snd_seq_query_subscribe_t *dst, const snd_seq_query_subscribe_t *src)
1600 * \brief Get the client id of a query_subscribe container
1601 * \param info query_subscribe container
1604 int snd_seq_query_subscribe_get_client(const snd_seq_query_subscribe_t *info)
1607 return info->root.client;
1611 * \brief Get the port id of a query_subscribe container
1612 * \param info query_subscribe container
1615 int snd_seq_query_subscribe_get_port(const snd_seq_query_subscribe_t *info)
1618 return info->root.port;
1622 * \brief Get the client/port address of a query_subscribe container
1623 * \param info query_subscribe container
1624 * \return client/port address pointer
1626 const snd_seq_addr_t *snd_seq_query_subscribe_get_root(const snd_seq_query_subscribe_t *info)
1629 return (snd_seq_addr_t *)&info->root;
1633 * \brief Get the query type of a query_subscribe container
1634 * \param info query_subscribe container
1635 * \return query type
1637 snd_seq_query_subs_type_t snd_seq_query_subscribe_get_type(const snd_seq_query_subscribe_t *info)
1644 * \brief Get the index of subscriber of a query_subscribe container
1645 * \param info query_subscribe container
1646 * \return subscriber's index
1648 int snd_seq_query_subscribe_get_index(const snd_seq_query_subscribe_t *info)
1655 * \brief Get the number of subscriptions of a query_subscribe container
1656 * \param info query_subscribe container
1657 * \return number of subscriptions
1659 int snd_seq_query_subscribe_get_num_subs(const snd_seq_query_subscribe_t *info)
1662 return info->num_subs;
1666 * \brief Get the address of subscriber of a query_subscribe container
1667 * \param info query_subscribe container
1668 * \return subscriber's address pointer
1670 const snd_seq_addr_t *snd_seq_query_subscribe_get_addr(const snd_seq_query_subscribe_t *info)
1673 return (snd_seq_addr_t *)&info->addr;
1677 * \brief Get the queue id of subscriber of a query_subscribe container
1678 * \param info query_subscribe container
1679 * \return subscriber's queue id
1681 int snd_seq_query_subscribe_get_queue(const snd_seq_query_subscribe_t *info)
1688 * \brief Get the exclusive mode of a query_subscribe container
1689 * \param info query_subscribe container
1690 * \return 1 if exclusive mode
1692 int snd_seq_query_subscribe_get_exclusive(const snd_seq_query_subscribe_t *info)
1695 return (info->flags & SNDRV_SEQ_PORT_SUBS_EXCLUSIVE) ? 1 : 0;
1699 * \brief Get the time-update mode of a query_subscribe container
1700 * \param info query_subscribe container
1701 * \return 1 if update timestamp
1703 int snd_seq_query_subscribe_get_time_update(const snd_seq_query_subscribe_t *info)
1706 return (info->flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP) ? 1 : 0;
1710 * \brief Get the real-time update mode of a query_subscribe container
1711 * \param info query_subscribe container
1712 * \return 1 if real-time update mode
1714 int snd_seq_query_subscribe_get_time_real(const snd_seq_query_subscribe_t *info)
1717 return (info->flags & SNDRV_SEQ_PORT_SUBS_TIMESTAMP) ? 1 : 0;
1721 * \brief Set the client id of a query_subscribe container
1722 * \param info query_subscribe container
1723 * \param client client id
1725 void snd_seq_query_subscribe_set_client(snd_seq_query_subscribe_t *info, int client)
1728 info->root.client = client;
1732 * \brief Set the port id of a query_subscribe container
1733 * \param info query_subscribe container
1734 * \param port port id
1736 void snd_seq_query_subscribe_set_port(snd_seq_query_subscribe_t *info, int port)
1739 info->root.port = port;
1743 * \brief Set the client/port address of a query_subscribe container
1744 * \param info query_subscribe container
1745 * \param addr client/port address pointer
1747 void snd_seq_query_subscribe_set_root(snd_seq_query_subscribe_t *info, const snd_seq_addr_t *addr)
1750 info->root = *(struct sndrv_seq_addr *)addr;
1754 * \brief Set the query type of a query_subscribe container
1755 * \param info query_subscribe container
1756 * \param type query type
1758 void snd_seq_query_subscribe_set_type(snd_seq_query_subscribe_t *info, snd_seq_query_subs_type_t type)
1765 * \brief Set the subscriber's index to be queried
1766 * \param info query_subscribe container
1767 * \param index index to be queried
1769 void snd_seq_query_subscribe_set_index(snd_seq_query_subscribe_t *info, int index)
1772 info->index = index;
1777 * \brief query port subscriber list
1778 * \param seq sequencer handle
1779 * \param subs subscription to query
1780 * \return 0 on success otherwise a negative error code
1782 * Queries the subscribers accessing to a port.
1783 * The query information is specified in subs argument.
1786 int snd_seq_query_port_subscribers(snd_seq_t *seq, snd_seq_query_subscribe_t * subs)
1788 assert(seq && subs);
1789 return seq->ops->query_port_subscribers(seq, subs);
1792 /*----------------------------------------------------------------*/
1799 * \brief get size of #snd_seq_queue_info_t
1800 * \return size in bytes
1802 size_t snd_seq_queue_info_sizeof()
1804 return sizeof(snd_seq_queue_info_t);
1808 * \brief allocate an empty #snd_seq_queue_info_t using standard malloc
1809 * \param ptr returned pointer
1810 * \return 0 on success otherwise negative error code
1812 int snd_seq_queue_info_malloc(snd_seq_queue_info_t **ptr)
1815 *ptr = calloc(1, sizeof(snd_seq_queue_info_t));
1822 * \brief frees a previously allocated #snd_seq_queue_info_t
1823 * \param pointer to object to free
1825 void snd_seq_queue_info_free(snd_seq_queue_info_t *obj)
1831 * \brief copy one #snd_seq_queue_info_t to another
1832 * \param dst pointer to destination
1833 * \param src pointer to source
1835 void snd_seq_queue_info_copy(snd_seq_queue_info_t *dst, const snd_seq_queue_info_t *src)
1843 * \brief Get the queue id of a queue_info container
1844 * \param info queue_info container
1847 int snd_seq_queue_info_get_queue(const snd_seq_queue_info_t *info)
1854 * \brief Get the name of a queue_info container
1855 * \param info queue_info container
1856 * \return name string
1858 const char *snd_seq_queue_info_get_name(const snd_seq_queue_info_t *info)
1865 * \brief Get the owner client id of a queue_info container
1866 * \param info queue_info container
1867 * \return owner client id
1869 int snd_seq_queue_info_get_owner(const snd_seq_queue_info_t *info)
1876 * \brief Get the lock status of a queue_info container
1877 * \param info queue_info container
1878 * \return lock status --- non-zero = locked
1880 int snd_seq_queue_info_get_locked(const snd_seq_queue_info_t *info)
1883 return info->locked;
1887 * \brief Get the conditional bit flags of a queue_info container
1888 * \param info queue_info container
1889 * \return conditional bit flags
1891 unsigned int snd_seq_queue_info_get_flags(const snd_seq_queue_info_t *info)
1898 * \brief Set the name of a queue_info container
1899 * \param info queue_info container
1900 * \param name name string
1902 void snd_seq_queue_info_set_name(snd_seq_queue_info_t *info, const char *name)
1904 assert(info && name);
1905 strncpy(info->name, name, sizeof(info->name));
1909 * \brief Set the owner client id of a queue_info container
1910 * \param info queue_info container
1911 * \param owner client id
1913 void snd_seq_queue_info_set_owner(snd_seq_queue_info_t *info, int owner)
1916 info->owner = owner;
1920 * \brief Set the lock status of a queue_info container
1921 * \param info queue_info container
1922 * \param locked lock status
1924 void snd_seq_queue_info_set_locked(snd_seq_queue_info_t *info, int locked)
1927 info->locked = locked;
1931 * \brief Set the conditional bit flags of a queue_info container
1932 * \param info queue_info container
1933 * \param flags conditional bit flags
1935 void snd_seq_queue_info_set_flags(snd_seq_queue_info_t *info, unsigned int flags)
1938 info->flags = flags;
1943 * \brief create a queue
1944 * \param seq sequencer handle
1945 * \param info queue information to initialize
1946 * \return the queue id (zero or positive) on success otherwise a negative error code
1948 int snd_seq_create_queue(snd_seq_t *seq, snd_seq_queue_info_t *info)
1951 assert(seq && info);
1952 info->owner = seq->client;
1953 err = seq->ops->create_queue(seq, info);
1960 * \brief allocate a queue with the specified name
1961 * \param seq sequencer handle
1962 * \param name the name of the new queue
1963 * \return the queue id (zero or positive) on success otherwise a negative error code
1965 int snd_seq_alloc_named_queue(snd_seq_t *seq, const char *name)
1967 snd_seq_queue_info_t info;
1968 memset(&info, 0, sizeof(info));
1971 strncpy(info.name, name, sizeof(info.name) - 1);
1972 return snd_seq_create_queue(seq, &info);
1976 * \brief allocate a queue
1977 * \param seq sequencer handle
1978 * \return the queue id (zero or positive) on success otherwise a negative error code
1980 int snd_seq_alloc_queue(snd_seq_t *seq)
1982 return snd_seq_alloc_named_queue(seq, NULL);
1986 * \brief delete the specified queue
1987 * \param seq sequencer handle
1988 * \param q queue id to delete
1989 * \return 0 on success otherwise a negative error code
1991 int snd_seq_free_queue(snd_seq_t *seq, int q)
1993 snd_seq_queue_info_t info;
1995 memset(&info, 0, sizeof(info));
1997 return seq->ops->delete_queue(seq, &info);
2001 * \brief obtain queue attributes
2002 * \param seq sequencer handle
2003 * \param q queue id to query
2004 * \param info information returned
2005 * \return 0 on success otherwise a negative error code
2007 int snd_seq_get_queue_info(snd_seq_t *seq, int q, snd_seq_queue_info_t *info)
2009 assert(seq && info);
2011 return seq->ops->get_queue_info(seq, info);
2015 * \brief change the queue attributes
2016 * \param seq sequencer handle
2017 * \param q queue id to change
2018 * \param info information changed
2019 * \return 0 on success otherwise a negative error code
2021 int snd_seq_set_queue_info(snd_seq_t *seq, int q, snd_seq_queue_info_t *info)
2023 assert(seq && info);
2025 return seq->ops->set_queue_info(seq, info);
2029 * \brief query the matching queue with the specified name
2030 * \param seq sequencer handle
2031 * \param name the name string to query
2032 * \return the queue id if found or negative error code
2034 * Searches the matching queue with the specified name string.
2036 int snd_seq_query_named_queue(snd_seq_t *seq, const char *name)
2039 snd_seq_queue_info_t info;
2040 assert(seq && name);
2041 strncpy(info.name, name, sizeof(info.name));
2042 err = seq->ops->get_named_queue(seq, &info);
2049 * \brief Get the queue usage flag to the client
2050 * \param seq sequencer handle
2052 * \param client client id
2053 * \return 1 = client is allowed to access the queue, 0 = not allowed,
2054 * otherwise a negative error code
2056 int snd_seq_get_queue_usage(snd_seq_t *seq, int q)
2058 struct sndrv_seq_queue_client info;
2061 memset(&info, 0, sizeof(info));
2063 info.client = seq->client;
2064 if ((err = seq->ops->get_queue_client(seq, &info)) < 0)
2070 * \brief Set the queue usage flag to the client
2071 * \param seq sequencer handle
2073 * \param client client id
2074 * \param used non-zero if the client is allowed
2075 * \return 0 on success otherwise a negative error code
2077 int snd_seq_set_queue_usage(snd_seq_t *seq, int q, int used)
2079 struct sndrv_seq_queue_client info;
2081 memset(&info, 0, sizeof(info));
2083 info.client = seq->client;
2084 info.used = used ? 1 : 0;
2085 return seq->ops->set_queue_client(seq, &info);
2090 * \brief get size of #snd_seq_queue_status_t
2091 * \return size in bytes
2093 size_t snd_seq_queue_status_sizeof()
2095 return sizeof(snd_seq_queue_status_t);
2099 * \brief allocate an empty #snd_seq_queue_status_t using standard malloc
2100 * \param ptr returned pointer
2101 * \return 0 on success otherwise negative error code
2103 int snd_seq_queue_status_malloc(snd_seq_queue_status_t **ptr)
2106 *ptr = calloc(1, sizeof(snd_seq_queue_status_t));
2113 * \brief frees a previously allocated #snd_seq_queue_status_t
2114 * \param pointer to object to free
2116 void snd_seq_queue_status_free(snd_seq_queue_status_t *obj)
2122 * \brief copy one #snd_seq_queue_status_t to another
2123 * \param dst pointer to destination
2124 * \param src pointer to source
2126 void snd_seq_queue_status_copy(snd_seq_queue_status_t *dst, const snd_seq_queue_status_t *src)
2134 * \brief Get the queue id of a queue_status container
2135 * \param info queue_status container
2138 int snd_seq_queue_status_get_queue(const snd_seq_queue_status_t *info)
2145 * \brief Get the number of events of a queue_status container
2146 * \param info queue_status container
2147 * \return number of events
2149 int snd_seq_queue_status_get_events(const snd_seq_queue_status_t *info)
2152 return info->events;
2156 * \brief Get the tick time of a queue_status container
2157 * \param info queue_status container
2160 snd_seq_tick_time_t snd_seq_queue_status_get_tick_time(const snd_seq_queue_status_t *info)
2167 * \brief Get the real time of a queue_status container
2168 * \param info queue_status container
2169 * \param time real time
2171 const snd_seq_real_time_t *snd_seq_queue_status_get_real_time(const snd_seq_queue_status_t *info)
2174 return (snd_seq_real_time_t *)&info->time;
2178 * \brief Get the running status bits of a queue_status container
2179 * \param info queue_status container
2180 * \return running status bits
2182 unsigned int snd_seq_queue_status_get_status(const snd_seq_queue_status_t *info)
2185 return info->running;
2190 * \brief obtain the running state of the queue
2191 * \param seq sequencer handle
2192 * \param q queue id to query
2193 * \param status pointer to store the current status
2194 * \return 0 on success otherwise a negative error code
2196 * Obtains the running state of the specified queue q.
2198 int snd_seq_get_queue_status(snd_seq_t *seq, int q, snd_seq_queue_status_t * status)
2200 assert(seq && status);
2201 memset(status, 0, sizeof(snd_seq_queue_status_t));
2203 return seq->ops->get_queue_status(seq, status);
2208 * \brief get size of #snd_seq_queue_tempo_t
2209 * \return size in bytes
2211 size_t snd_seq_queue_tempo_sizeof()
2213 return sizeof(snd_seq_queue_tempo_t);
2217 * \brief allocate an empty #snd_seq_queue_tempo_t using standard malloc
2218 * \param ptr returned pointer
2219 * \return 0 on success otherwise negative error code
2221 int snd_seq_queue_tempo_malloc(snd_seq_queue_tempo_t **ptr)
2224 *ptr = calloc(1, sizeof(snd_seq_queue_tempo_t));
2231 * \brief frees a previously allocated #snd_seq_queue_tempo_t
2232 * \param pointer to object to free
2234 void snd_seq_queue_tempo_free(snd_seq_queue_tempo_t *obj)
2240 * \brief copy one #snd_seq_queue_tempo_t to another
2241 * \param dst pointer to destination
2242 * \param src pointer to source
2244 void snd_seq_queue_tempo_copy(snd_seq_queue_tempo_t *dst, const snd_seq_queue_tempo_t *src)
2252 * \brief Get the queue id of a queue_status container
2253 * \param info queue_status container
2256 int snd_seq_queue_tempo_get_queue(const snd_seq_queue_tempo_t *info)
2263 * \brief Get the tempo of a queue_status container
2264 * \param info queue_status container
2265 * \return tempo value
2267 unsigned int snd_seq_queue_tempo_get_tempo(const snd_seq_queue_tempo_t *info)
2274 * \brief Get the ppq of a queue_status container
2275 * \param info queue_status container
2278 int snd_seq_queue_tempo_get_ppq(const snd_seq_queue_tempo_t *info)
2285 * \brief Get the timer skew value of a queue_status container
2286 * \param info queue_status container
2287 * \return timer skew value
2289 unsigned int snd_seq_queue_tempo_get_skew(const snd_seq_queue_tempo_t *info)
2292 return info->skew_value;
2296 * \brief Get the timer skew base value of a queue_status container
2297 * \param info queue_status container
2298 * \return timer skew base value
2300 unsigned int snd_seq_queue_tempo_get_skew_base(const snd_seq_queue_tempo_t *info)
2303 return info->skew_base;
2307 * \brief Set the tempo of a queue_status container
2308 * \param info queue_status container
2309 * \param tempo tempo value
2311 void snd_seq_queue_tempo_set_tempo(snd_seq_queue_tempo_t *info, unsigned int tempo)
2314 info->tempo = tempo;
2318 * \brief Set the ppq of a queue_status container
2319 * \param info queue_status container
2320 * \param ppq ppq value
2322 void snd_seq_queue_tempo_set_ppq(snd_seq_queue_tempo_t *info, int ppq)
2329 * \brief Set the timer skew value of a queue_status container
2330 * \param info queue_status container
2331 * \param skew timer skew value
2333 * The skew of timer is calculated as skew / base.
2334 * For example, to play with double speed, pass base * 2 as the skew value.
2336 void snd_seq_queue_tempo_set_skew(snd_seq_queue_tempo_t *info, unsigned int skew)
2339 info->skew_value = skew;
2343 * \brief Set the timer skew base value of a queue_status container
2344 * \param info queue_status container
2345 * \param base timer skew base value
2347 void snd_seq_queue_tempo_set_skew_base(snd_seq_queue_tempo_t *info, unsigned int base)
2350 info->skew_base = base;
2354 * \brief obtain the current tempo of the queue
2355 * \param seq sequencer handle
2356 * \param q queue id to be queried
2357 * \param tempo pointer to store the current tempo
2358 * \return 0 on success otherwise a negative error code
2360 int snd_seq_get_queue_tempo(snd_seq_t *seq, int q, snd_seq_queue_tempo_t * tempo)
2362 assert(seq && tempo);
2363 memset(tempo, 0, sizeof(snd_seq_queue_tempo_t));
2365 return seq->ops->get_queue_tempo(seq, tempo);
2369 * \brief set the tempo of the queue
2370 * \param seq sequencer handle
2371 * \param q queue id to change the tempo
2372 * \param tempo tempo information
2373 * \return 0 on success otherwise a negative error code
2375 int snd_seq_set_queue_tempo(snd_seq_t *seq, int q, snd_seq_queue_tempo_t * tempo)
2377 assert(seq && tempo);
2379 return seq->ops->set_queue_tempo(seq, tempo);
2383 /*----------------------------------------------------------------*/
2386 * \brief get size of #snd_seq_queue_timer_t
2387 * \return size in bytes
2389 size_t snd_seq_queue_timer_sizeof()
2391 return sizeof(snd_seq_queue_timer_t);
2395 * \brief allocate an empty #snd_seq_queue_timer_t using standard malloc
2396 * \param ptr returned pointer
2397 * \return 0 on success otherwise negative error code
2399 int snd_seq_queue_timer_malloc(snd_seq_queue_timer_t **ptr)
2402 *ptr = calloc(1, sizeof(snd_seq_queue_timer_t));
2409 * \brief frees a previously allocated #snd_seq_queue_timer_t
2410 * \param pointer to object to free
2412 void snd_seq_queue_timer_free(snd_seq_queue_timer_t *obj)
2418 * \brief copy one #snd_seq_queue_timer_t to another
2419 * \param dst pointer to destination
2420 * \param src pointer to source
2422 void snd_seq_queue_timer_copy(snd_seq_queue_timer_t *dst, const snd_seq_queue_timer_t *src)
2430 * \brief Get the queue id of a queue_timer container
2431 * \param info queue_timer container
2434 int snd_seq_queue_timer_get_queue(const snd_seq_queue_timer_t *info)
2441 * \brief Get the timer type of a queue_timer container
2442 * \param info queue_timer container
2443 * \return timer type
2445 snd_seq_queue_timer_type_t snd_seq_queue_timer_get_type(const snd_seq_queue_timer_t *info)
2448 return (snd_seq_queue_timer_type_t)info->type;
2452 * \brief Get the timer id of a queue_timer container
2453 * \param info queue_timer container
2454 * \return timer id pointer
2456 const snd_timer_id_t *snd_seq_queue_timer_get_id(const snd_seq_queue_timer_t *info)
2459 return &info->u.alsa.id;
2463 * \brief Get the timer resolution of a queue_timer container
2464 * \param info queue_timer container
2465 * \return timer resolution
2467 unsigned int snd_seq_queue_timer_get_resolution(const snd_seq_queue_timer_t *info)
2470 return info->u.alsa.resolution;
2474 * \brief Set the timer type of a queue_timer container
2475 * \param info queue_timer container
2476 * \param type timer type
2478 void snd_seq_queue_timer_set_type(snd_seq_queue_timer_t *info, snd_seq_queue_timer_type_t type)
2481 info->type = (int)type;
2485 * \brief Set the timer id of a queue_timer container
2486 * \param info queue_timer container
2487 * \param id timer id pointer
2489 void snd_seq_queue_timer_set_id(snd_seq_queue_timer_t *info, const snd_timer_id_t *id)
2492 info->u.alsa.id = *id;
2496 * \brief Set the timer resolution of a queue_timer container
2497 * \param info queue_timer container
2498 * \param resolution timer resolution
2500 void snd_seq_queue_timer_set_resolution(snd_seq_queue_timer_t *info, unsigned int resolution)
2503 info->u.alsa.resolution = resolution;
2508 * \brief obtain the queue timer information
2509 * \param seq sequencer handle
2510 * \param q queue id to query
2511 * \param timer pointer to store the timer information
2512 * \return 0 on success otherwise a negative error code
2514 int snd_seq_get_queue_timer(snd_seq_t *seq, int q, snd_seq_queue_timer_t * timer)
2516 assert(seq && timer);
2517 memset(timer, 0, sizeof(snd_seq_queue_timer_t));
2519 return seq->ops->get_queue_timer(seq, timer);
2523 * \brief set the queue timer information
2524 * \param seq sequencer handle
2525 * \param q queue id to change the timer
2526 * \param timer timer information
2527 * \return 0 on success otherwise a negative error code
2529 int snd_seq_set_queue_timer(snd_seq_t *seq, int q, snd_seq_queue_timer_t * timer)
2531 assert(seq && timer);
2533 return seq->ops->set_queue_timer(seq, timer);
2536 /*----------------------------------------------------------------*/
2539 * \brief create an event cell
2540 * \return the cell pointer allocated
2542 snd_seq_event_t *snd_seq_create_event(void)
2544 return (snd_seq_event_t *) calloc(1, sizeof(snd_seq_event_t));
2548 * \brief free an event
2550 * this is obsolete. only for compatibility
2553 int snd_seq_free_event(snd_seq_event_t *ev ATTRIBUTE_UNUSED)
2555 int snd_seq_free_event(snd_seq_event_t *ev)
2562 * \brief calculates the (encoded) byte-stream size of the event
2563 * \param ev the event
2564 * \return the size of decoded bytes
2566 ssize_t snd_seq_event_length(snd_seq_event_t *ev)
2568 ssize_t len = sizeof(snd_seq_event_t);
2570 if (sndrv_seq_ev_is_variable(ev))
2571 len += ev->data.ext.len;
2575 /*----------------------------------------------------------------*/
2578 * output to sequencer
2582 * \brief output an event
2583 * \param seq sequencer handle
2584 * \param ev event to be output
2585 * \return the number of remaining events or a negative error code
2587 * An event is once expanded on the output buffer.
2588 * The output buffer will be drained automatically if it becomes full.
2590 * If events remain unprocessed on output buffer before drained,
2591 * the size of total byte data on output buffer is returned.
2592 * If the output buffer is empty, this returns zero.
2594 int snd_seq_event_output(snd_seq_t *seq, snd_seq_event_t *ev)
2598 result = snd_seq_event_output_buffer(seq, ev);
2599 if (result == -EAGAIN) {
2600 result = snd_seq_drain_output(seq);
2603 return snd_seq_event_output_buffer(seq, ev);
2609 * \brief output an event onto the lib buffer without draining buffer
2610 * \param seq sequencer handle
2611 * \param ev event to be output
2612 * \return the byte size of remaining events. \c -EAGAIN if the buffer becomes full.
2614 * This function doesn't drain buffer unlike snd_seq_event_output().
2616 int snd_seq_event_output_buffer(snd_seq_t *seq, snd_seq_event_t *ev)
2620 len = snd_seq_event_length(ev);
2623 if ((size_t) len >= seq->obufsize)
2625 if ((seq->obufsize - seq->obufused) < (size_t) len)
2627 memcpy(seq->obuf + seq->obufused, ev, sizeof(snd_seq_event_t));
2628 seq->obufused += sizeof(snd_seq_event_t);
2629 if (sndrv_seq_ev_is_variable(ev)) {
2630 memcpy(seq->obuf + seq->obufused, ev->data.ext.ptr, ev->data.ext.len);
2631 seq->obufused += ev->data.ext.len;
2633 return seq->obufused;
2637 * allocate the temporary buffer
2639 static int alloc_tmpbuf(snd_seq_t *seq, size_t len)
2641 size_t size = ((len + sizeof(snd_seq_event_t) - 1) / sizeof(snd_seq_event_t));
2642 if (seq->tmpbuf == NULL) {
2643 if (size > DEFAULT_TMPBUF_SIZE)
2644 seq->tmpbufsize = size;
2646 seq->tmpbufsize = DEFAULT_TMPBUF_SIZE;
2647 seq->tmpbuf = malloc(seq->tmpbufsize * sizeof(snd_seq_event_t));
2648 if (seq->tmpbuf == NULL)
2650 } else if (len > seq->tmpbufsize) {
2651 seq->tmpbuf = realloc(seq->tmpbuf, size * sizeof(snd_seq_event_t));
2652 if (seq->tmpbuf == NULL)
2654 seq->tmpbufsize = size;
2660 * \brief output an event directly to the sequencer NOT through output buffer
2661 * \param seq sequencer handle
2662 * \param ev event to be output
2663 * \return the byte size sent to sequencer or a negative error code
2665 * This function sends an event to the sequencer directly not through the
2666 * output buffer. When the event is a variable length event, a temporary
2667 * buffer is allocated inside alsa-lib and the data is copied there before
2670 int snd_seq_event_output_direct(snd_seq_t *seq, snd_seq_event_t *ev)
2675 len = snd_seq_event_length(ev);
2678 else if (len == sizeof(*ev)) {
2681 if (alloc_tmpbuf(seq, (size_t)len) < 0)
2684 memcpy(seq->tmpbuf + 1, ev->data.ext.ptr, ev->data.ext.len);
2687 return seq->ops->write(seq, buf, (size_t) len);
2691 * \brief return the size of pending events on output buffer
2692 * \param seq sequencer handle
2693 * \return the byte size of total of pending events
2695 int snd_seq_event_output_pending(snd_seq_t *seq)
2698 return seq->obufused;
2702 * \brief drain output buffer to sequencer
2703 * \param seq sequencer handle
2704 * \return 0 when all events are drained and sent to sequencer.
2705 * When events still remain on the buffer, the byte size of remaining
2706 * events are returned. On error a negative error code is returned.
2708 int snd_seq_drain_output(snd_seq_t *seq)
2710 ssize_t result, processed = 0;
2712 while (seq->obufused > 0) {
2713 result = seq->ops->write(seq, seq->obuf, seq->obufused);
2715 if (result == -EAGAIN && processed)
2716 return seq->obufused;
2719 if ((size_t)result < seq->obufused)
2720 memmove(seq->obuf, seq->obuf + result, seq->obufused - result);
2721 seq->obufused -= result;
2727 * \brief extract the first event in output buffer
2728 * \param seq sequencer handle
2729 * \param ev_res event pointer to be extracted
2730 * \return 0 on success otherwise a negative error code
2732 * Extracts the first event in output buffer.
2733 * If ev_res is NULL, just remove the event.
2735 int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res)
2742 if ((olen = seq->obufused) < sizeof(snd_seq_event_t))
2744 memcpy(&ev, (snd_seq_event_t*)seq->obuf, sizeof(snd_seq_event_t));
2745 len = snd_seq_event_length(&ev);
2747 /* extract the event */
2748 if (alloc_tmpbuf(seq, len) < 0)
2750 memcpy(seq->tmpbuf, seq->obuf, len);
2751 *ev_res = seq->tmpbuf;
2753 seq->obufused = olen - len;
2754 memmove(seq->obuf, seq->obuf + len, seq->obufused);
2758 /*----------------------------------------------------------------*/
2761 * input from sequencer
2765 * read from sequencer to input buffer
2767 static ssize_t snd_seq_event_read_buffer(snd_seq_t *seq)
2770 len = seq->ops->read(seq, seq->ibuf, seq->ibufsize * sizeof(snd_seq_event_t));
2773 seq->ibuflen = len / sizeof(snd_seq_event_t);
2775 return seq->ibuflen;
2778 static int snd_seq_event_retrieve_buffer(snd_seq_t *seq, snd_seq_event_t **retp)
2781 snd_seq_event_t *ev;
2783 *retp = ev = &seq->ibuf[seq->ibufptr];
2786 if (! sndrv_seq_ev_is_variable(ev))
2788 ncells = (ev->data.ext.len + sizeof(snd_seq_event_t) - 1) / sizeof(snd_seq_event_t);
2789 if (seq->ibuflen < ncells) {
2790 seq->ibuflen = 0; /* clear buffer */
2794 ev->data.ext.ptr = ev + 1;
2795 seq->ibuflen -= ncells;
2796 seq->ibufptr += ncells;
2801 * \brief retrieve an event from sequencer
2802 * \param seq sequencer handle
2803 * \param ev event pointer to be stored
2806 * Obtains an input event from sequencer.
2807 * The event is created via snd_seq_create_event(), and its pointer is stored on
2810 * This function firstly receives the event byte-stream data from sequencer
2811 * as much as possible at once. Then it retrieves the first event record
2812 * and store the pointer on ev.
2813 * By calling this function sequentially, events are extracted from the input buffer.
2815 * If there is no input from sequencer, function falls into sleep
2816 * in blocking mode until an event is received,
2817 * or returns \c -EAGAIN error in non-blocking mode.
2818 * Occasionally, this function may return \c -ENOSPC error.
2819 * This means that the input FIFO of sequencer overran, and some events are
2821 * Once this error is returned, the input FIFO is cleared automatically.
2823 * Function returns the byte size of remaining events on the input buffer
2824 * if an event is successfully received.
2825 * Application can determine from the returned value whether to call
2826 * input once more or not.
2828 int snd_seq_event_input(snd_seq_t *seq, snd_seq_event_t **ev)
2833 if (seq->ibuflen <= 0) {
2834 if ((err = snd_seq_event_read_buffer(seq)) < 0)
2838 return snd_seq_event_retrieve_buffer(seq, ev);
2842 * read input data from sequencer if available
2844 static int snd_seq_event_input_feed(snd_seq_t *seq, int timeout)
2848 pfd.fd = seq->poll_fd;
2849 pfd.events = POLLIN;
2850 err = poll(&pfd, 1, timeout);
2855 if (pfd.revents & POLLIN)
2856 return snd_seq_event_read_buffer(seq);
2857 return seq->ibuflen;
2861 * \brief check events in input buffer
2862 * \return the byte size of remaining input events on input buffer.
2864 * If events remain on the input buffer of user-space, function returns
2865 * the total byte size of events on it.
2866 * If fetch_sequencer argument is non-zero,
2867 * this function checks the presence of events on sequencer FIFO
2868 * When events exist, they are transferred to the input buffer,
2869 * and the number of received events are returned.
2870 * If fetch_sequencer argument is zero and
2871 * no events remain on the input buffer, function simply returns zero.
2873 int snd_seq_event_input_pending(snd_seq_t *seq, int fetch_sequencer)
2875 if (seq->ibuflen == 0 && fetch_sequencer) {
2876 return snd_seq_event_input_feed(seq, 0);
2878 return seq->ibuflen;
2881 /*----------------------------------------------------------------*/
2884 * clear event buffers
2888 * \brief remove all events on user-space output buffer
2889 * \param seq sequencer handle
2891 * Removes all events on user-space output buffer.
2892 * Unlike snd_seq_drain_output(), this function doesn't remove
2893 * events on output memory pool of sequencer.
2895 int snd_seq_drop_output_buffer(snd_seq_t *seq)
2903 * \brief remove all events on user-space input FIFO
2904 * \param seq sequencer handle
2906 int snd_seq_drop_input_buffer(snd_seq_t *seq)
2915 * \brief remove all events on output buffer
2916 * \param seq sequencer handle
2918 * Removes all events on both user-space output buffer and
2919 * output memory pool on kernel.
2921 int snd_seq_drop_output(snd_seq_t *seq)
2923 snd_seq_remove_events_t rminfo;
2925 seq->obufused = 0; /* drain output buffer */
2927 memset(&rminfo, 0, sizeof(rminfo));
2928 rminfo.remove_mode = SNDRV_SEQ_REMOVE_OUTPUT;
2930 return snd_seq_remove_events(seq, &rminfo);
2934 * \brief clear input buffer and and remove events in sequencer queue
2935 * \param seq sequencer handle
2937 int snd_seq_drop_input(snd_seq_t *seq)
2939 snd_seq_remove_events_t rminfo;
2942 seq->ibufptr = 0; /* drain input buffer */
2945 memset(&rminfo, 0, sizeof(rminfo));
2946 rminfo.remove_mode = SNDRV_SEQ_REMOVE_INPUT;
2948 return snd_seq_remove_events(seq, &rminfo);
2953 * \brief get size of #snd_seq_remove_events_t
2954 * \return size in bytes
2956 size_t snd_seq_remove_events_sizeof()
2958 return sizeof(snd_seq_remove_events_t);
2962 * \brief allocate an empty #snd_seq_remove_events_t using standard malloc
2963 * \param ptr returned pointer
2964 * \return 0 on success otherwise negative error code
2966 int snd_seq_remove_events_malloc(snd_seq_remove_events_t **ptr)
2969 *ptr = calloc(1, sizeof(snd_seq_remove_events_t));
2976 * \brief frees a previously allocated #snd_seq_remove_events_t
2977 * \param pointer to object to free
2979 void snd_seq_remove_events_free(snd_seq_remove_events_t *obj)
2985 * \brief copy one #snd_seq_remove_events_t to another
2986 * \param dst pointer to destination
2987 * \param src pointer to source
2989 void snd_seq_remove_events_copy(snd_seq_remove_events_t *dst, const snd_seq_remove_events_t *src)
2997 * \brief Get the removal condition bits
2998 * \param info remove_events container
2999 * \return removal condition bits
3001 unsigned int snd_seq_remove_events_get_condition(const snd_seq_remove_events_t *info)
3004 return info->remove_mode;
3008 * \brief Get the queue as removal condition
3009 * \param info remove_events container
3012 int snd_seq_remove_events_get_queue(const snd_seq_remove_events_t *info)
3019 * \brief Get the event timestamp as removal condition
3020 * \param info remove_events container
3021 * \return time stamp
3023 const snd_seq_timestamp_t *snd_seq_remove_events_get_time(const snd_seq_remove_events_t *info)
3026 return (snd_seq_timestamp_t *)&info->time;
3030 * \brief Get the event destination address as removal condition
3031 * \param info remove_events container
3032 * \return destination address
3034 const snd_seq_addr_t *snd_seq_remove_events_get_dest(const snd_seq_remove_events_t *info)
3037 return (snd_seq_addr_t *)&info->dest;
3041 * \brief Get the event channel as removal condition
3042 * \param info remove_events container
3043 * \return channel number
3045 int snd_seq_remove_events_get_channel(const snd_seq_remove_events_t *info)
3048 return info->channel;
3052 * \brief Get the event type as removal condition
3053 * \param info remove_events container
3054 * \return event type
3056 int snd_seq_remove_events_get_event_type(const snd_seq_remove_events_t *info)
3063 * \brief Get the event tag id as removal condition
3064 * \param info remove_events container
3067 int snd_seq_remove_events_get_tag(const snd_seq_remove_events_t *info)
3074 * \brief Set the removal condition bits
3075 * \param info remove_events container
3076 * \param flags removal condition bits
3078 void snd_seq_remove_events_set_condition(snd_seq_remove_events_t *info, unsigned int flags)
3081 info->remove_mode = flags;
3085 * \brief Set the queue as removal condition
3086 * \param info remove_events container
3087 * \param queue queue id
3089 void snd_seq_remove_events_set_queue(snd_seq_remove_events_t *info, int queue)
3092 info->queue = queue;
3096 * \brief Set the timestamp as removal condition
3097 * \param info remove_events container
3098 * \param time timestamp pointer
3100 void snd_seq_remove_events_set_time(snd_seq_remove_events_t *info, const snd_seq_timestamp_t *time)
3103 info->time = *(union sndrv_seq_timestamp *)time;
3107 * \brief Set the destination address as removal condition
3108 * \param info remove_events container
3109 * \param addr destination address
3111 void snd_seq_remove_events_set_dest(snd_seq_remove_events_t *info, const snd_seq_addr_t *addr)
3114 info->dest = *(struct sndrv_seq_addr *)addr;
3118 * \brief Set the channel as removal condition
3119 * \param info remove_events container
3120 * \param channel channel number
3122 void snd_seq_remove_events_set_channel(snd_seq_remove_events_t *info, int channel)
3125 info->channel = channel;
3129 * \brief Set the event type as removal condition
3130 * \param info remove_events container
3131 * \param type event type
3133 void snd_seq_remove_events_set_event_type(snd_seq_remove_events_t *info, int type)
3140 * \brief Set the event tag as removal condition
3141 * \param info remove_events container
3144 void snd_seq_remove_events_set_tag(snd_seq_remove_events_t *info, int tag)
3151 /* compare timestamp between events */
3152 /* return 1 if a >= b; otherwise return 0 */
3153 static inline int snd_seq_compare_tick_time(snd_seq_tick_time_t *a, snd_seq_tick_time_t *b)
3159 static inline int snd_seq_compare_real_time(snd_seq_real_time_t *a, snd_seq_real_time_t *b)
3161 /* compare real time */
3162 if (a->tv_sec > b->tv_sec)
3164 if ((a->tv_sec == b->tv_sec) && (a->tv_nsec >= b->tv_nsec))
3169 /* Routine to match events to be removed */
3170 static int remove_match(snd_seq_remove_events_t *info, snd_seq_event_t *ev)
3174 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST) {
3175 if (ev->dest.client != info->dest.client ||
3176 ev->dest.port != info->dest.port)
3179 if (info->remove_mode & SNDRV_SEQ_REMOVE_DEST_CHANNEL) {
3180 if (! sndrv_seq_ev_is_channel_type(ev))
3182 /* data.note.channel and data.control.channel are identical */
3183 if (ev->data.note.channel != info->channel)
3186 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_AFTER) {
3187 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK)
3188 res = snd_seq_compare_tick_time(&ev->time.tick, (snd_seq_tick_time_t *)&info->time.tick);
3190 res = snd_seq_compare_real_time(&ev->time.time, (snd_seq_real_time_t *)&info->time.time);
3194 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_BEFORE) {
3195 if (info->remove_mode & SNDRV_SEQ_REMOVE_TIME_TICK)
3196 res = snd_seq_compare_tick_time(&ev->time.tick, (snd_seq_tick_time_t *)&info->time.tick);
3198 res = snd_seq_compare_real_time(&ev->time.time, (snd_seq_real_time_t *)&info->time.time);
3202 if (info->remove_mode & SNDRV_SEQ_REMOVE_EVENT_TYPE) {
3203 if (ev->type != info->type)
3206 if (info->remove_mode & SNDRV_SEQ_REMOVE_IGNORE_OFF) {
3207 /* Do not remove off events */
3209 case SNDRV_SEQ_EVENT_NOTEOFF:
3210 /* case SNDRV_SEQ_EVENT_SAMPLE_STOP: */
3216 if (info->remove_mode & SNDRV_SEQ_REMOVE_TAG_MATCH) {
3217 if (info->tag != ev->tag)
3225 * \brief remove events on input/output buffers
3226 * \param seq sequencer handle
3227 * \param rmp remove event container
3229 * Removes matching events with the given condition from input/output buffers.
3230 * The removal condition is specified in rmp argument.
3232 int snd_seq_remove_events(snd_seq_t *seq, snd_seq_remove_events_t *rmp)
3234 if (rmp->remove_mode & SNDRV_SEQ_REMOVE_INPUT) {
3236 * First deal with any events that are still buffered
3239 snd_seq_drop_input_buffer(seq);
3242 if (rmp->remove_mode & SNDRV_SEQ_REMOVE_OUTPUT) {
3244 * First deal with any events that are still buffered
3247 if (rmp->remove_mode & ~(SNDRV_SEQ_REMOVE_INPUT|SNDRV_SEQ_REMOVE_OUTPUT)) {
3248 /* The simple case - remove all */
3249 snd_seq_drop_output_buffer(seq);
3253 snd_seq_event_t *ev;
3256 while (ep - seq->obuf < (ssize_t)seq->obufused) {
3258 ev = (snd_seq_event_t *) ep;
3259 len = snd_seq_event_length(ev);
3261 if (remove_match(rmp, ev)) {
3263 seq->obufused -= len;
3264 memmove(ep, ep + len, seq->obufused - (ep - seq->obuf));
3272 return seq->ops->remove_events(seq, rmp);
3275 /*----------------------------------------------------------------*/
3278 * client memory pool
3282 * \brief get size of #snd_seq_client_pool_t
3283 * \return size in bytes
3285 size_t snd_seq_client_pool_sizeof()
3287 return sizeof(snd_seq_client_pool_t);
3291 * \brief allocate an empty #snd_seq_client_pool_t using standard malloc
3292 * \param ptr returned pointer
3293 * \return 0 on success otherwise negative error code
3295 int snd_seq_client_pool_malloc(snd_seq_client_pool_t **ptr)
3298 *ptr = calloc(1, sizeof(snd_seq_client_pool_t));
3305 * \brief frees a previously allocated #snd_seq_client_pool_t
3306 * \param pointer to object to free
3308 void snd_seq_client_pool_free(snd_seq_client_pool_t *obj)
3314 * \brief copy one #snd_seq_client_pool_t to another
3315 * \param dst pointer to destination
3316 * \param src pointer to source
3318 void snd_seq_client_pool_copy(snd_seq_client_pool_t *dst, const snd_seq_client_pool_t *src)
3326 * \brief Get the client id of a queue_info container
3327 * \param info client_pool container
3330 int snd_seq_client_pool_get_client(const snd_seq_client_pool_t *info)
3333 return info->client;
3337 * \brief Get the output pool size of a queue_info container
3338 * \param info client_pool container
3339 * \return output pool size
3341 size_t snd_seq_client_pool_get_output_pool(const snd_seq_client_pool_t *info)
3344 return info->output_pool;
3348 * \brief Get the input pool size of a queue_info container
3349 * \param info client_pool container
3350 * \return input pool size
3352 size_t snd_seq_client_pool_get_input_pool(const snd_seq_client_pool_t *info)
3355 return info->input_pool;
3359 * \brief Get the output room size of a queue_info container
3360 * \param info client_pool container
3361 * \return output room size
3363 size_t snd_seq_client_pool_get_output_room(const snd_seq_client_pool_t *info)
3366 return info->output_room;
3370 * \brief Get the available size on output pool of a queue_info container
3371 * \param info client_pool container
3372 * \return available output size
3374 size_t snd_seq_client_pool_get_output_free(const snd_seq_client_pool_t *info)
3377 return info->output_free;
3381 * \brief Get the available size on input pool of a queue_info container
3382 * \param info client_pool container
3383 * \return available input size
3385 size_t snd_seq_client_pool_get_input_free(const snd_seq_client_pool_t *info)
3388 return info->input_free;
3392 * \brief Set the output pool size of a queue_info container
3393 * \param info client_pool container
3394 * \param size output pool size
3396 void snd_seq_client_pool_set_output_pool(snd_seq_client_pool_t *info, size_t size)
3399 info->output_pool = size;
3403 * \brief Set the input pool size of a queue_info container
3404 * \param info client_pool container
3405 * \param size input pool size
3407 void snd_seq_client_pool_set_input_pool(snd_seq_client_pool_t *info, size_t size)
3410 info->input_pool = size;
3414 * \brief Set the output room size of a queue_info container
3415 * \param info client_pool container
3416 * \param size output room size
3418 void snd_seq_client_pool_set_output_room(snd_seq_client_pool_t *info, size_t size)
3421 info->output_room = size;
3426 * \brief obtain the pool information of the current client
3427 * \param seq sequencer handle
3428 * \param info information to be stored
3430 int snd_seq_get_client_pool(snd_seq_t *seq, snd_seq_client_pool_t *info)
3432 assert(seq && info);
3433 info->client = seq->client;
3434 return seq->ops->get_client_pool(seq, info);
3438 * \brief set the pool information
3439 * \param seq sequencer handle
3440 * \param info information to update
3442 * Sets the pool information of the current client.
3443 * The client field in \a info is replaced automatically with the current id.
3445 int snd_seq_set_client_pool(snd_seq_t *seq, snd_seq_client_pool_t *info)
3447 assert(seq && info);
3448 info->client = seq->client;
3449 return seq->ops->set_client_pool(seq, info);
3452 /*----------------------------------------------------------------*/
3459 * \brief set a bit flag
3461 void snd_seq_set_bit(int nr, void *array)
3463 ((unsigned int *)array)[nr >> 5] |= 1UL << (nr & 31);
3467 * \brief change a bit flag
3469 int snd_seq_change_bit(int nr, void *array)
3473 result = ((((unsigned int *)array)[nr >> 5]) & (1UL << (nr & 31))) ? 1 : 0;
3474 ((unsigned int *)array)[nr >> 5] |= 1UL << (nr & 31);
3479 * \brief get a bit flag state
3481 int snd_seq_get_bit(int nr, void *array)
3483 return ((((unsigned int *)array)[nr >> 5]) & (1UL << (nr & 31))) ? 1 : 0;
3492 * \brief get size of #snd_instr_header_t
3493 * \return size in bytes
3495 size_t snd_instr_header_sizeof(void)
3497 return sizeof(snd_instr_header_t);
3501 * \brief allocate an empty #snd_instr_header_t using standard malloc
3502 * \param ptr returned pointer
3503 * \param len additional data length
3504 * \return 0 on success otherwise negative error code
3506 int snd_instr_header_malloc(snd_instr_header_t **ptr, size_t len)
3509 *ptr = calloc(1, sizeof(snd_instr_header_t) + len);
3517 * \brief frees a previously allocated #snd_instr_header_t
3518 * \param pointer to object to free
3520 void snd_instr_header_free(snd_instr_header_t *obj)
3526 * \brief copy one #snd_instr_header_t to another
3527 * \param dst pointer to destination
3528 * \param src pointer to source
3530 void snd_instr_header_copy(snd_instr_header_t *dst, const snd_instr_header_t *src)
3537 * \brief Get the instrument id of an instr_header container
3538 * \param info instr_header container
3539 * \return instrument id pointer
3541 const snd_seq_instr_t *snd_instr_header_get_id(const snd_instr_header_t *info)
3544 return (snd_seq_instr_t *)&info->id.instr;
3548 * \brief Get the cluster id of an instr_header container
3549 * \param info instr_header container
3550 * \return cluster id
3552 snd_seq_instr_cluster_t snd_instr_header_get_cluster(const snd_instr_header_t *info)
3555 return info->id.cluster;
3559 * \brief Get the command of an instr_header container
3560 * \param info instr_header container
3561 * \return command type
3563 unsigned int snd_instr_header_get_cmd(const snd_instr_header_t *info)
3570 * \brief Get the length of extra data of an instr_header container
3571 * \param info instr_header container
3572 * \return the length in bytes
3574 size_t snd_instr_header_get_len(const snd_instr_header_t *info)
3581 * \brief Get the data name of an instr_header container
3582 * \param info instr_header container
3583 * \return the name string
3585 const char *snd_instr_header_get_name(const snd_instr_header_t *info)
3588 return info->data.name;
3592 * \brief Get the data type of an instr_header container
3593 * \param info instr_header container
3594 * \return the data type
3596 int snd_instr_header_get_type(const snd_instr_header_t *info)
3599 return info->data.type;
3603 * \brief Get the data format of an instr_header container
3604 * \param info instr_header container
3605 * \return the data format string
3607 const char *snd_instr_header_get_format(const snd_instr_header_t *info)
3610 return info->data.data.format;
3614 * \brief Get the data alias of an instr_header container
3615 * \param info instr_header container
3616 * \return the data alias id
3618 const snd_seq_instr_t *snd_instr_header_get_alias(const snd_instr_header_t *info)
3621 return (snd_seq_instr_t *)&info->data.data.alias;
3625 * \brief Get the extra data pointer of an instr_header container
3626 * \param info instr_header container
3627 * \return the extra data pointer
3629 void *snd_instr_header_get_data(const snd_instr_header_t *info)
3632 return (void*)((char*)info + sizeof(*info));
3636 * \brief Get the flag to follow alias of an instr_header container
3637 * \param info instr_header container
3638 * \return 1 if follow alias
3640 int snd_instr_header_get_follow_alias(const snd_instr_header_t *info)
3643 return (info->flags & SNDRV_SEQ_INSTR_QUERY_FOLLOW_ALIAS) ? 1 : 0;
3647 * \brief Set the instrument id of an instr_header container
3648 * \param info instr_header container
3649 * \param id instrument id pointer
3651 void snd_instr_header_set_id(snd_instr_header_t *info, const snd_seq_instr_t *id)
3654 info->id.instr = *(struct sndrv_seq_instr *)id;
3658 * \brief Set the cluster id of an instr_header container
3659 * \param info instr_header container
3660 * \param cluster cluster id
3662 void snd_instr_header_set_cluster(snd_instr_header_t *info, snd_seq_instr_cluster_t cluster)
3665 info->id.cluster = cluster;
3669 * \brief Set the command of an instr_header container
3670 * \param info instr_header container
3671 * \param cmd command type
3673 void snd_instr_header_set_cmd(snd_instr_header_t *info, unsigned int cmd)
3680 * \brief Set the length of extra data of an instr_header container
3681 * \param info instr_header container
3682 * \param len size of extra data in bytes
3684 void snd_instr_header_set_len(snd_instr_header_t *info, size_t len)
3691 * \brief Set the data name of an instr_header container
3692 * \param info instr_header container
3693 * \param name the name string
3695 void snd_instr_header_set_name(snd_instr_header_t *info, const char *name)
3697 assert(info && name);
3698 strncpy(info->data.name, name, sizeof(info->data.name));
3702 * \brief Set the data type of an instr_header container
3703 * \param info instr_header container
3704 * \param type the data type
3706 void snd_instr_header_set_type(snd_instr_header_t *info, int type)
3709 info->data.type = type;
3713 * \brief Set the data format of an instr_header container
3714 * \param info instr_header container
3715 * \param format the data format string
3717 void snd_instr_header_set_format(snd_instr_header_t *info, const char *format)
3719 assert(info && format);
3720 strncpy(info->data.data.format, format, sizeof(info->data.data.format));
3724 * \brief Set the data alias id of an instr_header container
3725 * \param info instr_header container
3726 * \param instr alias instrument id
3728 void snd_instr_header_set_alias(snd_instr_header_t *info, const snd_seq_instr_t *instr)
3730 assert(info && instr);
3731 info->data.data.alias = *(struct sndrv_seq_instr *)instr;
3735 * \brief Set the flag to follow alias of an instr_header container
3736 * \param info instr_header container
3737 * \param val 1 if follow alias
3739 void snd_instr_header_set_follow_alias(snd_instr_header_t *info, int val)
3743 info->flags |= SNDRV_SEQ_INSTR_QUERY_FOLLOW_ALIAS;
3745 info->flags &= ~SNDRV_SEQ_INSTR_QUERY_FOLLOW_ALIAS;