Mercurial > hg > index.fcgi > lsonify > lsonify-1pba
diff 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 |
line diff
1.1 --- a/metro.c Sat May 16 23:03:46 2009 -0700 1.2 +++ b/metro.c Sun May 17 02:32:01 2009 -0700 1.3 @@ -49,7 +49,7 @@ 1.4 1.5 { 1.6 fprintf (stderr, "\n" 1.7 -"usage: jack_metro \n" 1.8 +"usage: lsonify \n" 1.9 " [ --frequency OR -f frequency (in Hz) ]\n" 1.10 " [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n" 1.11 " [ --duration OR -D duration (in ms) ]\n" 1.12 @@ -57,6 +57,7 @@ 1.13 " [ --decay OR -d decay (in percent of duration) ]\n" 1.14 " [ --name OR -n jack name for metronome client ]\n" 1.15 " [ --transport OR -t transport aware ]\n" 1.16 +" [ --nophysical OR -p to prevent auto-connect to all physical ports]\n" 1.17 " --bpm OR -b beats per minute\n" 1.18 ); 1.19 } 1.20 @@ -118,16 +119,16 @@ 1.21 int i, attack_length, decay_length; 1.22 double *amp; 1.23 double max_amp = 0.5; 1.24 - int option_index; 1.25 int opt; 1.26 int got_bpm = 0; 1.27 int attack_percent = 1, decay_percent = 10, dur_arg = 100; 1.28 char *client_name = 0; 1.29 - char *bpm_string = "bpm"; 1.30 + char *port_string = "out"; 1.31 int verbose = 0; 1.32 + int connect_physical_ports = 1; 1.33 jack_status_t status; 1.34 1.35 - const char *options = "f:A:D:a:d:b:n:thv"; 1.36 + const char *options = "f:A:D:a:d:b:n:tphv"; 1.37 struct option long_options[] = 1.38 { 1.39 {"frequency", 1, 0, 'f'}, 1.40 @@ -138,12 +139,13 @@ 1.41 {"bpm", 1, 0, 'b'}, 1.42 {"name", 1, 0, 'n'}, 1.43 {"transport", 0, 0, 't'}, 1.44 + {"nophysical", 0, 0, 'p'}, 1.45 {"help", 0, 0, 'h'}, 1.46 {"verbose", 0, 0, 'v'}, 1.47 {0, 0, 0, 0} 1.48 }; 1.49 1.50 - while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) { 1.51 + while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != EOF) { 1.52 switch (opt) { 1.53 case 'f': 1.54 if ((freq = atoi (optarg)) <= 0) { 1.55 @@ -179,9 +181,6 @@ 1.56 fprintf (stderr, "invalid bpm\n"); 1.57 return -1; 1.58 } 1.59 - bpm_string = (char *) malloc ((strlen (optarg) + 4) * sizeof (char)); 1.60 - strcpy (bpm_string, optarg); 1.61 - strcat (bpm_string, "_bpm"); 1.62 break; 1.63 case 'n': 1.64 client_name = (char *) malloc (strlen (optarg) * sizeof (char)); 1.65 @@ -193,6 +192,9 @@ 1.66 case 't': 1.67 transport_aware = 1; 1.68 break; 1.69 + case 'p': 1.70 + connect_physical_ports = 0; 1.71 + break; 1.72 default: 1.73 fprintf (stderr, "unknown option %c\n", opt); 1.74 case 'h': 1.75 @@ -208,15 +210,16 @@ 1.76 1.77 /* Initial Jack setup, get sample rate */ 1.78 if (!client_name) { 1.79 - client_name = (char *) malloc (9 * sizeof (char)); 1.80 - strcpy (client_name, "metro"); 1.81 + pid_t pid = getpid(); 1.82 + client_name = (char *) malloc (32 * sizeof (char)); 1.83 + snprintf (client_name, 32, "metro_%d", pid); 1.84 } 1.85 if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) { 1.86 fprintf (stderr, "jack server not running?\n"); 1.87 return 1; 1.88 } 1.89 jack_set_process_callback (client, process, 0); 1.90 - output_port = jack_port_register (client, bpm_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 1.91 + output_port = jack_port_register (client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); 1.92 1.93 sr = jack_get_sample_rate (client); 1.94 1.95 @@ -263,6 +266,14 @@ 1.96 return 1; 1.97 } 1.98 1.99 + /* connect to physical ports */ 1.100 + if (connect_physical_ports) { 1.101 + const char **ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); 1.102 + const char **c; 1.103 + for (c = ports; c && *c; c++) 1.104 + jack_connect (client, jack_port_name(output_port), *c); 1.105 + } 1.106 + 1.107 while (1) { 1.108 sleep(1); 1.109 };