Mercurial > hg > index.fcgi > lsonify > lsonify-1pba
comparison metro.c @ 1:46d4c88917a2
add Makefile; rename string to refer to "lsonify" instead of jack_metro; connect to physical input ports on startup
author | paulo@localhost |
---|---|
date | Sun, 17 May 2009 02:32:01 -0700 |
parents | 047192fef940 |
children |
comparison
equal
deleted
inserted
replaced
0:ad2566db6ba4 | 1:03ebe23290fd |
---|---|
47 void | 47 void |
48 usage () | 48 usage () |
49 | 49 |
50 { | 50 { |
51 fprintf (stderr, "\n" | 51 fprintf (stderr, "\n" |
52 "usage: jack_metro \n" | 52 "usage: lsonify \n" |
53 " [ --frequency OR -f frequency (in Hz) ]\n" | 53 " [ --frequency OR -f frequency (in Hz) ]\n" |
54 " [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n" | 54 " [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n" |
55 " [ --duration OR -D duration (in ms) ]\n" | 55 " [ --duration OR -D duration (in ms) ]\n" |
56 " [ --attack OR -a attack (in percent of duration) ]\n" | 56 " [ --attack OR -a attack (in percent of duration) ]\n" |
57 " [ --decay OR -d decay (in percent of duration) ]\n" | 57 " [ --decay OR -d decay (in percent of duration) ]\n" |
58 " [ --name OR -n jack name for metronome client ]\n" | 58 " [ --name OR -n jack name for metronome client ]\n" |
59 " [ --transport OR -t transport aware ]\n" | 59 " [ --transport OR -t transport aware ]\n" |
60 " [ --nophysical OR -p to prevent auto-connect to all physical ports]\n" | |
60 " --bpm OR -b beats per minute\n" | 61 " --bpm OR -b beats per minute\n" |
61 ); | 62 ); |
62 } | 63 } |
63 | 64 |
64 void | 65 void |
116 | 117 |
117 sample_t scale; | 118 sample_t scale; |
118 int i, attack_length, decay_length; | 119 int i, attack_length, decay_length; |
119 double *amp; | 120 double *amp; |
120 double max_amp = 0.5; | 121 double max_amp = 0.5; |
121 int option_index; | |
122 int opt; | 122 int opt; |
123 int got_bpm = 0; | 123 int got_bpm = 0; |
124 int attack_percent = 1, decay_percent = 10, dur_arg = 100; | 124 int attack_percent = 1, decay_percent = 10, dur_arg = 100; |
125 char *client_name = 0; | 125 char *client_name = 0; |
126 char *bpm_string = "bpm"; | 126 char *port_string = "out"; |
127 int verbose = 0; | 127 int verbose = 0; |
128 int connect_physical_ports = 1; | |
128 jack_status_t status; | 129 jack_status_t status; |
129 | 130 |
130 const char *options = "f:A:D:a:d:b:n:thv"; | 131 const char *options = "f:A:D:a:d:b:n:tphv"; |
131 struct option long_options[] = | 132 struct option long_options[] = |
132 { | 133 { |
133 {"frequency", 1, 0, 'f'}, | 134 {"frequency", 1, 0, 'f'}, |
134 {"amplitude", 1, 0, 'A'}, | 135 {"amplitude", 1, 0, 'A'}, |
135 {"duration", 1, 0, 'D'}, | 136 {"duration", 1, 0, 'D'}, |
136 {"attack", 1, 0, 'a'}, | 137 {"attack", 1, 0, 'a'}, |
137 {"decay", 1, 0, 'd'}, | 138 {"decay", 1, 0, 'd'}, |
138 {"bpm", 1, 0, 'b'}, | 139 {"bpm", 1, 0, 'b'}, |
139 {"name", 1, 0, 'n'}, | 140 {"name", 1, 0, 'n'}, |
140 {"transport", 0, 0, 't'}, | 141 {"transport", 0, 0, 't'}, |
142 {"nophysical", 0, 0, 'p'}, | |
141 {"help", 0, 0, 'h'}, | 143 {"help", 0, 0, 'h'}, |
142 {"verbose", 0, 0, 'v'}, | 144 {"verbose", 0, 0, 'v'}, |
143 {0, 0, 0, 0} | 145 {0, 0, 0, 0} |
144 }; | 146 }; |
145 | 147 |
146 while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) { | 148 while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != EOF) { |
147 switch (opt) { | 149 switch (opt) { |
148 case 'f': | 150 case 'f': |
149 if ((freq = atoi (optarg)) <= 0) { | 151 if ((freq = atoi (optarg)) <= 0) { |
150 fprintf (stderr, "invalid frequency\n"); | 152 fprintf (stderr, "invalid frequency\n"); |
151 return -1; | 153 return -1; |
177 got_bpm = 1; | 179 got_bpm = 1; |
178 if ((bpm = atoi (optarg)) < 0) { | 180 if ((bpm = atoi (optarg)) < 0) { |
179 fprintf (stderr, "invalid bpm\n"); | 181 fprintf (stderr, "invalid bpm\n"); |
180 return -1; | 182 return -1; |
181 } | 183 } |
182 bpm_string = (char *) malloc ((strlen (optarg) + 4) * sizeof (char)); | |
183 strcpy (bpm_string, optarg); | |
184 strcat (bpm_string, "_bpm"); | |
185 break; | 184 break; |
186 case 'n': | 185 case 'n': |
187 client_name = (char *) malloc (strlen (optarg) * sizeof (char)); | 186 client_name = (char *) malloc (strlen (optarg) * sizeof (char)); |
188 strcpy (client_name, optarg); | 187 strcpy (client_name, optarg); |
189 break; | 188 break; |
190 case 'v': | 189 case 'v': |
191 verbose = 1; | 190 verbose = 1; |
192 break; | 191 break; |
193 case 't': | 192 case 't': |
194 transport_aware = 1; | 193 transport_aware = 1; |
194 break; | |
195 case 'p': | |
196 connect_physical_ports = 0; | |
195 break; | 197 break; |
196 default: | 198 default: |
197 fprintf (stderr, "unknown option %c\n", opt); | 199 fprintf (stderr, "unknown option %c\n", opt); |
198 case 'h': | 200 case 'h': |
199 usage (); | 201 usage (); |
206 return -1; | 208 return -1; |
207 } | 209 } |
208 | 210 |
209 /* Initial Jack setup, get sample rate */ | 211 /* Initial Jack setup, get sample rate */ |
210 if (!client_name) { | 212 if (!client_name) { |
211 client_name = (char *) malloc (9 * sizeof (char)); | 213 pid_t pid = getpid(); |
212 strcpy (client_name, "metro"); | 214 client_name = (char *) malloc (32 * sizeof (char)); |
215 snprintf (client_name, 32, "metro_%d", pid); | |
213 } | 216 } |
214 if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) { | 217 if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) { |
215 fprintf (stderr, "jack server not running?\n"); | 218 fprintf (stderr, "jack server not running?\n"); |
216 return 1; | 219 return 1; |
217 } | 220 } |
218 jack_set_process_callback (client, process, 0); | 221 jack_set_process_callback (client, process, 0); |
219 output_port = jack_port_register (client, bpm_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); | 222 output_port = jack_port_register (client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); |
220 | 223 |
221 sr = jack_get_sample_rate (client); | 224 sr = jack_get_sample_rate (client); |
222 | 225 |
223 /* setup wave table parameters */ | 226 /* setup wave table parameters */ |
224 wave_length = 60 * sr / bpm; | 227 wave_length = 60 * sr / bpm; |
261 if (jack_activate (client)) { | 264 if (jack_activate (client)) { |
262 fprintf (stderr, "cannot activate client"); | 265 fprintf (stderr, "cannot activate client"); |
263 return 1; | 266 return 1; |
264 } | 267 } |
265 | 268 |
269 /* connect to physical ports */ | |
270 if (connect_physical_ports) { | |
271 const char **ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); | |
272 const char **c; | |
273 for (c = ports; c && *c; c++) | |
274 jack_connect (client, jack_port_name(output_port), *c); | |
275 } | |
276 | |
266 while (1) { | 277 while (1) { |
267 sleep(1); | 278 sleep(1); |
268 }; | 279 }; |
269 | 280 |
270 } | 281 } |