From: Paul Brossier Date: Wed, 12 Aug 2015 14:31:40 +0000 (+0200) Subject: examples/parse_args.h: only parse time format string once, warn if unknown X-Git-Tag: 0.4.4~302^2~5 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=df7be4385dc2c85d14e8c8c168c782e6b60eedb6;p=aubio.git examples/parse_args.h: only parse time format string once, warn if unknown --- diff --git a/examples/aubioonset.c b/examples/aubioonset.c index 458f1ad2..8f30bad1 100644 --- a/examples/aubioonset.c +++ b/examples/aubioonset.c @@ -49,13 +49,8 @@ void process_block(fvec_t *ibuf, fvec_t *obuf) void process_print (void) { if ( is_onset ) { - if (strcmp (time_format, "samples") == 0) { - outmsg ("%d\n", aubio_onset_get_last (o) ); - } else if (strcmp (time_format, "ms") == 0) { - outmsg ("%f\n", aubio_onset_get_last_ms (o) ); - } else { - outmsg ("%f\n", aubio_onset_get_last_s (o) ); - } + print_time(aubio_onset_get_last (o)); + outmsg ("\n"); } } diff --git a/examples/parse_args.h b/examples/parse_args.h index 3ab7e7f3..0548038a 100644 --- a/examples/parse_args.h +++ b/examples/parse_args.h @@ -35,7 +35,7 @@ extern char_t * pitch_method; extern char_t * pitch_unit; extern smpl_t pitch_tolerance; // time stuff -extern char_t * time_format; +extern uint_t time_format; // tempo stuff extern char_t * tempo_method; // more general stuff @@ -208,7 +208,15 @@ parse_args (int argc, char **argv) pitch_tolerance = (smpl_t) atof (optarg); break; case 'T': - time_format = optarg; + if (strcmp (optarg, "samples") == 0) { + time_format = 2; + } else if (strcmp (optarg, "ms") == 0) { + time_format = 1; + } else if (strcmp (optarg, "seconds") == 0) { + time_format = 0; + } else { + errmsg ("Warning: did not get '%s' time-format string\n", optarg); + } break; case 's': /* silence threshold */ silence_threshold = (smpl_t) atof (optarg); diff --git a/examples/utils.c b/examples/utils.c index 2cb87d24..a28f4097 100644 --- a/examples/utils.c +++ b/examples/utils.c @@ -48,7 +48,7 @@ char_t * pitch_unit = "default"; char_t * pitch_method = "default"; smpl_t pitch_tolerance = 0.0; // will be set if != 0. // time stuff -char_t * time_format = "seconds"; +uint_t time_format = 0; // for "seconds", 1 for "ms", 2 for "samples" // tempo stuff char_t * tempo_method = "default"; // more general stuff @@ -209,9 +209,9 @@ send_noteon (int pitch, int velo) void print_time (uint_t time_in_samples) { /* output times in selected format */ - if (strcmp (time_format, "samples") == 0) { + if (time_format == 2) { outmsg ("%d", time_in_samples); - } else if (strcmp (time_format, "ms") == 0) { + } else if (time_format == 1) { outmsg ("%f", 1000. * time_in_samples / (float) samplerate); } else { outmsg ("%f", time_in_samples / (float) samplerate);