]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Changes and cleanups for the timer API.
authorJaroslav Kysela <perex@perex.cz>
Thu, 30 Nov 2000 19:17:55 +0000 (19:17 +0000)
committerJaroslav Kysela <perex@perex.cz>
Thu, 30 Nov 2000 19:17:55 +0000 (19:17 +0000)
The device lists use the next device syntax now.

12 files changed:
aserver/aserver.c
include/aserver.h
include/control.h
include/timer.h
src/control/cards.c
src/control/control.c
src/control/control_hw.c
src/control/control_local.h
src/control/control_shm.c
src/control/defaults.c
src/timer/timer.c
test/timer.c

index 384054e3ad5f91ea042b41cd90674ab9432ef00c..b0acfbda4eb628c84c3a25829e134e0f97c88269 100644 (file)
@@ -603,15 +603,24 @@ int ctl_shm_cmd(client_t *client)
        case SND_CTL_IOCTL_CONTROL_WRITE:
                ctrl->result = snd_ctl_cwrite(ctl, &ctrl->u.cwrite);
                break;
+       case SND_CTL_IOCTL_HWDEP_NEXT_DEVICE:
+               ctrl->result = snd_ctl_hwdep_next_device(ctl, &ctrl->u.device);
+               break;
        case SND_CTL_IOCTL_HWDEP_INFO:
                ctrl->result = snd_ctl_hwdep_info(ctl, &ctrl->u.hwdep_info);
                break;
+       case SND_CTL_IOCTL_PCM_NEXT_DEVICE:
+               ctrl->result = snd_ctl_pcm_next_device(ctl, &ctrl->u.device);
+               break;
        case SND_CTL_IOCTL_PCM_INFO:
                ctrl->result = snd_ctl_pcm_info(ctl, &ctrl->u.pcm_info);
                break;
        case SND_CTL_IOCTL_PCM_PREFER_SUBDEVICE:
                ctrl->result = snd_ctl_pcm_prefer_subdevice(ctl, ctrl->u.pcm_prefer_subdevice);
                break;
+       case SND_CTL_IOCTL_RAWMIDI_NEXT_DEVICE:
+               ctrl->result = snd_ctl_rawmidi_next_device(ctl, &ctrl->u.device);
+               break;
        case SND_CTL_IOCTL_RAWMIDI_INFO:
                ctrl->result = snd_ctl_rawmidi_info(ctl, &ctrl->u.rawmidi_info);
                break;
index 6106d43a87eef30aad29e73e940ad69bea17c920..db8439e62d8b1db6a87498c235b7b88b2a44e493 100644 (file)
@@ -81,6 +81,7 @@ typedef struct {
        int result;
        int cmd;
        union {
+               int device;
                snd_ctl_hw_info_t hw_info;
                snd_control_list_t clist;
                snd_control_info_t cinfo;
index f786b014d902a847556e858e975ceebeaf628ef4..cd8e0e534a6464f20689fed4d0417bc7215e0270 100644 (file)
@@ -27,8 +27,7 @@ extern "C" {
 #endif
 
 int snd_card_load(int card);
-int snd_cards(void);
-unsigned int snd_cards_mask(void);
+int snd_card_next(int *card);
 int snd_card_get_index(const char *name);
 int snd_card_get_name(int card, char **name);
 int snd_card_get_longname(int card, char **name);
@@ -49,9 +48,12 @@ int snd_ctl_clist(snd_ctl_t *handle, snd_control_list_t * list);
 int snd_ctl_cinfo(snd_ctl_t *handle, snd_control_info_t * sw);
 int snd_ctl_cread(snd_ctl_t *handle, snd_control_t * control);
 int snd_ctl_cwrite(snd_ctl_t *handle, snd_control_t * control);
+int snd_ctl_hwdep_next_device(snd_ctl_t *handle, int * device);
 int snd_ctl_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info);
+int snd_ctl_pcm_next_device(snd_ctl_t *handle, int *device);
 int snd_ctl_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info);
 int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev);
+int snd_ctl_rawmidi_next_device(snd_ctl_t *handle, int * device);
 int snd_ctl_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info);
 int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev);
 
index d01c57ebce3ee9a2dc8cef1b36f81a927f1e0377..c693feeadccb53d3cba6881aa9adf0e7922d3640 100644 (file)
@@ -14,7 +14,7 @@ typedef struct _snd_timer snd_timer_t;
 int snd_timer_open(snd_timer_t **handle);
 int snd_timer_close(snd_timer_t *handle);
 int snd_timer_poll_descriptor(snd_timer_t *handle);
-int snd_timer_general_info(snd_timer_t *handle, snd_timer_general_info_t * info);
+int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t *tid);
 int snd_timer_select(snd_timer_t *handle, snd_timer_select_t *tselect);
 int snd_timer_info(snd_timer_t *handle, snd_timer_info_t *timer);
 int snd_timer_params(snd_timer_t *handle, snd_timer_params_t *params);
index 064e6dbf292f5875db1c03763dd50973183c46dc..ef89ecd6d4d36a7eaa443c50400b5479c055d502 100644 (file)
@@ -52,39 +52,22 @@ int snd_card_load(int card)
        return open_dev;
 }
 
-int snd_cards(void)
+int snd_card_next(int *rcard)
 {
-       int idx, count;
-       unsigned int mask;
-
-       mask = snd_cards_mask();
-       for (idx = 0, count = 0; idx < SND_CARDS; idx++) {
-               if (mask & (1 << idx))
-                       count++;
-       }
-       return count;
-}
-
-/*
- *  this routine uses very ugly method...
- *    need to do... (use only stat on /proc/asound?)
- *    now is information cached over static variable
- */
-
-unsigned int snd_cards_mask(void)
-{
-       int idx;
-       unsigned int mask;
-       static unsigned int save_mask = 0;
-
-       if (save_mask)
-               return save_mask;
-       for (idx = 0, mask = 0; idx < SND_CARDS; idx++) {
-               if (snd_card_load(idx) >= 0)
-                       mask |= 1 << idx;
+       int card;
+       
+       if (rcard == NULL)
+               return -EINVAL;
+       card = *rcard;
+       card = card < 0 ? 0 : card + 1;
+       for (; card < 32; card++) {
+               if (!snd_card_load(card)) {
+                       *rcard = card;
+                       return 0;
+               }
        }
-       save_mask = mask;
-       return mask;
+       *rcard = -1;
+       return 0;
 }
 
 int snd_card_get_index(const char *string)
index 2aa84f2e894e31d83a25c715843f430d774e5fd0..584fd9461b4056a62f4f821614c44dc6c29f9dd5 100644 (file)
@@ -81,12 +81,24 @@ int snd_ctl_cwrite(snd_ctl_t *ctl, snd_control_t *control)
        return ctl->ops->cwrite(ctl, control);
 }
 
+int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int * device)
+{
+       assert(ctl && device);
+       return ctl->ops->hwdep_next_device(ctl, device);
+}
+
 int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
 {
        assert(ctl && info);
        return ctl->ops->hwdep_info(ctl, info);
 }
 
+int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int * device)
+{
+       assert(ctl && device);
+       return ctl->ops->pcm_next_device(ctl, device);
+}
+
 int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
 {
        assert(ctl && info);
@@ -99,6 +111,12 @@ int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
        return ctl->ops->pcm_prefer_subdevice(ctl, subdev);
 }
 
+int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device)
+{
+       assert(ctl && device);
+       return ctl->ops->rawmidi_next_device(ctl, device);
+}
+
 int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
 {
        assert(ctl && info);
index 152e99c771efa974eaf96558c5ba9d5f65ddb14c..5f5166b51a50f5407747bf2e97425640b74550d0 100644 (file)
@@ -94,6 +94,14 @@ static int snd_ctl_hw_cwrite(snd_ctl_t *handle, snd_control_t *control)
        return 0;
 }
 
+static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device)
+{
+       snd_ctl_hw_t *hw = handle->private;
+       if (ioctl(hw->fd, SND_CTL_IOCTL_HWDEP_NEXT_DEVICE, device) < 0)
+               return -errno;
+       return 0;
+}
+
 static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
 {
        snd_ctl_hw_t *hw = handle->private;
@@ -102,6 +110,14 @@ static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
        return 0;
 }
 
+static int snd_ctl_hw_pcm_next_device(snd_ctl_t *handle, int * device)
+{
+       snd_ctl_hw_t *hw = handle->private;
+       if (ioctl(hw->fd, SND_CTL_IOCTL_PCM_NEXT_DEVICE, device) < 0)
+               return -errno;
+       return 0;
+}
+
 static int snd_ctl_hw_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info)
 {
        snd_ctl_hw_t *hw = handle->private;
@@ -118,6 +134,14 @@ static int snd_ctl_hw_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev)
        return 0;
 }
 
+static int snd_ctl_hw_rawmidi_next_device(snd_ctl_t *handle, int * device)
+{
+       snd_ctl_hw_t *hw = handle->private;
+       if (ioctl(hw->fd, SND_CTL_IOCTL_RAWMIDI_NEXT_DEVICE, device) < 0)
+               return -errno;
+       return 0;
+}
+
 static int snd_ctl_hw_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info)
 {
        snd_ctl_hw_t *hw = handle->private;
@@ -148,9 +172,12 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
        cinfo: snd_ctl_hw_cinfo,
        cread: snd_ctl_hw_cread,
        cwrite: snd_ctl_hw_cwrite,
+       hwdep_next_device: snd_ctl_hw_hwdep_next_device,
        hwdep_info: snd_ctl_hw_hwdep_info,
+       pcm_next_device: snd_ctl_hw_pcm_next_device,
        pcm_info: snd_ctl_hw_pcm_info,
        pcm_prefer_subdevice: snd_ctl_hw_pcm_prefer_subdevice,
+       rawmidi_next_device: snd_ctl_hw_rawmidi_next_device,
        rawmidi_info: snd_ctl_hw_rawmidi_info,
        rawmidi_prefer_subdevice: snd_ctl_hw_rawmidi_prefer_subdevice,
        read: snd_ctl_hw_read,
index 3cfb7f55a2ddf7c7f065bc15d1cb3c5f691ce33d..9a13521efe7a65a577fac59fafa24a768286211f 100644 (file)
@@ -39,9 +39,12 @@ typedef struct {
        int (*cinfo)(snd_ctl_t *handle, snd_control_info_t *info);
        int (*cread)(snd_ctl_t *handle, snd_control_t *control);
        int (*cwrite)(snd_ctl_t *handle, snd_control_t *control);
+       int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
        int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
+       int (*pcm_next_device)(snd_ctl_t *handle, int *device);
        int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
        int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
+       int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
        int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
        int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
        int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
index ccf217ba27bca8c82a2fecbc565e1c5e98c9c16d..fad8a41a9426c373ea223d074774538a9d340217 100644 (file)
@@ -184,6 +184,20 @@ static int snd_ctl_shm_cwrite(snd_ctl_t *ctl, snd_control_t *control)
        return err;
 }
 
+static int snd_ctl_shm_hwdep_next_device(snd_ctl_t *ctl, int * device)
+{
+       snd_ctl_shm_t *shm = ctl->private;
+       snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
+       int err;
+       ctrl->u.device = *device;
+       ctrl->cmd = SND_CTL_IOCTL_HWDEP_NEXT_DEVICE;
+       err = snd_ctl_shm_action(ctl);
+       if (err < 0)
+               return err;
+       *device = ctrl->u.device;
+       return err;
+}
+
 static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
 {
        snd_ctl_shm_t *shm = ctl->private;
@@ -198,6 +212,20 @@ static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
        return err;
 }
 
+static int snd_ctl_shm_pcm_next_device(snd_ctl_t *ctl, int * device)
+{
+       snd_ctl_shm_t *shm = ctl->private;
+       snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
+       int err;
+       ctrl->u.device = *device;
+       ctrl->cmd = SND_CTL_IOCTL_PCM_NEXT_DEVICE;
+       err = snd_ctl_shm_action(ctl);
+       if (err < 0)
+               return err;
+       *device = ctrl->u.device;
+       return err;
+}
+
 static int snd_ctl_shm_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
 {
        snd_ctl_shm_t *shm = ctl->private;
@@ -225,6 +253,20 @@ static int snd_ctl_shm_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
        return err;
 }
 
+static int snd_ctl_shm_rawmidi_next_device(snd_ctl_t *ctl, int * device)
+{
+       snd_ctl_shm_t *shm = ctl->private;
+       snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
+       int err;
+       ctrl->u.device = *device;
+       ctrl->cmd = SND_CTL_IOCTL_RAWMIDI_NEXT_DEVICE;
+       err = snd_ctl_shm_action(ctl);
+       if (err < 0)
+               return err;
+       *device = ctrl->u.device;
+       return err;
+}
+
 static int snd_ctl_shm_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
 {
        snd_ctl_shm_t *shm = ctl->private;
@@ -274,9 +316,12 @@ snd_ctl_ops_t snd_ctl_shm_ops = {
        cinfo: snd_ctl_shm_cinfo,
        cread: snd_ctl_shm_cread,
        cwrite: snd_ctl_shm_cwrite,
+       hwdep_next_device: snd_ctl_shm_hwdep_next_device,
        hwdep_info: snd_ctl_shm_hwdep_info,
+       pcm_next_device: snd_ctl_shm_pcm_next_device,
        pcm_info: snd_ctl_shm_pcm_info,
        pcm_prefer_subdevice: snd_ctl_shm_pcm_prefer_subdevice,
+       rawmidi_next_device: snd_ctl_shm_rawmidi_next_device,
        rawmidi_info: snd_ctl_shm_rawmidi_info,
        rawmidi_prefer_subdevice: snd_ctl_shm_rawmidi_prefer_subdevice,
        read: snd_ctl_shm_read,
index bb87c8eb8cc0b6b46d635657578a5188fb3356f6..e73e72f89e520dc33dcee56c829abc827e1b07af 100644 (file)
@@ -51,16 +51,14 @@ static int defaults_device(const char *env)
 int snd_defaults_card(void)
 {
        int result;
-       unsigned int mask;
 
        result = defaults_card("ALSA_CARD");
        if (result >= 0)
                return result;
-       mask = snd_cards_mask();
-       for (result = 0; result < 31; result++)
-               if (mask & (1 << result))
-                       return result;
-       return -ENOENT;
+       result = -1;
+       if (snd_card_next(&result))
+               return -ENOENT;
+       return result;
 }
 
 int snd_defaults_mixer_card(void)
@@ -85,7 +83,22 @@ int snd_defaults_pcm_card(void)
 
 int snd_defaults_pcm_device(void)
 {
-       return defaults_device("ALSA_PCM_DEVICE");
+       snd_ctl_t *handle;
+       char id[16];
+       int result;
+
+       result = defaults_device("ALSA_PCM_DEVICE");
+       if (result >= 0)
+               return result;
+       sprintf(id, "hw:%i", snd_defaults_pcm_card());
+       if (snd_ctl_open(&handle, id) < 0)
+               return -ENOENT;
+       result = -1;
+       if (snd_ctl_pcm_next_device(handle, &result) < 0) {
+               snd_ctl_close(handle);
+               return -ENOENT;
+       }
+       return result;
 }
 
 int snd_defaults_rawmidi_card(void)
@@ -100,5 +113,20 @@ int snd_defaults_rawmidi_card(void)
 
 int snd_defaults_rawmidi_device(void)
 {
-       return defaults_device("ALSA_RAWMIDI_DEVICE");
+       snd_ctl_t *handle;
+       char id[16];
+       int result;
+
+       result = defaults_device("ALSA_RAWMIDI_DEVICE");
+       if (result >= 0)
+               return result;
+       sprintf(id, "hw:%i", snd_defaults_rawmidi_card());
+       if (snd_ctl_open(&handle, id) < 0)
+               return -ENOENT;
+       result = -1;
+       if (snd_ctl_rawmidi_next_device(handle, &result) < 0) {
+               snd_ctl_close(handle);
+               return -ENOENT;
+       }
+       return result;
 }
index 535e79d5adbe4d414a719272a04b70649a1758f9..2edbb55c285d7b6bffd6d777f812ca496f16d874 100644 (file)
@@ -42,11 +42,8 @@ int snd_timer_open(snd_timer_t **handle)
 
        *handle = NULL;
        
-       if ((fd = open(SND_FILE_TIMER, O_RDONLY)) < 0) {
-               snd_cards_mask();
-               if ((fd = open(SND_FILE_TIMER, O_RDONLY)) < 0)
-                       return -errno;
-       }
+       if ((fd = open(SND_FILE_TIMER, O_RDONLY)) < 0)
+               return -errno;
        if (ioctl(fd, SND_TIMER_IOCTL_PVERSION, &ver) < 0) {
                close(fd);
                return -errno;
@@ -88,14 +85,14 @@ int snd_timer_poll_descriptor(snd_timer_t *handle)
        return tmr->fd;
 }
 
-int snd_timer_general_info(snd_timer_t *handle, snd_timer_general_info_t * info)
+int snd_timer_next_device(snd_timer_t *handle, snd_timer_id_t * tid)
 {
        snd_timer_t *tmr;
 
        tmr = handle;
-       if (!tmr || !info)
+       if (!tmr || !tid)
                return -EINVAL;
-       if (ioctl(tmr->fd, SND_TIMER_IOCTL_GINFO, info) < 0)
+       if (ioctl(tmr->fd, SND_TIMER_IOCTL_NEXT_DEVICE, tid) < 0)
                return -errno;
        return 0;
 }
index 24953014a8bd4ff90b8e02293820c93dede7a253..4b2d2ea9759fc5ead495e61aa9155e893b818349 100644 (file)
@@ -50,29 +50,35 @@ void read_loop(void *handle, int master_ticks, int timeout)
 int main(int argc, char *argv[])
 {
        int idx, err;
-       int timer = SND_TIMER_GLOBAL(SND_TIMER_GLOBAL_SYSTEM);
-       int slave = 0;
-       int slave_type = SND_TIMER_STYPE_SEQUENCER, slave_id = 0;
+       int type = SND_TIMER_TYPE_GLOBAL;
+       int stype = SND_TIMER_TYPE_NONE;
+       int card = 0;
+       int device = SND_TIMER_GLOBAL_SYSTEM;
+       int subdevice = 0;
+       int list = 0;
        snd_timer_t *handle;
-       snd_timer_general_info_t ginfo;
        snd_timer_select_t sel;
        snd_timer_info_t info;
        snd_timer_params_t params;
 
        idx = 1;
        while (idx < argc) {
-               if (!strncmp(argv[idx], "timer=", 6)) {
-                       timer = atoi(argv[idx]+6);
-               } else if (!strcmp(argv[idx], "slave")) {
-                       slave = 1;
-               } else if (!strncmp(argv[idx], "slave_type=", 11)) {
-                       slave_type = atoi(argv[idx]+11);
-               } else if (!strncmp(argv[idx], "slave_id=", 9)) {
-                       slave_id = atoi(argv[idx]+9);
+               if (!strncmp(argv[idx], "type=", 5)) {
+                       type = atoi(argv[idx]+5);
+               } else if (!strncmp(argv[idx], "stype=", 6)) {
+                       stype = atoi(argv[idx]+6);
+               } else if (!strncmp(argv[idx], "card=", 5)) {
+                       card = atoi(argv[idx]+5);
+               } else if (!strncmp(argv[idx], "device=", 7)) {
+                       device = atoi(argv[idx]+7);
+               } else if (!strncmp(argv[idx], "subdevice=", 10)) {
+                       subdevice = atoi(argv[idx]+10);
+               } else if (!strcmp(argv[idx], "list")) {
+                       list = 1;
                }
                idx++;
        }
-       if (slave && slave_type == SND_TIMER_STYPE_NONE) {
+       if (type == SND_TIMER_TYPE_SLAVE && stype == SND_TIMER_STYPE_NONE) {
                fprintf(stderr, "sync_type is not set\n");
                exit(0);
        }
@@ -80,30 +86,37 @@ int main(int argc, char *argv[])
                fprintf(stderr, "timer open %i (%s)\n", err, snd_strerror(err));
                exit(0);
        }
-       if (snd_timer_general_info(handle, &ginfo)<0) {
-               fprintf(stderr, "timer general info %i (%s)\n", err, snd_strerror(err));
-               exit(0);
+       if (list) {
+               bzero(&sel.id, sizeof(sel.id));
+               sel.id.type = -1;
+               while (1) {
+                       if ((err = snd_timer_next_device(handle, &sel.id)) < 0) {
+                               fprintf(stderr, "timer next device error: %s\n", snd_strerror(err));
+                               break;
+                       }
+                       if (sel.id.type < 0)
+                               break;
+                       printf("Timer device: type %i, stype %i, card %i, device %i, subdevice %i\n",
+                                       sel.id.type, sel.id.stype, sel.id.card, sel.id.device, sel.id.subdevice);
+               }
        }
-       printf("Global timers = %i\n", ginfo.count);
-       printf("Using timer %i, slave %i, slave_type %i, slave_id %i\n", timer, slave, slave_type, slave_id);
+       printf("Using timer type %i, slave type %i, card %i, device %i, subdevice %i\n", type, stype, card, device, subdevice);
        bzero(&sel, sizeof(sel));
-       sel.slave = slave;
-       if (!sel.slave) {
-               sel.data.number = timer;
-       } else {
-               sel.data.slave.type = slave_type;
-               sel.data.slave.id = slave_id;
-       }
+       sel.id.type = type;
+       sel.id.stype = stype;
+       sel.id.card = card;
+       sel.id.device = device;
+       sel.id.subdevice = subdevice;
        if ((err = snd_timer_select(handle, &sel)) < 0) {
                fprintf(stderr, "timer select %i (%s)\n", err, snd_strerror(err));
                exit(0);
        }
-       if (!sel.slave) {
+       if (type != SND_TIMER_TYPE_SLAVE) {
                if ((err = snd_timer_info(handle, &info)) < 0) {
                        fprintf(stderr, "timer info %i (%s)\n", err, snd_strerror(err));
                        exit(0);
                }
-               printf("Timer %i info:\n", sel.data.number);
+               printf("Timer info:\n");
                printf("  flags = 0x%x\n", info.flags);
                printf("  id = '%s'\n", info.id);
                printf("  name = '%s'\n", info.name);
@@ -125,7 +138,7 @@ int main(int argc, char *argv[])
                fprintf(stderr, "timer start %i (%s)\n", err, snd_strerror(err));
                exit(0);
        }
-       read_loop(handle, 25, sel.slave ? 10000 : 1);
+       read_loop(handle, 25, type == SND_TIMER_TYPE_SLAVE ? 10000 : 1);
        show_status(handle);
        snd_timer_close(handle);
        return 0;