shithub: aubio

Download patch

ref: 0a509c6152bae66fbd43f98beb38be593111a9a9
parent: a93dab375dc53ce539d187fb22a0a18cba8de66d
author: Paul Brossier <piem@piem.org>
date: Sat Dec 7 18:51:09 EST 2013

examples/: check if sink_uri exists, add -f to force overwrite

--- a/examples/parse_args.h
+++ b/examples/parse_args.h
@@ -40,6 +40,8 @@
 extern smpl_t silence_threshold;
 extern uint_t mix_input;
 
+extern uint_t force_overwrite;
+
 // functions defined in utils.c
 extern void examples_common_init (int argc, char **argv);
 extern void examples_common_del (void);
@@ -78,6 +80,7 @@
       "       -s      --silence          select silence threshold\n"
 #ifdef PROG_HAS_OUTPUT
       "       -m      --mix-input        mix input signal with output signal\n"
+      "       -f      --force-overwrite  overwrite output file if\n"
 #endif
 #ifdef PROG_HAS_JACK
       "       -j      --jack             use Jack\n"
@@ -105,7 +108,7 @@
 #ifdef PROG_HAS_PITCH
     "p:u:l:"
 #endif /* PROG_HAS_PITCH */
-    "s:m";
+    "s:mf";
   int next_option;
   struct option long_options[] = {
     {"help",                  0, NULL, 'h'},
@@ -131,6 +134,7 @@
 #endif /* PROG_HAS_PITCH */
     {"silence",               1, NULL, 's'},
     {"mix-input",             0, NULL, 'm'},
+    {"force-overwrite",       0, NULL, 'f'},
     {NULL,                    0, NULL, 0}
   };
   prog_name = argv[0];
@@ -155,6 +159,9 @@
         break;
       case 'o':
         sink_uri = optarg;
+        break;
+      case 'f':                /* force_overwrite flag */
+        force_overwrite = 1;
         break;
       case 'r':
         samplerate = atoi (optarg);
--- a/examples/utils.c
+++ b/examples/utils.c
@@ -53,6 +53,8 @@
 smpl_t silence_threshold = -90.;
 uint_t mix_input = 0;
 
+uint_t force_overwrite = 0;
+
 //
 // internal memory stuff
 aubio_source_t *this_source = NULL;
@@ -88,6 +90,12 @@
       samplerate = aubio_source_get_samplerate(this_source);
     }
     if (sink_uri != NULL) {
+      uint_t sink_exists = (access(sink_uri, F_OK) == 0 );
+      if (!force_overwrite && sink_exists) {
+        outmsg ("Output file %s already exists, use -f to overwrite.\n",
+            sink_uri);
+        exit (1);
+      }
       this_sink = new_aubio_sink ((char_t*)sink_uri, samplerate);
       if (this_sink == NULL) {
         outmsg ("Could not open output file %s\n", sink_uri);