From 629eef1b3c59a9935b5f57d1e9e5d99f4ec40e01 Mon Sep 17 00:00:00 2001 From: Markus Peloquin Date: Thu, 9 Apr 2020 00:49:15 -0700 Subject: [PATCH] Fix misguided brace style --- decode.cpp | 18 +++------ encode.cpp | 21 ++++------- encode.hpp | 10 ++--- errors.cpp | 3 +- errors.hpp | 4 +- gain_analysis.c | 27 +++++--------- gain_analysis.h | 42 ++++++++++----------- gain_analysis.hpp | 34 +++++++---------- main.cpp | 78 ++++++++++++++++++-------------------- replaygain_writer.cpp | 87 +++++++++++++++---------------------------- replaygain_writer.hpp | 35 +++++++++-------- sanitize.cpp | 3 +- transcode.cpp | 6 +-- transcode.hpp | 36 +++++++++--------- 14 files changed, 167 insertions(+), 237 deletions(-) diff --git a/decode.cpp b/decode.cpp index f72550e..cae5c61 100644 --- a/decode.cpp +++ b/decode.cpp @@ -34,8 +34,7 @@ bool same_file(FILE *, FILE *); class Sox_init { public: Sox_init() : _valid(false) {} - ~Sox_init() - { + ~Sox_init() { if (_valid) sox_quit(); } @@ -227,8 +226,7 @@ Flac_decoder::next_frame(struct flacsplit::Frame &frame) { FLAC__StreamDecoderWriteStatus Flac_decoder::write_callback(const FLAC__Frame *frame, - const FLAC__int32 *const *buffer) -{ + const FLAC__int32 *const *buffer) { if (!_last_buffer.get()) // the number of channels should be constant _last_buffer.reset(new const FLAC__int32 *[ @@ -249,8 +247,7 @@ Flac_decoder::write_callback(const FLAC__Frame *frame, } FLAC__StreamDecoderSeekStatus -Flac_decoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ +Flac_decoder::seek_callback(FLAC__uint64 absolute_byte_offset) { long off = absolute_byte_offset; if (static_cast(off) != absolute_byte_offset) throw std::runtime_error("bad offset"); @@ -261,8 +258,7 @@ Flac_decoder::seek_callback(FLAC__uint64 absolute_byte_offset) } FLAC__StreamDecoderTellStatus -Flac_decoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ +Flac_decoder::tell_callback(FLAC__uint64 *absolute_byte_offset) { long off = ftell(_fp); if (off < 0) return FLAC__STREAM_DECODER_TELL_STATUS_ERROR; @@ -271,8 +267,7 @@ Flac_decoder::tell_callback(FLAC__uint64 *absolute_byte_offset) } FLAC__StreamDecoderLengthStatus -Flac_decoder::length_callback(FLAC__uint64 *stream_length) -{ +Flac_decoder::length_callback(FLAC__uint64 *stream_length) { struct stat st; if (fstat(fileno(_fp), &st)) return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR; @@ -345,8 +340,7 @@ Wave_decoder::next_frame(struct flacsplit::Frame &frame) { } enum flacsplit::file_format -get_file_format(FILE *fp) -{ +get_file_format(FILE *fp) { const char *const RIFF = "RIFF"; const char *const WAVE = "WAVE"; const char *const FLAC = "fLaC"; diff --git a/encode.cpp b/encode.cpp index 0e54bf5..b2ed0ec 100644 --- a/encode.cpp +++ b/encode.cpp @@ -81,14 +81,12 @@ class Flac_encoder : FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *) override; private: - virtual void set_meta(const flacsplit::Music_info &track) - { + virtual void set_meta(const flacsplit::Music_info &track) { set_meta(track, true); } void set_meta(const flacsplit::Music_info &, bool); - FLAC__StreamMetadata *cast_metadata(FLAC::Metadata::Prototype &meta) - { + FLAC__StreamMetadata *cast_metadata(FLAC::Metadata::Prototype &meta) { return const_cast( static_cast(meta)); } @@ -152,8 +150,7 @@ Flac_encoder::add_frame(const struct flacsplit::Frame &frame) { void Flac_encoder::set_meta(const flacsplit::Music_info &track, - bool add_replaygain_padding) -{ + bool add_replaygain_padding) { using FLAC::Metadata::VorbisComment; const std::string &album = track.album(); @@ -232,8 +229,7 @@ Flac_encoder::set_meta(const flacsplit::Music_info &track, #if 0 FLAC__StreamEncoderReadStatus -Flac_encoder::read_callback(FLAC__byte *buffer, size_t *bytes) -{ +Flac_encoder::read_callback(FLAC__byte *buffer, size_t *bytes) { //FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE //FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM //FLAC__STREAM_ENCODER_READ_STATUS_ABORT @@ -244,16 +240,14 @@ Flac_encoder::read_callback(FLAC__byte *buffer, size_t *bytes) FLAC__StreamEncoderWriteStatus Flac_encoder::write_callback(const FLAC__byte *buffer, size_t bytes, - unsigned /*samples*/, unsigned /*current_frame*/) -{ + unsigned /*samples*/, unsigned /*current_frame*/) { if (fwrite(buffer, bytes, 1, _fp)) return FLAC__STREAM_ENCODER_WRITE_STATUS_OK; return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR; } FLAC__StreamEncoderSeekStatus -Flac_encoder::seek_callback(FLAC__uint64 absolute_byte_offset) -{ +Flac_encoder::seek_callback(FLAC__uint64 absolute_byte_offset) { long off = absolute_byte_offset; if (static_cast(off) != absolute_byte_offset) { @@ -266,8 +260,7 @@ Flac_encoder::seek_callback(FLAC__uint64 absolute_byte_offset) } FLAC__StreamEncoderTellStatus -Flac_encoder::tell_callback(FLAC__uint64 *absolute_byte_offset) -{ +Flac_encoder::tell_callback(FLAC__uint64 *absolute_byte_offset) { long off = ftell(_fp); if (off < 0) return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR; diff --git a/encode.hpp b/encode.hpp index 39490ef..bb1444e 100644 --- a/encode.hpp +++ b/encode.hpp @@ -37,16 +37,16 @@ class Basic_encoder { virtual void add_frame(const struct Frame &) = 0; virtual bool finish() = 0; - - //virtual void set_meta(const Music_info &) = 0; }; class Encoder : public Basic_encoder { public: struct Bad_format : std::exception { - virtual ~Bad_format() throw () {} - virtual const char *what() const throw () - { return "bad format"; } + virtual ~Bad_format() noexcept {} + + virtual const char *what() const noexcept override { + return "bad format"; + } }; //! \throw Bad_format diff --git a/errors.cpp b/errors.cpp index 7822314..0d3b99d 100644 --- a/errors.cpp +++ b/errors.cpp @@ -18,8 +18,7 @@ #include "errors.hpp" -flacsplit::Unix_error::Unix_error(int errnum) -{ +flacsplit::Unix_error::Unix_error(int errnum) { this->errnum = errnum < 0 ? errno : errnum; msg = strerror(this->errnum); } diff --git a/errors.hpp b/errors.hpp index cacdb25..0c460b9 100644 --- a/errors.hpp +++ b/errors.hpp @@ -31,7 +31,7 @@ struct Bad_format : std::exception { struct Bad_samplefreq : std::exception { virtual ~Bad_samplefreq() noexcept {} - const char *what() const noexcept { + const char *what() const noexcept override { return "bad sample frequency"; } }; @@ -47,7 +47,7 @@ struct Not_enough_samples : public std::exception { virtual ~Not_enough_samples() noexcept {} - const char *what() const noexcept { + const char *what() const noexcept override { return _msg.c_str(); } diff --git a/gain_analysis.c b/gain_analysis.c index bb3e09e..655a390 100644 --- a/gain_analysis.c +++ b/gain_analysis.c @@ -234,8 +234,7 @@ static const Float_t ABButter[9][2*BUTTER_ORDER + 1] = { static void filter_yule(const Float_t *input, Float_t *output, size_t nSamples, - const Float_t *kernel) -{ + const Float_t *kernel) { while (nSamples--) { /* 1e-10 is a hack to avoid slowdown because of denormals */ *output = 1e-10 + input[ 0] * kernel[ 0] - @@ -256,8 +255,7 @@ filter_yule(const Float_t *input, Float_t *output, size_t nSamples, static void filter_butter(const Float_t *input, Float_t *output, size_t nSamples, - const Float_t *kernel) -{ + const Float_t *kernel) { while (nSamples--) { *output = input[0] * kernel[0] - output[-1] * kernel[1] + input[-1] * kernel[2] - @@ -268,8 +266,7 @@ filter_butter(const Float_t *input, Float_t *output, size_t nSamples, } enum replaygain_status -replaygain_reset_frequency(struct replaygain_ctx *ctx, unsigned long freq) -{ +replaygain_reset_frequency(struct replaygain_ctx *ctx, unsigned long freq) { /* zero out initial values */ memset(ctx->linprebuf, 0, sizeof(Float_t) * MAX_ORDER); memset(ctx->rinprebuf, 0, sizeof(Float_t) * MAX_ORDER); @@ -307,8 +304,7 @@ replaygain_reset_frequency(struct replaygain_ctx *ctx, unsigned long freq) } struct replaygain_ctx * -replaygain_alloc(unsigned long freq, enum replaygain_status *out_status) -{ +replaygain_alloc(unsigned long freq, enum replaygain_status *out_status) { struct replaygain_ctx *ctx; enum replaygain_status status; @@ -338,14 +334,12 @@ replaygain_alloc(unsigned long freq, enum replaygain_status *out_status) } static inline Float_t -fsqr(const Float_t d) -{ +fsqr(const Float_t d) { return d * d; } static Float_t -peak_value(const Float_t *samples, size_t num_samples) -{ +peak_value(const Float_t *samples, size_t num_samples) { Float_t peak = 0.0; while (num_samples--) { Float_t sample = *samples++; @@ -359,8 +353,7 @@ peak_value(const Float_t *samples, size_t num_samples) enum replaygain_status replaygain_analyze(struct replaygain_ctx *ctx, const Float_t *lsamples, - const Float_t *rsamples, size_t num_samples, unsigned channels) -{ + const Float_t *rsamples, size_t num_samples, unsigned channels) { unsigned long batchsamples; unsigned long cursamplepos; size_t copy_samples; @@ -531,8 +524,7 @@ replaygain_analyze(struct replaygain_ctx *ctx, const Float_t *lsamples, } Float_t -replaygain_adjustment(const struct replaygain_value *out) -{ +replaygain_adjustment(const struct replaygain_value *out) { uint32_t elems; int32_t upper; size_t i; @@ -555,8 +547,7 @@ replaygain_adjustment(const struct replaygain_value *out) } void -replaygain_pop(struct replaygain_ctx *ctx, struct replaygain_value *out) -{ +replaygain_pop(struct replaygain_ctx *ctx, struct replaygain_value *out) { memcpy(out, &ctx->value, sizeof(ctx->value)); memset(&ctx->value, 0, sizeof(ctx->value)); diff --git a/gain_analysis.h b/gain_analysis.h index a906727..44b6777 100644 --- a/gain_analysis.h +++ b/gain_analysis.h @@ -125,11 +125,10 @@ __BEGIN_DECLS * \return The context, which must be passed to * replaygain_free() when finished */ -struct replaygain_ctx * - replaygain_alloc(unsigned long samplefreq, - enum replaygain_status *out_status); +struct replaygain_ctx *replaygain_alloc(unsigned long samplefreq, + enum replaygain_status *out_status); -__INLINE void replaygain_free(struct replaygain_ctx *ctx); +__INLINE void replaygain_free(struct replaygain_ctx *ctx); /** Reset the sampling frequency * @@ -138,9 +137,8 @@ __INLINE void replaygain_free(struct replaygain_ctx *ctx); * \retval REPLAYGAIN_ERR_SAMPLEFREQ * \retval REPLAYGAIN_OK */ -enum replaygain_status - replaygain_reset_frequency(struct replaygain_ctx *ctx, - unsigned long freq); +enum replaygain_status replaygain_reset_frequency(struct replaygain_ctx *ctx, + unsigned long freq); /** Accumulate samples into a calculation * @@ -155,54 +153,53 @@ enum replaygain_status * \retval REPLAYGAIN_ERROR Bad number of channels or some exceptional * error */ -enum replaygain_status - replaygain_analyze(struct replaygain_ctx *ctx, - const double *left_samples, const double *right_samples, - size_t num_samples, unsigned num_channels); +enum replaygain_status replaygain_analyze(struct replaygain_ctx *ctx, + const double *left_samples, + const double *right_samples, size_t num_samples, + unsigned num_channels); /** Return current calculation, reset context * * \param ctx Analyzing context * \param[out] out The accumulated Replaygain sample */ -void replaygain_pop(struct replaygain_ctx *ctx, - struct replaygain_value *out); +void replaygain_pop(struct replaygain_ctx *ctx, + struct replaygain_value *out); /** Combine result of one sample with another * * \param sum The accumulated value * \param addition The value to add to sum */ -__INLINE void replaygain_accum(struct replaygain_value *sum, - const struct replaygain_value *addition); +__INLINE void replaygain_accum(struct replaygain_value *sum, + const struct replaygain_value *addition); /** Decibal adjustment for a sample * * \param value A value calculation * \return How many decibals to adjust by */ -double replaygain_adjustment(const struct replaygain_value *value); +double replaygain_adjustment( + const struct replaygain_value *value); /** Peak level of all samples. * * \param value A value calculation * \return Peak level normalized to [0,1] */ -__INLINE double replaygain_peak(const struct replaygain_value *value); +__INLINE double replaygain_peak(const struct replaygain_value *value); __INLINE void -replaygain_free(struct replaygain_ctx *ctx) -{ +replaygain_free(struct replaygain_ctx *ctx) { free(ctx); } __INLINE void replaygain_accum(struct replaygain_value *sum, - const struct replaygain_value *addition) -{ + const struct replaygain_value *addition) { for (size_t i = 0; i < ANALYZE_SIZE; i++) sum->value[i] += addition->value[i]; if (addition->peak > sum->peak) @@ -210,8 +207,7 @@ replaygain_accum(struct replaygain_value *sum, } __INLINE double -replaygain_peak(const struct replaygain_value *sum) -{ +replaygain_peak(const struct replaygain_value *sum) { const double MAX = (double)(1 << 15); return sum->peak / MAX; } diff --git a/gain_analysis.hpp b/gain_analysis.hpp index f527f05..b3feb7a 100644 --- a/gain_analysis.hpp +++ b/gain_analysis.hpp @@ -97,8 +97,7 @@ class Sample { return v; } - double peak() const - { + double peak() const { return replaygain_peak(&_value); } @@ -115,12 +114,12 @@ class Sample { class Sample_accum { public: /** Construct and initialize to zero */ - Sample_accum() - { reset(); } + Sample_accum() { + reset(); + } /** Reset the sum to zero */ - void reset() - { + void reset() { _dirty = true; memset(&_sum, 0, sizeof(_sum)); } @@ -129,15 +128,15 @@ class Sample_accum { * * \param value The value to add */ - void add(const Sample &value) - { *this += value; } + void add(const Sample &value) { + *this += value; + } /** Combine result of one sample with another * * \param value The value to add */ - Sample_accum &operator+=(const Sample &value) - { + Sample_accum &operator+=(const Sample &value) { replaygain_accum(&_sum, &value._value); return *this; } @@ -162,8 +161,7 @@ class Sample_accum { return v; } - double peak() const - { + double peak() const { return replaygain_peak(&_sum); } @@ -198,8 +196,7 @@ class Analyzer { } } - ~Analyzer() - { + ~Analyzer() { replaygain_free(_ctx); } @@ -208,8 +205,7 @@ class Analyzer { * \param freq The frequency to reset to * \retval false Bad sample frequency */ - bool reset_sample_frequency(unsigned long freq) - { + bool reset_sample_frequency(unsigned long freq) { return replaygain_reset_frequency(_ctx, freq) == REPLAYGAIN_OK; } @@ -227,8 +223,7 @@ class Analyzer { * event */ bool add(const double *left_samples, const double *right_samples, - size_t num_samples, unsigned num_channels) - { + size_t num_samples, unsigned num_channels) { enum replaygain_status status; status = replaygain_analyze(_ctx, left_samples, @@ -240,8 +235,7 @@ class Analyzer { * * \param[out] out The accumulated Replaygain value */ - void pop(Sample &out) - { + void pop(Sample &out) { replaygain_pop(_ctx, &out._value); } diff --git a/main.cpp b/main.cpp index ac67ca3..1037cc7 100644 --- a/main.cpp +++ b/main.cpp @@ -81,22 +81,30 @@ void usage(const boost::program_options::options_description &); class Cuetools_cd { public: Cuetools_cd() : _cd(nullptr) {} + Cuetools_cd(const Cd *cd) : _cd(const_cast(cd)) {} - ~Cuetools_cd() - { if (_cd) cd_delete(_cd); } - Cuetools_cd &operator=(const Cd *cd) - { + + ~Cuetools_cd() { + if (_cd) cd_delete(_cd); + } + + Cuetools_cd &operator=(const Cd *cd) { if (_cd) cd_delete(_cd); _cd = const_cast(cd); return *this; } - operator Cd *() - { return _cd; } - operator const Cd *() - { return _cd; } - operator bool() - { return _cd; } + operator Cd *() { + return _cd; + } + + operator const Cd *() { + return _cd; + } + + operator bool() { + return _cd; + } private: Cd *_cd; @@ -104,15 +112,11 @@ class Cuetools_cd { class File_handle { public: - File_handle() : - _fp(nullptr) - {} - File_handle(FILE *fp) : - _fp(fp) - {} + File_handle() : _fp(nullptr) {} - ~File_handle() - { + File_handle(FILE *fp) : _fp(fp) {} + + ~File_handle() { if (_fp) fclose(_fp); } @@ -152,7 +156,8 @@ class File_handle { //! \throw flacsplit::Unix_error template -void create_dirs(In begin, In end, const std::string *out_dir) { +void +create_dirs(In begin, In end, const std::string *out_dir) { std::ostringstream out; bool first = true; while (begin != end) { @@ -192,8 +197,7 @@ void create_dirs(In begin, In end, const std::string *out_dir) { // character uninterpreted (and if '\\' is the last character of 'str', it is // copied itself) std::string -escape_cue_string(const std::string &str) -{ +escape_cue_string(const std::string &str) { if (str.empty()) return ""; char quote = str[0]; @@ -218,8 +222,7 @@ escape_cue_string(const std::string &str) } bool -extension(const std::string &str, std::string &base, std::string &ext) -{ +extension(const std::string &str, std::string &base, std::string &ext) { size_t dot = str.rfind('.'); if (dot == std::string::npos) return false; @@ -229,8 +232,7 @@ extension(const std::string &str, std::string &base, std::string &ext) } FILE * -find_file(const std::string &path, std::string &out_path, bool use_flac) -{ +find_file(const std::string &path, std::string &out_path, bool use_flac) { std::string base; std::string ext; std::string guess; @@ -289,8 +291,9 @@ frametime(uint32_t frames) { #endif //! \throw flacsplit::Unix_error -void get_cue_extra(const std::string &path, - std::string &out_genre, std::string &out_date, unsigned &out_offset) { +void +get_cue_extra(const std::string &path, std::string &out_genre, + std::string &out_date, unsigned &out_offset) { std::ifstream in(path.c_str()); if (!in) { std::ostringstream out; @@ -347,8 +350,7 @@ void get_cue_extra(const std::string &path, void make_album_path(const flacsplit::Music_info &album, - std::vector &out_path_vec, std::string &out_path) -{ + std::vector &out_path_vec, std::string &out_path) { std::vector path_vec; path_vec.push_back(album.artist()); @@ -367,8 +369,7 @@ make_album_path(const flacsplit::Music_info &album, } void -make_track_name(const flacsplit::Music_info &track, std::string &name) -{ +make_track_name(const flacsplit::Music_info &track, std::string &name) { std::ostringstream nameout; nameout << std::setfill('0') << std::setw(2) << static_cast(track.track()) @@ -377,8 +378,7 @@ make_track_name(const flacsplit::Music_info &track, std::string &name) } bool -once(const std::string &cue_path, const struct options *options) -{ +once(const std::string &cue_path, const struct options *options) { using namespace flacsplit; std::string cue_dir; @@ -666,8 +666,7 @@ once(const std::string &cue_path, const struct options *options) void split_path(const std::string &path, std::string &dirname, - std::string &basename) -{ + std::string &basename) { size_t slash = path.rfind("/"); if (slash == 0) { dirname = "/"; @@ -685,8 +684,7 @@ split_path(const std::string &path, std::string &dirname, } void -transform_sample_fmt(const Frame &frame, double **out) -{ +transform_sample_fmt(const Frame &frame, double **out) { for (unsigned c = 0; c < frame.channels; c++) { const int32_t *channel_in = frame.data[c]; double *channel_out = out[c]; @@ -697,8 +695,7 @@ transform_sample_fmt(const Frame &frame, double **out) } void -usage(const boost::program_options::options_description &desc) -{ +usage(const boost::program_options::options_description &desc) { std::cout << "Usage: " << prog << " [OPTIONS...] CUESHEET...\n" << desc; } @@ -707,8 +704,7 @@ usage(const boost::program_options::options_description &desc) } // end flacsplit int -main(int argc, char **argv) -{ +main(int argc, char **argv) { using namespace flacsplit; namespace po = boost::program_options; diff --git a/replaygain_writer.cpp b/replaygain_writer.cpp index 9c67fa3..5377060 100644 --- a/replaygain_writer.cpp +++ b/replaygain_writer.cpp @@ -18,8 +18,7 @@ namespace flacsplit { namespace { inline flacsplit::Metadata_editor * -as_editor(FLAC__IOHandle handle) -{ +as_editor(FLAC__IOHandle handle) { return reinterpret_cast(handle); } @@ -48,47 +47,39 @@ class Metadata_editor { virtual ~Metadata_editor() {} - std::unique_ptr iterator() - { + std::unique_ptr iterator() { auto iter = std::make_unique(); iter->init(_chain); return iter; } - bool check_if_tempfile_needed(bool use_padding) const - { + bool check_if_tempfile_needed(bool use_padding) const { return const_cast( _chain).check_if_tempfile_needed(use_padding); } - FLAC::Metadata::Chain::Status status() - { + FLAC::Metadata::Chain::Status status() { return _chain.status(); } - bool valid() const - { + bool valid() const { return _chain.is_valid(); } - bool write(bool use_padding) - { + bool write(bool use_padding) { return _chain.write(use_padding, this, _callbacks); } - virtual size_t read_callback(uint8_t *buf, size_t size, size_t nmemb) - { + virtual size_t read_callback(uint8_t *buf, size_t size, size_t nmemb) { return fread(buf, size, nmemb, _fp); } virtual size_t write_callback(const uint8_t *buf, size_t size, - size_t nmemb) - { + size_t nmemb) { return fwrite(buf, size, nmemb, _fp); } - virtual int seek_callback(off_t offset, int whence) - { + virtual int seek_callback(off_t offset, int whence) { long loffset = offset; if (loffset != offset) throw std::runtime_error("bad narrow cast"); @@ -96,24 +87,20 @@ class Metadata_editor { return fseek(_fp, offset, whence); } - virtual off_t tell_callback() const - { + virtual off_t tell_callback() const { return ftell(const_cast(_fp)); } - virtual int eof_callback() const - { + virtual int eof_callback() const { return feof(const_cast(_fp)); } - virtual int close_callback() - { + virtual int close_callback() { return 0; } private: - static ::FLAC__IOCallbacks make_callbacks() - { + static ::FLAC__IOCallbacks make_callbacks() { ::FLAC__IOCallbacks callbacks; callbacks.close = metadata_editor_close; callbacks.eof = metadata_editor_eof; @@ -146,16 +133,14 @@ class Replaygain_writer_impl : public Metadata_editor { static int -metadata_editor_close(FLAC__IOHandle handle) -{ +metadata_editor_close(FLAC__IOHandle handle) { //std::cerr << "close()\n"; return as_editor(handle)->close_callback(); } static int -metadata_editor_eof(FLAC__IOHandle handle) -{ +metadata_editor_eof(FLAC__IOHandle handle) { //std::cerr << "eof()\n"; return as_editor(handle)->eof_callback(); @@ -163,8 +148,7 @@ metadata_editor_eof(FLAC__IOHandle handle) static size_t metadata_editor_read(void *ptr, size_t size, size_t nmemb, - FLAC__IOHandle handle) -{ + FLAC__IOHandle handle) { //std::cerr << "read(buf," << size << ',' << nmemb << ")\n"; uint8_t *buf = reinterpret_cast(ptr); @@ -172,26 +156,22 @@ metadata_editor_read(void *ptr, size_t size, size_t nmemb, } static int -metadata_editor_seek(FLAC__IOHandle handle, - FLAC__int64 offset, int whence) -{ +metadata_editor_seek(FLAC__IOHandle handle, FLAC__int64 offset, int whence) { //std::cerr << "seek(" << offset << ',' << whence << ")\n"; return as_editor(handle)->seek_callback(offset, whence); } static FLAC__int64 -metadata_editor_tell(FLAC__IOHandle handle) -{ +metadata_editor_tell(FLAC__IOHandle handle) { //std::cerr << "tell()\n"; return as_editor(handle)->tell_callback(); } static size_t -metadata_editor_write(const void *ptr, size_t size, - size_t nmemb, FLAC__IOHandle handle) -{ +metadata_editor_write(const void *ptr, size_t size, size_t nmemb, + FLAC__IOHandle handle) { //std::cerr << "write(buf," << size << ',' << nmemb << ")\n"; const uint8_t *buf = reinterpret_cast(ptr); @@ -204,33 +184,28 @@ flacsplit::Replaygain_writer::Replaygain_writer(FILE *fp) : _impl(new Replaygain_writer_impl(fp)) {} -flacsplit::Replaygain_writer::~Replaygain_writer() -{} +flacsplit::Replaygain_writer::~Replaygain_writer() {} void flacsplit::Replaygain_writer::add_replaygain( - const flacsplit::Replaygain_stats &gain_stats) -{ + const flacsplit::Replaygain_stats &gain_stats) { _impl->add_replaygain(gain_stats); } bool -flacsplit::Replaygain_writer::check_if_tempfile_needed() const -{ +flacsplit::Replaygain_writer::check_if_tempfile_needed() const { return _impl->check_if_tempfile_needed(true); } void -flacsplit::Replaygain_writer::save() -{ +flacsplit::Replaygain_writer::save() { _impl->save(); } FLAC::Metadata::VorbisComment * -flacsplit::Replaygain_writer_impl::find_comment() -{ +flacsplit::Replaygain_writer_impl::find_comment() { auto iter = iterator(); do { FLAC::Metadata::VorbisComment *comment = @@ -244,8 +219,7 @@ flacsplit::Replaygain_writer_impl::find_comment() inline void flacsplit::Replaygain_writer_impl::add_replaygain( - const flacsplit::Replaygain_stats &gain_stats) -{ + const flacsplit::Replaygain_stats &gain_stats) { FLAC::Metadata::VorbisComment *comment = find_comment(); if (!comment) { throw std::runtime_error( @@ -256,8 +230,7 @@ flacsplit::Replaygain_writer_impl::add_replaygain( } inline void -flacsplit::Replaygain_writer_impl::save() -{ +flacsplit::Replaygain_writer_impl::save() { write(true); } @@ -265,8 +238,7 @@ flacsplit::Replaygain_writer_impl::save() void flacsplit::append_replaygain_tags(FLAC::Metadata::VorbisComment &comment, - const flacsplit::Replaygain_stats &gain_stats) -{ + const flacsplit::Replaygain_stats &gain_stats) { using FLAC::Metadata::VorbisComment; std::ostringstream formatter; @@ -309,8 +281,7 @@ flacsplit::append_replaygain_tags(FLAC::Metadata::VorbisComment &comment, } void -flacsplit::delete_replaygain_tags(FLAC::Metadata::VorbisComment &comment) -{ +flacsplit::delete_replaygain_tags(FLAC::Metadata::VorbisComment &comment) { using FLAC::Metadata::VorbisComment; // move backwards so the entries don't get shifted on us for (unsigned i = comment.get_num_comments(); i != 0;) { diff --git a/replaygain_writer.hpp b/replaygain_writer.hpp index 05986ae..75616ce 100644 --- a/replaygain_writer.hpp +++ b/replaygain_writer.hpp @@ -15,44 +15,39 @@ class Replaygain_writer_impl; class Replaygain_stats { public: - double album_gain() const - { + double album_gain() const { return _album_gain; } - void album_gain(double album_gain) - { + + void album_gain(double album_gain) { _album_gain = album_gain; } - double album_peak() const - { + double album_peak() const { return _album_peak; } - void album_peak(double album_peak) - { + + void album_peak(double album_peak) { _album_peak = album_peak; } - double reference_loudness() const - { + double reference_loudness() const { return 89.0; } - double track_gain() const - { + double track_gain() const { return _track_gain; } - void track_gain(double track_gain) - { + + void track_gain(double track_gain) { _track_gain = track_gain; } - double track_peak() const - { + double track_peak() const { return _track_peak; } - void track_peak(double track_peak) - { + + void track_peak(double track_peak) { _track_peak = track_peak; } @@ -66,9 +61,13 @@ class Replaygain_stats { class Replaygain_writer { public: Replaygain_writer(FILE *); + ~Replaygain_writer(); + void add_replaygain(const flacsplit::Replaygain_stats &); + bool check_if_tempfile_needed() const; + void save(); private: diff --git a/sanitize.cpp b/sanitize.cpp index 5b03afc..836571f 100644 --- a/sanitize.cpp +++ b/sanitize.cpp @@ -83,8 +83,7 @@ const uint16_t LATIN_MAP_END = LATIN_MAP_BEGIN + } // end anon namespace std::string -flacsplit::sanitize(const std::string &str) -{ +flacsplit::sanitize(const std::string &str) { std::vector guessed; std::string res; const char *s = str.c_str(); diff --git a/transcode.cpp b/transcode.cpp index c3c0024..7a11404 100644 --- a/transcode.cpp +++ b/transcode.cpp @@ -26,8 +26,7 @@ flacsplit::Music_info::Music_info() : {} std::shared_ptr -flacsplit::Music_info::create_hidden(const Music_info &parent) -{ +flacsplit::Music_info::create_hidden(const Music_info &parent) { auto info = std::shared_ptr(); info->_parent = &parent; info->_title = "[hidden]"; @@ -74,8 +73,7 @@ flacsplit::Music_info::Music_info(const Cdtext *cdtext0, } std::string -flacsplit::iso8859_to_utf8(const std::string &str) -{ +flacsplit::iso8859_to_utf8(const std::string &str) { const char *s = str.c_str(); int32_t length = str.size(); int32_t i = 0; diff --git a/transcode.hpp b/transcode.hpp index edac01e..389ff7a 100644 --- a/transcode.hpp +++ b/transcode.hpp @@ -38,59 +38,59 @@ class Music_info { public: Music_info(const Cdtext *cdtext); + Music_info(const Cdtext *cdtext, const Music_info &parent, uint8_t track); static std::shared_ptr create_hidden( const Music_info &parent); - const std::string &album() const - { + const std::string &album() const{ return _parent ? _parent->_title : _title; } - const std::string &album_artist() const - { + + const std::string &album_artist() const{ // album: return artist // track: return parent artist if different, else "" return !_parent ? _artist : _artist.empty() ? _artist : _parent->_artist; } - const std::string &artist() const - { + + const std::string &artist() const{ // album: return artist // track: return own artist if non-empty, else parent artist return _artist.empty() && _parent ? _parent->_artist : _artist; } - const std::string &date() const - { + + const std::string &date() const{ return _date.empty() && _parent ? _parent->_date : _date; } - void date(const std::string &date) - { + + void date(const std::string &date){ _date = date; } - const std::string &genre() const - { + + const std::string &genre() const{ return _genre.empty() && _parent ? _parent->_genre : _genre; } - void genre(const std::string &genre) - { + + void genre(const std::string &genre){ _genre = genre; } - const std::string &title() const - { + + const std::string &title() const{ return _title; } - uint8_t track() const - { + + uint8_t track() const { return _track; }