[beast] TOOLS: Added del-chunk command to bsewavetool to delete chunks.



commit 16ff5c1da56d5ac976b6315c2b0656e50d920a2c
Author: Stefan Westerfeld <stefan space twc de>
Date:   Wed Jun 23 15:20:24 2010 +0200

    TOOLS: Added del-chunk command to bsewavetool to delete chunks.

 docs/bsewavetool.1.doxi |   15 +++++++++++
 tools/bsewavetool.cc    |   60 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 0 deletions(-)
---
diff --git a/docs/bsewavetool.1.doxi b/docs/bsewavetool.1.doxi
index 0c83989..70533d5 100644
--- a/docs/bsewavetool.1.doxi
+++ b/docs/bsewavetool.1.doxi
@@ -117,6 +117,21 @@ bsewavetool - A tool for editing the native multisample format for @beast and @b
           little-endian, big-endian [little-endian].
         @done
 
+ subheading del-chunk {-m=midi-note|-f=osc-freq|--chunk-key=key|--all-chunks}
+        Removes one or more chunks from the bsewave file.
+
+        @manb{Options:}
+        @itemize{none}
+        @item @manb{-f} @mani{<osc-freq>} @*
+          Oscillator frequency to select a wave chunk.
+        @item @manb{-m} @mani{<midi-note>} @*
+          Alternative way to specify oscillator frequency.
+        @item @manb{--chunk-key} @mani{<key>} @*
+          Select wave chunk using chunk key from list-chunks.
+        @item @manb{--all-chunks} @*
+          Delete all chunks.
+        @done
+
 @subheading xinfo {-m=midi-note|-f=osc-freq|--chunk-key=key|--all-chunks|--wave} key=[value] ...
         Add, change or remove an XInfo string of a bsewave file.
         Omission of [value] deletes the XInfo associated with the key.
diff --git a/tools/bsewavetool.cc b/tools/bsewavetool.cc
index 4c05838..22e4f05 100644
--- a/tools/bsewavetool.cc
+++ b/tools/bsewavetool.cc
@@ -1227,6 +1227,66 @@ public:
   }
 } cmd_add_chunk ("add-chunk"), cmd_add_raw_chunk ("add-raw-chunk", AddChunk::RAW);
 
+class DelChunkCmd : public Command {
+  vector<gfloat> m_freq_list;
+  bool           m_all_chunks;
+public:
+  void
+  blurb (bool bshort)
+  {
+    g_print ("{-m=midi-note|-f=osc-freq|--chunk-key=key|--all-chunks}\n");
+    if (bshort)
+      return;
+    g_print ("    Removes one or more chunks from the bsewave file.\n");
+    g_print ("    Options:\n");
+    g_print ("    -f <osc-freq>       oscillator frequency to select a wave chunk\n");
+    g_print ("    -m <midi-note>      alternative way to specify oscillator frequency\n");
+    g_print ("    --chunk-key <key>   select wave chunk using chunk key from list-chunks\n");
+    g_print ("    --all-chunks        delete all chunks\n");
+    /*       "**********1*********2*********3*********4*********5*********6*********7*********" */
+  }
+  guint
+  parse_args (guint  argc,
+              char **argv)
+  {
+    bool seen_selection = false;
+    for (guint i = 1; i < argc; i++)
+      {
+	if (parse_chunk_selection (argv, i, argc, m_all_chunks, m_freq_list))
+          seen_selection = true;
+      }
+    return !seen_selection ? 1 : 0; /* # args missing */
+  }
+  bool
+  exec (Wave *wave)
+  {
+    /* get the wave into storage order */
+    wave->sort();
+    list<WaveChunk>::iterator it = wave->chunks.begin();
+    while (it != wave->chunks.end())
+      {
+        list<WaveChunk>::iterator next_it = it;
+        next_it++;
+
+        if (m_all_chunks || wave->match (*it, m_freq_list))
+          {
+            GslDataHandle *dhandle = it->dhandle;
+            double osc_freq = gsl_data_handle_osc_freq (dhandle);
+            sfi_info ("DELETE: osc-freq=%g", osc_freq);
+
+            wave->remove (it);
+          }
+        it = next_it;
+      }
+    return true;
+  }
+  DelChunkCmd (const char *command_name) :
+    Command (command_name),
+    m_all_chunks (false)
+  {
+  }
+} cmd ("del-chunk");
+
 class XInfoCmd : public Command {
   vector<char*> args;
 public:



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]