* - fix tempo event bug
* - add command line options
*
+ * 19990827 Takashi Iwai <iwai@ww.uni-erlangen.de>
+ * - use snd_seq_alloc_queue()
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
#define USE_BLOCKING_MODE
/* default destination queue, client and port numbers */
-#define DEST_QUEUE_NUMBER 7
#define DEST_CLIENT_NUMBER 65
#define DEST_PORT_NUMBER 0
static int local_ticks = 0;
static int local_tempo = 500000;
-static int dest_queue = DEST_QUEUE_NUMBER;
+static int dest_queue = 0;
static int dest_client = DEST_CLIENT_NUMBER;
static int dest_port = DEST_PORT_NUMBER;
static int source_channel = 0;
write_ev_var(&ev, len, msg);
}
+static snd_seq_event_t *wait_for_event(void)
+{
+ int left;
+ snd_seq_event_t *input_event;
+
+#ifdef USE_BLOCKING_MODE
+ /* read event - blocked until any event is read */
+ left = snd_seq_event_input(seq_handle, &input_event);
+#else
+ /* 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_file_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));
+ exit(1);
+ }
+ }
+#endif
+ if (left < 0) {
+ printf("alsa_sync error!:%s\n", snd_strerror(left));
+ return NULL;
+ }
+
+ return input_event;
+}
+
/* synchronize to the end of event */
static void alsa_sync(void)
{
int left;
- snd_seq_event_t* input_event;
+ snd_seq_event_t *input_event;
snd_seq_event_t ev;
/* send echo event to self client. */
printf("alsa_sync syncing... send ECHO(%d) event to myself. time=%f\n",
SND_SEQ_EVENT_ECHO, (double) Mf_currtime+1);
ev.source.port = source_port;
- ev.source.channel = source_channel;
ev.dest.queue = dest_queue;
ev.dest.client = snd_seq_client_id(seq_handle);
ev.dest.port = source_port;
left = snd_seq_flush_output(seq_handle);
/* wait for the timer start event */
-#ifdef USE_BLOCKING_MODE
- /* read event - blocked until any event is read */
- left = snd_seq_event_input(seq_handle, &input_event);
-#else
- /* 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_file_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));
- exit(1);
+ for (;;) {
+ input_event = wait_for_event();
+ if (input_event) {
+ if (verbose >= VERB_MUCH)
+ printf("alsa_sync got event. type=%d, flags=%d\n",
+ input_event->type, input_event->flags);
+ if (input_event->type == SND_SEQ_EVENT_ECHO)
+ break;
+ snd_seq_free_event(input_event);
}
}
-#endif
- if (left < 0) {
- printf("alsa_sync error!:%s\n", snd_strerror(left));
- return;
- }
-
- if (verbose >= VERB_MUCH)
- printf("alsa_sync got event. type=%d, flags=%d\n",
- input_event->type, input_event->flags);
- snd_seq_free_event(input_event);
-
if (verbose >= VERB_MUCH)
printf("alsa_sync synced\n");
}
/* wait for start of the queue */
static void wait_start(void)
{
- int left;
- snd_seq_event_t* input_event;
-
+ snd_seq_event_t *input_event;
+
/* wait the start event from the system timer */
- do {
-#ifdef USE_BLOCKING_MODE
- /* read event - blocked until any event is read */
- left = snd_seq_event_input(seq_handle, &input_event);
-#else
- /* 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_file_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));
- exit(1);
- }
+ for (;;) {
+ input_event = wait_for_event();
+ if (input_event) {
+ if (verbose >= VERB_MUCH)
+ printf("wait_start got event. type=%d, flags=%d\n",
+ input_event->type, input_event->flags);
+ if (input_event->type == SND_SEQ_EVENT_START &&
+ input_event->data.addr.queue == dest_queue)
+ break;
+ snd_seq_free_event(input_event);
}
-#endif
- if (left < 0) {
- printf("alsa_sync error!:%s\n", snd_strerror(left));
- return;
- }
-
- if (verbose >= VERB_MUCH)
- printf("wait_start got event. type=%d, flags=%d\n",
- input_event->type, input_event->flags);
- snd_seq_free_event(input_event);
-
- } while (input_event->type != SND_SEQ_EVENT_START);
-
+ }
if (verbose >= VERB_MUCH)
printf("start received\n");
}
fprintf(stderr, "usage: playmidi1 [options] [file]\n");
fprintf(stderr, " options:\n");
fprintf(stderr, " -v: verbose mode\n");
- fprintf(stderr, " -a queue:client:port : set destination address (default=%d:%d:%d)\n",
- DEST_QUEUE_NUMBER, DEST_CLIENT_NUMBER, DEST_PORT_NUMBER);
+ fprintf(stderr, " -a client:port : set destination address (default=%d:%d)\n",
+ DEST_CLIENT_NUMBER, DEST_PORT_NUMBER);
fprintf(stderr, " -s: slave mode (allow external clock synchronisation)\n");
-
}
/* parse destination address (-a option) */
-void parse_address(char *arg, int *queuep, int *clientp, int *portp)
+void parse_address(char *arg, int *clientp, int *portp)
{
char *next;
- *queuep = atoi(arg);
- if ((next = strchr(arg, ':')) != NULL) {
- *clientp = atoi(next + 1);
- if ((next = strchr(next + 1, ':')) != NULL)
- *portp = atoi(next + 1);
- }
+ *clientp = atoi(arg);
+ if ((next = strchr(arg, ':')) != NULL)
+ *portp = atoi(next + 1);
}
int main(int argc, char *argv[])
{
snd_seq_client_info_t inf;
snd_seq_port_info_t src_port_info;
- snd_seq_queue_client_t queue_info;
snd_seq_port_subscribe_t subscribe;
snd_seq_client_pool_t pool;
int tmp;
verbose++;
break;
case 'a':
- parse_address(optarg, &dest_queue, &dest_client, &dest_port);
+ parse_address(optarg, &dest_client, &dest_port);
break;
case 's':
slave = 1;
source_port = src_port_info.port;
/* setup queue */
- bzero(&queue_info,sizeof(queue_info));
- queue_info.used = 1;
- tmp = snd_seq_set_queue_client(seq_handle, dest_queue, &queue_info);
- if (tmp < 0) {
- perror("queue_client");
+ dest_queue = snd_seq_alloc_queue(seq_handle);
+ if (dest_queue < 0) {
+ perrror("alloc queue");
exit(1);
}