From: Drake Wilson Subject: Sequencer documentation follow-up Date: Sun, 8 Jun 2003 22:06:30 -0400 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: <20030608220629.A7532@octothorpe.dyndns.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="ZfOjI3PrQbgiZnxM" Return-path: Content-Disposition: inline Errors-To: alsa-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: To: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --ZfOjI3PrQbgiZnxM Content-Type: multipart/mixed; boundary="EeQfGwPcQSOJBaQU" Content-Disposition: inline --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline ... I have a draft, or part thereof. It is in similar spirit to the module overviews in the API reference, and I hope it to be of some use, if not optimal. I was going to post this earlier, but a) it's written in a weird XML schema, in XSLTing which to HTML I have not had much success, b) I've been somewhat ill recently, and c) I was hesitant to do so for unknown reasons. It should probably be integrated with the doxygeneratees in some form; my initial impulse was to convert it to Texinfo, but that may not be the best of ideas. Comments are appreciated. No warranty or guarantee of any sort is made, naturally. Attached: alsa-seq.fooml, 13 KB, XML. ---> Drake Wilson --EeQfGwPcQSOJBaQU Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="alsa-seq.fooml" Content-Transfer-Encoding: quoted-printable ?xml version=3D"1.0" encoding=3D"utf-8"?> ALSA 0.9.x Sequencer Interface Overview Draft 0.0.0 Drake Wilson Copyright © 2003 Drake Wilson. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation, with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the License may be found at .
Opening and Closing In order to use the ALSA sequencer, one must first open it. This is done with a call to snd_seq_open, giving the name of the sequencer device one wishes to open and the mode thereof, similarly to an open call. Closing the device is accomplished with snd_seq_close, which is similarly similar to close. The following constants are used for opening the sequencer device: SND_SEQ_OPEN_OUTPUTopen for output only SND_SEQ_OPEN_INPUTopen for input only SND_SEQ_OPEN_DUPLEXopen for both input and output SND_SEQ_NONBLOCKmake I/O non-blocking; see also snd_seq_nonblock
Clients and Ports In ALSA, each connection to a sequencer device is represented as a client. Usually, a process only connects to a sequencer device once, and thus has only one client representation. Each is given a client ID, an unsigned one-byte integer (between 0 and 255 inclusive). Each client may have zero or more ports open; each port within a client is given a port ID, another unsigned one-byte integer. Client and port IDs are fixed and are assigned by the ALSA system. Generally, user-space clients start at 128, MIDI device clients start at 64, and system clients start at 0. Each client and each port has a name, which is an ASCII string. Normally, ports are given names when they are created; clients are given a default name when they are created, which is changed later with snd_seq_set_client_name. A client ID and a port ID together comprise a sequencer address, stored as a snd_seq_addr_t, with respective client and port fields. Usually, when an address is written as a string, it is written as client, then port, separated by either a colon or period. The port number is given in decimal; the client may be either given as a decimal number or a name string. The function snd_seq_parse_address parses an address in this format from ASCII string into snd_seq_addr_t structure. The easiest way to create and delete ports is to use the snd_seq_create_simple_port and snd_seq_delete_simple_port functions. When creating a port in this manner, one specifies a port name, as well as capabilities and type. The capabilities associated with a port describe what permissions the host client has with the port, and what permissions potential subscribers to the port have. The type of the port describes what sort of device is at the end. The following constants are used for this: SND_SEQ_PORT_CAP_READallow read from port SND_SEQ_PORT_CAP_SUBS_READallow read subscription from port SND_SEQ_PORT_CAP_WRITEallow write to port SND_SEQ_PORT_CAP_SUBS_WRITEallow write subscription to port SND_SEQ_PORT_CAP_NO_EXPORTdisallow external routing SND_SEQ_PORT_TYPE_APPLICATIONport is attached to an application device SND_SEQ_PORT_TYPE_SAMPLEport is attached to a sampling device SND_SEQ_PORT_TYPE_DIRECT_SAMPLEport is attached to a sampling device supporting download SND_SEQ_PORT_TYPE_MIDI_GENERICport is attached to a generic MIDI device SND_SEQ_PORT_TYPE_MIDI_GMport is attached to a GM compatible device SND_SEQ_PORT_TYPE_MIDI_GSport is attached to a GS compatible device SND_SEQ_PORT_TYPE_MIDI_MT32port is attached to an MT-32 compatible device SND_SEQ_PORT_TYPE_MIDI_XGport is attached to an XG compatible device SND_SEQ_PORT_TYPE_SYNTHport is attached to a synthesizer device SND_SEQ_PORT_TYPE_SPECIFICport is attached to a hardware-specific type of device It is also possible to use a snd_seq_port_info_t, with snd_seq_create_port and snd_seq_delete_port (which acts exactly or almost exactly like snd_seq_delete_simple_port). A snd_seq_port_info_t contains a port's owning client, name, capability bits, and type, as specified separately in snd_seq_create_simple_port, but also information about the number of MIDI channels and voices and the number of synthesized voices available at a given port. It is also possible to iterate through ports on another client using snd_seq_query_next_port. Iterating through clients is accomplished with the corresponding snd_seq_client_info_t structure and snd_seq_query_next_client function.
Subscriptions When ports are created with the appropriate capabilities, other clients may subscribe to them. Thus may events be communicated between clients; events from a port to which other clients have read-subscribed may be set to be broadcast to all subscribers with snd_seq_ev_set_subs. Events may also be set to be broadcast to all clients and all ports with snd_seq_ev_set_broadcast; however, excessive use of such is not recommended, and multicasting by subscription is generally a much better approach. Subscribing to ports is done most simply with the snd_seq_connect_from and snd_seq_connect_to functions. These functions take a port on the current client, and respectively a source or destination client/port pair. Note that the port which is being subscribed on the current client does not have to have subscription capability from other clients in order for it to be connected to other ports which do have such capability.
Queues Each client may have one or more queues associated with it. Queues are used for scheduling events. Each queue, like each client and each port, also has an identification number, which is an integer and specific to the client to which it is attached, and a name, which is an ASCII string. Events may be scheduled on queues with snd_seq_ev_schedule_tick for times in ticks or snd_seq_ev_schedule_real for times in nanoseconds (or actually seconds and nanoseconds&em;see snd_seq_real_time_t). The primary structures that deal with queues are snd_seq_queue_info_t, snd_seq_queue_status_t, snd_seq_queue_tempo_t, and snd_seq_queue_timer_t. A queue info structure contains relatively permanent data: a queue's name, owner client, flags, and lockedness. A queue status structure, on the other hand, contains more transient and time-dependent data: the number of events in a queue, the running status bits, and the time on the queue in ticks and seconds/nanoseconds. A queue tempo structure contains the speed information for a queue: the PPQ resolution, μsPQ tempo, and timer skew (expressed as integers skew/skew_base). A queue timer structure contains the less mutable timer information for a queue: the timer ID, resolution, and type. Queues may be created with snd_seq_create_queue, or just allocated with snd_seq_alloc_queue or snd_seq_alloc_named_queue. They may be deleted with snd_seq_free_queue.
Events The primary unit of information passed through the ALSA sequencer is the event. Many sequencer events correspond to MIDI events; others are control events for ALSA itself, for communication between applications, or for other purposes. To create events, one usually uses the macros in the middle-level interface. For MIDI events, one generally sets an event of type SND_SEQ_EVENT_FOOBAR using the corresponding macro snd_seq_ev_set_foobar. (Note the difference in case.) The arguments to the macro are a pointer to the event, and the data for the event. The following MIDI event types are defined: SND_SEQ_EVENT_NOTEON SND_SEQ_EVENT_NOTEOFFnote on and note off. Takes channel, note number, and velocity (snd_seq_ev_note_t). SND_SEQ_EVENT_NOTEnote on combined with note off. Takes channel, note number, velocity, and duration in ticks (snd_seq_ev_note_t). SND_SEQ_EVENT_KEYPRESSpolyphonic pressure. Takes channel, note number, and velocity (snd_seq_ev_note_t). SND_SEQ_EVENT_CHANPRESSchannel pressure. Takes channel and value (snd_seq_ev_ctrl_t). SND_SEQ_EVENT_CONTROLLERcontinuous controller data. Takes channel, controller number, and value (snd_seq_ev_ctrl_t). SND_SEQ_EVENT_PGMCHANGEprogram change. Takes channel and program (snd_seq_ev_ctrl_t). SND_SEQ_EVENT_PITCHBENDpitch bend. Takes channel and value, with value between -8192 and 8191 (snd_seq_ev_ctrl_t). SND_SEQ_EVENT_SYSEXsystem exclusive data. Takes length and pointer to data (snd_seq_ev_ext_t). Each event also has a source, destination, and scheduling mode. The source client is determined by the handle to which an event is output. The source port and destination may be set by snd_seq_ev_set_source and snd_seq_ev_set_dest (which takes a client and port as separate arguments). Broadcasting to all and broadcasting to subscribers are special destinations, which may be set by snd_seq_ev_set_broadcast and snd_seq_ev_set_subs, respectively. The scheduling mode of an event determines whether it is sent directly or on a queue, and if on a queue, which queue, and when. Direct scheduling may be set with snd_seq_ev_set_direct, which takes only the event. Queue scheduling may be set with snd_seq_ev_schedule_tick,=20 to give a time in ticks, or snd_seq_ev_schedule_real, to give a time using a snd_seq_real_time_t. Each takes event, queue ID (see Queues), relativity (true iff the scheduling is relative to the current time), and time (in a format dependent on which scheduling macro is being used). Events may be queried by means of the event C structure, snd_seq_event_t, which has the following elements: typea snd_seq_event_type_t with the type of the event. sourcedest snd_seq_addr_t fields containing the source and destination ports queuetimethe queue associated with the event, and its timestamp for input or output as a snd_seq_timestamp_t. notecontrolextMIDI data associated with the event. Which one is used depends on the type of event; see the table above. They are of types snd_seq_ev_note_t, snd_seq_ev_ctrl_t, and snd_seq_ev_ext_t, respectively.
Reading and Writing Synchronous (blocking) I/O is primarily accomplished with the functions snd_seq_event_output and snd_seq_event_input. These functions behave much like standard blocking write and read calls. There are also snd_seq_event_output_buffer and snd_seq_event_output_direct, which output without flushing the buffer and output without buffering, respectively. Nonblocking I/O can be accomplished by setting nonblocking mode with the snd_seq_nonblock call; waiting for I/O is a little bit more complicated, and involves polling. One must first call snd_seq_poll_descriptors_count to obtain the number of descriptors to poll, then allocate space for such and use snd_seq_poll_descriptors to obtain the actual descriptors, followed by a poll on them.
Reference
--EeQfGwPcQSOJBaQU-- --ZfOjI3PrQbgiZnxM Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE+4+ul1fuSPH+onEsRAsnOAJ4wx2IJD7kHFudDw/Lm/zljbdCVVgCg/RiF yrjzg4H/4NJ/F5HgfMJqUAU= =bxzg -----END PGP SIGNATURE----- --ZfOjI3PrQbgiZnxM-- ------------------------------------------------------- This SF.net email is sponsored by: Etnus, makers of TotalView, The best thread debugger on the planet. Designed with thread debugging features you've never dreamed of, try TotalView 6 free at www.etnus.com.