ALSA project - the C library reference
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
Sequencer Middle Level Interface
MIDI Sequencer

Macros

#define snd_seq_ev_clear(ev)   memset(ev, 0, sizeof(snd_seq_event_t))
 initialize event record
#define snd_seq_ev_set_tag(ev, t)   ((ev)->tag = (t))
 set the tag for given event
#define snd_seq_ev_set_dest(ev, c, p)   ((ev)->dest.client = (c), (ev)->dest.port = (p))
 set the explicit destination
#define snd_seq_ev_set_subs(ev)
 set broadcasting to subscribers
#define snd_seq_ev_set_broadcast(ev)
 set broadcasting to all clients/ports
#define snd_seq_ev_set_source(ev, p)   ((ev)->source.port = (p))
 set the source port
#define snd_seq_ev_set_direct(ev)   ((ev)->queue = SND_SEQ_QUEUE_DIRECT)
 set direct passing mode (without queued)
#define snd_seq_ev_schedule_tick(ev, q, relative, ttick)
 set tick-scheduling mode on queue
#define snd_seq_ev_schedule_real(ev, q, relative, rtime)
 set real-time-scheduling mode on queue
#define snd_seq_ev_set_priority(ev, high_prior)
 set event priority
#define snd_seq_ev_set_fixed(ev)
 set fixed data
#define snd_seq_ev_set_variable(ev, datalen, dataptr)
 set variable data
#define snd_seq_ev_set_varusr(ev, datalen, dataptr)
 set varusr data
#define snd_seq_ev_set_queue_control(ev, typ, q, val)
 set queue controls
#define snd_seq_ev_set_queue_start(ev, q)   snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_START, q, 0)
 set the start queue event
#define snd_seq_ev_set_queue_stop(ev, q)   snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_STOP, q, 0)
 set the stop queue event
#define snd_seq_ev_set_queue_continue(ev, q)   snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_CONTINUE, q, 0)
 set the stop queue event
#define snd_seq_ev_set_queue_tempo(ev, q, val)   snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_TEMPO, q, val)
 set the stop queue event
#define snd_seq_ev_set_queue_pos_real(ev, q, rtime)
 set the real-time position of a queue
#define snd_seq_ev_set_queue_pos_tick(ev, q, ttime)
 set the tick-time position of a queue
#define snd_seq_start_queue(seq, q, ev)   snd_seq_control_queue(seq, q, SND_SEQ_EVENT_START, 0, ev)
 start the specified queue
#define snd_seq_stop_queue(seq, q, ev)   snd_seq_control_queue(seq, q, SND_SEQ_EVENT_STOP, 0, ev)
 stop the specified queue
#define snd_seq_continue_queue(seq, q, ev)   snd_seq_control_queue(seq, q, SND_SEQ_EVENT_CONTINUE, 0, ev)
 continue the specified queue
#define snd_seq_change_queue_tempo(seq, q, tempo, ev)   snd_seq_control_queue(seq, q, SND_SEQ_EVENT_TEMPO, tempo, ev)
 change the tempo of the specified queue
#define snd_seq_ev_set_note(ev, ch, key, vel, dur)
 set note event
#define snd_seq_ev_set_noteon(ev, ch, key, vel)
 set note-on event
#define snd_seq_ev_set_noteoff(ev, ch, key, vel)
 set note-off event
#define snd_seq_ev_set_keypress(ev, ch, key, vel)
 set key-pressure event
#define snd_seq_ev_set_controller(ev, ch, cc, val)
 set MIDI controller event
#define snd_seq_ev_set_pgmchange(ev, ch, val)
 set program change event
#define snd_seq_ev_set_pitchbend(ev, ch, val)
 set pitch-bend event
#define snd_seq_ev_set_chanpress(ev, ch, val)
 set channel pressure event
#define snd_seq_ev_set_sysex(ev, datalen, dataptr)
 set sysex event

Functions

int snd_seq_control_queue (snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev)
 queue controls - start/stop/continue
int snd_seq_create_simple_port (snd_seq_t *seq, const char *name, unsigned int caps, unsigned int type)
 create a port - simple version
int snd_seq_delete_simple_port (snd_seq_t *seq, int port)
 delete the port
int snd_seq_connect_from (snd_seq_t *seq, int my_port, int src_client, int src_port)
 simple subscription (w/o exclusive & time conversion)
int snd_seq_connect_to (snd_seq_t *seq, int my_port, int dest_client, int dest_port)
 simple subscription (w/o exclusive & time conversion)
int snd_seq_disconnect_from (snd_seq_t *seq, int my_port, int src_client, int src_port)
 simple disconnection
int snd_seq_disconnect_to (snd_seq_t *seq, int my_port, int dest_client, int dest_port)
 simple disconnection
int snd_seq_set_client_name (snd_seq_t *seq, const char *name)
 set client name
int snd_seq_set_client_event_filter (snd_seq_t *seq, int event_type)
 add client event filter
int snd_seq_set_client_pool_output (snd_seq_t *seq, size_t size)
 change the output pool size of the given client
int snd_seq_set_client_pool_output_room (snd_seq_t *seq, size_t size)
 change the output room size of the given client
int snd_seq_set_client_pool_input (snd_seq_t *seq, size_t size)
 change the input pool size of the given client
int snd_seq_sync_output_queue (snd_seq_t *seq)
 wait until all events are processed
int snd_seq_parse_address (snd_seq_t *seq, snd_seq_addr_t *addr, const char *str)
 parse the given string and get the sequencer address
int snd_seq_reset_pool_output (snd_seq_t *seq)
 reset client output pool
int snd_seq_reset_pool_input (snd_seq_t *seq)
 reset client input pool

Detailed Description

Sequencer Middle Level Interface


Macro Definition Documentation

#define snd_seq_change_queue_tempo (   seq,
  q,
  tempo,
  ev 
)    snd_seq_control_queue(seq, q, SND_SEQ_EVENT_TEMPO, tempo, ev)

change the tempo of the specified queue

Parameters:
seqsequencer handle
qqueue id
tempothe new tempo value
evoptional event record (see snd_seq_control_queue)
#define snd_seq_continue_queue (   seq,
  q,
  ev 
)    snd_seq_control_queue(seq, q, SND_SEQ_EVENT_CONTINUE, 0, ev)

continue the specified queue

Parameters:
seqsequencer handle
qqueue id to continue
evoptional event record (see snd_seq_control_queue)
#define snd_seq_ev_clear (   ev)    memset(ev, 0, sizeof(snd_seq_event_t))

initialize event record

Parameters:
evevent record pointer

This macro clears the given event record pointer to the default status.

#define snd_seq_ev_schedule_real (   ev,
  q,
  relative,
  rtime 
)
Value:
(ev)->flags |= SND_SEQ_TIME_STAMP_REAL,\
(ev)->flags |= (relative) ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS,\
(ev)->time.time = *(rtime),\
(ev)->queue = (q))

set real-time-scheduling mode on queue

Parameters:
evevent instance
qqueue id to schedule
relativerelative time-stamp if non-zero
rtimetime-stamp to be delivered

This macro sets the scheduling of the event in the realtime mode.

See also:
snd_seq_ev_schedule_tick(), snd_seq_ev_set_direct()
#define snd_seq_ev_schedule_tick (   ev,
  q,
  relative,
  ttick 
)
Value:
(ev)->flags |= SND_SEQ_TIME_STAMP_TICK,\
(ev)->flags |= (relative) ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS,\
(ev)->time.tick = (ttick),\
(ev)->queue = (q))

set tick-scheduling mode on queue

Parameters:
evevent instance
qqueue id to schedule
relativerelative time-stamp if non-zero
tticktick time-stamp to be delivered

This macro sets the scheduling of the event in the MIDI tick mode.

See also:
snd_seq_ev_schedule_real(), snd_seq_ev_set_direct()
#define snd_seq_ev_set_broadcast (   ev)
Value:
((ev)->dest.client = SND_SEQ_ADDRESS_BROADCAST,\
(ev)->dest.port = SND_SEQ_ADDRESS_BROADCAST)

set broadcasting to all clients/ports

Parameters:
evevent record

This macro sets the destination as the broadcasting.

See also:
snd_seq_ev_set_dest()
#define snd_seq_ev_set_chanpress (   ev,
  ch,
  val 
)
Value:
((ev)->type = SND_SEQ_EVENT_CHANPRESS,\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))

set channel pressure event

Parameters:
evevent record
chchannel number
valchannel pressure value
#define snd_seq_ev_set_controller (   ev,
  ch,
  cc,
  val 
)
Value:
((ev)->type = SND_SEQ_EVENT_CONTROLLER,\
(ev)->data.control.channel = (ch),\
(ev)->data.control.param = (cc),\
(ev)->data.control.value = (val))

set MIDI controller event

Parameters:
evevent record
chchannel number
cccontroller number
valcontrol value
#define snd_seq_ev_set_dest (   ev,
  c,
 
)    ((ev)->dest.client = (c), (ev)->dest.port = (p))

set the explicit destination

Parameters:
evevent record
cdestination client id
pdestination port id

This macro sets the client and port id numbers to the given event record.

See also:
snd_seq_ev_set_subs()
#define snd_seq_ev_set_direct (   ev)    ((ev)->queue = SND_SEQ_QUEUE_DIRECT)

set direct passing mode (without queued)

Parameters:
evevent instance

This macro sets the event to the direct passing mode to be delivered immediately without queueing.

See also:
snd_seq_ev_schedule_tick(), snd_seq_ev_schedule_real()
#define snd_seq_ev_set_fixed (   ev)
Value:
((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\

set fixed data

Parameters:
evevent instance

Sets the event length mode as fixed size.

See also:
snd_seq_ev_set_variable(), snd_seq_ev_set_varusr()
#define snd_seq_ev_set_keypress (   ev,
  ch,
  key,
  vel 
)
Value:
((ev)->type = SND_SEQ_EVENT_KEYPRESS,\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))

set key-pressure event

Parameters:
evevent record
chchannel number
keynote key
velvelocity
#define snd_seq_ev_set_note (   ev,
  ch,
  key,
  vel,
  dur 
)
Value:
((ev)->type = SND_SEQ_EVENT_NOTE,\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel),\
(ev)->data.note.duration = (dur))

set note event

Parameters:
evevent record
chchannel number
keynote key
velvelocity
durduration (in tick or msec)
#define snd_seq_ev_set_noteoff (   ev,
  ch,
  key,
  vel 
)
Value:
((ev)->type = SND_SEQ_EVENT_NOTEOFF,\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))

set note-off event

Parameters:
evevent record
chchannel number
keynote key
velvelocity
#define snd_seq_ev_set_noteon (   ev,
  ch,
  key,
  vel 
)
Value:
((ev)->type = SND_SEQ_EVENT_NOTEON,\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))

set note-on event

Parameters:
evevent record
chchannel number
keynote key
velvelocity
#define snd_seq_ev_set_pgmchange (   ev,
  ch,
  val 
)
Value:
((ev)->type = SND_SEQ_EVENT_PGMCHANGE,\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))

set program change event

Parameters:
evevent record
chchannel number
valprogram number
#define snd_seq_ev_set_pitchbend (   ev,
  ch,
  val 
)
Value:
((ev)->type = SND_SEQ_EVENT_PITCHBEND,\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))

set pitch-bend event

Parameters:
evevent record
chchannel number
valpitch bend; zero centered from -8192 to 8191
#define snd_seq_ev_set_priority (   ev,
  high_prior 
)
Value:
((ev)->flags &= ~SND_SEQ_PRIORITY_MASK,\
(ev)->flags |= (high_prior) ? SND_SEQ_PRIORITY_HIGH : SND_SEQ_PRIORITY_NORMAL)

set event priority

Parameters:
evevent instance
high_prior1 for high priority mode
#define snd_seq_ev_set_queue_continue (   ev,
 
)    snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_CONTINUE, q, 0)

set the stop queue event

Parameters:
evevent record
qqueue id to continue
See also:
snd_seq_ev_set_queue_start(), snd_seq_ev_set_queue_stop()
#define snd_seq_ev_set_queue_control (   ev,
  typ,
  q,
  val 
)
Value:
((ev)->type = (typ),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.value = (val))

set queue controls

Parameters:
evevent record
typevent type
qqueue id
valcontrol value
#define snd_seq_ev_set_queue_pos_real (   ev,
  q,
  rtime 
)
Value:
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.time = *(rtime))

set the real-time position of a queue

Parameters:
evevent record
qqueue id to change tempo
rtimethe new real-time pointer
#define snd_seq_ev_set_queue_pos_tick (   ev,
  q,
  ttime 
)
Value:
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.tick = (ttime))

set the tick-time position of a queue

Parameters:
evevent record
qqueue id to change tempo
ttimethe new tick-time
#define snd_seq_ev_set_queue_start (   ev,
 
)    snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_START, q, 0)

set the start queue event

Parameters:
evevent record
qqueue id to start
See also:
snd_seq_ev_set_queue_stop(), snd_seq_ev_set_queue_continue()
#define snd_seq_ev_set_queue_stop (   ev,
 
)    snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_STOP, q, 0)

set the stop queue event

Parameters:
evevent record
qqueue id to stop
See also:
snd_seq_ev_set_queue_start(), snd_seq_ev_set_queue_continue()
#define snd_seq_ev_set_queue_tempo (   ev,
  q,
  val 
)    snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_TEMPO, q, val)

set the stop queue event

Parameters:
evevent record
qqueue id to change tempo
valthe new tempo value
#define snd_seq_ev_set_source (   ev,
 
)    ((ev)->source.port = (p))

set the source port

Parameters:
evevent record
psource port id

This macro sets the source port id number.

#define snd_seq_ev_set_subs (   ev)
Value:
((ev)->dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS,\
(ev)->dest.port = SND_SEQ_ADDRESS_UNKNOWN)

set broadcasting to subscribers

Parameters:
evevent record

This macro sets the destination as the subscribers.

See also:
snd_seq_ev_set_dest()
#define snd_seq_ev_set_sysex (   ev,
  datalen,
  dataptr 
)
Value:
((ev)->type = SND_SEQ_EVENT_SYSEX,\
snd_seq_ev_set_variable(ev, datalen, dataptr))

set sysex event

Parameters:
evevent record
datalenlength of sysex data
dataptrsysex data pointer

the sysex data must contain the start byte 0xf0 and the end byte 0xf7.

#define snd_seq_ev_set_tag (   ev,
 
)    ((ev)->tag = (t))

set the tag for given event

Parameters:
evevent record
tevent tag

This macro sets the tag to the given event record.

#define snd_seq_ev_set_variable (   ev,
  datalen,
  dataptr 
)
Value:
((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\
(ev)->data.ext.len = (datalen),\
(ev)->data.ext.ptr = (dataptr))

set variable data

Parameters:
evevent instance
datalenlength of the external data
dataptrpointer of the external data

Sets the event length mode as variable length and stores the data.

See also:
snd_seq_ev_set_fixed(), snd_seq_ev_set_varusr()
#define snd_seq_ev_set_varusr (   ev,
  datalen,
  dataptr 
)
Value:
((ev)->flags &= ~SND_SEQ_EVENT_LENGTH_MASK,\
(ev)->flags |= SND_SEQ_EVENT_LENGTH_VARUSR,\
(ev)->data.ext.len = (datalen),\
(ev)->data.ext.ptr = (dataptr))

set varusr data

Parameters:
evevent instance
datalenlength of the external data
dataptrpointer of the external data

Sets the event length mode as variable user-space data and stores the data.

See also:
snd_seq_ev_set_fixed(), snd_seq_ev_set_variable()
#define snd_seq_start_queue (   seq,
  q,
  ev 
)    snd_seq_control_queue(seq, q, SND_SEQ_EVENT_START, 0, ev)

start the specified queue

Parameters:
seqsequencer handle
qqueue id to start
evoptional event record (see snd_seq_control_queue)
#define snd_seq_stop_queue (   seq,
  q,
  ev 
)    snd_seq_control_queue(seq, q, SND_SEQ_EVENT_STOP, 0, ev)

stop the specified queue

Parameters:
seqsequencer handle
qqueue id to stop
evoptional event record (see snd_seq_control_queue)

Function Documentation

int snd_seq_connect_from ( snd_seq_t seq,
int  myport,
int  src_client,
int  src_port 
)

simple subscription (w/o exclusive & time conversion)

Parameters:
seqsequencer handle
myportthe port id as receiver
src_clientsender client id
src_portsender port id
Returns:
0 on success or negative error code

Connect from the given sender client:port to the given destination port in the current client.

See also:
snd_seq_subscribe_port(), snd_seq_disconnect_from()
int snd_seq_connect_to ( snd_seq_t seq,
int  myport,
int  dest_client,
int  dest_port 
)

simple subscription (w/o exclusive & time conversion)

Parameters:
seqsequencer handle
myportthe port id as sender
dest_clientdestination client id
dest_portdestination port id
Returns:
0 on success or negative error code

Connect from the given receiver port in the current client to the given destination client:port.

See also:
snd_seq_subscribe_port(), snd_seq_disconnect_to()
int snd_seq_control_queue ( snd_seq_t seq,
int  q,
int  type,
int  value,
snd_seq_event_t ev 
)

queue controls - start/stop/continue

Parameters:
seqsequencer handle
qqueue id to control
typeevent type
valueevent value
evevent instance

This function sets up general queue control event and sends it. To send at scheduled time, set the schedule in ev. If ev is NULL, the event is composed locally and sent immediately to the specified queue. In any cases, you need to call snd_seq_drain_output() appropriately to feed the event.

See also:
snd_seq_alloc_queue()
int snd_seq_create_simple_port ( snd_seq_t seq,
const char *  name,
unsigned int  caps,
unsigned int  type 
)

create a port - simple version

Parameters:
seqsequencer handle
namethe name of the port
capscapability bits
typetype bits
Returns:
the created port number or negative error code

Creates a port with the given capability and type bits.

See also:
snd_seq_create_port(), snd_seq_delete_simple_port()
int snd_seq_delete_simple_port ( snd_seq_t seq,
int  port 
)

delete the port

Parameters:
seqsequencer handle
portport id
Returns:
0 on success or negative error code
See also:
snd_seq_delete_port(), snd_seq_create_simple_port()
int snd_seq_disconnect_from ( snd_seq_t seq,
int  myport,
int  src_client,
int  src_port 
)

simple disconnection

Parameters:
seqsequencer handle
myportthe port id as receiver
src_clientsender client id
src_portsender port id
Returns:
0 on success or negative error code

Remove connection from the given sender client:port to the given destination port in the current client.

See also:
snd_seq_unsubscribe_port(), snd_seq_connect_from()
int snd_seq_disconnect_to ( snd_seq_t seq,
int  myport,
int  dest_client,
int  dest_port 
)

simple disconnection

Parameters:
seqsequencer handle
myportthe port id as sender
dest_clientdestination client id
dest_portdestination port id
Returns:
0 on success or negative error code

Remove connection from the given sender client:port to the given destination port in the current client.

See also:
snd_seq_unsubscribe_port(), snd_seq_connect_to()
int snd_seq_parse_address ( snd_seq_t seq,
snd_seq_addr_t addr,
const char *  arg 
)

parse the given string and get the sequencer address

Parameters:
seqsequencer handle
addrthe address pointer to be returned
argthe string to be parsed
Returns:
0 on success or negative error code

This function parses the sequencer client and port numbers from the given string. The client and port tokens are separated by either colon or period, e.g. 128:1. When seq is not NULL, the function accepts also a client name not only digit numbers. Actually arg need to be only a prefix of the wanted client. That is, if a client named "Foobar XXL Master 2012" with number 128 is available, then parsing "Foobar" will return the address 128:0 if no other client is an exact match.

int snd_seq_reset_pool_input ( snd_seq_t seq)

reset client input pool

Parameters:
seqsequencer handle
Returns:
0 on success or negative error code

So far, this works identically like snd_seq_drop_input().

int snd_seq_reset_pool_output ( snd_seq_t seq)

reset client output pool

Parameters:
seqsequencer handle
Returns:
0 on success or negative error code

So far, this works identically like snd_seq_drop_output().

int snd_seq_set_client_event_filter ( snd_seq_t seq,
int  event_type 
)

add client event filter

Parameters:
seqsequencer handle
event_typeevent type to be added
Returns:
0 on success or negative error code
See also:
snd_seq_set_client_info()
int snd_seq_set_client_name ( snd_seq_t seq,
const char *  name 
)

set client name

Parameters:
seqsequencer handle
namename string
Returns:
0 on success or negative error code
See also:
snd_seq_set_client_info()
int snd_seq_set_client_pool_input ( snd_seq_t seq,
size_t  size 
)

change the input pool size of the given client

Parameters:
seqsequencer handle
sizeinput pool size
Returns:
0 on success or negative error code
See also:
snd_seq_set_client_pool()
int snd_seq_set_client_pool_output ( snd_seq_t seq,
size_t  size 
)

change the output pool size of the given client

Parameters:
seqsequencer handle
sizeoutput pool size
Returns:
0 on success or negative error code
See also:
snd_seq_set_client_pool()
int snd_seq_set_client_pool_output_room ( snd_seq_t seq,
size_t  size 
)

change the output room size of the given client

Parameters:
seqsequencer handle
sizeoutput room size
Returns:
0 on success or negative error code
See also:
snd_seq_set_client_pool()
int snd_seq_sync_output_queue ( snd_seq_t seq)

wait until all events are processed

Parameters:
seqsequencer handle
Returns:
0 on success or negative error code

This function waits until all events of this client are processed.

See also:
snd_seq_drain_output()