metaflac: add --scan-replay-gain option
authorBen Boeckel <mathstuf@gmail.com>
Thu, 13 Aug 2015 01:45:04 +0000 (21:45 -0400)
committerErik de Castro Lopo <erikd@mega-nerd.com>
Thu, 13 Aug 2015 20:21:26 +0000 (06:21 +1000)
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
doc/html/documentation_tools_metaflac.html
man/metaflac.1
man/metaflac.sgml
src/metaflac/operations.c
src/metaflac/options.c
src/metaflac/options.h
src/metaflac/usage.c
test/test_metaflac.sh
test/test_replaygain.sh

index d858b51..f7e8a06 100644 (file)
                        </tr>
                        <tr>
                                <td nowrap="nowrap" align="right" valign="top" bgcolor="#F4F4CC">
+                                       <a name="metaflac_shorthand_add_replay_gain_scan" />
+                                       <span class="argument">--scan-replay-gain</span>
+                               </td>
+                               <td>
+                                       Like <span class="argument">--add-replay-gain</span>, but only analyzes the files rather than writing them to the tags.
+                               </td>
+                       </tr>
+                       <tr>
+                               <td nowrap="nowrap" align="right" valign="top" bgcolor="#F4F4CC">
                                        <a name="metaflac_shorthand_remove_replay_gain" />
                                        <span class="argument">--remove-replay-gain</span>
                                </td>
                <a href="#metaflac_shorthand_remove_replay_gain"><span class="argument">--remove-replay-gain</span></a><br />
                <a href="#metaflac_shorthand_remove_tag"><span class="argument">--remove-tag</span></a><br />
                <a href="#metaflac_operations_remove"><span class="argument">--remove</span></a><br />
+               <a href="#metaflac_shorthand_scan_replay_gain"><span class="argument">--scan-replay-gain</span></a><br />
                <a href="#metaflac_shorthand_set_tag_from_file"><span class="argument">--set-tag-from-file</span></a><br />
                <a href="#metaflac_shorthand_set_tag"><span class="argument">--set-tag</span></a><br />
                <a href="#metaflac_shorthand_show_bps"><span class="argument">--show-bps</span></a><br />
index c3a14e0..e9e77f7 100644 (file)
@@ -199,6 +199,10 @@ number of channels.  The sample rate must be one of 8, 11.025,
 12, 16, 18.9, 22.05, 24, 28, 32, 37.8, 44.1, 48, 56, 64, 88.2,
 96, 112, 128, 144, 176.4, or 192kHz.
 .TP
+\fB--scan-replay-gain\fR
+Like --add-replay-gain, but only analyzes the files rather than
+writing them to the tags.
+.TP
 \fB--remove-replay-gain\fR
 Removes the ReplayGain tags.
 .TP
index 6ad942f..a87ea58 100644 (file)
@@ -380,6 +380,16 @@ manpage.1: manpage.sgml
         </listitem>
       </varlistentry>
       <varlistentry>
+       <term><option>--scan-replay-gain</option></term>
+        <listitem>
+         <para>
+            
+           Like --add-replay-gain, but only analyzes the files rather
+           than writing them to the tags.
+         </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
        <term><option>--remove-replay-gain</option></term>
         <listitem>
          <para>
index 23d4bff..f725125 100644 (file)
@@ -44,7 +44,7 @@ static FLAC__bool do_major_operation__remove_all(FLAC__Metadata_Chain *chain, co
 static FLAC__bool do_shorthand_operations(const CommandLineOptions *options);
 static FLAC__bool do_shorthand_operations_on_file(const char *filename, const CommandLineOptions *options);
 static FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_filename, FLAC__Metadata_Chain *chain, const Operation *operation, FLAC__bool *needs_write, FLAC__bool utf8_convert);
-static FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime);
+static FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime, FLAC__bool scan);
 static FLAC__bool do_shorthand_operation__add_padding(const char *filename, FLAC__Metadata_Chain *chain, unsigned length, FLAC__bool *needs_write);
 
 static FLAC__bool passes_filter(const CommandLineOptions *options, const FLAC__StreamMetadata *block, unsigned block_number);
@@ -266,7 +266,9 @@ FLAC__bool do_shorthand_operations(const CommandLineOptions *options)
        if(ok && options->num_files > 0) {
                for(i = 0; i < options->ops.num_operations; i++) {
                        if(options->ops.operations[i].type == OP__ADD_REPLAY_GAIN)
-                               ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime);
+                               ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime, false);
+                       else if(options->ops.operations[i].type == OP__SCAN_REPLAY_GAIN)
+                               ok = do_shorthand_operation__add_replay_gain(options->filenames, options->num_files, options->preserve_modtime, true);
                }
        }
 
@@ -375,7 +377,8 @@ FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_f
                        ok = do_shorthand_operation__add_seekpoints(filename, chain, operation->argument.add_seekpoint.specification, needs_write);
                        break;
                case OP__ADD_REPLAY_GAIN:
-                       /* this command is always executed last */
+               case OP__SCAN_REPLAY_GAIN:
+                       /* these commands are always executed last */
                        ok = true;
                        break;
                case OP__ADD_PADDING:
@@ -390,7 +393,7 @@ FLAC__bool do_shorthand_operation(const char *filename, FLAC__bool prefix_with_f
        return ok;
 }
 
-FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime)
+FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned num_files, FLAC__bool preserve_modtime, FLAC__bool scan)
 {
        FLAC__StreamMetadata streaminfo;
        float *title_gains = 0, *title_peaks = 0;
@@ -465,11 +468,15 @@ FLAC__bool do_shorthand_operation__add_replay_gain(char **filenames, unsigned nu
        grabbag__replaygain_get_album(&album_gain, &album_peak);
 
        for(i = 0; i < num_files; i++) {
-               if(0 != (error = grabbag__replaygain_store_to_file(filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i], preserve_modtime))) {
-                       flac_fprintf(stderr, "%s: ERROR: writing tags (%s)\n", filenames[i], error);
-                       free(title_gains);
-                       free(title_peaks);
-                       return false;
+               if(!scan) {
+                       if(0 != (error = grabbag__replaygain_store_to_file(filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i], preserve_modtime))) {
+                               flac_fprintf(stderr, "%s: ERROR: writing tags (%s)\n", filenames[i], error);
+                               free(title_gains);
+                               free(title_peaks);
+                               return false;
+                       }
+               } else {
+                       flac_fprintf(stdout, "%s: %f %f %f %f\n", filenames[i], album_gain, album_peak, title_gains[i], title_peaks[i]);
                }
        }
 
index db60d4e..9d15443 100644 (file)
@@ -79,6 +79,7 @@ struct share__option long_options_[] = {
        { "export-picture-to", 1, 0, 0 },
        { "add-seekpoint", 1, 0, 0 },
        { "add-replay-gain", 0, 0, 0 },
+       { "scan-replay-gain", 0, 0, 0 },
        { "remove-replay-gain", 0, 0, 0 },
        { "add-padding", 1, 0, 0 },
        /* major operations */
@@ -612,6 +613,9 @@ FLAC__bool parse_option(int option_index, const char *option_argument, CommandLi
        else if(0 == strcmp(opt, "add-replay-gain")) {
                (void) append_shorthand_operation(options, OP__ADD_REPLAY_GAIN);
        }
+       else if(0 == strcmp(opt, "scan-replay-gain")) {
+               (void) append_shorthand_operation(options, OP__SCAN_REPLAY_GAIN);
+       }
        else if(0 == strcmp(opt, "remove-replay-gain")) {
                const FLAC__byte * const tags[5] = {
                        GRABBAG__REPLAYGAIN_TAG_REFERENCE_LOUDNESS,
index 0e7fa5a..c0b0822 100644 (file)
@@ -65,6 +65,7 @@ typedef enum {
        OP__EXPORT_PICTURE_TO,
        OP__ADD_SEEKPOINT,
        OP__ADD_REPLAY_GAIN,
+       OP__SCAN_REPLAY_GAIN,
        OP__ADD_PADDING,
        OP__LIST,
        OP__APPEND,
index ce90421..9342a86 100644 (file)
@@ -218,6 +218,8 @@ int long_usage(const char *message, ...)
        fprintf(out, "                      must have the same resolution, sample rate, and number\n");
        fprintf(out, "                      of channels.  The sample rate must be one of 8, 11.025,\n");
        fprintf(out, "                      12, 16, 22.05, 24, 32, 44.1, or 48 kHz.\n");
+       fprintf(out, "--scan-replay-gain    Like --add-replay-gain, but only analyzes the files\n");
+       fprintf(out, "                      rather than writing them to tags.\n");
        fprintf(out, "--remove-replay-gain  Removes the ReplayGain tags.\n");
        fprintf(out, "--add-seekpoint={#|X|#x|#s}  Add seek points to a SEEKTABLE block\n");
        fprintf(out, "       #  : a specific sample number for a seek point\n");
index bfa6610..3e2c841 100755 (executable)
@@ -274,6 +274,10 @@ run_metaflac --remove-replay-gain $flacfile
 check_flac
 metaflac_test case42 "--remove-replay-gain" "--list"
 
+run_metaflac --scan-replay-gain $flacfile
+check_flac
+metaflac_test case42 "--scan-replay-gain" "--list"
+
 # CUESHEET blocks
 cs_in=${top_srcdir}/test/cuesheets/good.000.cue
 cs_out=metaflac.cue
index fef7494..4296759 100755 (executable)
@@ -126,6 +126,7 @@ for ACTION in $REPLAYGAIN_FREQ ; do
     [ $MULTIPLE -eq 1 -o -n "${REPLAYGAIN_FREQ##* $RATE/*}" ] || break
     echo -n "Testing FLAC replaygain $RATE ($FREQ x $MULTIPLE) ... "
     tonegenerator $RATE $flacfile
+    run_metaflac --scan-replay-gain $flacfile
     run_metaflac --add-replay-gain $flacfile
     run_metaflac --list $flacfile | grep REPLAYGAIN.*GAIN= |
     while read -r REPLAYGAIN ; do