add shorthand option --remove-replay-gain to metaflac
authorJosh Coalson <jcoalson@users.sourceforce.net>
Wed, 31 Aug 2005 00:30:41 +0000 (00:30 +0000)
committerJosh Coalson <jcoalson@users.sourceforce.net>
Wed, 31 Aug 2005 00:30:41 +0000 (00:30 +0000)
doc/html/changelog.html
doc/html/documentation.html
include/share/grabbag/replaygain.h
man/metaflac.sgml
src/metaflac/options.c
src/metaflac/usage.c
src/share/grabbag/replaygain.c
test/test_metaflac.sh

index 93cb415472b722231d90b245780be15f0ea56f94..d154b2ccf5d30a9349e6757951d9079b1f8f0be0 100644 (file)
@@ -94,6 +94,7 @@
                        <li>
                                metaflac:
                                <ul>
+                                       <li>Added shorthand operation <a href="documentation.html#metaflac_shorthand_remove_replay_gain"><span class="argument">--remove-replay-gain</span></a> for removing ReplayGain tags.</li>
                                        <li>Importing of non-CDDA-compliant cuesheets now issues a warning.</li>
                                </ul>
                        </li>
index 6631a2b57b2f517a404e2ffc7abe3996284b2fde..df12b16b059c3e7efeea94fe7ebc238bbc66f5f9 100644 (file)
                                        Calculates the title and album gains/peaks of the given FLAC files as if all the files were part of one album, then stores them in the <span class="code">VORBIS_COMMENT</span> block.  The tags are the same as those used by <span class="commandname">vorbisgain</span>.  Existing ReplayGain tags will be replaced.  If only one FLAC file is given, the album and title gains will be the same.  Since this operation requires two passes, it is always executed last, after all other operations have been completed and written to disk.  All FLAC files specified must have the same resolution, sample rate, and number of channels.  The sample rate must be one of 8, 11.025, 12, 16, 22.05, 24, 32, 44.1, or 48 kHz.
                                </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>
+                               <td>
+                                       Removes the ReplayGain tags.
+                               </td>
+                       </tr>
                        <tr>
                                <td nowrap="nowrap" align="right" valign="top" bgcolor="#F4F4CC">
                                        <a name="metaflac_shorthand_add_seekpoint" />
index 2d1111ce1eb6bd17921aca0059ad693ab1de8356..e8af2d01821a753d6ab5e7625a34d710ea6dba03 100644 (file)
@@ -35,6 +35,11 @@ extern "C" {
 
 extern const unsigned GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED;
 
+extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN; /* = "REPLAYGAIN_TRACK_GAIN" */
+extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK; /* = "REPLAYGAIN_TRACK_PEAK" */
+extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN; /* = "REPLAYGAIN_ALBUM_GAIN" */
+extern const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK; /* = "REPLAYGAIN_ALBUM_PEAK" */
+
 FLAC__bool grabbag__replaygain_is_valid_sample_frequency(unsigned sample_frequency);
 
 FLAC__bool grabbag__replaygain_init(unsigned sample_frequency);
index 042364667509b49c5df77fb9b1c88ec2e94576ba..b2177e86fbc4ac57343ce23fe2929acedba2a847 100644 (file)
@@ -303,6 +303,14 @@ manpage.1: manpage.sgml
          </para>
         </listitem>
       </varlistentry>
+      <varlistentry>
+       <term><option>--remove-replay-gain</option></term>
+        <listitem>
+         <para>
+           Removes the ReplayGain tags.
+         </para>
+        </listitem>
+      </varlistentry>
       <varlistentry>
        <term><option>--add-seekpoint</option>={<replaceable>#</replaceable>|<replaceable>X</replaceable>|<replaceable>#x</replaceable>|<replaceable>#s</replaceable>}</term>
        <listitem>
index dd6f3878f4126f20dd6a9aad4c050d2fb97e782c..0f38b6f159dbcfd69b259ce57751d257a4689186 100644 (file)
@@ -20,6 +20,7 @@
 #include "usage.h"
 #include "utils.h"
 #include "FLAC/assert.h"
+#include "share/grabbag/replaygain.h"
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -76,6 +77,7 @@ struct share__option long_options_[] = {
        { "export-cuesheet-to", 1, 0, 0 },
        { "add-seekpoint", 1, 0, 0 },
        { "add-replay-gain", 0, 0, 0 },
+       { "remove-replay-gain", 0, 0, 0 },
        { "add-padding", 1, 0, 0 },
        /* major operations */
        { "help", 0, 0, 0 },
@@ -568,6 +570,19 @@ 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, "remove-replay-gain")) {
+               const FLAC__byte * const tags[4] = {
+                       GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN,
+                       GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK,
+                       GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN,
+                       GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK
+               };
+               size_t i;
+               for(i = 0; i < sizeof(tags)/sizeof(tags[0]); i++) {
+                       op = append_shorthand_operation(options, OP__REMOVE_VC_FIELD);
+                       op->argument.vc_field_name.value = local_strdup((const char *)tags[i]);
+               }
+       }
        else if(0 == strcmp(opt, "add-padding")) {
                op = append_shorthand_operation(options, OP__ADD_PADDING);
                FLAC__ASSERT(0 != option_argument);
index 7f92e0b10aa57465495fa24fc317d1d52bc1b533..aa9ff4266431fc1f850ecac9ce34ef9b74d7f8f9 100644 (file)
@@ -149,6 +149,7 @@ 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, "--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");
        fprintf(out, "       X  : a placeholder point (always goes at the end of the SEEKTABLE)\n");
index f209769cfebc3fb40c907c5f2f9f2c26cbf66466..251e0e6dbac37a9f62a6190f39360c486da854db 100644 (file)
 #endif
 #define local_max(a,b) ((a)>(b)?(a):(b))
 
-static const FLAC__byte * const tag_title_gain_ = (const FLAC__byte * const)"REPLAYGAIN_TRACK_GAIN";
-static const FLAC__byte * const tag_title_peak_ = (const FLAC__byte * const)"REPLAYGAIN_TRACK_PEAK";
-static const FLAC__byte * const tag_album_gain_ = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_GAIN";
-static const FLAC__byte * const tag_album_peak_ = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_PEAK";
 static const char *peak_format_ = "%s=%1.8f";
 static const char *gain_format_ = "%s=%+2.2f dB";
 
@@ -58,6 +54,11 @@ const unsigned GRABBAG__REPLAYGAIN_MAX_TAG_SPACE_REQUIRED = 148;
        FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN/8 + 21 + 1 + 12
 */
 
+const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN = (const FLAC__byte * const)"REPLAYGAIN_TRACK_GAIN";
+const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK = (const FLAC__byte * const)"REPLAYGAIN_TRACK_PEAK";
+const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_GAIN";
+const FLAC__byte * const GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK = (const FLAC__byte * const)"REPLAYGAIN_ALBUM_PEAK";
+
 
 static FLAC__bool get_file_stats_(const char *filename, struct stat *stats)
 {
@@ -384,14 +385,14 @@ const char *grabbag__replaygain_store_to_vorbiscomment_album(FLAC__StreamMetadat
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
        if(
-               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)tag_album_gain_) < 0 ||
-               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)tag_album_peak_) < 0
+               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN) < 0 ||
+               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK) < 0
        )
                return "memory allocation error";
 
        if(
-               !append_tag_(block, peak_format_, tag_album_peak_, album_peak) ||
-               !append_tag_(block, gain_format_, tag_album_gain_, album_gain)
+               !append_tag_(block, peak_format_, GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK, album_peak) ||
+               !append_tag_(block, gain_format_, GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN, album_gain)
        )
                return "memory allocation error";
 
@@ -404,14 +405,14 @@ const char *grabbag__replaygain_store_to_vorbiscomment_title(FLAC__StreamMetadat
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
        if(
-               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)tag_title_gain_) < 0 ||
-               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)tag_title_peak_) < 0
+               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN) < 0 ||
+               FLAC__metadata_object_vorbiscomment_remove_entries_matching(block, (const char *)GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK) < 0
        )
                return "memory allocation error";
 
        if(
-               !append_tag_(block, peak_format_, tag_title_peak_, title_peak) ||
-               !append_tag_(block, gain_format_, tag_title_gain_, title_gain)
+               !append_tag_(block, peak_format_, GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK, title_peak) ||
+               !append_tag_(block, gain_format_, GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN, title_gain)
        )
                return "memory allocation error";
 
@@ -587,9 +588,9 @@ FLAC__bool grabbag__replaygain_load_from_vorbiscomment(const FLAC__StreamMetadat
        FLAC__ASSERT(0 != block);
        FLAC__ASSERT(block->type == FLAC__METADATA_TYPE_VORBIS_COMMENT);
 
-       if(0 > (gain_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? tag_album_gain_ : tag_title_gain_))))
+       if(0 > (gain_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_GAIN : GRABBAG__REPLAYGAIN_TAG_TITLE_GAIN))))
                return false;
-       if(0 > (peak_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? tag_album_peak_ : tag_title_peak_))))
+       if(0 > (peak_offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, /*offset=*/0, (const char *)(album_mode? GRABBAG__REPLAYGAIN_TAG_ALBUM_PEAK : GRABBAG__REPLAYGAIN_TAG_TITLE_PEAK))))
                return false;
 
        if(!parse_double_(block->data.vorbis_comment.comments + gain_offset, gain))
index 26ab690a2f8bb63baab51c0b932f42839fc7edbc..744199f83b97c235dc59e0d3fbe3a0cd0388bb30 100755 (executable)
@@ -324,6 +324,14 @@ rm -f $cs_out $cs_out2
 (set -x && run_metaflac --add-replay-gain $flacfile)
 check_exit
 check_flac
+(set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
+check_exit
+
+(set -x && run_metaflac --remove-replay-gain $flacfile)
+check_exit
+check_flac
+(set -x && run_metaflac --list --block-type=VORBIS_COMMENT $flacfile)
+check_exit
 
 echo -n "Testing FLAC file with unknown metadata... "
 cp -p metaflac.flac.in $flacfile