From 6e72ca3977da2d33b2f5fd322bc826b931350ddb Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Tue, 4 May 1999 19:21:28 +0000 Subject: [PATCH] Recoded the universal switch interface... --- include/control.h | 8 +++++ include/mixer.h | 6 +--- include/pcm.h | 6 ---- include/rawmidi.h | 6 ---- src/control/control.c | 33 ++++++++++++++++++++ src/mixer/mixer.c | 43 -------------------------- src/pcm/pcm.c | 72 ------------------------------------------- src/rawmidi/rawmidi.c | 72 ------------------------------------------- 8 files changed, 42 insertions(+), 204 deletions(-) diff --git a/include/control.h b/include/control.h index d32c1176..5fa336ed 100644 --- a/include/control.h +++ b/include/control.h @@ -5,6 +5,13 @@ * * ****************************************************************************/ +typedef struct snd_ctl_callbacks { + void *private_data; /* should be used by an application */ + void (*rebuild) (void *private_data); + void (*xswitch) (void *private_data, int cmd, int iface, snd_switch_list_item_t *item); + void *reserved[29]; /* reserved for the future use - must be NULL!!! */ +} snd_ctl_callbacks_t; + #ifdef __cplusplus extern "C" { #endif @@ -51,6 +58,7 @@ int snd_ctl_rawmidi_output_switch_write(void *handle, int dev, snd_switch_t * sw int snd_ctl_rawmidi_input_switch_list(void *handle, int dev, snd_switch_list_t *list); int snd_ctl_rawmidi_input_switch_read(void *handle, int dev, snd_switch_t * sw); int snd_ctl_rawmidi_input_switch_write(void *handle, int dev, snd_switch_t * sw); +int snd_ctl_read(void *handle, snd_ctl_callbacks_t * callbacks); #ifdef __cplusplus } diff --git a/include/mixer.h b/include/mixer.h index c9ef66d2..4bcf6a7c 100644 --- a/include/mixer.h +++ b/include/mixer.h @@ -10,8 +10,7 @@ typedef struct snd_mixer_callbacks { void (*rebuild) (void *private_data); void (*element) (void *private_data, int cmd, snd_mixer_eid_t *eid); void (*group) (void *private_data, int cmd, snd_mixer_gid_t *gid); - void (*xswitch) (void *private_data, int cmd, snd_switch_list_item_t *item); - void *reserved[27]; /* reserved for the future use - must be NULL!!! */ + void *reserved[28]; /* reserved for the future use - must be NULL!!! */ } snd_mixer_callbacks_t; #ifdef __cplusplus @@ -29,9 +28,6 @@ int snd_mixer_group(void *handle, snd_mixer_group_t * group); int snd_mixer_element_info(void *handle, snd_mixer_element_info_t * info); int snd_mixer_element_read(void *handle, snd_mixer_element_t * element); int snd_mixer_element_write(void *handle, snd_mixer_element_t * element); -int snd_mixer_switch_list(void *handle, snd_switch_list_t * list); -int snd_mixer_switch_read(void *handle, snd_switch_t * sw); -int snd_mixer_switch_write(void *handle, snd_switch_t * sw); int snd_mixer_read(void *handle, snd_mixer_callbacks_t * callbacks); void snd_mixer_set_bit(unsigned int *bitmap, int bit, int val); diff --git a/include/pcm.h b/include/pcm.h index 95c2a70f..a56badc6 100644 --- a/include/pcm.h +++ b/include/pcm.h @@ -20,12 +20,6 @@ int snd_pcm_block_mode(void *handle, int enable); int snd_pcm_info(void *handle, snd_pcm_info_t * info); int snd_pcm_playback_info(void *handle, snd_pcm_playback_info_t * info); int snd_pcm_record_info(void *handle, snd_pcm_record_info_t * info); -int snd_pcm_playback_switch_list(void *handle, snd_switch_list_t * list); -int snd_pcm_playback_switch_read(void *handle, snd_switch_t * sw); -int snd_pcm_playback_switch_write(void *handle, snd_switch_t * sw); -int snd_pcm_record_switch_list(void *handle, snd_switch_list_t * list); -int snd_pcm_record_switch_read(void *handle, snd_switch_t * sw); -int snd_pcm_record_switch_write(void *handle, snd_switch_t * sw); int snd_pcm_playback_format(void *handle, snd_pcm_format_t * format); int snd_pcm_record_format(void *handle, snd_pcm_format_t * format); int snd_pcm_playback_params(void *handle, snd_pcm_playback_params_t * params); diff --git a/include/rawmidi.h b/include/rawmidi.h index 64250ff9..53278279 100644 --- a/include/rawmidi.h +++ b/include/rawmidi.h @@ -18,12 +18,6 @@ int snd_rawmidi_close(void *handle); int snd_rawmidi_file_descriptor(void *handle); int snd_rawmidi_block_mode(void *handle, int enable); int snd_rawmidi_info(void *handle, snd_rawmidi_info_t * info); -int snd_rawmidi_output_switch_list(void *handle, snd_switch_list_t * list); -int snd_rawmidi_output_switch_read(void *handle, snd_switch_t * sw); -int snd_rawmidi_output_switch_write(void *handle, snd_switch_t * sw); -int snd_rawmidi_input_switch_list(void *handle, snd_switch_list_t * list); -int snd_rawmidi_input_switch_read(void *handle, snd_switch_t * sw); -int snd_rawmidi_input_switch_write(void *handle, snd_switch_t * sw); int snd_rawmidi_output_params(void *handle, snd_rawmidi_output_params_t * params); int snd_rawmidi_input_params(void *handle, snd_rawmidi_input_params_t * params); int snd_rawmidi_output_status(void *handle, snd_rawmidi_output_status_t * status); diff --git a/src/control/control.c b/src/control/control.c index 39840948..ce8b6324 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -450,3 +450,36 @@ int snd_ctl_rawmidi_input_switch_write(void *handle, int dev, snd_switch_t * sw) return -errno; return 0; } + +int snd_control_read(void *handle, snd_ctl_callbacks_t * callbacks) +{ + snd_ctl_t *ctl; + int result, count; + snd_ctl_read_t r; + + ctl = (snd_ctl_t *) handle; + if (!ctl) + return -EINVAL; + count = 0; + while ((result = read(ctl->fd, &r, sizeof(r))) > 0) { + if (result != sizeof(r)) + return -EIO; + if (!callbacks) + continue; + switch (r.cmd) { + case SND_CTL_READ_REBUILD: + if (callbacks->rebuild) + callbacks->rebuild(callbacks->private_data); + break; + case SND_CTL_READ_SWITCH_VALUE: + case SND_CTL_READ_SWITCH_CHANGE: + case SND_CTL_READ_SWITCH_ADD: + case SND_CTL_READ_SWITCH_REMOVE: + if (callbacks->xswitch) + callbacks->xswitch(callbacks->private_data, r.cmd, r.data.sw.iface, &r.data.sw.switem); + break; + } + count++; + } + return result >= 0 ? count : -errno; +} diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index a9a32348..779caa83 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -193,42 +193,6 @@ int snd_mixer_element_write(void *handle, snd_mixer_element_t * element) return 0; } -int snd_mixer_switch_list(void *handle, snd_switch_list_t * list) -{ - snd_mixer_t *mixer; - - mixer = (snd_mixer_t *) handle; - if (!mixer || !list) - return -EINVAL; - if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_LIST, &list) < 0) - return -errno; - return 0; -} - -int snd_mixer_switch_read(void *handle, snd_switch_t * sw) -{ - snd_mixer_t *mixer; - - mixer = (snd_mixer_t *) handle; - if (!mixer || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_READ, sw) < 0) - return -errno; - return 0; -} - -int snd_mixer_switch_write(void *handle, snd_switch_t * sw) -{ - snd_mixer_t *mixer; - - mixer = (snd_mixer_t *) handle; - if (!mixer || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(mixer->fd, SND_MIXER_IOCTL_SWITCH_WRITE, sw) < 0) - return -errno; - return 0; -} - int snd_mixer_read(void *handle, snd_mixer_callbacks_t * callbacks) { snd_mixer_t *mixer; @@ -263,13 +227,6 @@ int snd_mixer_read(void *handle, snd_mixer_callbacks_t * callbacks) if (callbacks->group) callbacks->group(callbacks->private_data, r.cmd, &r.data.gid); break; - case SND_MIXER_READ_SWITCH_VALUE: - case SND_MIXER_READ_SWITCH_CHANGE: - case SND_MIXER_READ_SWITCH_ADD: - case SND_MIXER_READ_SWITCH_REMOVE: - if (callbacks->xswitch) - callbacks->xswitch(callbacks->private_data, r.cmd, &r.data.switem); - break; } count++; } diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 262ce9af..ea83c1c0 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -151,78 +151,6 @@ int snd_pcm_record_info(void *handle, snd_pcm_record_info_t * info) return 0; } -int snd_pcm_playback_switch_list(void *handle, snd_switch_list_t * list) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !list) - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_LIST, &list) < 0) - return -errno; - return 0; -} - -int snd_pcm_playback_switch_read(void *handle, snd_switch_t * sw) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_READ, sw) < 0) - return -errno; - return 0; -} - -int snd_pcm_playback_switch_write(void *handle, snd_switch_t * sw) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_PSWITCH_WRITE, sw) < 0) - return -errno; - return 0; -} - -int snd_pcm_record_switch_list(void *handle, snd_switch_list_t * list) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !list) - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_LIST, list) < 0) - return -errno; - return 0; -} - -int snd_pcm_record_switch_read(void *handle, snd_switch_t * sw) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_READ, sw) < 0) - return -errno; - return 0; -} - -int snd_pcm_record_switch_write(void *handle, snd_switch_t * sw) -{ - snd_pcm_t *pcm; - - pcm = (snd_pcm_t *) handle; - if (!pcm || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(pcm->fd, SND_PCM_IOCTL_RSWITCH_WRITE, sw) < 0) - return -errno; - return 0; -} - int snd_pcm_playback_format(void *handle, snd_pcm_format_t * format) { snd_pcm_t *pcm; diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c index 95910af1..9155b20f 100644 --- a/src/rawmidi/rawmidi.c +++ b/src/rawmidi/rawmidi.c @@ -127,78 +127,6 @@ int snd_rawmidi_info(void *handle, snd_rawmidi_info_t * info) return 0; } -int snd_rawmidi_output_switch_list(void *handle, snd_switch_list_t * list) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi || !list) - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_LIST, list) < 0) - return -errno; - return 0; -} - -int snd_rawmidi_output_switch_read(void *handle, snd_switch_t * sw) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_READ, sw) < 0) - return -errno; - return 0; -} - -int snd_rawmidi_output_switch_write(void *handle, snd_switch_t * sw) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_OSWITCH_WRITE, sw) < 0) - return -errno; - return 0; -} - -int snd_rawmidi_input_switch_list(void *handle, snd_switch_list_t * list) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi) - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_LIST, list) < 0) - return -errno; - return 0; -} - -int snd_rawmidi_input_switch_read(void *handle, snd_switch_t * sw) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_READ, sw) < 0) - return -errno; - return 0; -} - -int snd_rawmidi_input_switch_write(void *handle, snd_switch_t * sw) -{ - snd_rawmidi_t *rmidi; - - rmidi = (snd_rawmidi_t *) handle; - if (!rmidi || !sw || sw->name[0] == '\0') - return -EINVAL; - if (ioctl(rmidi->fd, SND_RAWMIDI_IOCTL_ISWITCH_WRITE, sw) < 0) - return -errno; - return 0; -} - int snd_rawmidi_output_params(void *handle, snd_rawmidi_output_params_t * params) { snd_rawmidi_t *rmidi; -- 2.47.1