Remove use of try/catch during internal client loading, set default nperiod to 2...
[jack2.git] / example-clients / alias.c
blob9d1b098be7022b5d11ffef2b17254f15429b6743
1 /*
2 This program is free software; you can redistribute it and/or modify
3 it under the terms of the GNU General Public License as published by
4 the Free Software Foundation; either version 2 of the License, or
5 (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <string.h>
21 #include <getopt.h>
22 #include <jack/jack.h>
23 //#include <config.h>
25 char * my_name;
27 void
28 show_version (void)
30 //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
33 void
34 show_usage (void)
36 show_version ();
37 fprintf (stderr, "\nUsage: %s [options] portname alias\n", my_name);
38 fprintf (stderr, "List active Jack ports, and optionally display extra information.\n\n");
39 fprintf (stderr, "Display options:\n");
40 fprintf (stderr, " -u, --unalias remove `alias' as an alias for `port'\n");
41 fprintf (stderr, " -h, --help Display this help message\n");
42 fprintf (stderr, " --version Output version information and exit\n\n");
43 fprintf (stderr, "For more information see http://jackaudio.org/\n");
46 int
47 main (int argc, char *argv[])
49 jack_client_t *client;
50 jack_status_t status;
51 char* portname;
52 char* alias;
53 int unset = 0;
54 int ret;
55 int c;
56 int option_index;
57 extern int optind;
58 jack_port_t* port;
60 struct option long_options[] = {
61 { "unalias", 0, 0, 'u' },
62 { "help", 0, 0, 'h' },
63 { "version", 0, 0, 'v' },
64 { 0, 0, 0, 0 }
67 if (argc < 3) {
68 show_usage ();
69 return 1;
72 my_name = strrchr(argv[0], '/');
73 if (my_name == 0) {
74 my_name = argv[0];
75 } else {
76 my_name ++;
79 while ((c = getopt_long (argc, argv, "uhv", long_options, &option_index)) >= 0) {
80 switch (c) {
81 case 'u':
82 unset = 1;
83 break;
84 case 'h':
85 show_usage ();
86 return 1;
87 break;
88 case 'v':
89 show_version ();
90 return 1;
91 break;
92 default:
93 show_usage ();
94 return 1;
95 break;
99 portname = argv[optind++];
100 alias = argv[optind];
102 /* Open a client connection to the JACK server. Starting a
103 * new server only to list its ports seems pointless, so we
104 * specify JackNoStartServer. */
105 //JOQ: need a new server name option
107 client = jack_client_open ("lsp", JackNoStartServer, &status);
109 if (client == NULL) {
110 if (status & JackServerFailed) {
111 fprintf (stderr, "JACK server not running\n");
112 } else {
113 fprintf (stderr, "jack_client_open() failed, "
114 "status = 0x%2.0x\n", status);
116 return 1;
119 if ((port = jack_port_by_name (client, portname)) == 0) {
120 fprintf (stderr, "No port named \"%s\"\n", portname);
121 return 1;
124 if (!unset) {
125 ret = jack_port_set_alias (port, alias);
126 } else {
127 ret = jack_port_unset_alias (port, alias);
130 jack_client_close (client);
132 return ret;