2008-08-16 03:09:01 +00:00
|
|
|
/*
|
2016-04-02 08:20:28 +00:00
|
|
|
** Copyright (C) 2008-2016 Erik de Castro Lopo <erikd@mega-nerd.com>
|
2010-10-11 09:33:52 +00:00
|
|
|
** Copyright (C) 2008-2010 George Blood Audio
|
2008-08-16 03:09:01 +00:00
|
|
|
**
|
|
|
|
** All rights reserved.
|
|
|
|
**
|
|
|
|
** Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
**
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
|
|
|
** * Neither the author nor the names of any contributors may be used
|
|
|
|
** to endorse or promote products derived from this software without
|
|
|
|
** specific prior written permission.
|
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
#include <sndfile.h>
|
|
|
|
|
2008-09-25 10:19:03 +00:00
|
|
|
#include "common.h"
|
2008-08-16 07:18:38 +00:00
|
|
|
|
2008-08-16 03:09:01 +00:00
|
|
|
#define BUFFER_LEN (1 << 16)
|
|
|
|
|
|
|
|
|
2008-08-16 05:46:33 +00:00
|
|
|
static void usage_exit (const char *progname, int exit_code) ;
|
|
|
|
static void missing_param (const char * option) ;
|
|
|
|
static void read_localtime (struct tm * timedata) ;
|
2008-09-25 10:28:40 +00:00
|
|
|
static int has_bext_fields_set (const METADATA_INFO * info) ;
|
2008-08-16 05:46:33 +00:00
|
|
|
|
2008-08-16 03:09:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv [])
|
2008-09-25 10:28:40 +00:00
|
|
|
{ METADATA_INFO info ;
|
2008-08-16 03:09:01 +00:00
|
|
|
struct tm timedata ;
|
|
|
|
const char *progname ;
|
2008-08-16 05:46:33 +00:00
|
|
|
const char * filenames [2] = { NULL, NULL } ;
|
2016-04-02 08:20:28 +00:00
|
|
|
char date [128], time [128] ;
|
2008-09-03 10:32:01 +00:00
|
|
|
int k ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
/* Store the program name. */
|
2011-03-21 10:17:59 +00:00
|
|
|
progname = program_name (argv [0]) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
/* Check if we've been asked for help. */
|
2008-08-18 00:18:05 +00:00
|
|
|
if (argc < 3 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
|
2008-08-16 03:09:01 +00:00
|
|
|
usage_exit (progname, 0) ;
|
|
|
|
|
2014-06-23 07:11:39 +00:00
|
|
|
/* Set all fields of the struct to zero bytes. */
|
2008-09-03 10:32:01 +00:00
|
|
|
memset (&info, 0, sizeof (info)) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
/* Get the time in case we need it later. */
|
2008-08-16 05:46:33 +00:00
|
|
|
read_localtime (&timedata) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
for (k = 1 ; k < argc ; k++)
|
2016-04-02 08:20:28 +00:00
|
|
|
{ if (argv [k][0] != '-')
|
2008-08-16 05:46:33 +00:00
|
|
|
{ if (filenames [0] == NULL)
|
|
|
|
filenames [0] = argv [k] ;
|
|
|
|
else if (filenames [1] == NULL)
|
|
|
|
filenames [1] = argv [k] ;
|
|
|
|
else
|
|
|
|
{ printf ("Error : Already have two file names on the command line and then found '%s'.\n\n", argv [k]) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
usage_exit (progname, 1) ;
|
|
|
|
} ;
|
|
|
|
continue ;
|
|
|
|
} ;
|
|
|
|
|
2012-01-21 03:24:38 +00:00
|
|
|
#define HANDLE_BEXT_ARG(cmd, field) \
|
2008-09-14 08:00:23 +00:00
|
|
|
if (strcmp (argv [k], cmd) == 0) \
|
|
|
|
{ k ++ ; \
|
|
|
|
if (k == argc) missing_param (argv [k - 1]) ; \
|
|
|
|
info.field = argv [k] ; \
|
|
|
|
continue ; \
|
2008-08-16 05:46:33 +00:00
|
|
|
} ;
|
|
|
|
|
2008-09-14 08:00:23 +00:00
|
|
|
HANDLE_BEXT_ARG ("--bext-description", description) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-originator", originator) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-orig-ref", originator_reference) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-umid", umid) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-orig-date", origination_date) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-orig-time", origination_time) ;
|
2019-08-21 16:43:24 +00:00
|
|
|
HANDLE_BEXT_ARG ("--bext-loudness-value", loudness_value) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-loudness-range", loudness_range) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-max-truepeak", max_true_peak_level) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-max-momentary", max_momentary_loudness) ;
|
|
|
|
HANDLE_BEXT_ARG ("--bext-max-shortterm", max_shortterm_loudness) ;
|
2008-09-14 08:00:23 +00:00
|
|
|
HANDLE_BEXT_ARG ("--bext-coding-hist", coding_history) ;
|
2010-02-22 07:31:20 +00:00
|
|
|
HANDLE_BEXT_ARG ("--bext-time-ref", time_ref) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
2012-01-21 03:24:38 +00:00
|
|
|
#define HANDLE_STR_ARG(cmd, field) \
|
2008-09-09 11:12:59 +00:00
|
|
|
if (strcmp (argv [k], cmd) == 0) \
|
|
|
|
{ k ++ ; \
|
|
|
|
if (k == argc) missing_param (argv [k - 1]) ; \
|
|
|
|
info.field = argv [k] ; \
|
|
|
|
continue ; \
|
|
|
|
} ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
2010-05-07 12:10:58 +00:00
|
|
|
HANDLE_STR_ARG ("--str-comment", comment) ;
|
2008-09-09 11:12:59 +00:00
|
|
|
HANDLE_STR_ARG ("--str-title", title) ;
|
|
|
|
HANDLE_STR_ARG ("--str-copyright", copyright) ;
|
|
|
|
HANDLE_STR_ARG ("--str-artist", artist) ;
|
|
|
|
HANDLE_STR_ARG ("--str-date", date) ;
|
|
|
|
HANDLE_STR_ARG ("--str-album", album) ;
|
|
|
|
HANDLE_STR_ARG ("--str-license", license) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
/* Following options do not take an argument. */
|
2008-08-25 10:04:11 +00:00
|
|
|
if (strcmp (argv [k], "--bext-auto-time-date") == 0)
|
2016-04-02 08:20:28 +00:00
|
|
|
{ snprintf (time, sizeof (time), "%02d:%02d:%02d", timedata.tm_hour, timedata.tm_min, timedata.tm_sec) ;
|
|
|
|
info.origination_time = time ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
2016-04-02 08:20:28 +00:00
|
|
|
snprintf (date, sizeof (date), "%04d-%02d-%02d", timedata.tm_year + 1900, timedata.tm_mon + 1, timedata.tm_mday) ;
|
|
|
|
info.origination_date = date ;
|
2008-08-16 03:09:01 +00:00
|
|
|
continue ;
|
|
|
|
} ;
|
|
|
|
|
2008-08-25 10:04:11 +00:00
|
|
|
if (strcmp (argv [k], "--bext-auto-time") == 0)
|
2016-04-02 08:20:28 +00:00
|
|
|
{ snprintf (time, sizeof (time), "%02d:%02d:%02d", timedata.tm_hour, timedata.tm_min, timedata.tm_sec) ;
|
|
|
|
info.origination_time = time ;
|
2008-08-16 03:09:01 +00:00
|
|
|
continue ;
|
|
|
|
} ;
|
|
|
|
|
2008-08-25 10:04:11 +00:00
|
|
|
if (strcmp (argv [k], "--bext-auto-date") == 0)
|
2016-04-02 08:20:28 +00:00
|
|
|
{ snprintf (date, sizeof (date), "%04d-%02d-%02d", timedata.tm_year + 1900, timedata.tm_mon + 1, timedata.tm_mday) ;
|
|
|
|
info.origination_date = strdup (date) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
continue ;
|
|
|
|
} ;
|
|
|
|
|
2008-09-09 11:12:59 +00:00
|
|
|
if (strcmp (argv [k], "--str-auto-date") == 0)
|
2016-04-02 08:20:28 +00:00
|
|
|
{ snprintf (date, sizeof (date), "%04d-%02d-%02d", timedata.tm_year + 1900, timedata.tm_mon + 1, timedata.tm_mday) ;
|
2008-08-24 09:12:17 +00:00
|
|
|
|
2016-04-02 08:20:28 +00:00
|
|
|
info.date = strdup (date) ;
|
2008-08-24 09:12:17 +00:00
|
|
|
continue ;
|
|
|
|
} ;
|
|
|
|
|
2008-08-16 03:09:01 +00:00
|
|
|
printf ("Error : Don't know what to do with command line arg '%s'.\n\n", argv [k]) ;
|
|
|
|
usage_exit (progname, 1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-09-03 10:32:01 +00:00
|
|
|
/* Find out if any of the 'bext' fields are set. */
|
|
|
|
info.has_bext_fields = has_bext_fields_set (&info) ;
|
|
|
|
|
2008-08-16 05:46:33 +00:00
|
|
|
if (filenames [0] == NULL)
|
|
|
|
{ printf ("Error : No input file specificed.\n\n") ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-08-16 07:18:38 +00:00
|
|
|
if (filenames [1] != NULL && strcmp (filenames [0], filenames [1]) == 0)
|
2008-08-16 05:46:33 +00:00
|
|
|
{ printf ("Error : Input and output files are the same.\n\n") ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2009-01-11 06:53:03 +00:00
|
|
|
if (info.coding_history != NULL && filenames [1] == NULL)
|
|
|
|
{ printf ("\n"
|
|
|
|
"Error : Trying to update coding history of an existing file which unfortunately\n"
|
|
|
|
" is not supported. Instead, create a new file using :\n"
|
|
|
|
"\n"
|
|
|
|
" %s --bext-coding-hist \"Coding history\" old_file.wav new_file.wav\n"
|
|
|
|
"\n",
|
|
|
|
progname) ;
|
|
|
|
exit (1) ;
|
|
|
|
} ;
|
|
|
|
|
2008-09-25 10:28:40 +00:00
|
|
|
sfe_apply_metadata_changes (filenames, &info) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
|
|
|
|
return 0 ;
|
|
|
|
} /* main */
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
** Print version and usage.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage_exit (const char *progname, int exit_code)
|
2008-10-01 10:57:15 +00:00
|
|
|
{ printf ("\nUsage :\n\n"
|
|
|
|
" %s [options] <file>\n"
|
|
|
|
" %s [options] <input file> <output file>\n"
|
|
|
|
"\n",
|
|
|
|
progname, progname) ;
|
|
|
|
|
|
|
|
puts (
|
|
|
|
"Where an option is made up of a pair of a field to set (one of\n"
|
|
|
|
"the 'bext' or metadata fields below) and a string. Fields are\n"
|
|
|
|
"as follows :\n"
|
|
|
|
) ;
|
|
|
|
|
|
|
|
puts (
|
|
|
|
" --bext-description Set the 'bext' description.\n"
|
|
|
|
" --bext-originator Set the 'bext' originator.\n"
|
|
|
|
" --bext-orig-ref Set the 'bext' originator reference.\n"
|
|
|
|
" --bext-umid Set the 'bext' UMID.\n"
|
|
|
|
" --bext-orig-date Set the 'bext' origination date.\n"
|
|
|
|
" --bext-orig-time Set the 'bext' origination time.\n"
|
2019-08-21 16:43:24 +00:00
|
|
|
" --bext-loudness-value Set the 'bext' loudness value.\n"
|
|
|
|
" --bext-loudness-range Set the 'bext' loudness range.\n"
|
|
|
|
" --bext-max-truepeak Set the 'bext' max. true peak level\n"
|
|
|
|
" --bext-max-momentary Set the 'bext' max. momentary loudness\n"
|
|
|
|
" --bext-max-shortterm Set the 'bext' max. short term loudness\n"
|
2010-02-22 07:31:20 +00:00
|
|
|
" --bext-coding-hist Set the 'bext' coding history.\n"
|
2014-06-23 07:11:39 +00:00
|
|
|
" --bext-time-ref Set the 'bext' Time ref.\n"
|
2008-10-01 10:57:15 +00:00
|
|
|
"\n"
|
2010-05-07 12:10:58 +00:00
|
|
|
" --str-comment Set the metadata comment.\n"
|
2008-10-01 10:57:15 +00:00
|
|
|
" --str-title Set the metadata title.\n"
|
|
|
|
" --str-copyright Set the metadata copyright.\n"
|
|
|
|
" --str-artist Set the metadata artist.\n"
|
|
|
|
" --str-date Set the metadata date.\n"
|
|
|
|
" --str-album Set the metadata album.\n"
|
|
|
|
" --str-license Set the metadata license.\n"
|
|
|
|
) ;
|
|
|
|
|
|
|
|
puts (
|
|
|
|
"There are also the following arguments which do not take a\n"
|
|
|
|
"parameter :\n\n"
|
|
|
|
" --bext-auto-time-date Set the 'bext' time and date to current time/date.\n"
|
|
|
|
" --bext-auto-time Set the 'bext' time to current time.\n"
|
|
|
|
" --bext-auto-date Set the 'bext' date to current date.\n"
|
|
|
|
" --str-auto-date Set the metadata date to current date.\n"
|
|
|
|
) ;
|
|
|
|
|
|
|
|
puts (
|
|
|
|
"Most of the above operations can be done in-place on an existing\n"
|
|
|
|
"file. If any operation cannot be performed, the application will\n"
|
|
|
|
"exit with an appropriate error message.\n"
|
|
|
|
) ;
|
|
|
|
|
2010-10-11 09:33:52 +00:00
|
|
|
printf ("Using %s.\n\n", sf_version_string ()) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
exit (exit_code) ;
|
|
|
|
} /* usage_exit */
|
|
|
|
|
|
|
|
static void
|
|
|
|
missing_param (const char * option)
|
|
|
|
{
|
|
|
|
printf ("Error : Option '%s' needs a parameter but doesn't seem to have one.\n\n", option) ;
|
|
|
|
exit (1) ;
|
|
|
|
} /* missing_param */
|
|
|
|
|
|
|
|
/*==============================================================================
|
|
|
|
*/
|
|
|
|
|
2008-09-03 10:32:01 +00:00
|
|
|
static int
|
2008-09-25 10:28:40 +00:00
|
|
|
has_bext_fields_set (const METADATA_INFO * info)
|
2008-09-03 10:32:01 +00:00
|
|
|
{
|
|
|
|
if (info->description || info->originator || info->originator_reference)
|
|
|
|
return 1 ;
|
2008-09-09 11:12:59 +00:00
|
|
|
|
2010-02-22 07:31:20 +00:00
|
|
|
if (info->origination_date || info->origination_time || info->umid || info->coding_history || info->time_ref)
|
2008-09-03 10:32:01 +00:00
|
|
|
return 1 ;
|
2008-09-09 11:12:59 +00:00
|
|
|
|
2019-08-21 16:43:24 +00:00
|
|
|
if (info->loudness_value || info->loudness_range || info->max_true_peak_level || info->max_momentary_loudness || info->max_shortterm_loudness)
|
|
|
|
return 1 ;
|
|
|
|
|
2008-09-03 10:32:01 +00:00
|
|
|
return 0 ;
|
|
|
|
} /* has_bext_fields_set */
|
|
|
|
|
2008-08-16 03:09:01 +00:00
|
|
|
static void
|
2008-08-16 05:46:33 +00:00
|
|
|
read_localtime (struct tm * timedata)
|
2008-08-16 03:09:01 +00:00
|
|
|
{ time_t current ;
|
|
|
|
|
|
|
|
time (¤t) ;
|
|
|
|
memset (timedata, 0, sizeof (struct tm)) ;
|
|
|
|
|
|
|
|
#if defined (HAVE_LOCALTIME_R)
|
|
|
|
/* If the re-entrant version is available, use it. */
|
2009-02-22 05:55:03 +00:00
|
|
|
localtime_r (¤t, timedata) ;
|
2008-08-16 03:09:01 +00:00
|
|
|
#elif defined (HAVE_LOCALTIME)
|
2009-02-22 05:55:03 +00:00
|
|
|
{
|
|
|
|
struct tm *tmptr ;
|
|
|
|
/* Otherwise use the standard one and copy the data to local storage. */
|
|
|
|
if ((tmptr = localtime (¤t)) != NULL)
|
|
|
|
memcpy (timedata, tmptr, sizeof (struct tm)) ;
|
|
|
|
}
|
2008-08-16 03:09:01 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return ;
|
2008-08-16 05:46:33 +00:00
|
|
|
} /* read_localtime */
|