root/jack2/branches/pipelining/example-clients/lsp.c

Revision 3916, 6.0 kB (checked in by sletz, 7 months ago)

rebase from trunk 3898:3915

Line 
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.
6
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.
11
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.
15 */
16
17 #include <stdio.h>
18 #include <stdlib.h>
19 #ifndef WIN32
20 #include <unistd.h>
21 #endif
22 #include <string.h>
23 #include <getopt.h>
24 #include <jack/jack.h>
25
26 char * my_name;
27
28 static void
29 show_version (void)
30 {
31         //fprintf (stderr, "%s: JACK Audio Connection Kit version " VERSION "\n", my_name);
32 }
33
34 static void
35 show_usage (void)
36 {
37         show_version ();
38         fprintf (stderr, "\nUsage: %s [options] [filter string]\n", my_name);
39         fprintf (stderr, "List active Jack ports, and optionally display extra information.\n");
40         fprintf (stderr, "Optionally filter ports which match ALL strings provided after any options.\n\n");
41         fprintf (stderr, "Display options:\n");
42         fprintf (stderr, "        -A, --aliases         List aliases for each port\n");
43         fprintf (stderr, "        -c, --connections     List connections to/from each port\n");
44         fprintf (stderr, "        -l, --latency         Display per-port latency in frames at each port\n");
45         fprintf (stderr, "        -L, --latency         Display total latency in frames at each port\n");
46         fprintf (stderr, "        -p, --properties      Display port properties. Output may include:\n"
47                          "                              input|output, can-monitor, physical, terminal\n\n");
48         fprintf (stderr, "        -t, --type            Display port type\n");
49         fprintf (stderr, "        -h, --help            Display this help message\n");
50         fprintf (stderr, "        --version             Output version information and exit\n\n");
51         fprintf (stderr, "For more information see http://jackaudio.org/\n");
52 }
53
54 int
55 main (int argc, char *argv[])
56 {
57         jack_client_t *client;
58         jack_status_t status;
59         const char **ports, **connections;
60         unsigned int i, j, k;
61         int skip_port;
62         int show_aliases = 0;
63         int show_con = 0;
64         int show_port_latency = 0;
65         int show_total_latency = 0;
66         int show_properties = 0;
67         int show_type = 0;
68         int c;
69         int option_index;
70         char* aliases[2];
71         jack_port_t *port;
72        
73         struct option long_options[] = {
74                 { "aliases", 0, 0, 'A' },
75                 { "connections", 0, 0, 'c' },
76                 { "port-latency", 0, 0, 'l' },
77                 { "total-latency", 0, 0, 'L' },
78                 { "properties", 0, 0, 'p' },
79                 { "type", 0, 0, 't' },
80                 { "help", 0, 0, 'h' },
81                 { "version", 0, 0, 'v' },
82                 { 0, 0, 0, 0 }
83         };
84
85         my_name = strrchr(argv[0], '/');
86         if (my_name == 0) {
87                 my_name = argv[0];
88         } else {
89                 my_name ++;
90         }
91
92         while ((c = getopt_long (argc, argv, "AclLphvt", long_options, &option_index)) >= 0) {
93                 switch (c) {
94                 case 'A':
95                         aliases[0] = (char *) malloc (jack_port_name_size());
96                         aliases[1] = (char *) malloc (jack_port_name_size());
97                         show_aliases = 1;
98                         break;
99                 case 'c':
100                         show_con = 1;
101                         break;
102                 case 'l':
103                         show_port_latency = 1;
104                         break;
105                 case 'L':
106                         show_total_latency = 1;
107                         break;
108                 case 'p':
109                         show_properties = 1;
110                         break;
111                 case 't':
112                         show_type = 1;
113                         break;
114                 case 'h':
115                         show_usage ();
116                         return 1;
117                         break;
118                 case 'v':
119                         show_version ();
120                         return 1;
121                         break;
122                 default:
123                         show_usage ();
124                         return 1;
125                         break;
126                 }
127         }
128
129         /* Open a client connection to the JACK server.  Starting a
130          * new server only to list its ports seems pointless, so we
131          * specify JackNoStartServer. */
132         //JOQ: need a new server name option
133
134         client = jack_client_open ("lsp", JackNoStartServer, &status);
135         if (client == NULL) {
136                 if (status & JackServerFailed) {
137                         fprintf (stderr, "JACK server not running\n");
138                 } else {
139                         fprintf (stderr, "jack_client_open() failed, "
140                                  "status = 0x%2.0x\n", status);
141                 }
142                 return 1;
143         }
144
145         ports = jack_get_ports (client, NULL, NULL, 0);
146     if (!ports)
147         goto error;
148
149         for (i = 0; ports[i]; ++i) {
150                 // skip over any that don't match ALL of the strings presented at command line
151                 skip_port = 0;
152                 for(k = optind; k < argc; k++){
153                         if(strstr(ports[i], argv[k]) == NULL ){
154                                 skip_port = 1;
155                         }
156                 }
157                 if (skip_port) continue;
158
159                 printf ("%s\n", ports[i]);
160                 port = jack_port_by_name (client, ports[i]);
161
162                 if (show_aliases) {
163                         int cnt;
164                         int i;
165
166                         cnt = jack_port_get_aliases (port, aliases);
167                         for (i = 0; i < cnt; ++i) {
168                                 printf ("   %s\n", aliases[i]);
169                         }
170                 }
171                                
172                 if (show_con) {
173                         if ((connections = jack_port_get_all_connections (client, jack_port_by_name(client, ports[i]))) != 0) {
174                                 for (j = 0; connections[j]; j++) {
175                                         printf ("   %s\n", connections[j]);
176                                 }
177                                 free (connections);
178                         }
179                 }
180                 if (show_port_latency) {
181                         if (port) {
182                                 printf ("       port latency = %d frames\n",
183                                         jack_port_get_latency (port));
184                         }
185                 }
186                 if (show_total_latency) {
187                         if (port) {
188                                 printf ("       total latency = %d frames\n",
189                                         jack_port_get_total_latency (client, port));
190                         }
191                 }
192                 if (show_properties) {
193                         if (port) {
194                                 int flags = jack_port_flags (port);
195                                 printf ("       properties: ");
196                                 if (flags & JackPortIsInput) {
197                                         fputs ("input,", stdout);
198                                 }
199                                 if (flags & JackPortIsOutput) {
200                                         fputs ("output,", stdout);
201                                 }
202                                 if (flags & JackPortCanMonitor) {
203                                         fputs ("can-monitor,", stdout);
204                                 }
205                                 if (flags & JackPortIsPhysical) {
206                                         fputs ("physical,", stdout);
207                                 }
208                                 if (flags & JackPortIsTerminal) {
209                                         fputs ("terminal,", stdout);
210                                 }
211                
212                 if (flags & JackPortIsActive) {
213                     fputs ("active,", stdout);
214                 } else {
215                     fputs ("non-active,", stdout);
216                 }
217                                 putc ('\n', stdout);
218                         }
219                 }
220                 if (show_type) {
221                         if (port) {
222                                 putc ('\t', stdout);
223                                 fputs (jack_port_type (port), stdout);
224                                 putc ('\n', stdout);
225                         }
226                 }
227         }
228    
229 error:
230         jack_client_close (client);
231         exit (0);
232 }
Note: See TracBrowser for help on using the browser.