examples/parse_args.h: only parse time format string once, warn if unknown
authorPaul Brossier <piem@piem.org>
Wed, 12 Aug 2015 14:31:40 +0000 (16:31 +0200)
committerPaul Brossier <piem@piem.org>
Wed, 12 Aug 2015 14:31:40 +0000 (16:31 +0200)
examples/aubioonset.c
examples/parse_args.h
examples/utils.c

index 458f1ad..8f30bad 100644 (file)
@@ -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");
   }
 }
 
index 3ab7e7f..0548038 100644 (file)
@@ -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);
index 2cb87d2..a28f409 100644 (file)
@@ -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);