Major change to sequencer API.

The sequencer API is totally recoded with the style of "encapsulation"
in other api.
The structure becomes opaque and accessed only via functions.

Other changes:
- There is no longer group in client and port info.
- snd_seq_query_subs_t is renamed to snd_seq_query_subscribe_t.
- snd_seq_delete_port takes only the port id argument instead of
  port_info structure.
- snd_seq_input/output_buffer_size are renamed
  as snd_seq_get_input/output_buffer_size.
  Similarly snd_seq_resize_input/output_buffer are renamed as
  snd_seq_set_input/output_buffer_size.
- snd_seq_get_named_queue is renamed to snd_seq_query_named_queue.
- Sync codes are removed temporarily from API.
- Subscription conditions are accessed via the corresponding functions.
  convert_time is named now as time_update.
- snd_seq_get/set_queue_owner are removed.
  Use snd_seq_get/set_queue_info instead.
- Instrument put/get/remove structure is unified as snd_instr_header_t.
This commit is contained in:
Jaroslav Kysela 2001-07-04 13:54:13 +00:00
parent d23ff765ad
commit 88e5e45151
20 changed files with 4410 additions and 1691 deletions

View file

@ -7,7 +7,7 @@ header_files=header.h version.h global.h input.h output.h error.h \
conf.h pcm.h rawmidi.h timer.h \
hwdep.h hwdep_m4.h control.h \
mixer.h \
seq.h seqmid.h seq_midi_event.h \
seq_event.h seq.h seqmid.h seq_midi_event.h \
conv.h instr.h footer.h
noinst_HEADERS=$(header_files) search.h list.h aserver.h local.h

View file

@ -11,41 +11,144 @@
* \{
*/
/* FM instrument support */
/* instrument get/put */
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _snd_instr_header snd_instr_header_t;
size_t snd_instr_header_sizeof(void);
#define snd_instr_header_alloca(ptr) \
do {\
assert(ptr);\
*ptr = (snd_instr_header_t *)alloca(snd_instr_header_sizeof());\
memset(*ptr, 0, snd_instr_header_sizeof());\
} while (0)
int snd_instr_header_malloc(snd_instr_header_t **ptr, size_t len);
void snd_instr_header_free(snd_instr_header_t *ptr);
void snd_instr_header_copy(snd_instr_header_t *dst, const snd_instr_header_t *src);
const snd_seq_instr_t *snd_instr_header_get_id(const snd_instr_header_t *info);
snd_seq_instr_cluster_t snd_instr_header_get_cluster(const snd_instr_header_t *info);
unsigned int snd_instr_header_get_cmd(const snd_instr_header_t *info);
size_t snd_instr_header_get_len(const snd_instr_header_t *info);
const char *snd_instr_header_get_name(const snd_instr_header_t *info);
int snd_instr_header_get_type(const snd_instr_header_t *info);
const char *snd_instr_header_get_format(const snd_instr_header_t *info);
const snd_seq_instr_t *snd_instr_header_get_alias(const snd_instr_header_t *info);
void *snd_instr_header_get_data(const snd_instr_header_t *info);
int snd_instr_header_get_follow_alias(const snd_instr_header_t *info);
void snd_instr_header_set_id(snd_instr_header_t *info, const snd_seq_instr_t *id);
void snd_instr_header_set_cluster(snd_instr_header_t *info, snd_seq_instr_cluster_t cluster);
void snd_instr_header_set_cmd(snd_instr_header_t *info, unsigned int cmd);
void snd_instr_header_set_len(snd_instr_header_t *info, size_t len);
void snd_instr_header_set_name(snd_instr_header_t *info, const char *name);
void snd_instr_header_set_type(snd_instr_header_t *info, int type);
void snd_instr_header_set_format(snd_instr_header_t *info, const char *format);
void snd_instr_header_set_alias(snd_instr_header_t *info, const snd_seq_instr_t *instr);
void snd_instr_header_set_follow_alias(snd_instr_header_t *info, int bool);
#ifdef __cplusplus
}
#endif
/**
* Instrument abstraction layer
* - based on events
*/
/** instrument types */
#define SND_SEQ_INSTR_ATYPE_DATA 0 /**< instrument data */
#define SND_SEQ_INSTR_ATYPE_ALIAS 1 /**< instrument alias */
/** instrument ASCII identifiers */
#define SND_SEQ_INSTR_ID_DLS1 "DLS1" /**< DLS1 */
#define SND_SEQ_INSTR_ID_DLS2 "DLS2" /**< DLS2 */
#define SND_SEQ_INSTR_ID_SIMPLE "Simple Wave" /**< Simple Wave */
#define SND_SEQ_INSTR_ID_SOUNDFONT "SoundFont" /**< SoundFont */
#define SND_SEQ_INSTR_ID_GUS_PATCH "GUS Patch" /**< Gravis Patch */
#define SND_SEQ_INSTR_ID_INTERWAVE "InterWave FFFF" /**< InterWave FFFF */
#define SND_SEQ_INSTR_ID_OPL2_3 "OPL2/3 FM" /**< OPL2/3 FM */
#define SND_SEQ_INSTR_ID_OPL4 "OPL4" /**< OPL4 */
/** instrument types */
#define SND_SEQ_INSTR_TYPE0_DLS1 (1<<0) /**< MIDI DLS v1 */
#define SND_SEQ_INSTR_TYPE0_DLS2 (1<<1) /**< MIDI DLS v2 */
#define SND_SEQ_INSTR_TYPE1_SIMPLE (1<<0) /**< Simple Wave */
#define SND_SEQ_INSTR_TYPE1_SOUNDFONT (1<<1) /**< EMU SoundFont */
#define SND_SEQ_INSTR_TYPE1_GUS_PATCH (1<<2) /**< Gravis UltraSound Patch */
#define SND_SEQ_INSTR_TYPE1_INTERWAVE (1<<3) /**< InterWave FFFF */
#define SND_SEQ_INSTR_TYPE2_OPL2_3 (1<<0) /**< Yamaha OPL2/3 FM */
#define SND_SEQ_INSTR_TYPE2_OPL4 (1<<1) /**< Yamaha OPL4 */
/** put commands */
#define SND_SEQ_INSTR_PUT_CMD_CREATE 0 /**< create a new layer */
#define SND_SEQ_INSTR_PUT_CMD_REPLACE 1 /**< replace the old layer with new one */
#define SND_SEQ_INSTR_PUT_CMD_MODIFY 2 /**< modify the existing layer */
#define SND_SEQ_INSTR_PUT_CMD_ADD 3 /**< add one to the existing layer */
#define SND_SEQ_INSTR_PUT_CMD_REMOVE 4 /**< remove the layer */
/** get commands */
#define SND_SEQ_INSTR_GET_CMD_FULL 0 /**< get the full data stream */
#define SND_SEQ_INSTR_GET_CMD_PARTIAL 1 /**< get the partial data stream */
/** free commands */
#define SND_SEQ_INSTR_FREE_CMD_ALL 0 /**< remove all matching instruments */
#define SND_SEQ_INSTR_FREE_CMD_PRIVATE 1 /**< remove only private instruments */
#define SND_SEQ_INSTR_FREE_CMD_CLUSTER 2 /**< remove only cluster instruments */
#define SND_SEQ_INSTR_FREE_CMD_SINGLE 3 /**< remove single instrument */
/**
* FM instrument support
*/
/** FM instrument data structure */
typedef void snd_instr_fm_t;
#ifdef __cplusplus
extern "C" {
#endif
int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm, const char *name, snd_seq_instr_put_t **put, size_t *size);
int snd_instr_fm_convert_from_stream(snd_seq_instr_get_t *data, size_t size, snd_instr_fm_t **fm);
int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm, const char *name, snd_instr_header_t **put, size_t *size);
int snd_instr_fm_convert_from_stream(snd_instr_header_t *data, size_t size, snd_instr_fm_t **fm);
int snd_instr_fm_free(snd_instr_fm_t *fm);
#ifdef __cplusplus
}
#endif
/* Simple Wave support */
/**
* Simple Wave support
*/
/** simple instrument data structure */
typedef void snd_instr_simple_t;
#ifdef __cplusplus
extern "C" {
#endif
int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple, const char *name, snd_seq_instr_put_t **put, size_t *size);
int snd_instr_simple_convert_from_stream(snd_seq_instr_get_t *data, size_t size, snd_instr_simple_t **simple);
int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple, const char *name, snd_instr_header_t **put, size_t *size);
int snd_instr_simple_convert_from_stream(snd_instr_header_t *data, size_t size, snd_instr_simple_t **simple);
int snd_instr_simple_free(snd_instr_simple_t *simple);
#ifdef __cplusplus
}
#endif
/* InterWave FFFF support */
/**
* InterWave FFFF support
*/
/** IW FFFF instrument data structure */
typedef void snd_instr_iwffff_t;
/** IW FFFF handler */
typedef struct _snd_iwffff_handle snd_iwffff_handle_t;
#ifdef __cplusplus
@ -57,8 +160,8 @@ int snd_instr_iwffff_open_rom(snd_iwffff_handle_t **handle, int card, int bank,
int snd_instr_iwffff_open_rom_file(snd_iwffff_handle_t **handle, const char *name, int bank, int file);
int snd_instr_iwffff_close(snd_iwffff_handle_t *handle);
int snd_instr_iwffff_load(snd_iwffff_handle_t *handle, int bank, int prg, snd_instr_iwffff_t **iwffff);
int snd_instr_iwffff_convert_to_stream(snd_instr_iwffff_t *iwffff, const char *name, snd_seq_instr_put_t **data, size_t *size);
int snd_instr_iwffff_convert_from_stream(snd_seq_instr_get_t *data, size_t size, snd_instr_iwffff_t **iwffff);
int snd_instr_iwffff_convert_to_stream(snd_instr_iwffff_t *iwffff, const char *name, snd_instr_header_t **data, size_t *size);
int snd_instr_iwffff_convert_from_stream(snd_instr_header_t *data, size_t size, snd_instr_iwffff_t **iwffff);
int snd_instr_iwffff_free(snd_instr_iwffff_t *iwffff);
#ifdef __cplusplus

View file

@ -46,6 +46,28 @@
#define _snd_hwdep_info sndrv_hwdep_info
#define _SND_SEQ_IN_LOCAL 1
#define _snd_seq_queue_tempo sndrv_seq_queue_tempo
#define _snd_seq_client_info sndrv_seq_client_info
#define _snd_seq_port_info sndrv_seq_port_info
#define _snd_seq_system_info sndrv_seq_system_info
#define _snd_seq_queue_info sndrv_seq_queue_info
#define _snd_seq_queue_status sndrv_seq_queue_status
#define _snd_seq_queue_timer sndrv_seq_queue_timer
#define _snd_seq_port_subscribe sndrv_seq_port_subscribe
#define _snd_seq_query_subscribe sndrv_seq_query_subs
#define _snd_seq_client_pool sndrv_seq_client_pool
#define _snd_seq_remove_events sndrv_seq_remove_events
#define _snd_instr_header sndrv_seq_instr_header
typedef struct sndrv_seq_addr snd_seq_addr_t;
#define snd_seq_tick_time_t sndrv_seq_tick_time_t
typedef struct sndrv_seq_real_time snd_seq_real_time_t;
typedef union sndrv_seq_timestamp snd_seq_timestamp_t;
typedef struct sndrv_seq_instr snd_seq_instr_t;
typedef struct sndrv_seq_event snd_seq_event_t;
#define snd_seq_instr_cluster_t sndrv_seq_instr_cluster_t
#include "asoundlib.h"
#include "list.h"

File diff suppressed because it is too large Load diff

432
include/seq_event.h Normal file
View file

@ -0,0 +1,432 @@
/**
* \defgroup Sequencer Sequencer Interface
* Sequencer Interface
* \{
*/
/** \} */
/**
* \defgroup SeqEvents Sequencer Event Definitions
* Sequencer Event Definitions
* \ingroup Sequencer
* \{
*/
/**
* Sequencer event data type
*/
typedef unsigned char snd_seq_event_type_t;
enum snd_seq_event_type {
/** system status; event data type = #snd_seq_result_t */
SND_SEQ_EVENT_SYSTEM = 0,
/** returned result status; event data type = #snd_seq_result_t */
SND_SEQ_EVENT_RESULT,
/** note on and off with duration; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTE = 5,
/** note on; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEON,
/** note off; event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_NOTEOFF,
/** key pressure change (aftertouch); event data type = #snd_seq_ev_note_t */
SND_SEQ_EVENT_KEYPRESS,
/** controller; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROLLER = 10,
/** program change; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_PGMCHANGE,
/** channel pressure; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CHANPRESS,
/** pitchwheel; event data type = #snd_seq_ev_ctrl_t; data is from -8192 to 8191) */
SND_SEQ_EVENT_PITCHBEND,
/** 14 bit controller value; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_CONTROL14,
/** 14 bit NRPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_NONREGPARAM,
/** 14 bit RPN; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_REGPARAM,
/** SPP with LSB and MSB values; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGPOS = 20,
/** Song Select with song ID number; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_SONGSEL,
/** midi time code quarter frame; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_QFRAME,
/** SMF Time Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_TIMESIGN,
/** SMF Key Signature event; event data type = #snd_seq_ev_ctrl_t */
SND_SEQ_EVENT_KEYSIGN,
/** MIDI Real Time Start message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_START = 30,
/** MIDI Real Time Continue message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CONTINUE,
/** MIDI Real Time Stop message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_STOP,
/** Set tick queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TICK,
/** Set realtime queue position; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SETPOS_TIME,
/** (SMF) Tempo event; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TEMPO,
/** MIDI Real Time Clock message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_CLOCK,
/** MIDI Real Time Tick message; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_TICK,
/** Sync signal; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SYNC,
/** Sync position changed; event data type = #snd_seq_ev_queue_control_t */
SND_SEQ_EVENT_SYNC_POS,
/** Tune request; event data type = none */
SND_SEQ_EVENT_TUNE_REQUEST = 40,
/** Reset to power-on state; event data type = none */
SND_SEQ_EVENT_RESET,
/** Active sensing event; event data type = none */
SND_SEQ_EVENT_SENSING,
/** Echo-back event; event data type = any type */
SND_SEQ_EVENT_ECHO = 50,
/** OSS emulation raw event; event data type = any type */
SND_SEQ_EVENT_OSS,
/** New client has connected; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_START,
/** Client has left the system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_EXIT,
/** Client status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_CLIENT_CHANGE,
/** New port was created; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_START,
/** Port was deleted from system; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_EXIT,
/** Port status/info has changed; event data type = #snd_seq_addr_t */
SND_SEQ_EVENT_PORT_CHANGE,
/** Ports connected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_SUBSCRIBED,
/** Ports disconnected; event data type = #snd_seq_connect_t */
SND_SEQ_EVENT_PORT_UNSUBSCRIBED,
/** Sample select; event data type = #snd_seq_ev_sample_control_t */
SND_SEQ_EVENT_SAMPLE = 70,
/** Sample cluster select; event data type = #snd_seq_ev_sample_control_t */
SND_SEQ_EVENT_SAMPLE_CLUSTER,
/** voice start */
SND_SEQ_EVENT_SAMPLE_START,
/** voice stop */
SND_SEQ_EVENT_SAMPLE_STOP,
/** playback frequency */
SND_SEQ_EVENT_SAMPLE_FREQ,
/** volume and balance */
SND_SEQ_EVENT_SAMPLE_VOLUME,
/** sample loop */
SND_SEQ_EVENT_SAMPLE_LOOP,
/** sample position */
SND_SEQ_EVENT_SAMPLE_POSITION,
/** private (hardware dependent) event */
SND_SEQ_EVENT_SAMPLE_PRIVATE1,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR0 = 90,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR1,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR2,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR3,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR4,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR5,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR6,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR7,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR8,
/** user-defined event; event data type = any (fixed size) */
SND_SEQ_EVENT_USR9,
/** begin of instrument management */
SND_SEQ_EVENT_INSTR_BEGIN = 100,
/** end of instrument management */
SND_SEQ_EVENT_INSTR_END,
/** query instrument interface info */
SND_SEQ_EVENT_INSTR_INFO,
/** result of instrument interface info */
SND_SEQ_EVENT_INSTR_INFO_RESULT,
/** query instrument format info */
SND_SEQ_EVENT_INSTR_FINFO,
/** result of instrument format info */
SND_SEQ_EVENT_INSTR_FINFO_RESULT,
/** reset instrument instrument memory */
SND_SEQ_EVENT_INSTR_RESET,
/** get instrument interface status */
SND_SEQ_EVENT_INSTR_STATUS,
/** result of instrument interface status */
SND_SEQ_EVENT_INSTR_STATUS_RESULT,
/** put an instrument to port */
SND_SEQ_EVENT_INSTR_PUT,
/** get an instrument from port */
SND_SEQ_EVENT_INSTR_GET,
/** result of instrument query */
SND_SEQ_EVENT_INSTR_GET_RESULT,
/** free instrument(s) */
SND_SEQ_EVENT_INSTR_FREE,
/** get instrument list */
SND_SEQ_EVENT_INSTR_LIST,
/** result of instrument list */
SND_SEQ_EVENT_INSTR_LIST_RESULT,
/** set cluster parameters */
SND_SEQ_EVENT_INSTR_CLUSTER,
/** get cluster parameters */
SND_SEQ_EVENT_INSTR_CLUSTER_GET,
/** result of cluster parameters */
SND_SEQ_EVENT_INSTR_CLUSTER_RESULT,
/** instrument change */
SND_SEQ_EVENT_INSTR_CHANGE,
/** system exclusive data (variable length); event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_SYSEX = 130,
/** error event; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_BOUNCE,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR0 = 135,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR1,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR2,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR3,
/** reserved for user apps; event data type = #snd_seq_ev_ext_t */
SND_SEQ_EVENT_USR_VAR4,
/** NOP; ignored in any case */
SND_SEQ_EVENT_NONE = 255
};
#ifndef _SND_SEQ_IN_LOCAL
/** Sequencer event address */
typedef struct snd_seq_addr {
unsigned char client; /**< Client id */
unsigned char port; /**< Port id */
} snd_seq_addr_t;
/** Connection (subscription) between ports */
typedef struct snd_seq_connect {
snd_seq_addr_t sender; /**< sender address */
snd_seq_addr_t dest; /**< destination address */
} snd_seq_connect_t;
/** Real-time data record */
typedef struct snd_seq_real_time {
unsigned int tv_sec; /**< seconds */
unsigned int tv_nsec; /**< nanoseconds */
} snd_seq_real_time_t;
/** (MIDI) Tick-time data record */
typedef unsigned int snd_seq_tick_time_t;
/** unioned time stamp */
typedef union snd_seq_timestamp {
snd_seq_tick_time_t tick; /**< tick-time */
struct snd_seq_real_time time; /**< real-time */
} snd_seq_timestamp_t;
/**
* Event mode flags
*
* NOTE: only 8 bits available!
*/
#define SND_SEQ_TIME_STAMP_TICK (0<<0) /**< timestamp in clock ticks */
#define SND_SEQ_TIME_STAMP_REAL (1<<0) /**< timestamp in real time */
#define SND_SEQ_TIME_STAMP_MASK (1<<0) /**< mask for timestamp bits */
#define SND_SEQ_TIME_MODE_ABS (0<<1) /**< absolute timestamp */
#define SND_SEQ_TIME_MODE_REL (1<<1) /**< relative to current time */
#define SND_SEQ_TIME_MODE_MASK (1<<1) /**< mask for time mode bits */
#define SND_SEQ_EVENT_LENGTH_FIXED (0<<2) /**< fixed event size */
#define SND_SEQ_EVENT_LENGTH_VARIABLE (1<<2) /**< variable event size */
#define SND_SEQ_EVENT_LENGTH_VARUSR (2<<2) /**< variable event size - user memory space */
#define SND_SEQ_EVENT_LENGTH_VARIPC (3<<2) /**< variable event size - IPC */
#define SND_SEQ_EVENT_LENGTH_MASK (3<<2) /**< mask for event length bits */
#define SND_SEQ_PRIORITY_NORMAL (0<<4) /**< normal priority */
#define SND_SEQ_PRIORITY_HIGH (1<<4) /**< event should be processed before others */
#define SND_SEQ_PRIORITY_MASK (1<<4) /**< mask for priority bits */
/** Note event */
typedef struct snd_seq_ev_note {
unsigned char channel; /**< channel number */
unsigned char note; /**< note */
unsigned char velocity; /**< velocity */
unsigned char off_velocity; /**< note-off velocity; only for #SND_SEQ_EVENT_NOTE */
unsigned int duration; /**< duration until note-off; only for #SND_SEQ_EVENT_NOTE */
} snd_seq_ev_note_t;
/** Controller event */
typedef struct snd_seq_ev_ctrl {
unsigned char channel; /**< channel number */
unsigned char unused[3]; /**< reserved */
unsigned int param; /**< control parameter */
signed int value; /**< control value */
} snd_seq_ev_ctrl_t;
/** generic set of bytes (12x8 bit) */
typedef struct snd_seq_ev_raw8 {
unsigned char d[12]; /**< 8 bit value */
} snd_seq_ev_raw8_t;
/** generic set of integers (3x32 bit) */
typedef struct snd_seq_ev_raw32 {
unsigned int d[3]; /**< 32 bit value */
} snd_seq_ev_raw32_t;
/** external stored data */
typedef struct snd_seq_ev_ext {
size_t len; /**< length of data */
void *ptr; /**< pointer to data (note: can be 64-bit) */
} snd_seq_ev_ext_t;
/** external stored data - IPC shared memory */
typedef struct snd_seq_ev_ipcshm {
size_t len; /**< length of data */
key_t ipc; /**< IPC key */
} snd_seq_ev_ipcshm_t;
/** Instrument cluster type */
typedef unsigned int snd_seq_instr_cluster_t;
/** Instrument type */
typedef struct snd_seq_instr {
snd_seq_instr_cluster_t cluster; /**< cluster id */
unsigned int std; /**< instrument standard id; the upper byte means a private instrument (owner - client id) */
unsigned short bank; /**< instrument bank id */
unsigned short prg; /**< instrument program id */
} snd_seq_instr_t;
/** sample number */
typedef struct snd_seq_ev_sample {
unsigned int std; /**< sample standard id */
unsigned short bank; /**< sample bank id */
unsigned short prg; /**< sample program id */
} snd_seq_ev_sample_t;
/** sample cluster */
typedef struct snd_seq_ev_cluster {
snd_seq_instr_cluster_t cluster; /**< cluster id */
} snd_seq_ev_cluster_t;
/** sample position */
typedef unsigned int snd_seq_position_t; /**< playback position (in samples) * 16 */
/** sample stop mode */
typedef enum snd_seq_stop_mode {
SND_SEQ_SAMPLE_STOP_IMMEDIATELY = 0, /**< terminate playing immediately */
SND_SEQ_SAMPLE_STOP_VENVELOPE = 1, /**< finish volume envelope */
SDN_SEQ_SAMPLE_STOP_LOOP = 2 /**< terminate loop and finish wave */
} snd_seq_stop_mode_t;
/** sample frequency */
typedef int snd_seq_frequency_t; /**< playback frequency in HZ * 16 */
/** sample volume control; if any value is set to -1 == do not change */
typedef struct snd_seq_ev_volume {
signed short volume; /**< range: 0-16383 */
signed short lr; /**< left-right balance; range: 0-16383 */
signed short fr; /**< front-rear balance; range: 0-16383 */
signed short du; /**< down-up balance; range: 0-16383 */
} snd_seq_ev_volume_t;
/** simple loop redefinition */
typedef struct snd_seq_ev_loop {
unsigned int start; /**< loop start (in samples) * 16 */
unsigned int end; /**< loop end (in samples) * 16 */
} snd_seq_ev_loop_t;
/** Sample control events */
typedef struct snd_seq_ev_sample_control {
unsigned char channel; /**< channel */
unsigned char unused[3]; /**< reserved */
union {
snd_seq_ev_sample_t sample;
snd_seq_ev_cluster_t cluster;
snd_seq_position_t position;
snd_seq_stop_mode_t stop_mode;
snd_seq_frequency_t frequency;
snd_seq_ev_volume_t volume;
snd_seq_ev_loop_t loop;
unsigned char raw8[8];
} param; /**< control parameters */
} snd_seq_ev_sample_control_t;
/** INSTR_BEGIN event */
typedef struct snd_seq_ev_instr_begin {
int timeout; /**< zero = forever, otherwise timeout in ms */
} snd_seq_ev_instr_begin_t;
/** Result events */
typedef struct snd_seq_result {
int event; /**< processed event type */
int result; /**< status */
} snd_seq_result_t;
/** queue timer control */
typedef struct snd_seq_ev_queue_control {
unsigned char queue; /**< affected queue */
unsigned char unused[3]; /**< reserved */
union {
signed int value; /**< affected value (e.g. tempo) */
snd_seq_timestamp_t time; /**< time */
unsigned int position; /**< sync position */
unsigned int d32[2]; /**< any data */
unsigned char d8[8]; /**< any data */
} param; /**< data value union */
} snd_seq_ev_queue_control_t;
/** Sequencer event */
typedef struct snd_seq_event {
snd_seq_event_type_t type; /**< event type */
unsigned char flags; /**< event flags */
unsigned char tag; /**< tag */
unsigned char queue; /**< schedule queue */
snd_seq_timestamp_t time; /**< schedule time */
snd_seq_addr_t source; /**< source address */
snd_seq_addr_t dest; /**< destination address */
union {
snd_seq_ev_note_t note;
snd_seq_ev_ctrl_t control;
snd_seq_ev_raw8_t raw8;
snd_seq_ev_raw32_t raw32;
snd_seq_ev_ext_t ext;
snd_seq_ev_ipcshm_t ipcshm;
snd_seq_ev_queue_control_t queue;
snd_seq_timestamp_t time;
snd_seq_addr_t addr;
snd_seq_connect_t connect;
snd_seq_result_t result;
snd_seq_ev_instr_begin_t instr_begin;
snd_seq_ev_sample_control_t sample;
} data; /**< event data... */
} snd_seq_event_t;
#endif /* _SND_SEQ_IN_LOCAL */
/** \} */

View file

@ -4,6 +4,10 @@
* *
****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/**
* \defgroup SeqMiddle Sequencer Middle Level Interface
* Sequencer Middle Level Interface
@ -11,72 +15,237 @@
* \{
*/
#ifdef __cplusplus
extern "C" {
#endif
/* initialize event record */
void snd_seq_ev_clear(snd_seq_event_t *ev);
/* set destination - following three macros are exclusive */
/* explicit destination */
void snd_seq_ev_set_dest(snd_seq_event_t *ev, int client, int port);
/* to subscribers */
void snd_seq_ev_set_subs(snd_seq_event_t *ev);
/* broadcast to all clients/ports */
void snd_seq_ev_set_broadcast(snd_seq_event_t *ev);
/* set source port */
void snd_seq_ev_set_source(snd_seq_event_t *ev, int port);
/* set scheduling - following three macros are exclusive */
/* direct event passing without enqueued */
void snd_seq_ev_set_direct(snd_seq_event_t *ev);
/* scheduled on tick-queue */
void snd_seq_ev_schedule_tick(snd_seq_event_t *ev, int q, int relative,
snd_seq_tick_time_t tick);
/* scheduled on real-time-queue */
void snd_seq_ev_schedule_real(snd_seq_event_t *ev, int q, int relative,
snd_seq_real_time_t *_time);
/* set event priority (optional) */
void snd_seq_ev_set_priority(snd_seq_event_t *ev, int high_prior);
/* set event data type - following three macros are exclusive */
/* fixed size event */
void snd_seq_ev_set_fixed(snd_seq_event_t *ev);
/* variable size event */
void snd_seq_ev_set_variable(snd_seq_event_t *ev, int len, void *ptr);
/* variable size event - user memory space */
void snd_seq_ev_set_varusr(snd_seq_event_t *ev, int len, void *ptr);
/* set queue control event data */
/* destination is overwritten to Timer port (0:0) */
int snd_seq_ev_set_queue_start(snd_seq_event_t *ev, int q);
int snd_seq_ev_set_queue_stop(snd_seq_event_t *ev, int q);
int snd_seq_ev_set_queue_continue(snd_seq_event_t *ev, int q);
int snd_seq_ev_set_queue_tempo(snd_seq_event_t *ev, int q, int tempo);
int snd_seq_ev_set_queue_control(snd_seq_event_t *ev, int type, int q, int value);
int snd_seq_ev_set_queue_pos_real(snd_seq_event_t *ev, int q, snd_seq_real_time_t *rtime);
int snd_seq_ev_set_queue_pos_tick(snd_seq_event_t *ev, int q, snd_seq_tick_time_t tick);
/*
* use/unuse a queue
/**
* \brief initialize event record
* \param ev event record pointer
*/
int snd_seq_use_queue(snd_seq_t *seq, int q, int use);
#define snd_seq_ev_clear(ev) \
memset(ev, 0, sizeof(snd_seq_event_t))
/* set and send a queue control event:
* to send at scheduled time, set the schedule in ev.
* if ev is NULL, event is sent immediately (to output queue).
* Note: to send actually to driver, you need to call snd_seq_flush_event()
* apropriately.
/**
* \brief set the explicit destination
* \param ev event record
* \param c destination client id
* \param p destination port id
*/
#define snd_seq_ev_set_dest(ev,c,p) \
((ev)->dest.client = (c), (ev)->dest.port = (p))
/**
* \brief set broadcasting to subscribers
* \param ev event record
*/
#define snd_seq_ev_set_subs(ev) \
((ev)->dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS,\
(ev)->dest.port = SND_SEQ_ADDRESS_UNKNOWN)
/**
* \brief set broadcasting to all clients/ports
* \param ev event record
*/
#define snd_seq_ev_set_broadcast(ev) \
((ev)->dest.client = SND_SEQ_ADDRESS_BROADCAST,\
(ev)->dest.port = SND_SEQ_ADDRESS_BROADCAST)
/**
* \brief set the source port
* \param ev event record
* \param p source port id
*/
#define snd_seq_ev_set_source(ev,p) \
((ev)->source.port = (p))
/**
* \brief set direct passing mode (without queued)
* \param ev event instance
*/
#define snd_seq_ev_set_direct(ev) \
((ev)->queue = SNDRV_SEQ_QUEUE_DIRECT)
/**
* \brief set tick-scheduling mode on queue
* \param ev event instance
* \param q queue id to schedule
* \param relative relative time-stamp if non-zero
* \param ttick tick time-stap to be delivered
*/
#define snd_seq_ev_schedule_tick(ev, q, relative, ttick) \
((ev)->flags &= ~(SNDRV_SEQ_TIME_STAMP_MASK | SNDRV_SEQ_TIME_MODE_MASK),\
(ev)->flags |= SNDRV_SEQ_TIME_STAMP_TICK,\
(ev)->flags |= (relative) ? SNDRV_SEQ_TIME_MODE_REL : SNDRV_SEQ_TIME_MODE_ABS,\
(ev)->time.tick = (ttick),\
(ev)->queue = (q))
/**
* \brief set real-time-scheduling mode on queue
* \param ev event instance
* \param q queue id to schedule
* \param relative relative time-stamp if non-zero
* \param rtime time-stamp to be delivered
*/
#define snd_seq_ev_schedule_real(ev, q, relative, rtime) \
((ev)->flags &= ~( SNDRV_SEQ_TIME_STAMP_MASK | SNDRV_SEQ_TIME_MODE_MASK),\
(ev)->flags |= SNDRV_SEQ_TIME_STAMP_REAL,\
(ev)->flags |= (relative) ? SNDRV_SEQ_TIME_MODE_REL : SNDRV_SEQ_TIME_MODE_ABS,\
(ev)->time.time = *(rtime),\
(ev)->queue = (q))
/**
* \brief set event priority
* \param ev event instance
* \param high_prior 1 for high priority mode
*/
#define snd_seq_ev_set_priority(ev, high_prior) \
((ev)->flags &= ~SNDRV_SEQ_PRIORITY_MASK,\
(ev)->flags |= (high_prior) ? SNDRV_SEQ_PRIORITY_HIGH : SNDRV_SEQ_PRIORITY_NORMAL)
/**
* \brief set fixed data
* \param ev event instance
*
* Sets the event length mode as fixed size.
*/
#define snd_seq_ev_set_fixed(ev) \
((ev)->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK,\
(ev)->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED)
/**
* \brief set variable data
* \param ev event instance
* \param datalen length of the external data
* \param dataptr pointer of the external data
*
* Sets the event length mode as variable length and stores the data.
*/
#define snd_seq_ev_set_variable(ev, datalen, dataptr) \
((ev)->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK,\
(ev)->flags |= SNDRV_SEQ_EVENT_LENGTH_VARIABLE,\
(ev)->data.ext.len = (datalen),\
(ev)->data.ext.ptr = (dataptr))
/**
* \brief set varusr data
* \param ev event instance
* \param len length of the external data
* \param ptr pointer of the external data
*
* Sets the event length mode as variable user-space data and stores the data.
*/
#define snd_seq_ev_set_varusr(ev, datalen, dataptr) \
((ev)->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK,\
(ev)->flags |= SNDRV_SEQ_EVENT_LENGTH_VARUSR,\
(ev)->data.ext.len = (datalen),\
(ev)->data.ext.ptr = (dataptr))
/**
* \brief set queue controls
* \param ev event record
* \param typ event type
* \param q queue id
* \param val control value
*/
#define snd_seq_ev_set_queue_control(ev, typ, q, val) \
((ev)->type = (typ),\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.value = (val))
/**
* \brief set the start queue event
* \param ev event record
* \param q queud id to start
*/
#define snd_seq_ev_set_queue_start(ev, q) \
snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_START, q, 0)
/**
* \brief set the stop queue event
* \param ev event record
* \param q queud id to stop
*/
#define snd_seq_ev_set_queue_stop(ev, q) \
snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_STOP, q, 0)
/**
* \brief set the stop queue event
* \param ev event record
* \param q queud id to continue
*/
#define snd_seq_ev_set_queue_continue(ev, q) \
snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_CONTINUE, q, 0)
/**
* \brief set the stop queue event
* \param ev event record
* \param q queud id to change tempo
* \param val the new tempo value
*/
#define snd_seq_ev_set_queue_tempo(ev, q, val) \
snd_seq_ev_set_queue_control(ev, SND_SEQ_EVENT_TEMPO, q, val)
/**
* \brief set the real-time position of a queue
* \param ev event record
* \param q queud id to change tempo
* \param rtime the new real-time pointer
*/
#define snd_seq_ev_set_queue_pos_real(ev, q, rtime) \
((ev)->type = SND_SEQ_EVENT_SETPOS_TIME,\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.time = *(rtime))
/**
* \brief set the tick-time position of a queue
* \param ev event record
* \param q queud id to change tempo
* \param ttime the new tick-time
*/
#define snd_seq_ev_set_queue_pos_tick(ev, q, ttime) \
((ev)->type = SND_SEQ_EVENT_SETPOS_TICK,\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.tick = (ttime))
/* set and send a queue control event */
int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev);
int snd_seq_start_queue(snd_seq_t *seq, int q, snd_seq_event_t *ev);
int snd_seq_stop_queue(snd_seq_t *seq, int q, snd_seq_event_t *ev);
int snd_seq_continue_queue(snd_seq_t *seq, int q, snd_seq_event_t *ev);
int snd_seq_change_queue_tempo(snd_seq_t *seq, int q, int tempo, snd_seq_event_t *ev);
int snd_seq_setpos_queue(snd_seq_t *seq, int q, snd_seq_timestamp_t *rtime, snd_seq_event_t *ev);
/**
* \brief start the specified queue
* \param seq sequencer handle
* \param q queue id to start
* \param ev optional event record (see #snd_seq_control_queue)
*/
#define snd_seq_start_queue(seq, q, ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_START, 0, ev)
/**
* \brief stop the specified queue
* \param seq sequencer handle
* \param q queue id to stop
* \param ev optional 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)
/**
* \brief continue the specified queue
* \param seq sequencer handle
* \param q queue id to continue
* \param ev optional 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)
/**
* \brief change the tempo of the specified queue
* \param seq sequencer handle
* \param q queue id
* \param tempo the new tempo value
* \param ev optional event record (see #snd_seq_control_queue)
*/
#define snd_seq_change_queue_tempo(seq, q, tempo, ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_TEMPO, tempo, ev)
/* create a port - simple version - return the port number */
int snd_seq_create_simple_port(snd_seq_t *seq, const char *name,
@ -96,12 +265,15 @@ int snd_seq_disconnect_to(snd_seq_t *seq, int my_port, int dest_client, int dest
* set client information
*/
int snd_seq_set_client_name(snd_seq_t *seq, const char *name);
int snd_seq_set_client_group(snd_seq_t *seq, const char *name);
int snd_seq_set_client_filter(snd_seq_t *seq, unsigned int filter);
int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type);
int snd_seq_set_client_pool_output(snd_seq_t *seq, int size);
int snd_seq_set_client_pool_output_room(snd_seq_t *seq, int size);
int snd_seq_set_client_pool_input(snd_seq_t *seq, int size);
int snd_seq_set_client_pool_output(snd_seq_t *seq, size_t size);
int snd_seq_set_client_pool_output_room(snd_seq_t *seq, size_t size);
int snd_seq_set_client_pool_input(snd_seq_t *seq, size_t size);
/*
* parse the given string and get the sequencer address
*/
int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *str);
/*
* reset client input/output pool
@ -109,115 +281,129 @@ int snd_seq_set_client_pool_input(snd_seq_t *seq, int size);
int snd_seq_reset_pool_output(snd_seq_t *seq);
int snd_seq_reset_pool_input(snd_seq_t *seq);
/*
* equivalent macros
/**
* \brief set note event
* \param ev event record
* \param ch channel number
* \param key note key
* \param vel velocity
* \param dur duration (in tick or msec)
*/
#define snd_seq_ev_clear(ev) memset(ev, 0, sizeof(snd_seq_event_t))
#define snd_seq_ev_set_dest(ev,c,p) \
((ev)->dest.client = (c), (ev)->dest.port = (p))
#define snd_seq_ev_set_subs(ev) \
((ev)->dest.client = SND_SEQ_ADDRESS_SUBSCRIBERS,\
(ev)->dest.port = SND_SEQ_ADDRESS_UNKNOWN)
#define snd_seq_ev_set_broadcast(ev) \
((ev)->dest.client = SND_SEQ_ADDRESS_BROADCAST,\
(ev)->dest.port = SND_SEQ_ADDRESS_BROADCAST)
#define snd_seq_ev_set_source(ev,p) ((ev)->source.port = (p))
/*
* queue controls
*/
#define snd_seq_ev_set_queue_control(ev,t,q,val) \
((ev)->type = (t),\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.value = (val))
#define snd_seq_ev_set_queue_start(ev,q) \
snd_seq_ev_set_queue_control(ev,SND_SEQ_EVENT_START,q,0)
#define snd_seq_ev_set_queue_stop(ev,q) \
snd_seq_ev_set_queue_control(ev,SND_SEQ_EVENT_STOP,q,0)
#define snd_seq_ev_set_queue_continue(ev,q) \
snd_seq_ev_set_queue_control(ev,SND_SEQ_EVENT_CONTINUE,q,0)
#define snd_seq_ev_set_queue_tempo(ev,q,val) \
snd_seq_ev_set_queue_control(ev,SND_SEQ_EVENT_TEMPO,q,val)
#define snd_seq_ev_set_queue_pos_real(ev,q,rtime) \
((ev)->type = SND_SEQ_EVENT_SETPOS_TIME,\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.time = *(rtime))
#define snd_seq_ev_set_queue_pos_tick(ev,q,ttime) \
((ev)->type = SND_SEQ_EVENT_SETPOS_TICK,\
snd_seq_ev_set_dest(ev, SND_SEQ_CLIENT_SYSTEM, SND_SEQ_PORT_SYSTEM_TIMER),\
(ev)->data.queue.queue = (q),\
(ev)->data.queue.param.time.tick = (ttime))
#define snd_seq_start_queue(seq,q,ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_START, 0, ev)
#define snd_seq_stop_queue(seq,q,ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_STOP, 0, ev)
#define snd_seq_continue_queue(seq,q,ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_CONTINUE, 0, ev)
#define snd_seq_change_queue_tempo(seq,q,tempo,ev) \
snd_seq_control_queue(seq, q, SND_SEQ_EVENT_TEMPO, tempo, ev)
/*
* macros to set standard event data
*/
#define snd_seq_ev_set_note(ev,ch,key,vel,dur) \
#define snd_seq_ev_set_note(ev, ch, key, vel, dur) \
((ev)->type = SND_SEQ_EVENT_NOTE,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel),\
(ev)->data.note.dulation = (dur))
#define snd_seq_ev_set_noteon(ev,ch,key,vel) \
(ev)->data.note.duration = (dur))
/**
* \brief set note-on event
* \param ev event record
* \param ch channel number
* \param key note key
* \param vel velocity
*/
#define snd_seq_ev_set_noteon(ev, ch, key, vel) \
((ev)->type = SND_SEQ_EVENT_NOTEON,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))
#define snd_seq_ev_set_noteoff(ev,ch,key,vel) \
/**
* \brief set note-off event
* \param ev event record
* \param ch channel number
* \param key note key
* \param vel velocity
*/
#define snd_seq_ev_set_noteoff(ev, ch, key, vel) \
((ev)->type = SND_SEQ_EVENT_NOTEOFF,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))
/**
* \brief set key-pressure event
* \param ev event record
* \param ch channel number
* \param key note key
* \param vel velocity
*/
#define snd_seq_ev_set_keypress(ev,ch,key,vel) \
((ev)->type = SND_SEQ_EVENT_KEYPRESS,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.note.channel = (ch),\
(ev)->data.note.note = (key),\
(ev)->data.note.velocity = (vel))
/**
* \brief set MIDI controller event
* \param ev event record
* \param ch channel number
* \param cc controller number
* \param val control value
*/
#define snd_seq_ev_set_controller(ev,ch,cc,val) \
((ev)->type = SND_SEQ_EVENT_CONTROLLER,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.control.channel = (ch),\
(ev)->data.control.param = (cc),\
(ev)->data.control.value = (val))
/**
* \brief set program change event
* \param ev event record
* \param ch channel number
* \param val program number
*/
#define snd_seq_ev_set_pgmchange(ev,ch,val) \
((ev)->type = SND_SEQ_EVENT_PGMCHANGE,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))
/**
* \brief set pitchbend event
* \param ev event record
* \param ch channel number
* \param val pitch bend; zero centered from -8192 to 8191
*/
#define snd_seq_ev_set_pitchbend(ev,ch,val) \
((ev)->type = SND_SEQ_EVENT_PITCHBEND,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))
/**
* \brief set channel pressure event
* \param ev event record
* \param ch channel number
* \param val channel pressure value
*/
#define snd_seq_ev_set_chanpress(ev,ch,val) \
((ev)->type = SND_SEQ_EVENT_CHANPRESS,\
snd_seq_ev_set_fixed(ev),\
(ev)->data.control.channel = (ch),\
(ev)->data.control.value = (val))
/**
* \brief set sysex event
* \param ev event record
* \param datalen length of sysex data
* \param dataptr sysex data pointer
*
* the sysex data must contain the start byte 0xf0 and the end byte 0xf7.
*/
#define snd_seq_ev_set_sysex(ev,datalen,dataptr) \
((ev)->type = SND_SEQ_EVENT_SYSEX,\
snd_seq_ev_set_variable(ev, datalen, dataptr))
/* etc. etc... */
/** \} */
#ifdef __cplusplus
}
#endif
/** \} */

View file

@ -27,7 +27,7 @@
#include <asm/byteorder.h>
#include <sound/ainstr_fm.h>
int snd_instr_fm_free(snd_instr_simple_t *fm)
int snd_instr_fm_free(snd_instr_fm_t *fm)
{
if (fm == NULL)
return 0;
@ -37,11 +37,10 @@ int snd_instr_fm_free(snd_instr_simple_t *fm)
int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm,
const char *name,
snd_seq_instr_put_t **__data,
snd_instr_header_t **__data,
size_t *__size)
{
snd_seq_instr_put_t *put;
snd_seq_instr_data_t *data;
snd_instr_header_t *put;
fm_instrument_t *instr;
fm_xinstrument_t *xinstr;
int idx;
@ -51,18 +50,15 @@ int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm,
instr = (fm_instrument_t *)fm;
*__data = NULL;
*__size = 0;
put = (snd_seq_instr_put_t *)malloc(sizeof(*put) + sizeof(fm_xinstrument_t));
if (put == NULL)
if (snd_instr_header_malloc(&put, sizeof(fm_xinstrument_t)) < 0)
return -ENOMEM;
/* build header */
memset(put, 0, sizeof(*put));
data = &put->data;
if (name)
strncpy(data->name, name, sizeof(data->name)-1);
data->type = SND_SEQ_INSTR_ATYPE_DATA;
strcpy(data->data.format, SND_SEQ_INSTR_ID_OPL2_3);
snd_instr_header_set_name(put, name);
snd_instr_header_set_type(put, SND_SEQ_INSTR_ATYPE_DATA);
snd_instr_header_set_format(put, SND_SEQ_INSTR_ID_OPL2_3);
/* build data section */
xinstr = (fm_xinstrument_t *)(data + 1);
xinstr = (fm_xinstrument_t *)snd_instr_header_get_data(put);
xinstr->stype = FM_STRU_INSTR;
xinstr->share_id[0] = __cpu_to_le32(instr->share_id[0]);
xinstr->share_id[1] = __cpu_to_le32(instr->share_id[1]);
@ -93,7 +89,7 @@ int snd_instr_fm_convert_to_stream(snd_instr_fm_t *fm,
return 0;
}
int snd_instr_fm_convert_from_stream(snd_seq_instr_get_t *__data ATTRIBUTE_UNUSED,
int snd_instr_fm_convert_from_stream(snd_instr_header_t *__data ATTRIBUTE_UNUSED,
size_t size ATTRIBUTE_UNUSED,
snd_instr_fm_t **simple ATTRIBUTE_UNUSED)
{

View file

@ -740,11 +740,10 @@ static int copy_env_to_stream(iwffff_xenv_t *xenv, iwffff_env_t *env, __u32 styp
int snd_instr_iwffff_conv_to_stream(snd_instr_iwffff_t *iwffff,
const char *name,
snd_seq_instr_put_t **__data,
snd_instr_header_t **__data,
long *__size)
{
snd_seq_instr_put_t *put;
snd_seq_instr_data_t *data;
snd_instr_header_t *put;
int size;
char *ptr;
iwffff_instrument_t *instr;
@ -759,19 +758,16 @@ int snd_instr_iwffff_conv_to_stream(snd_instr_iwffff_t *iwffff,
instr = (iwffff_instrument_t *)iwffff;
*__data = NULL;
*__size = 0;
size = sizeof(*data) + iwffff_size(iwffff);
put = (snd_seq_instr_put_t *)malloc(sizeof(*put) + size);
if (put == NULL)
size = iwffff_size(iwffff);
if (snd_instr_header_malloc(&put, size) < 0)
return -ENOMEM;
/* build header */
memset(put, 0, sizeof(*put));
data = &put->data;
if (name)
strncpy(data->name, name, sizeof(data->name)-1);
data->type = SND_SEQ_INSTR_ATYPE_DATA;
strcpy(data->data.format, SND_SEQ_INSTR_ID_INTERWAVE);
snd_instr_header_set_name(put, name);
snd_instr_header_set_type(put, SND_SEQ_INSTR_ATYPE_DATA);
snd_instr_header_set_format(put, SND_SEQ_INSTR_ID_INTERWAVE);
/* build data section */
xinstr = (iwffff_xinstrument_t *)(data + 1);
xinstr = (iwffff_xinstrument_t *)snd_instr_header_get_data(put);
xinstr->stype = IWFFFF_STRU_INSTR;
xinstr->exclusion = __cpu_to_le16(instr->exclusion);
xinstr->layer_type = __cpu_to_le16(instr->layer_type);
@ -827,11 +823,11 @@ int snd_instr_iwffff_conv_to_stream(snd_instr_iwffff_t *iwffff,
}
/* write result */
*__data = put;
*__size = size;
*__size = sizeof(*put) + size;
return 0;
}
int snd_instr_iwffff_convert_from_stream(snd_seq_instr_get_t *data ATTRIBUTE_UNUSED,
int snd_instr_iwffff_convert_from_stream(snd_instr_header_t *data ATTRIBUTE_UNUSED,
size_t size ATTRIBUTE_UNUSED,
snd_instr_iwffff_t **iwffff ATTRIBUTE_UNUSED)
{

View file

@ -50,11 +50,10 @@ static long simple_size(simple_instrument_t *instr)
int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple,
const char *name,
snd_seq_instr_put_t **__data,
snd_instr_header_t **__data,
size_t *__size)
{
snd_seq_instr_put_t *put;
snd_seq_instr_data_t *data;
snd_instr_header_t *put;
int size;
char *ptr;
simple_instrument_t *instr;
@ -66,18 +65,15 @@ int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple,
*__data = NULL;
*__size = 0;
size = simple_size(simple);
put = (snd_seq_instr_put_t *)malloc(sizeof(*put) + sizeof(simple_xinstrument_t) + size);
if (put == NULL)
if (snd_instr_header_malloc(&put, sizeof(simple_xinstrument_t) + size) < 0)
return -ENOMEM;
/* build header */
memset(put, 0, sizeof(*put));
data = &put->data;
if (name)
strncpy(data->name, name, sizeof(data->name)-1);
data->type = SND_SEQ_INSTR_ATYPE_DATA;
strcpy(data->data.format, SND_SEQ_INSTR_ID_SIMPLE);
snd_instr_header_set_name(put, name);
snd_instr_header_set_type(put, SND_SEQ_INSTR_ATYPE_DATA);
snd_instr_header_set_format(put, SND_SEQ_INSTR_ID_SIMPLE);
/* build data section */
xinstr = (simple_xinstrument_t *)(data + 1);
xinstr = (simple_xinstrument_t *)snd_instr_header_get_data(put);
xinstr->stype = SIMPLE_STRU_INSTR;
xinstr->share_id[0] = __cpu_to_le32(instr->share_id[0]);
xinstr->share_id[1] = __cpu_to_le32(instr->share_id[1]);
@ -101,7 +97,7 @@ int snd_instr_simple_convert_to_stream(snd_instr_simple_t *simple,
return 0;
}
int snd_instr_simple_convert_from_stream(snd_seq_instr_get_t *__data ATTRIBUTE_UNUSED,
int snd_instr_simple_convert_from_stream(snd_instr_header_t *__data ATTRIBUTE_UNUSED,
size_t size ATTRIBUTE_UNUSED,
snd_instr_simple_t **simple ATTRIBUTE_UNUSED)
{

View file

@ -1,6 +1,6 @@
EXTRA_LTLIBRARIES=libseq.la
libseq_la_SOURCES = seq_hw.c seq.c seqmid.c seq_midi_event.c
libseq_la_SOURCES = seq_hw.c seq.c seq_event.c seqmid.c seq_midi_event.c
noinst_HEADERS = seq_local.h
all: libseq.la

File diff suppressed because it is too large Load diff

55
src/seq/seq_event.c Normal file
View file

@ -0,0 +1,55 @@
/**
* \file seq/seq_event.c
* \author Takashi Iwai <tiwai@suse.de>
* \date 2001
*/
#include "../../include/asoundlib.h"
#define FIXED_EV(x) (_SND_SEQ_TYPE(SND_SEQ_EVFLG_FIXED) | _SND_SEQ_TYPE(x))
const unsigned int snd_seq_event_types[256] = {
[SND_SEQ_EVENT_SYSTEM ... SND_SEQ_EVENT_RESULT]
= FIXED_EV(SND_SEQ_EVFLG_RESULT),
[SND_SEQ_EVENT_NOTE]
= FIXED_EV(SND_SEQ_EVFLG_NOTE) | _SND_SEQ_TYPE_OPT(SND_SEQ_EVFLG_NOTE_TWOARG),
[SND_SEQ_EVENT_NOTEON ... SND_SEQ_EVENT_KEYPRESS]
= FIXED_EV(SND_SEQ_EVFLG_NOTE),
[SND_SEQ_EVENT_CONTROLLER ... SND_SEQ_EVENT_REGPARAM]
= FIXED_EV(SND_SEQ_EVFLG_CONTROL),
[SND_SEQ_EVENT_START ... SND_SEQ_EVENT_STOP]
= FIXED_EV(SND_SEQ_EVFLG_QUEUE),
[SND_SEQ_EVENT_SETPOS_TICK]
= FIXED_EV(SND_SEQ_EVFLG_QUEUE) | _SND_SEQ_TYPE_OPT(SND_SEQ_EVFLG_QUEUE_TICK),
[SND_SEQ_EVENT_SETPOS_TIME]
= FIXED_EV(SND_SEQ_EVFLG_QUEUE) | _SND_SEQ_TYPE_OPT(SND_SEQ_EVFLG_QUEUE_TIME),
[SND_SEQ_EVENT_TEMPO ... SND_SEQ_EVENT_SYNC_POS]
= FIXED_EV(SND_SEQ_EVFLG_QUEUE) | _SND_SEQ_TYPE_OPT(SND_SEQ_EVFLG_QUEUE_VALUE),
[SND_SEQ_EVENT_TUNE_REQUEST ... SND_SEQ_EVENT_SENSING]
= FIXED_EV(SND_SEQ_EVFLG_NONE),
[SND_SEQ_EVENT_ECHO ... SND_SEQ_EVENT_OSS]
= FIXED_EV(SND_SEQ_EVFLG_RAW) | FIXED_EV(SND_SEQ_EVFLG_SYSTEM),
[SND_SEQ_EVENT_CLIENT_START ... SND_SEQ_EVENT_PORT_CHANGE]
= FIXED_EV(SND_SEQ_EVFLG_MESSAGE),
[SND_SEQ_EVENT_PORT_SUBSCRIBED ... SND_SEQ_EVENT_PORT_UNSUBSCRIBED]
= FIXED_EV(SND_SEQ_EVFLG_CONNECTION),
[SND_SEQ_EVENT_SAMPLE ... SND_SEQ_EVENT_SAMPLE_PRIVATE1]
= FIXED_EV(SND_SEQ_EVFLG_SAMPLE),
[SND_SEQ_EVENT_USR0 ... SND_SEQ_EVENT_USR9]
= FIXED_EV(SND_SEQ_EVFLG_RAW) | FIXED_EV(SND_SEQ_EVFLG_USERS),
[SND_SEQ_EVENT_INSTR_BEGIN ... SND_SEQ_EVENT_INSTR_CHANGE]
= _SND_SEQ_TYPE(SND_SEQ_EVFLG_INSTR) | _SND_SEQ_TYPE(SND_SEQ_EVFLG_VARUSR),
[SND_SEQ_EVENT_SYSEX ... SND_SEQ_EVENT_BOUNCE]
= _SND_SEQ_TYPE(SND_SEQ_EVFLG_VARIABLE),
[SND_SEQ_EVENT_USR_VAR0 ... SND_SEQ_EVENT_USR_VAR4]
= _SND_SEQ_TYPE(SND_SEQ_EVFLG_VARIABLE) | _SND_SEQ_TYPE(SND_SEQ_EVFLG_USERS),
#if 0 // NYI
[SND_SEQ_EVENT_IPCSHM]
= _SND_SEQ_TYPE(SND_SEQ_EVFLG_IPC),
[SND_SEQ_EVENT_USR_VARIPC0 ... SND_SEQ_EVENT_USR_VARIPC4]
= _SND_SEQ_TYPE(SND_SEQ_EVFLG_IPC) | _SND_SEQ_TYPE(SND_SEQ_EVFLG_USERS),
#endif
[SND_SEQ_EVENT_NONE]
= FIXED_EV(SND_SEQ_EVFLG_NONE),
};

View file

@ -174,7 +174,7 @@ static int snd_seq_hw_unsubscribe_port(snd_seq_t *seq, snd_seq_port_subscribe_t
return 0;
}
static int snd_seq_hw_query_port_subscribers(snd_seq_t *seq, snd_seq_query_subs_t * subs)
static int snd_seq_hw_query_port_subscribers(snd_seq_t *seq, snd_seq_query_subscribe_t * subs)
{
snd_seq_hw_t *hw = seq->private_data;
if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_QUERY_SUBS, subs) < 0) {
@ -214,26 +214,6 @@ static int snd_seq_hw_set_queue_tempo(snd_seq_t *seq, snd_seq_queue_tempo_t * te
return 0;
}
static int snd_seq_hw_get_queue_owner(snd_seq_t *seq, snd_seq_queue_owner_t * owner)
{
snd_seq_hw_t *hw = seq->private_data;
if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_GET_QUEUE_OWNER, owner) < 0) {
SYSERR("SNDRV_SEQ_IOCTL_GET_QUEUE_OWNER failed");
return -errno;
}
return 0;
}
static int snd_seq_hw_set_queue_owner(snd_seq_t *seq, snd_seq_queue_owner_t * owner)
{
snd_seq_hw_t *hw = seq->private_data;
if (ioctl(hw->fd, SNDRV_SEQ_IOCTL_SET_QUEUE_OWNER, owner) < 0) {
SYSERR("SNDRV_SEQ_IOCTL_SET_QUEUE_OWNER failed");
return -errno;
}
return 0;
}
static int snd_seq_hw_get_queue_timer(snd_seq_t *seq, snd_seq_queue_timer_t * timer)
{
snd_seq_hw_t *hw = seq->private_data;
@ -409,8 +389,6 @@ snd_seq_ops_t snd_seq_hw_ops = {
get_queue_status: snd_seq_hw_get_queue_status,
get_queue_tempo: snd_seq_hw_get_queue_tempo,
set_queue_tempo: snd_seq_hw_set_queue_tempo,
get_queue_owner: snd_seq_hw_get_queue_owner,
set_queue_owner: snd_seq_hw_set_queue_owner,
get_queue_timer: snd_seq_hw_get_queue_timer,
set_queue_timer: snd_seq_hw_set_queue_timer,
get_queue_client: snd_seq_hw_get_queue_client,

View file

@ -32,6 +32,9 @@
#define SND_SEQ_IBUF_SIZE 500 /* in event_size aligned */
#define DEFAULT_TMPBUF_SIZE 20
typedef struct sndrv_seq_queue_client snd_seq_queue_client_t;
typedef struct {
int (*close)(snd_seq_t *seq);
int (*nonblock)(snd_seq_t *seq, int nonblock);
@ -45,12 +48,10 @@ typedef struct {
int (*get_port_subscription)(snd_seq_t *seq, snd_seq_port_subscribe_t * sub);
int (*subscribe_port)(snd_seq_t *seq, snd_seq_port_subscribe_t * sub);
int (*unsubscribe_port)(snd_seq_t *seq, snd_seq_port_subscribe_t * sub);
int (*query_port_subscribers)(snd_seq_t *seq, snd_seq_query_subs_t * subs);
int (*query_port_subscribers)(snd_seq_t *seq, snd_seq_query_subscribe_t * subs);
int (*get_queue_status)(snd_seq_t *seq, snd_seq_queue_status_t * status);
int (*get_queue_tempo)(snd_seq_t *seq, snd_seq_queue_tempo_t * tempo);
int (*set_queue_tempo)(snd_seq_t *seq, snd_seq_queue_tempo_t * tempo);
int (*get_queue_owner)(snd_seq_t *seq, snd_seq_queue_owner_t * owner);
int (*set_queue_owner)(snd_seq_t *seq, snd_seq_queue_owner_t * owner);
int (*get_queue_timer)(snd_seq_t *seq, snd_seq_queue_timer_t * timer);
int (*set_queue_timer)(snd_seq_t *seq, snd_seq_queue_timer_t * timer);
int (*get_queue_client)(snd_seq_t *seq, snd_seq_queue_client_t * client);

View file

@ -72,31 +72,31 @@ static struct status_event_list_t {
event_decode_t decode;
} status_event[] = {
/* 0x80 - 0xf0 */
{SND_SEQ_EVENT_NOTEOFF, 2, note_event, note_decode},
{SND_SEQ_EVENT_NOTEON, 2, note_event, note_decode},
{SND_SEQ_EVENT_KEYPRESS, 2, note_event, note_decode},
{SND_SEQ_EVENT_CONTROLLER, 2, two_param_ctrl_event, two_param_decode},
{SND_SEQ_EVENT_PGMCHANGE, 1, one_param_ctrl_event, one_param_decode},
{SND_SEQ_EVENT_CHANPRESS, 1, one_param_ctrl_event, one_param_decode},
{SND_SEQ_EVENT_PITCHBEND, 2, pitchbend_ctrl_event, pitchbend_decode},
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf0 */
{SNDRV_SEQ_EVENT_NOTEOFF, 2, note_event, note_decode},
{SNDRV_SEQ_EVENT_NOTEON, 2, note_event, note_decode},
{SNDRV_SEQ_EVENT_KEYPRESS, 2, note_event, note_decode},
{SNDRV_SEQ_EVENT_CONTROLLER, 2, two_param_ctrl_event, two_param_decode},
{SNDRV_SEQ_EVENT_PGMCHANGE, 1, one_param_ctrl_event, one_param_decode},
{SNDRV_SEQ_EVENT_CHANPRESS, 1, one_param_ctrl_event, one_param_decode},
{SNDRV_SEQ_EVENT_PITCHBEND, 2, pitchbend_ctrl_event, pitchbend_decode},
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf0 */
/* 0xf0 - 0xff */
{SND_SEQ_EVENT_SYSEX, 1, NULL, NULL}, /* sysex: 0xf0 */
{SND_SEQ_EVENT_QFRAME, 1, one_param_event, one_param_decode}, /* 0xf1 */
{SND_SEQ_EVENT_SONGPOS, 2, songpos_event, songpos_decode}, /* 0xf2 */
{SND_SEQ_EVENT_SONGSEL, 1, one_param_event, one_param_decode}, /* 0xf3 */
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf4 */
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf5 */
{SND_SEQ_EVENT_TUNE_REQUEST, 0, NULL, NULL}, /* 0xf6 */
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf7 */
{SND_SEQ_EVENT_CLOCK, 0, NULL, NULL}, /* 0xf8 */
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf9 */
{SND_SEQ_EVENT_START, 0, NULL, NULL}, /* 0xfa */
{SND_SEQ_EVENT_CONTINUE, 0, NULL, NULL}, /* 0xfb */
{SND_SEQ_EVENT_STOP, 0, NULL, NULL}, /* 0xfc */
{SND_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xfd */
{SND_SEQ_EVENT_SENSING, 0, NULL, NULL}, /* 0xfe */
{SND_SEQ_EVENT_RESET, 0, NULL, NULL}, /* 0xff */
{SNDRV_SEQ_EVENT_SYSEX, 1, NULL, NULL}, /* sysex: 0xf0 */
{SNDRV_SEQ_EVENT_QFRAME, 1, one_param_event, one_param_decode}, /* 0xf1 */
{SNDRV_SEQ_EVENT_SONGPOS, 2, songpos_event, songpos_decode}, /* 0xf2 */
{SNDRV_SEQ_EVENT_SONGSEL, 1, one_param_event, one_param_decode}, /* 0xf3 */
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf4 */
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf5 */
{SNDRV_SEQ_EVENT_TUNE_REQUEST, 0, NULL, NULL}, /* 0xf6 */
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf7 */
{SNDRV_SEQ_EVENT_CLOCK, 0, NULL, NULL}, /* 0xf8 */
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xf9 */
{SNDRV_SEQ_EVENT_START, 0, NULL, NULL}, /* 0xfa */
{SNDRV_SEQ_EVENT_CONTINUE, 0, NULL, NULL}, /* 0xfb */
{SNDRV_SEQ_EVENT_STOP, 0, NULL, NULL}, /* 0xfc */
{SNDRV_SEQ_EVENT_NONE, 0, NULL, NULL}, /* 0xfd */
{SNDRV_SEQ_EVENT_SENSING, 0, NULL, NULL}, /* 0xfe */
{SNDRV_SEQ_EVENT_RESET, 0, NULL, NULL}, /* 0xff */
};
static int extra_decode_ctrl14(snd_midi_event_t *dev, unsigned char *buf, int len, snd_seq_event_t *ev);
@ -105,9 +105,9 @@ static struct extra_event_list_t {
int event;
int (*decode)(snd_midi_event_t *dev, unsigned char *buf, int len, snd_seq_event_t *ev);
} extra_event[] = {
{SND_SEQ_EVENT_CONTROL14, extra_decode_ctrl14},
/*{SND_SEQ_EVENT_NONREGPARAM, extra_decode_nrpn},*/
/*{SND_SEQ_EVENT_REGPARAM, extra_decode_rpn},*/
{SNDRV_SEQ_EVENT_CONTROL14, extra_decode_ctrl14},
/*{SNDRV_SEQ_EVENT_NONREGPARAM, extra_decode_nrpn},*/
/*{SNDRV_SEQ_EVENT_REGPARAM, extra_decode_rpn},*/
};
#define numberof(ary) (sizeof(ary)/sizeof(ary[0]))
@ -201,7 +201,7 @@ long snd_midi_event_encode(snd_midi_event_t *dev, unsigned char *buf, long count
long result = 0;
int rc;
ev->type = SND_SEQ_EVENT_NONE;
ev->type = SNDRV_SEQ_EVENT_NONE;
while (count-- > 0) {
rc = snd_midi_event_encode_byte(dev, *buf++, ev);
@ -230,8 +230,8 @@ int snd_midi_event_encode_byte(snd_midi_event_t *dev, int c, snd_seq_event_t *ev
if (c >= MIDI_CMD_COMMON_CLOCK) {
/* real-time event */
ev->type = status_event[ST_SPECIAL + c - 0xf0].event;
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_FIXED;
ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;
return 1;
}
@ -258,16 +258,16 @@ int snd_midi_event_encode_byte(snd_midi_event_t *dev, int c, snd_seq_event_t *ev
}
if (dev->qlen == 0) {
ev->type = status_event[dev->type].event;
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_FIXED;
ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SNDRV_SEQ_EVENT_LENGTH_FIXED;
if (status_event[dev->type].encode) /* set data values */
status_event[dev->type].encode(dev, ev);
rc = 1;
} else if (dev->type == ST_SYSEX) {
if (c == MIDI_CMD_COMMON_SYSEX_END ||
dev->read >= dev->bufsize) {
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_VARIABLE;
ev->flags &= ~SNDRV_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SNDRV_SEQ_EVENT_LENGTH_VARIABLE;
ev->data.ext.len = dev->read;
ev->data.ext.ptr = dev->buf;
if (c != MIDI_CMD_COMMON_SYSEX_END)
@ -333,7 +333,7 @@ long snd_midi_event_decode(snd_midi_event_t *dev, unsigned char *buf, long count
long qlen;
unsigned int type;
if (ev->type == SND_SEQ_EVENT_NONE)
if (ev->type == SNDRV_SEQ_EVENT_NONE)
return -ENOENT;
for (type = 0; type < numberof(status_event); type++) {
@ -358,9 +358,9 @@ long snd_midi_event_decode(snd_midi_event_t *dev, unsigned char *buf, long count
qlen = ev->data.ext.len;
if (count < qlen)
return -ENOMEM;
switch (ev->flags & SND_SEQ_EVENT_LENGTH_MASK) {
case SND_SEQ_EVENT_LENGTH_FIXED:
case SND_SEQ_EVENT_LENGTH_VARIPC:
switch (ev->flags & SNDRV_SEQ_EVENT_LENGTH_MASK) {
case SNDRV_SEQ_EVENT_LENGTH_FIXED:
case SNDRV_SEQ_EVENT_LENGTH_VARIPC:
return -EINVAL; /* invalid event */
}
memcpy(dev->buf, ev->data.ext.ptr, qlen);

View file

@ -25,114 +25,10 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include "seq_local.h"
/**
* \brief set direct passing mode (without queued)
* \param ev event instance
*/
void snd_seq_ev_set_direct(snd_seq_event_t *ev)
{
ev->queue = SND_SEQ_QUEUE_DIRECT;
}
/**
* \brief set tick-scheduling mode on queue
* \param ev event instance
* \param q queue id to schedule
* \param relative relative time-stamp if non-zero
* \param tick tick time-stap to be delivered
*/
void snd_seq_ev_schedule_tick(snd_seq_event_t *ev, int q, int relative,
snd_seq_tick_time_t tick)
{
ev->flags &= ~(SND_SEQ_TIME_STAMP_MASK | SND_SEQ_TIME_MODE_MASK);
ev->flags |= SND_SEQ_TIME_STAMP_TICK;
ev->flags |= relative ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS;
ev->time.tick = tick;
ev->queue = q;
}
/**
* \brief set real-time-scheduling mode on queue
* \param ev event instance
* \param q queue id to schedule
* \param relative relative time-stamp if non-zero
* \param _time time-stamp to be delivered
*/
void snd_seq_ev_schedule_real(snd_seq_event_t *ev, int q, int relative,
snd_seq_real_time_t *_time)
{
ev->flags &= ~( SND_SEQ_TIME_STAMP_MASK | SND_SEQ_TIME_MODE_MASK);
ev->flags |= SND_SEQ_TIME_STAMP_REAL;
ev->flags |= relative ? SND_SEQ_TIME_MODE_REL : SND_SEQ_TIME_MODE_ABS;
ev->time.time = *_time;
ev->queue = q;
}
/**
* \brief set event priority
* \param ev event instance
* \param high_prior 1 for high priority mode
*/
void snd_seq_ev_set_priority(snd_seq_event_t *ev, int high_prior)
{
ev->flags &= ~SND_SEQ_PRIORITY_MASK;
ev->flags |= high_prior ? SND_SEQ_PRIORITY_HIGH : SND_SEQ_PRIORITY_NORMAL;
}
/**
* \brief set fixed data
*
* Sets the event length mode as fixed size.
*/
void snd_seq_ev_set_fixed(snd_seq_event_t *ev)
{
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_FIXED;
}
/**
* \brief set variable data
*
* Sets the event length mode as variable length and stores the data.
*/
void snd_seq_ev_set_variable(snd_seq_event_t *ev, int len, void *ptr)
{
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_VARIABLE;
ev->data.ext.len = len;
ev->data.ext.ptr = ptr;
}
/**
* \brief set varusr data
*
* Sets the event length mode as variable user-space data and stores the data.
*/
void snd_seq_ev_set_varusr(snd_seq_event_t *ev, int len, void *ptr)
{
ev->flags &= ~SND_SEQ_EVENT_LENGTH_MASK;
ev->flags |= SND_SEQ_EVENT_LENGTH_VARUSR;
ev->data.ext.len = len;
ev->data.ext.ptr = ptr;
}
/**
* \brief use or unuse a queue
*/
int snd_seq_use_queue(snd_seq_t *seq, int q, int use)
{
snd_seq_queue_client_t info;
memset(&info, 0, sizeof(info));
info.used = use;
return snd_seq_set_queue_client(seq, q, &info);
}
/**
* \brief queue controls - start/stop/continue
* \param seq sequencer handle
@ -141,8 +37,11 @@ int snd_seq_use_queue(snd_seq_t *seq, int q, int use)
* \param value event value
* \param ev event instance
*
* if ev is NULL, send events immediately.
* otherwise, duplicate the given event data.
* This function sets up general queue control event and sends it.
* To send at scheduled time, set the schedule in \a ev.
* If \a 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_event
* apropriately to feed the event.
*/
int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_event_t *ev)
{
@ -156,38 +55,16 @@ int snd_seq_control_queue(snd_seq_t *seq, int q, int type, int value, snd_seq_ev
return snd_seq_event_output(seq, ev);
}
/**
* \brief reset queue position
*
* new values of both real-time and tick values must be given.
*/
int snd_seq_setpos_queue(snd_seq_t *seq, int q, snd_seq_timestamp_t *rtime, snd_seq_event_t *ev)
{
snd_seq_event_t tmpev;
int result;
if (ev == NULL) {
snd_seq_ev_clear(&tmpev);
ev = &tmpev;
snd_seq_ev_set_direct(ev);
}
/* stop the timer */
result = snd_seq_stop_queue(seq, q, ev);
/* reset queue position */
snd_seq_ev_set_queue_pos_real(ev, q, &rtime->time);
result = snd_seq_event_output(seq, ev);
snd_seq_ev_set_queue_pos_tick(ev, q, rtime->tick);
result = snd_seq_event_output(seq, ev);
/* continue the timer */
result = snd_seq_continue_queue(seq, q, ev);
return result;
}
/**
* \brief create a port - simple version
* \param seq sequencer handle
* \param name the name of the port
* \param caps capability bits
* \param type type bits
* \return the created port number or negative error code
*
* return the port number
* Creates a port with the given capability and type bits.
*/
int snd_seq_create_simple_port(snd_seq_t *seq, const char *name,
unsigned int caps, unsigned int type)
@ -199,35 +76,38 @@ int snd_seq_create_simple_port(snd_seq_t *seq, const char *name,
if (name)
strncpy(pinfo.name, name, sizeof(pinfo.name) - 1);
pinfo.capability = caps;
pinfo.cap_group = caps;
pinfo.type = type;
pinfo.midi_channels = 16;
pinfo.midi_voices = 64; /* XXX */
pinfo.synth_voices = 0; /* XXX */
pinfo.kernel = NULL;
result = snd_seq_create_port(seq, &pinfo);
if (result < 0)
return result;
else
return pinfo.port;
return pinfo.addr.port;
}
/**
* \brief delete the port
* \param seq sequencer handle
* \param port port id
* \return 0 on success or negavie error code
*/
int snd_seq_delete_simple_port(snd_seq_t *seq, int port)
{
snd_seq_port_info_t pinfo;
memset(&pinfo, 0, sizeof(pinfo));
pinfo.port = port;
return snd_seq_delete_port(seq, &pinfo);
return snd_seq_delete_port(seq, port);
}
/**
* \brief sipmle subscription (w/o exclusive & time conversion)
* \brief simple subscription (w/o exclusive & time conversion)
* \param myport the port id as receiver
* \param src_client sender client id
* \param src_port sender port id
* \return 0 on success or negative error code
*
* Connect from the given sender client:port to the given destination port in the
* current client.
*/
int snd_seq_connect_from(snd_seq_t *seq, int myport, int src_client, int src_port)
{
@ -245,6 +125,13 @@ int snd_seq_connect_from(snd_seq_t *seq, int myport, int src_client, int src_por
/**
* \brief sipmle subscription (w/o exclusive & time conversion)
* \param myport the port id as sender
* \param dest_client destination client id
* \param dest_port destination port id
* \return 0 on success or negative error code
*
* Connect from the given receiver port in the current client
* to the given destination client:port.
*/
int snd_seq_connect_to(snd_seq_t *seq, int myport, int dest_client, int dest_port)
{
@ -261,7 +148,14 @@ int snd_seq_connect_to(snd_seq_t *seq, int myport, int dest_client, int dest_por
}
/**
* \brief sipmle disconnection (w/o exclusive & time conversion)
* \brief simple disconnection
* \param myport the port id as receiver
* \param src_client sender client id
* \param src_port sender port id
* \return 0 on success or negative error code
*
* Remove connection from the given sender client:port
* to the given destination port in the current client.
*/
int snd_seq_disconnect_from(snd_seq_t *seq, int myport, int src_client, int src_port)
{
@ -278,7 +172,14 @@ int snd_seq_disconnect_from(snd_seq_t *seq, int myport, int src_client, int src_
}
/**
* \brief sipmle disconnection (w/o exclusive & time conversion)
* \brief simple disconnection
* \param myport the port id as sender
* \param dest_client destination client id
* \param dest_port destination port id
* \return 0 on success or negative error code
*
* Remove connection from the given sender client:port
* to the given destination port in the current client.
*/
int snd_seq_disconnect_to(snd_seq_t *seq, int myport, int dest_client, int dest_port)
{
@ -297,8 +198,12 @@ int snd_seq_disconnect_to(snd_seq_t *seq, int myport, int dest_client, int dest_
/*
* set client information
*/
/**
* \brief set client name
* \param seq sequencer handle
* \param name name string
* \return 0 on success or negative error code
*/
int snd_seq_set_client_name(snd_seq_t *seq, const char *name)
{
@ -312,35 +217,10 @@ int snd_seq_set_client_name(snd_seq_t *seq, const char *name)
}
/**
* \brief set client group
*/
int snd_seq_set_client_group(snd_seq_t *seq, const char *name)
{
snd_seq_client_info_t info;
int err;
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
return err;
strncpy(info.group, name, sizeof(info.group) - 1);
return snd_seq_set_client_info(seq, &info);
}
/**
* \brief set client filter
*/
int snd_seq_set_client_filter(snd_seq_t *seq, unsigned int filter)
{
snd_seq_client_info_t info;
int err;
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
return err;
info.filter = filter;
return snd_seq_set_client_info(seq, &info);
}
/**
* \brief set client event filter
* \brief add client event filter
* \param seq sequencer handle
* \param event_type event type to be added
* \return 0 on success or negative error code
*/
int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type)
{
@ -349,15 +229,18 @@ int snd_seq_set_client_event_filter(snd_seq_t *seq, int event_type)
if ((err = snd_seq_get_client_info(seq, &info)) < 0)
return err;
info.filter |= SND_SEQ_FILTER_USE_EVENT;
info.filter |= SNDRV_SEQ_FILTER_USE_EVENT;
snd_seq_set_bit(event_type, info.event_filter);
return snd_seq_set_client_info(seq, &info);
}
/**
* \brief change the output pool size of the given client
* \param seq sequencer handle
* \param size output pool size
* \return 0 on success or negative error code
*/
int snd_seq_set_client_pool_output(snd_seq_t *seq, int size)
int snd_seq_set_client_pool_output(snd_seq_t *seq, size_t size)
{
snd_seq_client_pool_t info;
int err;
@ -370,8 +253,11 @@ int snd_seq_set_client_pool_output(snd_seq_t *seq, int size)
/**
* \brief change the output room size of the given client
* \param seq sequencer handle
* \param size output room size
* \return 0 on success or negative error code
*/
int snd_seq_set_client_pool_output_room(snd_seq_t *seq, int size)
int snd_seq_set_client_pool_output_room(snd_seq_t *seq, size_t size)
{
snd_seq_client_pool_t info;
int err;
@ -384,8 +270,11 @@ int snd_seq_set_client_pool_output_room(snd_seq_t *seq, int size)
/**
* \brief change the input pool size of the given client
* \param seq sequencer handle
* \param size input pool size
* \return 0 on success or negative error code
*/
int snd_seq_set_client_pool_input(snd_seq_t *seq, int size)
int snd_seq_set_client_pool_input(snd_seq_t *seq, size_t size)
{
snd_seq_client_pool_t info;
int err;
@ -398,27 +287,74 @@ int snd_seq_set_client_pool_input(snd_seq_t *seq, int size)
/**
* \brief reset client output pool
* \param seq sequencer handle
* \return 0 on success or negative error code
*/
int snd_seq_reset_pool_output(snd_seq_t *seq)
{
snd_seq_remove_events_t rmp;
struct sndrv_seq_remove_events rmp;
memset(&rmp, 0, sizeof(rmp));
rmp.output = 1;
rmp.remove_mode = 0; /* remove all */
rmp.remove_mode = SNDRV_SEQ_REMOVE_OUTPUT; /* remove all outputs */
return snd_seq_remove_events(seq, &rmp);
}
/**
* \brief reset client input pool
* \param seq sequencer handle
* \return 0 on success or negative error code
*/
int snd_seq_reset_pool_input(snd_seq_t *seq)
{
snd_seq_remove_events_t rmp;
memset(&rmp, 0, sizeof(rmp));
rmp.input = 1;
rmp.remove_mode = 0; /* remove all */
rmp.remove_mode = SNDRV_SEQ_REMOVE_INPUT; /* remove all inputs */
return snd_seq_remove_events(seq, &rmp);
}
/**
* \brief parse the given string and get the sequencer address
* \param seq sequencer handle
* \param addr the address pointer to be returned
* \param arg the string to be parsed
* \return 0 on success or negative error code
*/
int snd_seq_parse_address(snd_seq_t *seq, snd_seq_addr_t *addr, const char *arg)
{
char *p;
int client, port;
assert(seq && addr && arg);
if ((p = strpbrk(arg, ":.")) == NULL)
return -EINVAL;
if ((port = atoi(p + 1)) < 0)
return -EINVAL;
addr->port = port;
if (isdigit(*arg)) {
client = atoi(arg);
if (client < 0)
return -EINVAL;
addr->client = client;
} else {
/* convert from the name */
snd_seq_client_info_t cinfo;
int len;
*p = 0;
len = (int)(p - arg); /* length of client name */
if (len <= 0)
return -EINVAL;
cinfo.client = -1;
while (snd_seq_query_next_client(seq, &cinfo) >= 0) {
if (! strncmp(cinfo.name, arg, len)) {
addr->client = cinfo.client;
return 0;
}
}
return -ENOENT; /* not found */
}
return 0;
}

View file

@ -114,13 +114,11 @@ static void write_ev(snd_seq_event_t *ev)
return;
}
while ((rc = snd_seq_event_output(seq_handle, ev)) < 0) {
int seqfd;
fd_set fds;
seqfd = snd_seq_poll_descriptor(seq_handle);
FD_ZERO(&fds);
FD_SET(seqfd, &fds);
if ((rc = select(seqfd + 1, NULL, &fds, NULL, NULL)) < 0) {
printf("select error = %i (%s)\n", rc, snd_strerror(rc));
int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLOUT);
struct pollfd *pfds = alloca(sizeof(*pfds) * npfds);
snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLOUT);
if ((rc = poll(pfds, npfds, -1)) < 0) {
printf("poll error = %i (%s)\n", rc, snd_strerror(errno));
exit(1);
}
}
@ -147,7 +145,7 @@ static void mytext(int type, int leng, char *msg)
static void do_header(int format, int ntracks, int division)
{
snd_seq_queue_tempo_t tempo;
snd_seq_queue_tempo_t *tempo;
if (verbose >= VERB_INFO)
printf("smf format %d, %d tracks, %d ppq\n", format, ntracks, division);
@ -159,15 +157,16 @@ static void do_header(int format, int ntracks, int division)
exit(1);
}
/* set ppq */
snd_seq_queue_tempo_alloca(&tempo);
/* ppq must be set before starting timer */
if (snd_seq_get_queue_tempo(seq_handle, dest_queue, &tempo) < 0) {
if (snd_seq_get_queue_tempo(seq_handle, dest_queue, tempo) < 0) {
perror("get_queue_tempo");
exit(1);
}
if (tempo.ppq != ppq) {
slave_ppq = tempo.ppq;
tempo.ppq = ppq;
if (snd_seq_set_queue_tempo(seq_handle, dest_queue, &tempo) < 0) {
if (snd_seq_queue_tempo_get_ppq(tempo) != ppq) {
slave_ppq = snd_seq_queue_tempo_get_ppq(tempo);
snd_seq_queue_tempo_set_ppq(tempo, ppq);
if (snd_seq_set_queue_tempo(seq_handle, dest_queue, tempo) < 0) {
perror("set_queue_tempo");
if (!slave)
exit(1);
@ -176,7 +175,7 @@ static void do_header(int format, int ntracks, int division)
} else
slave_ppq = ppq;
if (verbose >= VERB_INFO)
printf("ALSA Timer updated, PPQ = %d\n", tempo.ppq);
printf("ALSA Timer updated, PPQ = %d\n", snd_seq_queue_tempo_get_ppq(tempo));
}
/* start playing... */
@ -364,13 +363,11 @@ static snd_seq_event_t *wait_for_event(void)
/* read event - using select syscall */
while ((left = snd_seq_event_input(seq_handle, &input_event)) >= 0 &&
input_event == NULL) {
int seqfd;
fd_set fds;
seqfd = snd_seq_poll_descriptor(seq_handle);
FD_ZERO(&fds);
FD_SET(seqfd, &fds);
if ((left = select(seqfd + 1, &fds, NULL, NULL, NULL)) < 0) {
printf("select error = %i (%s)\n", left, snd_strerror(left));
int npfds = snd_seq_poll_descriptors_count(seq_handle, POLLIN);
struct pollfd *pfds = alloca(sizeof(*pfds) * npfds);
snd_seq_poll_descriptors(seq_handle, pfds, npfds, POLLIN);
if ((left = poll(pfds, npfds, -1)) < 0) {
printf("poll error = %i (%s)\n", errno, snd_strerror(errno));
exit(1);
}
}
@ -525,13 +522,13 @@ int main(int argc, char *argv[])
/* open sequencer device */
/* Here we open the device read/write mode. */
/* Because we write SND_SEQ_EVENT_ECHO to myself to sync. */
tmp = snd_seq_open(&seq_handle, SND_SEQ_OPEN);
tmp = snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0);
if (tmp < 0) {
perror("open /dev/snd/seq");
exit(1);
}
tmp = snd_seq_block_mode(seq_handle, use_blocking_mode);
tmp = snd_seq_nonblock(seq_handle, !use_blocking_mode);
if (tmp < 0) {
perror("block_mode");
exit(1);
@ -557,7 +554,7 @@ int main(int argc, char *argv[])
/* setup queue */
if (dest_queue >= 0) {
if (snd_seq_use_queue(seq_handle, dest_queue, 1) < 0) {
if (snd_seq_set_queue_usage(seq_handle, dest_queue, 1) < 0) {
perror("use queue");
exit(1);
}
@ -580,7 +577,7 @@ int main(int argc, char *argv[])
if (slave) {
tmp = snd_seq_connect_from(seq_handle, my_port,
SND_SEQ_CLIENT_SYSTEM,
snd_seq_queue_sync_port(dest_queue));
dest_queue + 16 /*snd_seq_queue_sync_port(dest_queue)*/);
if (tmp < 0) {
perror("subscribe");
exit(1);

View file

@ -3,262 +3,99 @@
*/
static char *event_names[256] = {
/* 0 */ "System",
/* 1 */ "Result",
/* 2 */ "Reserved 2",
/* 3 */ "Reserved 3",
/* 4 */ "Reserved 4",
/* 5 */ "Note",
/* 6 */ "Note On",
/* 7 */ "Note Off",
/* 8 */ "Key Pressure",
/* 9 */ "Reserved 9",
/* 10 */ "Controller",
/* 11 */ "Program Change",
/* 12 */ "Channel Pressure",
/* 13 */ "Pitchbend",
/* 14 */ "Control14",
/* 15 */ "Nonregparam",
/* 16 */ "Regparam",
/* 17 */ "Reserved 17",
/* 18 */ "Reserved 18",
/* 19 */ "Reserved 19",
/* 20 */ "Song Position",
/* 21 */ "Song Select",
/* 22 */ "Qframe",
/* 23 */ "SMF Time Signature",
/* 24 */ "SMF Key Signature",
/* 25 */ "Reserved 25",
/* 26 */ "Reserved 26",
/* 27 */ "Reserved 27",
/* 28 */ "Reserved 28",
/* 29 */ "Reserved 29",
/* 30 */ "Start",
/* 31 */ "Continue",
/* 32 */ "Stop",
/* 33 */ "Set Position Tick",
/* 34 */ "Set Position Time",
/* 35 */ "Tempo",
/* 36 */ "Clock",
/* 37 */ "Tick",
/* 38 */ "Reserved 38",
/* 39 */ "Reserved 39",
/* 40 */ "Tune Request",
/* 41 */ "Reset",
/* 42 */ "Active Sensing",
/* 43 */ "Reserved 43",
/* 44 */ "Reserved 44",
/* 45 */ "Reserved 45",
/* 46 */ "Reserved 46",
/* 47 */ "Reserved 47",
/* 48 */ "Reserved 48",
/* 49 */ "Reserved 49",
/* 50 */ "Echo",
/* 51 */ "OSS",
/* 52 */ "Reserved 52",
/* 53 */ "Reserved 53",
/* 54 */ "Reserved 54",
/* 55 */ "Reserved 55",
/* 56 */ "Reserved 56",
/* 57 */ "Reserved 57",
/* 58 */ "Reserved 58",
/* 59 */ "Reserved 59",
/* 60 */ "Client Start",
/* 61 */ "Client Exit",
/* 62 */ "Client Change",
/* 63 */ "Port Start",
/* 64 */ "Port Exit",
/* 65 */ "Port Change",
/* 66 */ "Port Subscribed",
/* 67 */ "Port Used",
/* 68 */ "Port Unsubscribed",
/* 69 */ "Port Unused",
/* 70 */ "Sample",
/* 71 */ "Sample Cluster",
/* 72 */ "Sample Start",
/* 73 */ "Sample Stop",
/* 74 */ "Sample Freq",
/* 75 */ "Sample Volume",
/* 76 */ "Sample Loop",
/* 77 */ "Sample Position",
/* 78 */ "Sample Private1",
/* 79 */ "Reserved 79",
/* 80 */ "Reserved 80",
/* 81 */ "Reserved 81",
/* 82 */ "Reserved 82",
/* 83 */ "Reserved 83",
/* 84 */ "Reserved 84",
/* 85 */ "Reserved 85",
/* 86 */ "Reserved 86",
/* 87 */ "Reserved 87",
/* 88 */ "Reserved 88",
/* 89 */ "Reserved 89",
/* 90 */ "User 0",
/* 91 */ "User 1",
/* 92 */ "User 2",
/* 93 */ "User 3",
/* 94 */ "User 4",
/* 95 */ "User 5",
/* 96 */ "User 6",
/* 97 */ "User 7",
/* 98 */ "User 8",
/* 99 */ "User 9",
/* 100 */ "Instr Begin",
/* 101 */ "Instr End",
/* 102 */ "Instr Info",
/* 103 */ "Instr Info Result",
/* 104 */ "Instr Finfo",
/* 105 */ "Instr Finfo Result",
/* 106 */ "Instr Reset",
/* 107 */ "Instr Status",
/* 108 */ "Instr Status Result",
/* 109 */ "Instr Put",
/* 110 */ "Instr Get",
/* 111 */ "Instr Get Result",
/* 112 */ "Instr Free",
/* 113 */ "Instr List",
/* 114 */ "Instr List Result",
/* 115 */ "Instr Cluster",
/* 116 */ "Instr Cluster Get",
/* 117 */ "Instr Cluster Result",
/* 118 */ "Instr Change",
/* 119 */ "Reserved 119",
/* 120 */ "Reserved 120",
/* 121 */ "Reserved 121",
/* 122 */ "Reserved 122",
/* 123 */ "Reserved 123",
/* 124 */ "Reserved 124",
/* 125 */ "Reserved 125",
/* 126 */ "Reserved 126",
/* 127 */ "Reserved 127",
/* 128 */ "Reserved 128",
/* 129 */ "Reserved 129",
/* 130 */ "Sysex",
/* 131 */ "Bounce",
/* 132 */ "Reserved 132",
/* 133 */ "Reserved 133",
/* 134 */ "Reserved 134",
/* 135 */ "User Var0",
/* 136 */ "User Var1",
/* 137 */ "User Var2",
/* 138 */ "User Var3",
/* 139 */ "User Var4",
/* 140 */ "IPC Shm",
/* 141 */ "Reserved 141",
/* 142 */ "Reserved 142",
/* 143 */ "Reserved 143",
/* 144 */ "Reserved 144",
/* 145 */ "User IPC0",
/* 146 */ "User IPC1",
/* 147 */ "User IPC2",
/* 148 */ "User IPC3",
/* 149 */ "User IPC4",
/* 150 */ "Reserved 150",
/* 151 */ "Reserved 151",
/* 152 */ "Reserved 152",
/* 153 */ "Reserved 153",
/* 154 */ "Reserved 154",
/* 155 */ "Reserved 155",
/* 156 */ "Reserved 156",
/* 157 */ "Reserved 157",
/* 158 */ "Reserved 158",
/* 159 */ "Reserved 159",
/* 160 */ "Reserved 160",
/* 161 */ "Reserved 161",
/* 162 */ "Reserved 162",
/* 163 */ "Reserved 163",
/* 164 */ "Reserved 164",
/* 165 */ "Reserved 165",
/* 166 */ "Reserved 166",
/* 167 */ "Reserved 167",
/* 168 */ "Reserved 168",
/* 169 */ "Reserved 169",
/* 170 */ "Reserved 170",
/* 171 */ "Reserved 171",
/* 172 */ "Reserved 172",
/* 173 */ "Reserved 173",
/* 174 */ "Reserved 174",
/* 175 */ "Reserved 175",
/* 176 */ "Reserved 176",
/* 177 */ "Reserved 177",
/* 178 */ "Reserved 178",
/* 179 */ "Reserved 179",
/* 180 */ "Reserved 180",
/* 181 */ "Reserved 181",
/* 182 */ "Reserved 182",
/* 183 */ "Reserved 183",
/* 184 */ "Reserved 184",
/* 185 */ "Reserved 185",
/* 186 */ "Reserved 186",
/* 187 */ "Reserved 187",
/* 188 */ "Reserved 188",
/* 189 */ "Reserved 189",
/* 190 */ "Reserved 190",
/* 191 */ "Reserved 191",
/* 192 */ "Reserved 192",
/* 193 */ "Reserved 193",
/* 194 */ "Reserved 194",
/* 195 */ "Reserved 195",
/* 196 */ "Reserved 196",
/* 197 */ "Reserved 197",
/* 198 */ "Reserved 198",
/* 199 */ "Reserved 199",
/* 200 */ "Reserved 200",
/* 201 */ "Reserved 201",
/* 202 */ "Reserved 202",
/* 203 */ "Reserved 203",
/* 204 */ "Reserved 204",
/* 205 */ "Reserved 205",
/* 206 */ "Reserved 206",
/* 207 */ "Reserved 207",
/* 208 */ "Reserved 208",
/* 209 */ "Reserved 209",
/* 210 */ "Reserved 210",
/* 211 */ "Reserved 211",
/* 212 */ "Reserved 212",
/* 213 */ "Reserved 213",
/* 214 */ "Reserved 214",
/* 215 */ "Reserved 215",
/* 216 */ "Reserved 216",
/* 217 */ "Reserved 217",
/* 218 */ "Reserved 218",
/* 219 */ "Reserved 219",
/* 220 */ "Reserved 220",
/* 221 */ "Reserved 221",
/* 222 */ "Reserved 222",
/* 223 */ "Reserved 223",
/* 224 */ "Reserved 224",
/* 225 */ "Reserved 225",
/* 226 */ "Reserved 226",
/* 227 */ "Reserved 227",
/* 228 */ "Reserved 228",
/* 229 */ "Reserved 229",
/* 230 */ "Reserved 230",
/* 231 */ "Reserved 231",
/* 232 */ "Reserved 232",
/* 233 */ "Reserved 233",
/* 234 */ "Reserved 234",
/* 235 */ "Reserved 235",
/* 236 */ "Reserved 236",
/* 237 */ "Reserved 237",
/* 238 */ "Reserved 238",
/* 239 */ "Reserved 239",
/* 240 */ "Reserved 240",
/* 241 */ "Reserved 241",
/* 242 */ "Reserved 242",
/* 243 */ "Reserved 243",
/* 244 */ "Reserved 244",
/* 245 */ "Reserved 245",
/* 246 */ "Reserved 246",
/* 247 */ "Reserved 247",
/* 248 */ "Reserved 248",
/* 249 */ "Reserved 249",
/* 250 */ "Reserved 250",
/* 251 */ "Reserved 251",
/* 252 */ "Reserved 252",
/* 253 */ "Reserved 253",
/* 254 */ "Reserved 254",
/* 255 */ "None"
[SND_SEQ_EVENT_SYSTEM]= "System",
[SND_SEQ_EVENT_RESULT]= "Result",
[SND_SEQ_EVENT_NOTE]= "Note",
[SND_SEQ_EVENT_NOTEON]= "Note On",
[SND_SEQ_EVENT_NOTEOFF]= "Note Off",
[SND_SEQ_EVENT_KEYPRESS]= "Key Pressure",
[SND_SEQ_EVENT_CONTROLLER]= "Controller",
[SND_SEQ_EVENT_PGMCHANGE]= "Program Change",
[SND_SEQ_EVENT_CHANPRESS]= "Channel Pressure",
[SND_SEQ_EVENT_PITCHBEND]= "Pitchbend",
[SND_SEQ_EVENT_CONTROL14]= "Control14",
[SND_SEQ_EVENT_NONREGPARAM]= "Nonregparam",
[SND_SEQ_EVENT_REGPARAM]= "Regparam",
[SND_SEQ_EVENT_SONGPOS]= "Song Position",
[SND_SEQ_EVENT_SONGSEL]= "Song Select",
[SND_SEQ_EVENT_QFRAME]= "Qframe",
[SND_SEQ_EVENT_TIMESIGN]= "SMF Time Signature",
[SND_SEQ_EVENT_KEYSIGN]= "SMF Key Signature",
[SND_SEQ_EVENT_START]= "Start",
[SND_SEQ_EVENT_CONTINUE]= "Continue",
[SND_SEQ_EVENT_STOP]= "Stop",
[SND_SEQ_EVENT_SETPOS_TICK]= "Set Position Tick",
[SND_SEQ_EVENT_SETPOS_TIME]= "Set Position Time",
[SND_SEQ_EVENT_TEMPO]= "Tempo",
[SND_SEQ_EVENT_CLOCK]= "Clock",
[SND_SEQ_EVENT_TICK]= "Tick",
[SND_SEQ_EVENT_SYNC]= "Sync",
[SND_SEQ_EVENT_SYNC_POS]= "Sync Position",
[SND_SEQ_EVENT_TUNE_REQUEST]= "Tune Request",
[SND_SEQ_EVENT_RESET]= "Reset",
[SND_SEQ_EVENT_SENSING]= "Active Sensing",
[SND_SEQ_EVENT_ECHO]= "Echo",
[SND_SEQ_EVENT_OSS]= "OSS",
[SND_SEQ_EVENT_CLIENT_START]= "Client Start",
[SND_SEQ_EVENT_CLIENT_EXIT]= "Client Exit",
[SND_SEQ_EVENT_CLIENT_CHANGE]= "Client Change",
[SND_SEQ_EVENT_PORT_START]= "Port Start",
[SND_SEQ_EVENT_PORT_EXIT]= "Port Exit",
[SND_SEQ_EVENT_PORT_CHANGE]= "Port Change",
[SND_SEQ_EVENT_PORT_SUBSCRIBED]= "Port Subscribed",
[SND_SEQ_EVENT_PORT_UNSUBSCRIBED]= "Port Unsubscribed",
[SND_SEQ_EVENT_SAMPLE]= "Sample",
[SND_SEQ_EVENT_SAMPLE_CLUSTER]= "Sample Cluster",
[SND_SEQ_EVENT_SAMPLE_START]= "Sample Start",
[SND_SEQ_EVENT_SAMPLE_STOP]= "Sample Stop",
[SND_SEQ_EVENT_SAMPLE_FREQ]= "Sample Freq",
[SND_SEQ_EVENT_SAMPLE_VOLUME]= "Sample Volume",
[SND_SEQ_EVENT_SAMPLE_LOOP]= "Sample Loop",
[SND_SEQ_EVENT_SAMPLE_POSITION]= "Sample Position",
[SND_SEQ_EVENT_SAMPLE_PRIVATE1]= "Sample Private1",
[SND_SEQ_EVENT_USR0]= "User 0",
[SND_SEQ_EVENT_USR1]= "User 1",
[SND_SEQ_EVENT_USR2]= "User 2",
[SND_SEQ_EVENT_USR3]= "User 3",
[SND_SEQ_EVENT_USR4]= "User 4",
[SND_SEQ_EVENT_USR5]= "User 5",
[SND_SEQ_EVENT_USR6]= "User 6",
[SND_SEQ_EVENT_USR7]= "User 7",
[SND_SEQ_EVENT_USR8]= "User 8",
[SND_SEQ_EVENT_USR9]= "User 9",
[SND_SEQ_EVENT_INSTR_BEGIN]= "Instr Begin",
[SND_SEQ_EVENT_INSTR_END]= "Instr End",
[SND_SEQ_EVENT_INSTR_INFO]= "Instr Info",
[SND_SEQ_EVENT_INSTR_INFO_RESULT]= "Instr Info Result",
[SND_SEQ_EVENT_INSTR_FINFO]= "Instr Font Info",
[SND_SEQ_EVENT_INSTR_FINFO_RESULT]= "Instr Font Info Result",
[SND_SEQ_EVENT_INSTR_RESET]= "Instr Reset",
[SND_SEQ_EVENT_INSTR_STATUS]= "Instr Status",
[SND_SEQ_EVENT_INSTR_STATUS_RESULT]= "Instr Status Result",
[SND_SEQ_EVENT_INSTR_PUT]= "Instr Put",
[SND_SEQ_EVENT_INSTR_GET]= "Instr Get",
[SND_SEQ_EVENT_INSTR_GET_RESULT]= "Instr Get Result",
[SND_SEQ_EVENT_INSTR_FREE]= "Instr Free",
[SND_SEQ_EVENT_INSTR_LIST]= "Instr List",
[SND_SEQ_EVENT_INSTR_LIST_RESULT]= "Instr List Result",
[SND_SEQ_EVENT_INSTR_CLUSTER]= "Instr Cluster",
[SND_SEQ_EVENT_INSTR_CLUSTER_GET]= "Instr Cluster Get",
[SND_SEQ_EVENT_INSTR_CLUSTER_RESULT]= "Instr Cluster Result",
[SND_SEQ_EVENT_INSTR_CHANGE]= "Instr Change",
[SND_SEQ_EVENT_SYSEX]= "Sysex",
[SND_SEQ_EVENT_BOUNCE]= "Bounce",
[SND_SEQ_EVENT_USR_VAR0]= "User Var0",
[SND_SEQ_EVENT_USR_VAR1]= "User Var1",
[SND_SEQ_EVENT_USR_VAR2]= "User Var2",
[SND_SEQ_EVENT_USR_VAR3]= "User Var3",
[SND_SEQ_EVENT_USR_VAR4]= "User Var4",
[SND_SEQ_EVENT_IPCSHM]= "IPC Shm",
[SND_SEQ_EVENT_USR_VARIPC0]= "User IPC0",
[SND_SEQ_EVENT_USR_VARIPC1]= "User IPC1",
[SND_SEQ_EVENT_USR_VARIPC2]= "User IPC2",
[SND_SEQ_EVENT_USR_VARIPC3]= "User IPC3",
[SND_SEQ_EVENT_USR_VARIPC4]= "User IPC4",
[SND_SEQ_EVENT_NONE]= "None",
};
int decode_event(snd_seq_event_t * ev)
@ -267,15 +104,15 @@ int decode_event(snd_seq_event_t * ev)
printf("EVENT>>> Type = %d, flags = 0x%x", ev->type, ev->flags);
switch (ev->flags & SND_SEQ_TIME_STAMP_MASK) {
case SND_SEQ_TIME_STAMP_TICK:
printf(", time = %d ticks",
ev->time.tick);
break;
case SND_SEQ_TIME_STAMP_REAL:
printf(", time = %d.%09d",
(int)ev->time.time.tv_sec,
(int)ev->time.time.tv_nsec);
break;
case SND_SEQ_TIME_STAMP_TICK:
printf(", time = %d ticks",
ev->time.tick);
break;
case SND_SEQ_TIME_STAMP_REAL:
printf(", time = %d.%09d",
(int)ev->time.time.tv_sec,
(int)ev->time.time.tv_nsec);
break;
}
printf("\n%sSource = %d.%d, dest = %d.%d, queue = %d\n",
space,
@ -285,114 +122,120 @@ int decode_event(snd_seq_event_t * ev)
ev->dest.port,
ev->queue);
printf("%sEvent = %s", space, event_names[ev->type]);
if (event_names[ev->type])
printf("%sEvent = %s", space, event_names[ev->type]);
else
printf("%sEvent = Reserved %d\n", space, ev->type);
/* decode actual event data... */
switch (ev->type) {
case SND_SEQ_EVENT_NOTE:
printf("; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
ev->data.note.channel,
ev->data.note.note,
ev->data.note.velocity,
ev->data.note.off_velocity,
ev->data.note.duration);
break;
case SND_SEQ_EVENT_NOTE:
printf("; ch=%d, note=%d, velocity=%d, off_velocity=%d, duration=%d\n",
ev->data.note.channel,
ev->data.note.note,
ev->data.note.velocity,
ev->data.note.off_velocity,
ev->data.note.duration);
break;
case SND_SEQ_EVENT_NOTEON:
case SND_SEQ_EVENT_NOTEOFF:
case SND_SEQ_EVENT_KEYPRESS:
printf("; ch=%d, note=%d, velocity=%d\n",
ev->data.note.channel,
ev->data.note.note,
ev->data.note.velocity);
break;
case SND_SEQ_EVENT_NOTEON:
case SND_SEQ_EVENT_NOTEOFF:
case SND_SEQ_EVENT_KEYPRESS:
printf("; ch=%d, note=%d, velocity=%d\n",
ev->data.note.channel,
ev->data.note.note,
ev->data.note.velocity);
break;
case SND_SEQ_EVENT_CONTROLLER:
printf("; ch=%d, param=%i, value=%i\n",
ev->data.control.channel,
ev->data.control.param,
ev->data.control.value);
break;
case SND_SEQ_EVENT_CONTROLLER:
printf("; ch=%d, param=%i, value=%i\n",
ev->data.control.channel,
ev->data.control.param,
ev->data.control.value);
break;
case SND_SEQ_EVENT_PGMCHANGE:
printf("; ch=%d, program=%i\n",
ev->data.control.channel,
ev->data.control.value);
break;
case SND_SEQ_EVENT_PGMCHANGE:
printf("; ch=%d, program=%i\n",
ev->data.control.channel,
ev->data.control.value);
break;
case SND_SEQ_EVENT_CHANPRESS:
case SND_SEQ_EVENT_PITCHBEND:
printf("; ch=%d, value=%i\n",
ev->data.control.channel,
ev->data.control.value);
break;
case SND_SEQ_EVENT_CHANPRESS:
case SND_SEQ_EVENT_PITCHBEND:
printf("; ch=%d, value=%i\n",
ev->data.control.channel,
ev->data.control.value);
break;
case SND_SEQ_EVENT_SYSEX:
{
unsigned char *sysex = (unsigned char *) ev + sizeof(snd_seq_event_t);
int c;
case SND_SEQ_EVENT_SYSEX:
{
unsigned char *sysex = (unsigned char *) ev + sizeof(snd_seq_event_t);
unsigned int c;
printf("; len=%d [", ev->data.ext.len);
printf("; len=%d [", ev->data.ext.len);
for (c = 0; c < ev->data.ext.len; c++) {
printf("%02x%s", sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
}
printf("]\n");
for (c = 0; c < ev->data.ext.len; c++) {
printf("%02x%s", sysex[c], c < ev->data.ext.len - 1 ? ":" : "");
}
break;
printf("]\n");
}
break;
case SND_SEQ_EVENT_QFRAME:
printf("; frame=0x%02x\n", ev->data.control.value);
break;
case SND_SEQ_EVENT_QFRAME:
printf("; frame=0x%02x\n", ev->data.control.value);
break;
case SND_SEQ_EVENT_CLOCK:
case SND_SEQ_EVENT_START:
case SND_SEQ_EVENT_CONTINUE:
case SND_SEQ_EVENT_STOP:
printf("; queue = %i\n", ev->data.queue.queue);
break;
case SND_SEQ_EVENT_CLOCK:
case SND_SEQ_EVENT_START:
case SND_SEQ_EVENT_CONTINUE:
case SND_SEQ_EVENT_STOP:
printf("; queue = %i\n", ev->data.queue.queue);
break;
case SND_SEQ_EVENT_SENSING:
printf("\n");
break;
case SND_SEQ_EVENT_SENSING:
printf("\n");
break;
case SND_SEQ_EVENT_ECHO:
{
int i;
case SND_SEQ_EVENT_ECHO:
{
int i;
printf("; ");
for (i = 0; i < 8; i++) {
printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
}
}
break;
printf("; ");
for (i = 0; i < 8; i++) {
printf("%02i%s", ev->data.raw8.d[i], i < 7 ? ":" : "\n");
}
}
break;
case SND_SEQ_EVENT_CLIENT_START:
case SND_SEQ_EVENT_CLIENT_EXIT:
case SND_SEQ_EVENT_CLIENT_CHANGE:
printf("; client=%i\n", ev->data.addr.client);
break;
case SND_SEQ_EVENT_CLIENT_START:
case SND_SEQ_EVENT_CLIENT_EXIT:
case SND_SEQ_EVENT_CLIENT_CHANGE:
printf("; client=%i\n", ev->data.addr.client);
break;
case SND_SEQ_EVENT_PORT_START:
case SND_SEQ_EVENT_PORT_EXIT:
case SND_SEQ_EVENT_PORT_CHANGE:
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
case SND_SEQ_EVENT_PORT_USED:
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
case SND_SEQ_EVENT_PORT_UNUSED:
printf("; client=%i, port = %i\n", ev->data.addr.client, ev->data.addr.port);
break;
case SND_SEQ_EVENT_PORT_START:
case SND_SEQ_EVENT_PORT_EXIT:
case SND_SEQ_EVENT_PORT_CHANGE:
printf("; client=%i, port = %i\n", ev->data.addr.client, ev->data.addr.port);
break;
default:
printf("; not implemented\n");
case SND_SEQ_EVENT_PORT_SUBSCRIBED:
case SND_SEQ_EVENT_PORT_UNSUBSCRIBED:
printf("; %i:%i -> %i:%i\n",
ev->data.connect.sender.client, ev->data.connect.sender.port,
ev->data.connect.dest.client, ev->data.connect.dest.port);
break;
default:
printf("; not implemented\n");
}
switch (ev->flags & SND_SEQ_EVENT_LENGTH_MASK) {
case SND_SEQ_EVENT_LENGTH_FIXED:
return sizeof(snd_seq_event_t);
case SND_SEQ_EVENT_LENGTH_FIXED:
return sizeof(snd_seq_event_t);
case SND_SEQ_EVENT_LENGTH_VARIABLE:
return sizeof(snd_seq_event_t) + ev->data.ext.len;
case SND_SEQ_EVENT_LENGTH_VARIABLE:
return sizeof(snd_seq_event_t) + ev->data.ext.len;
}
return 0;
@ -411,11 +254,12 @@ void event_decoder_start_timer(snd_seq_t *handle, int queue, int client, int por
void event_decoder(snd_seq_t *handle, int argc, char *argv[])
{
snd_seq_event_t *ev;
snd_seq_port_info_t port;
snd_seq_port_subscribe_t sub;
fd_set in;
int client, queue, max, err, v1, v2;
snd_seq_port_info_t *pinfo;
snd_seq_port_subscribe_t *sub;
snd_seq_addr_t addr;
int client, port, queue, max, err, v1, v2;
char *ptr;
struct pollfd *pfds;
if ((client = snd_seq_client_id(handle))<0) {
fprintf(stderr, "Cannot determine client number: %s\n", snd_strerror(client));
@ -427,33 +271,37 @@ void event_decoder(snd_seq_t *handle, int argc, char *argv[])
return;
}
printf("Queue ID = %i\n", queue);
if ((err = snd_seq_block_mode(handle, 0))<0)
if ((err = snd_seq_nonblock(handle, 1))<0)
fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err));
bzero(&port, sizeof(port));
strcpy(port.name, "Input");
port.capability = SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ;
port.capability |= SND_SEQ_PORT_CAP_SUBS_WRITE;
if ((err = snd_seq_create_port(handle, &port)) < 0) {
snd_seq_port_info_alloca(&pinfo);
snd_seq_port_info_set_name(pinfo, "Input");
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_WRITE);
if ((err = snd_seq_create_port(handle, pinfo)) < 0) {
fprintf(stderr, "Cannot create input port: %s\n", snd_strerror(err));
return;
}
event_decoder_start_timer(handle, queue, client, port.port);
port = snd_seq_port_info_get_port(pinfo);
event_decoder_start_timer(handle, queue, client, port);
bzero(&sub, sizeof(sub));
sub.sender.client = SND_SEQ_CLIENT_SYSTEM;
sub.sender.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
sub.dest.client = client;
sub.dest.port = port.port;
sub.queue = queue;
sub.exclusive = 0;
sub.convert_time = 1;
sub.realtime = 1;
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
snd_seq_port_subscribe_alloca(&sub);
addr.client = SND_SEQ_CLIENT_SYSTEM;
addr.port = SND_SEQ_PORT_SYSTEM_ANNOUNCE;
snd_seq_port_subscribe_set_sender(sub, &addr);
addr.client = client;
addr.port = port;
snd_seq_port_subscribe_set_dest(sub, &addr);
snd_seq_port_subscribe_set_queue(sub, queue);
snd_seq_port_subscribe_set_time_update(sub, 1);
snd_seq_port_subscribe_set_time_real(sub, 1);
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
fprintf(stderr, "Cannot subscribe announce port: %s\n", snd_strerror(err));
return;
}
sub.sender.port = SND_SEQ_PORT_SYSTEM_TIMER;
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
addr.client = SND_SEQ_CLIENT_SYSTEM;
addr.port = SND_SEQ_PORT_SYSTEM_TIMER;
snd_seq_port_subscribe_set_sender(sub, &addr);
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
fprintf(stderr, "Cannot subscribe timer port: %s\n", snd_strerror(err));
return;
}
@ -462,27 +310,29 @@ void event_decoder(snd_seq_t *handle, int argc, char *argv[])
ptr = argv[max];
if (!ptr)
continue;
sub.realtime = 0;
snd_seq_port_subscribe_set_time_real(sub, 0);
if (tolower(*ptr) == 'r') {
sub.realtime = 1;
snd_seq_port_subscribe_set_time_real(sub, 1);
ptr++;
}
if (sscanf(ptr, "%i.%i", &v1, &v2) != 2) {
fprintf(stderr, "Wrong argument '%s'...\n", argv[max]);
return;
}
sub.sender.client = v1;
sub.sender.port = v2;
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
addr.client = v1;
addr.port = v2;
snd_seq_port_subscribe_set_sender(sub, &addr);
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err));
return;
}
}
max = snd_seq_poll_descriptors_count(handle, POLLIN);
pfds = alloca(sizeof(*pfds) * max);
while (1) {
FD_ZERO(&in);
FD_SET(max = snd_seq_poll_descriptor(handle), &in);
if (select(max + 1, &in, NULL, NULL, NULL) < 0)
snd_seq_poll_descriptors(handle, pfds, max, POLLIN);
if (poll(pfds, max, -1) < 0)
break;
do {
if ((err = snd_seq_event_input(handle, &ev))<0)

View file

@ -1,57 +1,65 @@
#ifdef USE_PCM
#ifdef USE_PCM // XXX not yet
/*
* PCM timer layer
*/
int pcard = 0;
int pdevice = 0;
int pfragment_size = 4096;
int period_size = 1024;
void set_format(snd_pcm_t *phandle)
void set_hwparams(snd_pcm_t *phandle)
{
int err;
snd_pcm_format_t format;
snd_pcm_hw_params_t *params;
bzero(&format, sizeof(format));
format.sfmt = SND_PCM_FORMAT_S16_LE;
format.channels = 2;
format.rate = 44100;
if ((err = snd_pcm_playback_format(phandle, &format)) < 0) {
fprintf(stderr, "Playback format error: %s\n", snd_strerror(err));
err = snd_output_stdio_attach(&log, stderr, 0);
if (err < 0) {
fprintf(stderr, "cannot attach output stdio\n");
exit(0);
}
}
void set_fragment(snd_pcm_t *phandle)
{
int err;
snd_pcm_playback_params_t pparams;
bzero(&pparams, sizeof(pparams));
pparams.fragment_size = pfragment_size;
pparams.fragments_max = -1; /* maximum */
pparams.fragments_room = 1;
if ((err = snd_pcm_playback_params(phandle, &pparams)) < 0) {
fprintf(stderr, "Fragment setup error: %s\n", snd_strerror(err));
snd_pcm_hw_params_alloca(&params);
err = snd_pcm_hw_params_any(phandle, params);
if (err < 0) {
fprintf(stderr, "Broken configuration for this PCM: no configurations available\n");
exit(0);
}
}
void show_playback_status(snd_pcm_t *phandle)
{
int err;
snd_pcm_playback_status_t pstatus;
if ((err = snd_pcm_playback_status(phandle, &pstatus)) < 0) {
fprintf(stderr, "Playback status error: %s\n", snd_strerror(err));
err = snd_pcm_hw_params_set_access(phandle, params,
SND_PCM_ACCESS_RW_INTERLEAVED);
if (err < 0) {
fprintf(stderr, "Access type not available\n");
exit(0);
}
printf("Playback status\n");
printf(" Real rate : %u\n", pstatus.rate);
printf(" Fragments : %i\n", pstatus.fragments);
printf(" Fragment size : %i\n", pstatus.fragment_size);
err = snd_pcm_hw_params_set_format(phandle, params, SND_PCM_FORMAT_S16_LE);
if (err < 0) {
fprintf(stderr, "cannot set format\n");
exit(0);
}
err = snd_pcm_hw_params_set_channels(phandle, params, 2);
if (err < 0) {
fprintf(stderr, "cannot set channels 2\n");
exit(0);
}
err = snd_pcm_hw_params_set_rate_near(phandle, params, 44100, 0);
if (err < 0) {
fprintf(stderr, "cannot set rate\n");
exit(0);
}
err = snd_pcm_hw_params_set_period_size_near(phandle, params, period_size);
if (err < 0) {
fprintf(stderr, "cannot set period size\n");
exit(0);
}
err = snd_pcm_hw_params(phandle, params);
if (err < 0) {
fprintf(stderr, "Unable to install hw params:\n");
exit(0);
}
snd_pcm_hw_params_dump(params, log);
}
#endif
/*
* Simple event sender
@ -89,23 +97,15 @@ void event_sender_start_timer(snd_seq_t *handle, int client, int queue, snd_pcm_
void event_sender_filter(snd_seq_t *handle)
{
int err;
snd_seq_client_info_t info;
if ((err = snd_seq_get_client_info(handle, &info)) < 0) {
fprintf(stderr, "Unable to get client info: %s\n", snd_strerror(err));
return;
}
info.filter = SND_SEQ_FILTER_USE_EVENT;
memset(&info.event_filter, 0, sizeof(info.event_filter));
snd_seq_set_bit(SND_SEQ_EVENT_ECHO, info.event_filter);
if ((err = snd_seq_set_client_info(handle, &info)) < 0) {
if ((err = snd_seq_set_client_event_filter(handle, SND_SEQ_EVENT_ECHO)) < 0) {
fprintf(stderr, "Unable to set client info: %s\n", snd_strerror(err));
return;
}
}
void send_event(snd_seq_t *handle, int queue, int client, int port,
snd_seq_port_subscribe_t *sub, int *time)
snd_seq_addr_t *dest, int *time)
{
int err;
snd_seq_event_t ev;
@ -119,8 +119,7 @@ void send_event(snd_seq_t *handle, int queue, int client, int port,
ev.type = SND_SEQ_EVENT_ECHO;
if ((err = snd_seq_event_output(handle, &ev))<0)
fprintf(stderr, "Event output error: %s\n", snd_strerror(err));
ev.dest.client = sub->dest.client;
ev.dest.port = sub->dest.port;
ev.dest = *dest;
ev.type = SND_SEQ_EVENT_PGMCHANGE;
ev.data.control.channel = 0;
ev.data.control.value = 16;
@ -141,10 +140,11 @@ void send_event(snd_seq_t *handle, int queue, int client, int port,
void event_sender(snd_seq_t *handle, int argc, char *argv[])
{
snd_seq_event_t *ev;
snd_seq_port_info_t port;
snd_seq_port_subscribe_t sub;
fd_set out, in;
int client, queue, max, err, v1, v2, time = 0, pcm_flag = 0;
snd_seq_port_info_t *pinfo;
snd_seq_port_subscribe_t *sub;
snd_seq_addr_t addr;
struct pollfd *pfds;
int client, port, queue, max, err, v1, v2, time = 0, pcm_flag = 0;
char *ptr;
snd_pcm_t *phandle = NULL;
@ -164,20 +164,22 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
}
printf("Queue ID = %i\n", queue);
event_sender_filter(handle);
if ((err = snd_seq_block_mode(handle, 0))<0)
if ((err = snd_seq_nonblock(handle, 1))<0)
fprintf(stderr, "Cannot set nonblock mode: %s\n", snd_strerror(err));
bzero(&port, sizeof(port));
port.capability = SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ;
strcpy(port.name, "Output");
if ((err = snd_seq_create_port(handle, &port)) < 0) {
snd_seq_port_info_alloca(&pinfo);
snd_seq_port_info_set_capability(pinfo, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_READ);
snd_seq_port_info_set_name(pinfo, "Output");
if ((err = snd_seq_create_port(handle, pinfo)) < 0) {
fprintf(stderr, "Cannot create output port: %s\n", snd_strerror(err));
return;
}
port = snd_seq_port_info_get_port(pinfo);
bzero(&sub, sizeof(sub));
sub.sender.client = client;
sub.sender.port = port.port;
sub.exclusive = 0;
snd_seq_port_subscribe_alloca(&sub);
addr.client = client;
addr.port = port;
snd_seq_port_subscribe_set_sender(sub, &addr);
for (max = 0; max < argc; max++) {
ptr = argv[max];
@ -191,26 +193,25 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
fprintf(stderr, "Wrong argument '%s'...\n", argv[max]);
return;
}
sub.dest.client = v1;
sub.dest.port = v2;
if ((err = snd_seq_subscribe_port(handle, &sub))<0) {
addr.client = v1;
addr.port = v2;
snd_seq_port_subscribe_set_dest(sub, &addr);
if ((err = snd_seq_subscribe_port(handle, sub))<0) {
fprintf(stderr, "Cannot subscribe port %i from client %i: %s\n", v2, v1, snd_strerror(err));
return;
}
}
printf("Destination client = %i, port = %i\n", sub.dest.client, sub.dest.port);
printf("Destination client = %i, port = %i\n", addr.client, addr.port);
#ifdef USE_PCM
if (pcm_flag) {
if ((err = snd_pcm_open(&phandle, pcard, pdevice, SND_PCM_OPEN_PLAYBACK)) < 0) {
if ((err = snd_pcm_open(&phandle, "default", SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf(stderr, "Playback open error: %s\n", snd_strerror(err));
exit(0);
}
set_format(phandle);
set_fragment(phandle);
show_playback_status(phandle);
pbuf = calloc(1, pfragment_size);
set_hwparams(phandle);
pbuf = calloc(1, period_size * 4);
if (pbuf == NULL) {
fprintf(stderr, "No enough memory...\n");
exit(0);
@ -220,43 +221,46 @@ void event_sender(snd_seq_t *handle, int argc, char *argv[])
event_sender_start_timer(handle, client, queue, phandle);
/* send the first event */
send_event(handle, queue, client, port.port, &sub, &time);
send_event(handle, queue, client, port, &addr, &time);
#ifdef USE_PCM
if (phandle)
max += snd_pcm_poll_descriptors_count(phandle);
#endif
pfds = alloca(sizeof(*pfds) * max);
while (1) {
FD_ZERO(&out);
FD_ZERO(&in);
max = snd_seq_poll_descriptor(handle);
FD_SET(snd_seq_poll_descriptor(handle), &in);
if (snd_seq_event_output_pending(handle)) {
FD_SET(snd_seq_poll_descriptor(handle), &out);
}
int nseqs = snd_seq_poll_descriptors_count(handle, POLLOUT|POLLIN);
if (snd_seq_event_output_pending(handle))
snd_seq_poll_descriptors(handle, pfds, nseqs, POLLOUT|POLLIN);
else
snd_seq_poll_descriptors(handle, pfds, nseqs, POLLIN);
max = nseqs;
#ifdef USE_PCM
if (phandle) {
if (snd_pcm_poll_descriptor(phandle) > max)
max = snd_pcm_poll_descriptor(phandle);
FD_SET(snd_pcm_poll_descriptor(phandle), &out);
int pmax = snd_pcm_poll_descriptors_count(phandle);
snd_seq_poll_descriptors(phandle, pfds + max, pmax);
max += pmax;
}
#endif
if (select(max + 1, &in, &out, NULL, NULL) < 0)
if (poll(pfds, max, -1) < 0)
break;
#ifdef USE_PCM
if (phandle && FD_ISSET(snd_pcm_poll_descriptor(phandle), &out)) {
if (snd_pcm_writei(phandle, pbuf, pfragment_size) != pfragment_size) {
if (phandle && (pfds[nseqs].revents & POLLOUT)) {
if (snd_pcm_writei(phandle, pbuf, period_size) != period_size) {
fprintf(stderr, "Playback write error!!\n");
exit(0);
}
}
#endif
if (FD_ISSET(snd_seq_poll_descriptor(handle), &out))
if (pfds[0].revents & POLLOUT)
snd_seq_drain_output(handle);
if (FD_ISSET(snd_seq_poll_descriptor(handle), &in)) {
if (pfds[0].revents & POLLIN) {
do {
if ((err = snd_seq_event_input(handle, &ev))<0)
break;
if (!ev)
continue;
if (ev->type == SND_SEQ_EVENT_ECHO)
send_event(handle, queue, client, port.port, &sub, &time);
send_event(handle, queue, client, port, &addr, &time);
decode_event(ev);
snd_seq_free_event(ev);
} while (err > 0);

View file

@ -16,20 +16,19 @@
#define HELPID_VERBOSE 1002
#define HELPID_VERSION 1003
snd_seq_system_info_t sysinfo;
int max_clients;
int max_ports;
int max_queues;
int debug = 0;
int verbose = 0;
void set_name(snd_seq_t *handle)
{
int err;
snd_seq_client_info_t info;
char name[64];
bzero(&info, sizeof(info));
info.client = snd_seq_client_id(handle);
info.type = USER_CLIENT;
snprintf(info.name, sizeof(info.name), "SeqUtil - %i", getpid());
if ((err = snd_seq_set_client_info(handle, &info)) < 0) {
sprintf(name, "SeqUtil - %i", getpid());
if ((err = snd_seq_set_client_name(handle, name)) < 0) {
fprintf(stderr, "Set client info error: %s\n", snd_strerror(err));
exit(0);
}
@ -38,78 +37,88 @@ void set_name(snd_seq_t *handle)
void system_info(snd_seq_t *handle)
{
int err;
snd_seq_system_info_t *sysinfo;
if ((err = snd_seq_system_info(handle, &sysinfo))<0) {
snd_seq_system_info_alloca(&sysinfo);
if ((err = snd_seq_system_info(handle, sysinfo))<0) {
fprintf(stderr, "System info error: %s\n", snd_strerror(err));
exit(0);
}
max_clients = snd_seq_system_info_get_clients(sysinfo);
max_ports = snd_seq_system_info_get_ports(sysinfo);
max_queues = snd_seq_system_info_get_ports(sysinfo);
}
void show_system_info(snd_seq_t *handle)
{
printf("System info\n");
printf(" Max queues : %i\n", sysinfo.queues);
printf(" Max clients : %i\n", sysinfo.clients);
printf(" Max ports : %i\n", sysinfo.ports);
printf(" Max queues : %i\n", max_queues);
printf(" Max clients : %i\n", max_clients);
printf(" Max ports : %i\n", max_ports);
}
void show_queue_status(snd_seq_t *handle, int queue)
{
int err, idx, min, max;
snd_seq_queue_status_t status;
snd_seq_queue_status_t *status;
snd_seq_queue_status_alloca(&status);
min = queue < 0 ? 0 : queue;
max = queue < 0 ? sysinfo.queues : queue + 1;
max = queue < 0 ? max_queues : queue + 1;
for (idx = min; idx < max; idx++) {
if ((err = snd_seq_get_queue_status(handle, idx, &status))<0) {
if ((err = snd_seq_get_queue_status(handle, idx, status))<0) {
if (err == -ENOENT)
continue;
fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
exit(0);
}
printf("Queue %i info\n", status.queue);
printf(" Tick : %u\n", status.tick);
printf(" Realtime : %li.%li\n", status.time.tv_sec, status.time.tv_nsec);
printf(" Flags : 0x%x\n", status.flags);
printf("Queue %i info\n", snd_seq_queue_status_get_queue(status));
printf(" Tick : %u\n", snd_seq_queue_status_get_tick_time(status));
printf(" Realtime : %i.%i\n",
snd_seq_queue_status_get_real_time(status)->tv_sec,
snd_seq_queue_status_get_real_time(status)->tv_nsec);
printf(" Flags : 0x%x\n", snd_seq_queue_status_get_status(status));
}
}
void show_port_info(snd_seq_t *handle, int client, int port)
{
int err, idx, min, max;
snd_seq_port_info_t info;
snd_seq_port_info_t *info;
snd_seq_port_info_alloca(&info);
min = port < 0 ? 0 : port;
max = port < 0 ? sysinfo.ports : port + 1;
max = port < 0 ? max_ports : port + 1;
for (idx = min; idx < max; idx++) {
if ((err = snd_seq_get_any_port_info(handle, client, idx, &info))<0) {
if ((err = snd_seq_get_any_port_info(handle, client, idx, info))<0) {
if (err == -ENOENT)
continue;
fprintf(stderr, "Port %i/%i info error: %s\n", client, idx, snd_strerror(err));
exit(0);
}
printf(" Port %i info\n", idx);
printf(" Client : %i\n", info.client);
printf(" Port : %i\n", info.port);
printf(" Name : %s\n", info.name);
printf(" Capability : 0x%x\n", info.capability);
printf(" Type : 0x%x\n", info.type);
printf(" Midi channels : %i\n", info.midi_channels);
printf(" Synth voices : %i\n", info.synth_voices);
printf(" Output subs : %i\n", info.write_use);
printf(" Input subs : %i\n", info.read_use);
printf(" Client : %i\n", snd_seq_port_info_get_client(info));
printf(" Port : %i\n", snd_seq_port_info_get_port(info));
printf(" Name : %s\n", snd_seq_port_info_get_name(info));
printf(" Capability : 0x%x\n", snd_seq_port_info_get_capability(info));
printf(" Type : 0x%x\n", snd_seq_port_info_get_type(info));
//printf(" Midi channels : %i\n", info.midi_channels);
//printf(" Synth voices : %i\n", info.synth_voices);
printf(" Output subs : %i\n", snd_seq_port_info_get_write_use(info));
printf(" Input subs : %i\n", snd_seq_port_info_get_read_use(info));
}
}
void show_client_info(snd_seq_t *handle, int client)
{
int err, idx, min, max;
snd_seq_client_info_t info;
snd_seq_client_info_t *info;
snd_seq_client_info_alloca(&info);
min = client < 0 ? 0 : client;
max = client < 0 ? sysinfo.clients : client + 1;
max = client < 0 ? max_clients : client + 1;
for (idx = min; idx < max; idx++) {
if ((err = snd_seq_get_any_client_info(handle, idx, &info))<0) {
if ((err = snd_seq_get_any_client_info(handle, idx, info))<0) {
if (err == -ENOENT)
continue;
fprintf(stderr, "Client %i info error: %s\n", idx, snd_strerror(err));
@ -117,9 +126,9 @@ void show_client_info(snd_seq_t *handle, int client)
}
printf("Client %i info\n", idx);
if (verbose)
printf(" Client : %i\n", info.client);
printf(" Type : %s\n", info.type == KERNEL_CLIENT ? "kernel" : "user");
printf(" Name : %s\n", info.name);
printf(" Client : %i\n", snd_seq_client_info_get_client(info));
printf(" Type : %s\n", snd_seq_client_info_get_type(info) == SND_SEQ_KERNEL_CLIENT ? "kernel" : "user");
printf(" Name : %s\n", snd_seq_client_info_get_name(info));
}
}
@ -190,7 +199,7 @@ int main(int argc, char *argv[])
fprintf(stderr, "seq: Specify command...\n");
return 0;
}
if ((err = snd_seq_open(&handle, SND_SEQ_OPEN))<0) {
if ((err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0))<0) {
fprintf(stderr, "Open error: %s\n", snd_strerror(err));
exit(0);
}