summaryrefslogtreecommitdiff
path: root/src/metaflac
diff options
context:
space:
mode:
authorBen Boeckel <mathstuf@gmail.com>2015-08-12 21:45:04 -0400
committerErik de Castro Lopo <erikd@mega-nerd.com>2015-08-14 06:21:26 +1000
commitf7c52c8aa8e2a4ccfd98e3ba8d6dbfa04d75a17b (patch)
tree37cfb7f86121b5c104176693383fa29e11eb9fc4 /src/metaflac
parent15a9062609c123b56df104a575dba657c2577e0b (diff)
downloadflac-f7c52c8aa8e2a4ccfd98e3ba8d6dbfa04d75a17b.tar.gz
metaflac: add --scan-replay-gain option
Signed-off-by: Erik de Castro Lopo <erikd@mega-nerd.com>
Diffstat (limited to 'src/metaflac')
-rw-r--r--src/metaflac/operations.c25
-rw-r--r--src/metaflac/options.c4
-rw-r--r--src/metaflac/options.h1
-rw-r--r--src/metaflac/usage.c2
4 files changed, 23 insertions, 9 deletions
diff --git a/src/metaflac/operations.c b/src/metaflac/operations.c
index 23d4bff1..f725125a 100644
--- a/src/metaflac/operations.c
+++ b/src/metaflac/operations.c
@@ -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]);
}
}
diff --git a/src/metaflac/options.c b/src/metaflac/options.c
index db60d4ef..9d15443a 100644
--- a/src/metaflac/options.c
+++ b/src/metaflac/options.c
@@ -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,
diff --git a/src/metaflac/options.h b/src/metaflac/options.h
index 0e7fa5af..c0b08226 100644
--- a/src/metaflac/options.h
+++ b/src/metaflac/options.h
@@ -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,
diff --git a/src/metaflac/usage.c b/src/metaflac/usage.c
index ce90421a..9342a865 100644
--- a/src/metaflac/usage.c
+++ b/src/metaflac/usage.c
@@ -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");