Sequencer Event API
MIDI Sequencer
Collaboration diagram for Sequencer Event API:

## Macros

#define | SND_SEQ_REMOVE_INPUT (1<<0)
#define | SND_SEQ_REMOVE_OUTPUT (1<<1)
#define | SND_SEQ_REMOVE_DEST (1<<2)
#define | SND_SEQ_REMOVE_DEST_CHANNEL (1<<3)
#define | SND_SEQ_REMOVE_TIME_BEFORE (1<<4)
#define | SND_SEQ_REMOVE_TIME_AFTER (1<<5)
#define | SND_SEQ_REMOVE_TIME_TICK (1<<6)
#define | SND_SEQ_REMOVE_EVENT_TYPE (1<<7)
#define | SND_SEQ_REMOVE_IGNORE_OFF (1<<8)
#define | SND_SEQ_REMOVE_TAG_MATCH (1<<9)
#define | snd_seq_remove_events_alloca(ptr) __snd_alloca(ptr, snd_seq_remove_events)

## Typedefs

typedef struct _snd_seq_remove_events | snd_seq_remove_events_t

## Functions

int | snd_seq_free_event (snd_seq_event_t *ev)
| (DEPRECATED) free an event More...
ssize_t | snd_seq_event_length (snd_seq_event_t *ev)
| calculates the (encoded) byte-stream size of the event More...
int | snd_seq_event_output (snd_seq_t *handle, snd_seq_event_t *ev)
| output an event More...
int | snd_seq_event_output_buffer (snd_seq_t *handle, snd_seq_event_t *ev)
| output an event onto the lib buffer without draining buffer More...
int | snd_seq_event_output_direct (snd_seq_t *handle, snd_seq_event_t *ev)
| output an event directly to the sequencer NOT through output buffer More...
int | snd_seq_event_input (snd_seq_t *handle, snd_seq_event_t **ev)
| retrieve an event from sequencer More...
int | snd_seq_event_input_pending (snd_seq_t *seq, int fetch_sequencer)
| check events in input buffer More...
int | snd_seq_drain_output (snd_seq_t *handle)
| drain output buffer to sequencer More...
int | snd_seq_event_output_pending (snd_seq_t *seq)
| return the size of pending events on output buffer More...
int | snd_seq_extract_output (snd_seq_t *handle, snd_seq_event_t **ev)
| extract the first event in output buffer More...
int | snd_seq_drop_output (snd_seq_t *handle)
| remove all events on output buffer More...
int | snd_seq_drop_output_buffer (snd_seq_t *handle)
| remove all events on user-space output buffer More...
int | snd_seq_drop_input (snd_seq_t *handle)
| clear input buffer and and remove events in sequencer queue More...
int | snd_seq_drop_input_buffer (snd_seq_t *handle)
| remove all events on user-space input FIFO More...
size_t | snd_seq_remove_events_sizeof (void)
| get size of snd_seq_remove_events_t More...
int | snd_seq_remove_events_malloc (snd_seq_remove_events_t **ptr)
| allocate an empty snd_seq_remove_events_t using standard malloc More...
void | snd_seq_remove_events_free (snd_seq_remove_events_t *ptr)
| frees a previously allocated snd_seq_remove_events_t More...
void | snd_seq_remove_events_copy (snd_seq_remove_events_t *dst, const snd_seq_remove_events_t *src)
| copy one snd_seq_remove_events_t to another More...
unsigned int | snd_seq_remove_events_get_condition (const snd_seq_remove_events_t *info)
| Get the removal condition bits. More...
int | snd_seq_remove_events_get_queue (const snd_seq_remove_events_t *info)
| Get the queue as removal condition. More...
const snd_seq_timestamp_t * | snd_seq_remove_events_get_time (const snd_seq_remove_events_t *info)
| Get the event timestamp as removal condition. More...
const snd_seq_addr_t * | snd_seq_remove_events_get_dest (const snd_seq_remove_events_t *info)
| Get the event destination address as removal condition. More...
int | snd_seq_remove_events_get_channel (const snd_seq_remove_events_t *info)
| Get the event channel as removal condition. More...
int | snd_seq_remove_events_get_event_type (const snd_seq_remove_events_t *info)
| Get the event type as removal condition. More...
int | snd_seq_remove_events_get_tag (const snd_seq_remove_events_t *info)
| Get the event tag id as removal condition. More...
void | snd_seq_remove_events_set_condition (snd_seq_remove_events_t *info, unsigned int flags)
| Set the removal condition bits. More...
void | snd_seq_remove_events_set_queue (snd_seq_remove_events_t *info, int queue)
| Set the queue as removal condition. More...
void | snd_seq_remove_events_set_time (snd_seq_remove_events_t *info, const snd_seq_timestamp_t *time)
| Set the timestamp as removal condition. More...
void | snd_seq_remove_events_set_dest (snd_seq_remove_events_t *info, const snd_seq_addr_t *addr)
| Set the destination address as removal condition. More...
void | snd_seq_remove_events_set_channel (snd_seq_remove_events_t *info, int channel)
| Set the channel as removal condition. More...
void | snd_seq_remove_events_set_event_type (snd_seq_remove_events_t *info, int type)
| Set the event type as removal condition. More...
void | snd_seq_remove_events_set_tag (snd_seq_remove_events_t *info, int tag)
| Set the event tag as removal condition. More...
int | snd_seq_remove_events (snd_seq_t *handle, snd_seq_remove_events_t *info)
| remove events on input/output buffers and pools More...

## Detailed Description

Sequencer Event API

## Macro Definition Documentation

## SND_SEQ_REMOVE_DEST

#define SND_SEQ_REMOVE_DEST (1<<2)

Restrict by destination q:client:port

## SND_SEQ_REMOVE_DEST_CHANNEL

#define SND_SEQ_REMOVE_DEST_CHANNEL (1<<3)

Restrict by channel

## SND_SEQ_REMOVE_EVENT_TYPE

#define SND_SEQ_REMOVE_EVENT_TYPE (1<<7)

Restrict to event type

## snd_seq_remove_events_alloca

#define snd_seq_remove_events_alloca | ( |  | ptr | ) | __snd_alloca(ptr, snd_seq_remove_events)

allocate a snd_seq_remove_events_t container on stack

## SND_SEQ_REMOVE_IGNORE_OFF

#define SND_SEQ_REMOVE_IGNORE_OFF (1<<8)

Do not flush off events

## SND_SEQ_REMOVE_INPUT

#define SND_SEQ_REMOVE_INPUT (1<<0)

Remove conditional flags Flush input queues

## SND_SEQ_REMOVE_OUTPUT

#define SND_SEQ_REMOVE_OUTPUT (1<<1)

Flush output queues

## SND_SEQ_REMOVE_TAG_MATCH

#define SND_SEQ_REMOVE_TAG_MATCH (1<<9)

Restrict to events with given tag

## SND_SEQ_REMOVE_TIME_AFTER

#define SND_SEQ_REMOVE_TIME_AFTER (1<<5)

Restrict to time or after

## SND_SEQ_REMOVE_TIME_BEFORE

#define SND_SEQ_REMOVE_TIME_BEFORE (1<<4)

Restrict to before time

## SND_SEQ_REMOVE_TIME_TICK

#define SND_SEQ_REMOVE_TIME_TICK (1<<6)

Time is in ticks

## Typedef Documentation

## snd_seq_remove_events_t

typedef struct _snd_seq_remove_events snd_seq_remove_events_t

event removal conditionals

## Function Documentation

## snd_seq_drain_output()

int snd_seq_drain_output | ( | snd_seq_t * | seq | ) |

drain output buffer to sequencer

Parameters

  seq | sequencer handle

Returns
  0 when all events are drained and sent to sequencer. When events still remain on the buffer, the byte size of remaining events are returned. On error a negative error code is returned.

This function drains all pending events on the output buffer. The function returns immediately after the events are sent to the queues regardless whether the events are processed or not. To get synchronization with the all event processes, use snd_seq_sync_output_queue() after calling this function.

See also
  snd_seq_event_output(), snd_seq_sync_output_queue()

## snd_seq_drop_input()

int snd_seq_drop_input | ( | snd_seq_t * | seq | ) |

clear input buffer and and remove events in sequencer queue

Parameters

  seq | sequencer handle

See also
  snd_seq_drop_input_buffer(), snd_seq_remove_events()

## snd_seq_drop_input_buffer()

int snd_seq_drop_input_buffer | ( | snd_seq_t * | seq | ) |

remove all events on user-space input FIFO

Parameters

  seq | sequencer handle

See also
  snd_seq_drop_input()

## snd_seq_drop_output()

int snd_seq_drop_output | ( | snd_seq_t * | seq | ) |

remove all events on output buffer

Parameters

  seq | sequencer handle

Removes all events on both user-space output buffer and output memory pool on kernel.

See also
  snd_seq_drain_output(), snd_seq_drop_output_buffer(), snd_seq_remove_events()

## snd_seq_drop_output_buffer()

int snd_seq_drop_output_buffer | ( | snd_seq_t * | seq | ) |

remove all events on user-space output buffer

Parameters

  seq | sequencer handle

Removes all events on user-space output buffer. Unlike snd_seq_drain_output(), this function doesn't remove events on output memory pool of sequencer.

See also
  snd_seq_drop_output()

## snd_seq_event_input()

int snd_seq_event_input | ( | snd_seq_t * | seq,
|  | snd_seq_event_t ** | ev
| ) |  |

retrieve an event from sequencer

Parameters

  seq | sequencer handle
  ev | event pointer to be stored

Returns

Obtains an input event from sequencer. The event is created via snd_seq_create_event(), and its pointer is stored on ev argument.

This function firstly receives the event byte-stream data from sequencer as much as possible at once. Then it retrieves the first event record and store the pointer on ev. By calling this function sequentially, events are extracted from the input buffer.

If there is no input from sequencer, function falls into sleep in blocking mode until an event is received, or returns `-EAGAIN` error in non-blocking mode. Occasionally, this function may return `-ENOSPC` error. This means that the input FIFO of sequencer overran, and some events are lost. Once this error is returned, the input FIFO is cleared automatically.

Function returns the byte size of remaining events on the input buffer if an event is successfully received. Application can determine from the returned value whether to call input once more or not.

See also
  snd_seq_event_input_pending(), snd_seq_drop_input()

## snd_seq_event_input_pending()

int snd_seq_event_input_pending | ( | snd_seq_t * | seq,
|  | int | fetch_sequencer
| ) |  |

check events in input buffer

Returns
  the byte size of remaining input events on input buffer.

If events remain on the input buffer of user-space, function returns the total byte size of events on it. If fetch_sequencer argument is non-zero, this function checks the presence of events on sequencer FIFO When events exist, they are transferred to the input buffer, and the number of received events are returned. If fetch_sequencer argument is zero and no events remain on the input buffer, function simply returns zero.

See also
  snd_seq_event_input()

## snd_seq_event_length()

ssize_t snd_seq_event_length | ( | snd_seq_event_t * | ev | ) |

calculates the (encoded) byte-stream size of the event

Parameters

  ev | the event

Returns
  the size of decoded bytes

## snd_seq_event_output()

int snd_seq_event_output | ( | snd_seq_t * | seq,
|  | snd_seq_event_t * | ev
| ) |  |

output an event

Parameters

  seq | sequencer handle
  ev | event to be output

Returns
  the number of remaining events or a negative error code

An event is once expanded on the output buffer. The output buffer will be drained automatically if it becomes full.

If events remain unprocessed on output buffer before drained, the size of total byte data on output buffer is returned. If the output buffer is empty, this returns zero.

See also
  snd_seq_event_output_direct(), snd_seq_event_output_buffer(), snd_seq_event_output_pending(), snd_seq_drain_output(), snd_seq_drop_output(), snd_seq_extract_output(), snd_seq_remove_events()

## snd_seq_event_output_buffer()

int snd_seq_event_output_buffer | ( | snd_seq_t * | seq,
|  | snd_seq_event_t * | ev
| ) |  |

output an event onto the lib buffer without draining buffer

Parameters

  seq | sequencer handle
  ev | event to be output

Returns
  the byte size of remaining events. `-EAGAIN` if the buffer becomes full.

This function doesn't drain buffer unlike snd_seq_event_output().

See also
  snd_seq_event_output()

## snd_seq_event_output_direct()

int snd_seq_event_output_direct | ( | snd_seq_t * | seq,
|  | snd_seq_event_t * | ev
| ) |  |

output an event directly to the sequencer NOT through output buffer

Parameters

  seq | sequencer handle
  ev | event to be output

Returns
  the byte size sent to sequencer or a negative error code

This function sends an event to the sequencer directly not through the output buffer. When the event is a variable length event, a temporary buffer is allocated inside alsa-lib and the data is copied there before actually sent.

See also
  snd_seq_event_output()

## snd_seq_event_output_pending()

int snd_seq_event_output_pending | ( | snd_seq_t * | seq | ) |

return the size of pending events on output buffer

Parameters

  seq | sequencer handle

Returns
  the byte size of total of pending events

See also
  snd_seq_event_output()

## snd_seq_extract_output()

int snd_seq_extract_output | ( | snd_seq_t * | seq,
|  | snd_seq_event_t ** | ev_res
| ) |  |

extract the first event in output buffer

Parameters

  seq | sequencer handle
  ev_res | event pointer to be extracted

Returns
  0 on success otherwise a negative error code

Extracts the first event in output buffer. If ev_res is NULL, just remove the event.

See also
  snd_seq_event_output()

## snd_seq_free_event()

int snd_seq_free_event | ( | snd_seq_event_t * | ev | ) |

(DEPRECATED) free an event

In the former version, this function was used to release the event pointer which was allocated by snd_seq_event_input(). In the current version, the event record is not allocated, so you don't have to call this function any more.

## snd_seq_remove_events()

int snd_seq_remove_events | ( | snd_seq_t * | seq,
|  | snd_seq_remove_events_t * | rmp
| ) |  |

remove events on input/output buffers and pools

Parameters

  seq | sequencer handle
  rmp | remove event container

Removes matching events with the given condition from input/output buffers and pools. The removal condition is specified in rmp argument.

See also
  snd_seq_event_output(), snd_seq_drop_output(), snd_seq_reset_pool_output()

## snd_seq_remove_events_copy()

void snd_seq_remove_events_copy | ( | snd_seq_remove_events_t * | dst,
|  | const snd_seq_remove_events_t * | src
| ) |  |

copy one snd_seq_remove_events_t to another

Parameters

  dst | pointer to destination
  src | pointer to source

## snd_seq_remove_events_free()

void snd_seq_remove_events_free | ( | snd_seq_remove_events_t * | obj | ) |

frees a previously allocated snd_seq_remove_events_t

Parameters

  obj | pointer to object to free

## snd_seq_remove_events_get_channel()

int snd_seq_remove_events_get_channel | ( | const snd_seq_remove_events_t * | info | ) |

Get the event channel as removal condition.

Parameters

  info | remove_events container

Returns
  channel number

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_condition()

unsigned int snd_seq_remove_events_get_condition | ( | const snd_seq_remove_events_t * | info | ) |

Get the removal condition bits.

Parameters

  info | remove_events container

Returns
  removal condition bits

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_dest()

const snd_seq_addr_t* snd_seq_remove_events_get_dest | ( | const snd_seq_remove_events_t * | info | ) |

Get the event destination address as removal condition.

Parameters

  info | remove_events container

Returns
  destination address

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_event_type()

int snd_seq_remove_events_get_event_type | ( | const snd_seq_remove_events_t * | info | ) |

Get the event type as removal condition.

Parameters

  info | remove_events container

Returns
  event type

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_queue()

int snd_seq_remove_events_get_queue | ( | const snd_seq_remove_events_t * | info | ) |

Get the queue as removal condition.

Parameters

  info | remove_events container

Returns
  queue id

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_tag()

int snd_seq_remove_events_get_tag | ( | const snd_seq_remove_events_t * | info | ) |

Get the event tag id as removal condition.

Parameters

  info | remove_events container

Returns
  tag id

See also
  snd_seq_remove_events()

## snd_seq_remove_events_get_time()

const snd_seq_timestamp_t* snd_seq_remove_events_get_time | ( | const snd_seq_remove_events_t * | info | ) |

Get the event timestamp as removal condition.

Parameters

  info | remove_events container

Returns
  time stamp

See also
  snd_seq_remove_events()

## snd_seq_remove_events_malloc()

int snd_seq_remove_events_malloc | ( | snd_seq_remove_events_t ** | ptr | ) |

allocate an empty snd_seq_remove_events_t using standard malloc

Parameters

  ptr | returned pointer

Returns
  0 on success otherwise negative error code

## snd_seq_remove_events_set_channel()

void snd_seq_remove_events_set_channel | ( | snd_seq_remove_events_t * | info,
|  | int | channel
| ) |  |

Set the channel as removal condition.

Parameters

  info | remove_events container
  channel | channel number

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_condition()

void snd_seq_remove_events_set_condition | ( | snd_seq_remove_events_t * | info,
|  | unsigned int | flags
| ) |  |

Set the removal condition bits.

Parameters

  info | remove_events container
  flags | removal condition bits

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_dest()

void snd_seq_remove_events_set_dest | ( | snd_seq_remove_events_t * | info,
|  | const snd_seq_addr_t * | addr
| ) |  |

Set the destination address as removal condition.

Parameters

  info | remove_events container
  addr | destination address

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_event_type()

void snd_seq_remove_events_set_event_type | ( | snd_seq_remove_events_t * | info,
|  | int | type
| ) |  |

Set the event type as removal condition.

Parameters

  info | remove_events container
  type | event type

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_queue()

void snd_seq_remove_events_set_queue | ( | snd_seq_remove_events_t * | info,
|  | int | queue
| ) |  |

Set the queue as removal condition.

Parameters

  info | remove_events container
  queue | queue id

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_tag()

void snd_seq_remove_events_set_tag | ( | snd_seq_remove_events_t * | info,
|  | int | tag
| ) |  |

Set the event tag as removal condition.

Parameters

  info | remove_events container
  tag | tag id

See also
  snd_seq_remove_events()

## snd_seq_remove_events_set_time()

void snd_seq_remove_events_set_time | ( | snd_seq_remove_events_t * | info,
|  | const snd_seq_timestamp_t * | time
| ) |  |

Set the timestamp as removal condition.

Parameters

  info | remove_events container
  time | timestamp pointer

See also
  snd_seq_remove_events()

## snd_seq_remove_events_sizeof()

size_t snd_seq_remove_events_sizeof | ( | void |  | ) |

get size of snd_seq_remove_events_t

Returns
  size in bytes