From 96dd664e6abdb7e4cbe648aa4df4de0d4d9f90aa Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 26 Dec 2001 18:52:58 +0000 Subject: [PATCH] Added port cleanup and other changes by Uros --- seq/sbiload/sbiload.c | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/seq/sbiload/sbiload.c b/seq/sbiload/sbiload.c index b27e489..28ea52b 100644 --- a/seq/sbiload/sbiload.c +++ b/seq/sbiload/sbiload.c @@ -120,7 +120,7 @@ static int parse_portdesc (char *portdesc); static int init_client (); static void -error_handler (const char *file, int line, const char *function, int err, const char *fmt, ...) +ignore_errors (const char *file, int line, const char *function, int err, const char *fmt, ...) { /* ignore */ } @@ -131,9 +131,11 @@ error_handler (const char *file, int line, const char *function, int err, const static void show_list () { snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; + int client, err; - snd_lib_error_set_handler (error_handler); + snd_lib_error_set_handler (ignore_errors); if ((err = snd_seq_open (&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) { fprintf (stderr, "Could not open sequencer: %s\n", snd_strerror (err)); return; @@ -143,7 +145,6 @@ show_list () { snd_seq_client_info_alloca(&cinfo); snd_seq_client_info_set_client(cinfo, -1); while (snd_seq_query_next_client(seq_handle, cinfo) >= 0) { - snd_seq_port_info_t *pinfo; client = snd_seq_client_info_get_client(cinfo); snd_seq_port_info_alloca(&pinfo); snd_seq_port_info_set_client(pinfo, client); @@ -537,13 +538,37 @@ init_client () { snd_seq_close (seq_handle); fprintf (stderr, "Unable to subscribe destination port: %s\n", snd_strerror (errno)); - return -1; } return 0; } +/* + * Unsubscribe client from destination port + * and close sequencer + */ +static void +finish_client () +{ + snd_seq_port_subscribe_t *sub; + snd_seq_addr_t addr; + int err; + + snd_seq_port_subscribe_alloca(&sub); + addr.client = seq_client; + addr.port = seq_port; + snd_seq_port_subscribe_set_sender(sub, &addr); + addr.client = seq_dest_client; + addr.port = seq_dest_port; + snd_seq_port_subscribe_set_dest(sub, &addr); + if ((err = snd_seq_unsubscribe_port (seq_handle, sub)) < 0) { + fprintf (stderr, "Unable to unsubscribe destination port: %s\n", + snd_strerror (errno)); + } + snd_seq_close (seq_handle); +} + /* * Load a .SBI FM instrument patch * sbiload [-p client:port] [-l] [-v level] instfile drumfile @@ -622,19 +647,19 @@ main (int argc, char **argv) { /* Process instrument and drum file */ if (optind < argc) { if (load_file (0, argv[optind++]) < 0) { - snd_seq_close (seq_handle); + finish_client(); return 1; } } if (optind < argc) { if (load_file (128, argv[optind]) < 0) { - snd_seq_close (seq_handle); + finish_client(); return 1; } } /* Unsubscribe destination port and close client */ - snd_seq_close (seq_handle); + finish_client(); return 0; } -- 2.47.1