# HG changeset patch # User paulo@localhost # Date 1242552721 25200 # Node ID 46d4c88917a2ae1835e798ae026ccee42d4fd490 # Parent 047192fef9402168efc780ffa4f75edd151f7745 add Makefile; rename string to refer to "lsonify" instead of jack_metro; connect to physical input ports on startup diff -r 047192fef940 -r 46d4c88917a2 Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Makefile Sun May 17 02:32:01 2009 -0700 @@ -0,0 +1,35 @@ +JACK_CFLAGS := $(shell pkg-config --cflags jack) +JACK_LDFLAGS := $(shell pkg-config --libs jack) + +CFLAGS = -g -Wall ${JACK_CFLAGS} +LDFLAGS = ${JACK_LDFLAGS} + +CC = gcc + +SRC = metro.c +OBJ = ${SRC:.c=.o} + +TARGET := lsonify + +.PHONY: all clean options + +all: options ${TARGET} + +options: + @echo build options: + @echo "CFLAGS = ${CFLAGS}" + @echo "LDFLAGS = ${LDFLAGS}" + @echo "CC = ${CC}" + +%.o: %.c + @echo CC $< + @${CC} -c ${CFLAGS} $< + +clean: + @echo rm ${OBJ} ${TARGET} + @rm ${OBJ} ${TARGET} + +${TARGET}: ${OBJ} + @echo CC -o $@ + @${CC} -o $@ ${OBJ} ${LDFLAGS} + diff -r 047192fef940 -r 46d4c88917a2 metro.c --- a/metro.c Sat May 16 23:03:46 2009 -0700 +++ b/metro.c Sun May 17 02:32:01 2009 -0700 @@ -49,7 +49,7 @@ { fprintf (stderr, "\n" -"usage: jack_metro \n" +"usage: lsonify \n" " [ --frequency OR -f frequency (in Hz) ]\n" " [ --amplitude OR -A maximum amplitude (between 0 and 1) ]\n" " [ --duration OR -D duration (in ms) ]\n" @@ -57,6 +57,7 @@ " [ --decay OR -d decay (in percent of duration) ]\n" " [ --name OR -n jack name for metronome client ]\n" " [ --transport OR -t transport aware ]\n" +" [ --nophysical OR -p to prevent auto-connect to all physical ports]\n" " --bpm OR -b beats per minute\n" ); } @@ -118,16 +119,16 @@ int i, attack_length, decay_length; double *amp; double max_amp = 0.5; - int option_index; int opt; int got_bpm = 0; int attack_percent = 1, decay_percent = 10, dur_arg = 100; char *client_name = 0; - char *bpm_string = "bpm"; + char *port_string = "out"; int verbose = 0; + int connect_physical_ports = 1; jack_status_t status; - const char *options = "f:A:D:a:d:b:n:thv"; + const char *options = "f:A:D:a:d:b:n:tphv"; struct option long_options[] = { {"frequency", 1, 0, 'f'}, @@ -138,12 +139,13 @@ {"bpm", 1, 0, 'b'}, {"name", 1, 0, 'n'}, {"transport", 0, 0, 't'}, + {"nophysical", 0, 0, 'p'}, {"help", 0, 0, 'h'}, {"verbose", 0, 0, 'v'}, {0, 0, 0, 0} }; - while ((opt = getopt_long (argc, argv, options, long_options, &option_index)) != EOF) { + while ((opt = getopt_long (argc, argv, options, long_options, NULL)) != EOF) { switch (opt) { case 'f': if ((freq = atoi (optarg)) <= 0) { @@ -179,9 +181,6 @@ fprintf (stderr, "invalid bpm\n"); return -1; } - bpm_string = (char *) malloc ((strlen (optarg) + 4) * sizeof (char)); - strcpy (bpm_string, optarg); - strcat (bpm_string, "_bpm"); break; case 'n': client_name = (char *) malloc (strlen (optarg) * sizeof (char)); @@ -193,6 +192,9 @@ case 't': transport_aware = 1; break; + case 'p': + connect_physical_ports = 0; + break; default: fprintf (stderr, "unknown option %c\n", opt); case 'h': @@ -208,15 +210,16 @@ /* Initial Jack setup, get sample rate */ if (!client_name) { - client_name = (char *) malloc (9 * sizeof (char)); - strcpy (client_name, "metro"); + pid_t pid = getpid(); + client_name = (char *) malloc (32 * sizeof (char)); + snprintf (client_name, 32, "metro_%d", pid); } if ((client = jack_client_open (client_name, JackNoStartServer, &status)) == 0) { fprintf (stderr, "jack server not running?\n"); return 1; } jack_set_process_callback (client, process, 0); - output_port = jack_port_register (client, bpm_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + output_port = jack_port_register (client, port_string, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); sr = jack_get_sample_rate (client); @@ -263,6 +266,14 @@ return 1; } + /* connect to physical ports */ + if (connect_physical_ports) { + const char **ports = jack_get_ports (client, NULL, NULL, JackPortIsPhysical | JackPortIsInput); + const char **c; + for (c = ports; c && *c; c++) + jack_connect (client, jack_port_name(output_port), *c); + } + while (1) { sleep(1); };