From 6d223c5588787728203ec87898d655c14645b6bb Mon Sep 17 00:00:00 2001 From: Markus Peloquin Date: Wed, 8 Apr 2020 19:13:12 -0700 Subject: [PATCH] Bump up to C++17 Compilation was broken so I figured might as well bump up to C++ 17. This also fixes a double-close of the input file. The file is closed by libflac when the Decoder goes out of scope. It's also closed when the File_handle goes out of scope. The fix was to release the FILE pointer after its ownership transfers to the decoder. I guess I'm not sure if libsox also runs into this :(. * Replace scoped_array/scoped_ptr/auto_ptr with unique_ptr * Replaced boost shared_ptr with std * Drop throw() specifiers. Replaced with doxygen-style comments * Encoder/Decoder were missing virtual destructors. Encoder also forgot to subclass Basic_encoder * Replaced some asserts with runtime exceptions. Which in retrospect could have just been an include of * Also switch to C11 for no reason --- Makefile | 4 +- decode.cpp | 150 +++++++++++++++++++++--------------------- decode.hpp | 46 +++++++------ encode.cpp | 52 ++++++++------- encode.hpp | 29 ++++---- errors.hpp | 46 ++++++++----- gain_analysis.hpp | 11 ++-- main.cpp | 95 +++++++++++++------------- replaygain_writer.cpp | 11 ++-- replaygain_writer.hpp | 4 +- transcode.cpp | 5 +- transcode.hpp | 5 +- 12 files changed, 243 insertions(+), 215 deletions(-) diff --git a/Makefile b/Makefile index de0d26b..1d708f7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ -CFLAGS += -Wall -W -O2 -std=c99 -pedantic -CXXFLAGS += -Wall -W -O2 +CFLAGS += -Wall -W -O3 -std=c11 -pedantic +CXXFLAGS += -Wall -W -O3 -std=c++17 CPPFLAGS += -Ilibcuefile/include LDFLAGS += -L/usr/local/lib LIBS += -lFLAC -lFLAC++ -lboost_program_options -licuuc -lsox diff --git a/decode.cpp b/decode.cpp index 930f3d3..692dbe7 100644 --- a/decode.cpp +++ b/decode.cpp @@ -17,8 +17,7 @@ #include #include - -#include +#include #include #include @@ -29,9 +28,8 @@ namespace { const unsigned FRAMES_PER_SEC = 75; -enum flacsplit::file_format - get_file_format(FILE *); -bool same_file(FILE *, FILE *) throw (flacsplit::Unix_error); +enum flacsplit::file_format get_file_format(FILE *); +bool same_file(FILE *, FILE *); class Sox_init { public: @@ -42,8 +40,8 @@ class Sox_init { sox_quit(); } - static void init() throw (flacsplit::Sox_error) - { + //! \throw flacsplit::Sox_error + static void init() { if (!_instance._valid) _instance.do_init(); } @@ -52,8 +50,8 @@ class Sox_init { Sox_init(const Sox_init &) {} void operator=(const Sox_init &) {} - void do_init() throw (flacsplit::Sox_error) - { + //! \throw flacsplit::Sox_error + void do_init() { _valid = true; if (sox_init() != SOX_SUCCESS) _valid = false; @@ -80,58 +78,61 @@ class Flac_decoder : flacsplit::Decode_error(), _msg(msg) {} - virtual ~Flac_decode_error() throw () {} - virtual const char *what() const throw () - { return _msg.c_str(); } + + virtual ~Flac_decode_error() noexcept {} + + const char *what() const noexcept override { + return _msg.c_str(); + } + std::string _msg; }; - Flac_decoder(FILE *fp) throw (Flac_decode_error); + //! Note that this takes ownership of the file (or rather, the FLAC + //! library takes ownership). + //! \throw Flac_decode_error + Flac_decoder(FILE *); + virtual ~Flac_decoder() {} - virtual void next_frame(struct flacsplit::Frame &) - throw (Flac_decode_error); + //! \throw Flac_decode_error + void next_frame(struct flacsplit::Frame &) override; - virtual void seek(uint64_t sample) throw () - { + void seek(uint64_t sample) override { seek_absolute(sample); } - virtual unsigned sample_rate() const - { + unsigned sample_rate() const override { return get_sample_rate(); } - virtual uint64_t total_samples() const - { + uint64_t total_samples() const override { return get_total_samples(); } protected: - virtual FLAC__StreamDecoderWriteStatus write_callback( - const FLAC__Frame *, const FLAC__int32 *const *); + FLAC__StreamDecoderWriteStatus write_callback( + const FLAC__Frame *, const FLAC__int32 *const *) override; - virtual FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64); + FLAC__StreamDecoderSeekStatus seek_callback(FLAC__uint64) override; - virtual FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *); + FLAC__StreamDecoderTellStatus tell_callback(FLAC__uint64 *) override; - virtual FLAC__StreamDecoderLengthStatus length_callback( - FLAC__uint64 *); + FLAC__StreamDecoderLengthStatus length_callback(FLAC__uint64 *) + override; - virtual bool eof_callback() - { + bool eof_callback() override { return feof(_fp); } - virtual void error_callback(FLAC__StreamDecoderErrorStatus status) - { + void error_callback(FLAC__StreamDecoderErrorStatus status) override { _last_status = FLAC__StreamDecoderErrorStatusString[status]; } private: FILE *_fp; const FLAC__Frame *_last_frame; - boost::scoped_array + std::unique_ptr _last_buffer; const char *_last_status; bool _frame_retrieved; @@ -144,58 +145,60 @@ class Wave_decoder : public flacsplit::Basic_decoder { flacsplit::Decode_error(), _msg(msg) {} - virtual ~Wave_decode_error() throw () {} - virtual const char *what() const throw () - { return _msg.c_str(); } + + virtual ~Wave_decode_error() {} + + const char *what() const noexcept override { + return _msg.c_str(); + } + std::string _msg; }; - Wave_decoder(const std::string &, FILE *) - throw (flacsplit::Sox_error); - virtual ~Wave_decoder() - { + //! \throw flacsplit::Sox_error + Wave_decoder(const std::string &, FILE *); + + virtual ~Wave_decoder() noexcept { sox_close(_fmt); } - virtual void next_frame(struct flacsplit::Frame &) - throw (Wave_decode_error); + //! \throw Wave_decode_error + void next_frame(struct flacsplit::Frame &) override; - virtual void seek(uint64_t sample) throw (Wave_decode_error) - { + //! \throw Wave_decode_error + void seek(uint64_t sample) override { sample *= _fmt->signal.channels; if (sox_seek(_fmt, sample, SOX_SEEK_SET) != SOX_SUCCESS) throw Wave_decode_error("sox_seek() error"); } - virtual unsigned sample_rate() const - { + unsigned sample_rate() const override { return _fmt->signal.rate; } - virtual uint64_t total_samples() const - { + uint64_t total_samples() const override { // a 32-bit size_t (sox_signalinfo_t::length) is big enough // for 2-channel 44.1 kHz for 13.5 hours return _fmt->signal.length / _fmt->signal.channels; } private: - boost::scoped_array _samples; - boost::scoped_array _transp; - boost::scoped_array _transp_ptrs; + std::unique_ptr _samples; + std::unique_ptr _transp; + std::unique_ptr _transp_ptrs; sox_format_t *_fmt; size_t _samples_len; }; Sox_init Sox_init::_instance; -Flac_decoder::Flac_decoder(FILE *fp) throw (Flac_decode_error) : +Flac_decoder::Flac_decoder(FILE *fp) : FLAC::Decoder::File(), Basic_decoder(), _fp(fp), - _last_frame(0), - _last_buffer(0), - _last_status(0), + _last_frame(nullptr), + _last_buffer(), + _last_status(nullptr), _frame_retrieved(false) { FLAC__StreamDecoderInitStatus status; @@ -206,9 +209,7 @@ Flac_decoder::Flac_decoder(FILE *fp) throw (Flac_decode_error) : } void -Flac_decoder::next_frame(struct flacsplit::Frame &frame) - throw (Flac_decode_error) -{ +Flac_decoder::next_frame(struct flacsplit::Frame &frame) { // a seek will trigger a call to write_callback(), so don't process // the next frame if it hasn't been seen yet here if (!_last_frame || _frame_retrieved) @@ -250,8 +251,8 @@ FLAC__StreamDecoderSeekStatus Flac_decoder::seek_callback(FLAC__uint64 absolute_byte_offset) { long off = absolute_byte_offset; - assert(static_cast(off) == - absolute_byte_offset); + if (static_cast(off) != absolute_byte_offset) + throw std::runtime_error("bad offset"); return fseek(_fp, off, SEEK_SET) ? FLAC__STREAM_DECODER_SEEK_STATUS_ERROR : @@ -278,8 +279,7 @@ Flac_decoder::length_callback(FLAC__uint64 *stream_length) return FLAC__STREAM_DECODER_LENGTH_STATUS_OK; } -Wave_decoder::Wave_decoder(const std::string &path, FILE *fp) - throw (flacsplit::Sox_error) : +Wave_decoder::Wave_decoder(const std::string &path, FILE *fp) : Basic_decoder(), _samples(), _transp() @@ -290,7 +290,8 @@ Wave_decoder::Wave_decoder(const std::string &path, FILE *fp) try { // XXX sox-14.4.0 has sox_format_t::fp declared as void* - assert(same_file(fp, reinterpret_cast(_fmt->fp))); + if (!same_file(fp, reinterpret_cast(_fmt->fp))) + throw std::runtime_error("file has moved?"); _samples_len = _fmt->signal.channels * _fmt->signal.rate / FRAMES_PER_SEC; _samples.reset(new sox_sample_t[_samples_len]); @@ -304,9 +305,7 @@ Wave_decoder::Wave_decoder(const std::string &path, FILE *fp) } void -Wave_decoder::next_frame(struct flacsplit::Frame &frame) - throw (Wave_decode_error) -{ +Wave_decoder::next_frame(struct flacsplit::Frame &frame) { size_t samples; samples = sox_read(_fmt, _samples.get(), _samples_len); if (samples < _samples_len) @@ -314,7 +313,8 @@ Wave_decoder::next_frame(struct flacsplit::Frame &frame) frame.data = _transp_ptrs.get(); frame.channels = _fmt->signal.channels; - assert(!(samples % frame.channels)); + if (samples % frame.channels) + throw std::runtime_error("bad number of samples"); frame.samples = samples / frame.channels; frame.rate = _fmt->signal.rate; @@ -327,18 +327,19 @@ Wave_decoder::next_frame(struct flacsplit::Frame &frame) SOX_SAMPLE_LOCALS; unsigned clips = 0; int32_t samp = SOX_SAMPLE_TO_SIGNED_16BIT( - _samples[i], clips); - assert(!clips); - _transp[j] = samp; + _samples.get()[i], clips); + if (clips) + throw std::runtime_error("should not clip"); + _transp.get()[j] = samp; i++; j += frame.samples; } } // make 2d array to return - _transp_ptrs[0] = _transp.get(); + _transp_ptrs.get()[0] = _transp.get(); for (size_t channel = 1; channel < frame.channels; channel++) - _transp_ptrs[channel] = _transp_ptrs[channel-1] + + _transp_ptrs.get()[channel] = _transp_ptrs.get()[channel-1] + frame.samples; } @@ -364,13 +365,12 @@ get_file_format(FILE *fp) /** Check that two C file pointers reference the same underlying file * (according to the device and inode). - * \throws flacsplit::Unix_error if there is a problem calling fstat(2) on an + * \throw flacsplit::Unix_error if there is a problem calling fstat(2) on an * underlying file descriptor * \return whether they are the same */ bool -same_file(FILE *a, FILE *b) throw (flacsplit::Unix_error) -{ +same_file(FILE *a, FILE *b) { struct stat st_a; struct stat st_b; @@ -384,7 +384,7 @@ same_file(FILE *a, FILE *b) throw (flacsplit::Unix_error) } // end anon flacsplit::Decoder::Decoder(const std::string &path, FILE *fp, - enum file_format format) throw (Bad_format, Sox_error) : + enum file_format format) : Basic_decoder(), _decoder() { diff --git a/decode.hpp b/decode.hpp index 5f0911e..b6c4967 100644 --- a/decode.hpp +++ b/decode.hpp @@ -16,10 +16,9 @@ #define DECODE_HPP #include +#include #include -#include - #include "errors.hpp" #include "transcode.hpp" @@ -31,33 +30,42 @@ struct Decode_error : std::exception { class Basic_decoder { public: - Basic_decoder() throw (Decode_error) {} - virtual ~Basic_decoder() {} - virtual void next_frame(struct Frame &) throw (Decode_error) = 0; - virtual void seek(uint64_t sample) throw (Decode_error) = 0; + //! \throw DecodeError + Basic_decoder() noexcept(false) {} + + virtual ~Basic_decoder() noexcept {} + + //! \throw DecodeError + virtual void next_frame(struct Frame &) = 0; + + //! \throw DecodeError + virtual void seek(uint64_t sample) = 0; + virtual unsigned sample_rate() const = 0; + virtual uint64_t total_samples() const = 0; }; class Decoder : public Basic_decoder { public: - Decoder(const std::string &, FILE *, enum file_format=FF_UNKNOWN) - throw (Bad_format, Sox_error); + //! \throw Bad_format + //! \throw Sox_error + Decoder(const std::string &, FILE *, enum file_format=FF_UNKNOWN); - ~Decoder() {} + virtual ~Decoder() {} - void next_frame(struct Frame &frame) throw (Decode_error) - { + //! \throw DecodeError + void next_frame(struct Frame &frame) override { _decoder->next_frame(frame); } - void seek(uint64_t sample) throw (Decode_error) - { + //! \throw DecodeError + void seek(uint64_t sample) override { _decoder->seek(sample); } - void seek_frame(uint64_t frame) throw (Decode_error) - { + //! \throw DecodeError + void seek_frame(uint64_t frame) { // sample rates aren't always divisible by 3*5*5 = 75, e.g. // 32 kHz, which MP3 supports @@ -68,18 +76,16 @@ class Decoder : public Basic_decoder { //seek(_decoder->sample_rate() * frame / 75); } - unsigned sample_rate() const - { + unsigned sample_rate() const override { return _decoder->sample_rate(); } - virtual uint64_t total_samples() const - { + uint64_t total_samples() const override { return _decoder->total_samples(); } private: - boost::scoped_ptr _decoder; + std::unique_ptr _decoder; }; } diff --git a/encode.cpp b/encode.cpp index c6fd68e..74d1b23 100644 --- a/encode.cpp +++ b/encode.cpp @@ -16,9 +16,9 @@ #if FLACPP_API_VERSION_CURRENT <= 8 # include #endif +#include #include #include -#include #include @@ -41,39 +41,44 @@ class Flac_encoder : flacsplit::Encode_error(), _msg(msg) {} - virtual ~Flac_encode_error() throw () {} - virtual const char *what() const throw () - { return _msg.c_str(); } + + virtual ~Flac_encode_error() noexcept {} + + const char *what() const noexcept override { + return _msg.c_str(); + } + std::string _msg; }; Flac_encoder(FILE *fp, const flacsplit::Music_info &, uint64_t=0); - virtual ~Flac_encoder() - { + + virtual ~Flac_encoder() { if (_init) finish(); } - virtual void add_frame(const struct flacsplit::Frame &) - throw (Flac_encode_error); + //! \throw Flac_encode_error + void add_frame(const struct flacsplit::Frame &) override; - virtual bool finish() - { - return FLAC::Encoder::File::finish(); + bool finish() override { + bool result = FLAC::Encoder::File::finish(); + _init = false; + return result; } protected: #if 0 - virtual FLAC__StreamEncoderReadStatus read_callback(FLAC__byte *, - size_t *); + FLAC__StreamEncoderReadStatus read_callback(FLAC__byte *, + size_t *) override; #endif - virtual FLAC__StreamEncoderWriteStatus write_callback( - const FLAC__byte *, size_t, unsigned, unsigned); + FLAC__StreamEncoderWriteStatus write_callback( + const FLAC__byte *, size_t, unsigned, unsigned) override; - virtual FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64); + FLAC__StreamEncoderSeekStatus seek_callback(FLAC__uint64) override; - virtual FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *); + FLAC__StreamEncoderTellStatus tell_callback(FLAC__uint64 *) override; private: virtual void set_meta(const flacsplit::Music_info &track) @@ -88,11 +93,11 @@ class Flac_encoder : static_cast(meta)); } - boost::scoped_ptr _padding; - boost::scoped_ptr _seek_table; + std::unique_ptr _padding; + std::unique_ptr _seek_table; FLAC::Metadata::VorbisComment _tag; - //std::vector > + //std::vector> // _entries; FILE *_fp; bool _init; @@ -129,9 +134,7 @@ Flac_encoder::Flac_encoder(FILE *fp, const flacsplit::Music_info &track, } void -Flac_encoder::add_frame(const struct flacsplit::Frame &frame) - throw (Flac_encode_error) -{ +Flac_encoder::add_frame(const struct flacsplit::Frame &frame) { if (!_init) { FLAC__StreamEncoderInitStatus status; @@ -273,8 +276,7 @@ Flac_encoder::tell_callback(FLAC__uint64 *absolute_byte_offset) } // end anon flacsplit::Encoder::Encoder(FILE *fp, const Music_info &track, - uint64_t total_samples, enum file_format format) throw (Bad_format) -{ + uint64_t total_samples, enum file_format format) { if (format != FF_FLAC) throw Bad_format(); _encoder.reset(new Flac_encoder(fp, track, total_samples)); diff --git a/encode.hpp b/encode.hpp index 6bab0bf..39490ef 100644 --- a/encode.hpp +++ b/encode.hpp @@ -15,8 +15,8 @@ #ifndef ENCODE_HPP #define ENCODE_HPP -#include -#include +#include +#include #include "errors.hpp" #include "transcode.hpp" @@ -30,13 +30,18 @@ struct Encode_error : std::exception { class Basic_encoder { public: Basic_encoder() {} + virtual ~Basic_encoder() {} - virtual void add_frame(const struct Frame &) throw (Encode_error) = 0; + + //! \throw Encode_error + virtual void add_frame(const struct Frame &) = 0; + virtual bool finish() = 0; - virtual void set_meta(const Music_info &) = 0; + + //virtual void set_meta(const Music_info &) = 0; }; -class Encoder { +class Encoder : public Basic_encoder { public: struct Bad_format : std::exception { virtual ~Bad_format() throw () {} @@ -44,23 +49,23 @@ class Encoder { { return "bad format"; } }; + //! \throw Bad_format Encoder(FILE *, const Music_info &track, uint64_t total_samples=0, - enum file_format=FF_FLAC) throw (Bad_format); + enum file_format=FF_FLAC); - ~Encoder() {} + virtual ~Encoder() {} - void add_frame(const struct Frame &frame) throw (Encode_error) - { + //! \throw Encode_error + void add_frame(const struct Frame &frame) override { _encoder->add_frame(frame); } - bool finish() - { + bool finish() override { return _encoder->finish(); } private: - boost::scoped_ptr _encoder; + std::unique_ptr _encoder; }; } diff --git a/errors.hpp b/errors.hpp index 5a624bb..cacdb25 100644 --- a/errors.hpp +++ b/errors.hpp @@ -21,27 +21,35 @@ namespace flacsplit { struct Bad_format : std::exception { - virtual ~Bad_format() throw () {} - virtual const char *what() const throw () - { return "bad format"; } + virtual ~Bad_format() noexcept {} + + const char *what() const noexcept override { + return "bad format"; + } }; struct Bad_samplefreq : std::exception { - const char *what() const throw () - { return "bad sample frequency"; } - virtual ~Bad_samplefreq() throw () {} + virtual ~Bad_samplefreq() noexcept {} + + const char *what() const noexcept { + return "bad sample frequency"; + } }; struct Not_enough_samples : public std::exception { Not_enough_samples() : _msg("not enough samples to calculate with") {} + Not_enough_samples(const std::string &msg) : _msg(msg) {} - const char *what() const throw () - { return _msg.c_str(); } - virtual ~Not_enough_samples() throw () {} + + virtual ~Not_enough_samples() noexcept {} + + const char *what() const noexcept { + return _msg.c_str(); + } private: std::string _msg; @@ -52,18 +60,26 @@ struct Sox_error : std::exception { std::exception(), _msg(msg) {} - virtual ~Sox_error() throw () {} - virtual const char *what() const throw () - { return _msg.c_str(); } + + virtual ~Sox_error() noexcept {} + + const char *what() const noexcept override { + return _msg.c_str(); + } + std::string _msg; }; struct Unix_error : std::exception { Unix_error(int errnum=-1); + Unix_error(const std::string &msg, int errnum=-1); - virtual ~Unix_error() throw () {} - virtual const char *what() const throw () - { return msg.c_str(); } + + virtual ~Unix_error() noexcept {} + + const char *what() const noexcept override { + return msg.c_str(); + } std::string msg; int errnum; diff --git a/gain_analysis.hpp b/gain_analysis.hpp index 18a0b78..5557b81 100644 --- a/gain_analysis.hpp +++ b/gain_analysis.hpp @@ -21,7 +21,7 @@ * double r_samples[4096]; * multigain::Sample_accum sample_accum; * - * std::auto_ptr rg; + * std::unique_ptr rg; * * try { * rg.reset(new multigain::Analyzer(44100)); @@ -86,8 +86,7 @@ class Sample { * \return The adjustment * \throw Not_enough_samples ... */ - double adjustment() const throw (Not_enough_samples) - { + double adjustment() const { double v; if (_dirty) { v = replaygain_adjustment(&_value); @@ -152,8 +151,7 @@ class Sample_accum { * \return The adjustment * \throw Not_enough_samples ... */ - double adjustment() const throw (Not_enough_samples) - { + double adjustment() const { double v; if (_dirty) { v = replaygain_adjustment(&_sum); @@ -182,8 +180,9 @@ class Analyzer { /** Construct the analyzer object * * \param samplefreq The input sample frequency + * \throw Bad_samplefreq */ - Analyzer(unsigned long freq) throw (Bad_samplefreq) : + Analyzer(unsigned long freq) : _ctx(0) { enum replaygain_status status; diff --git a/main.cpp b/main.cpp index 6bec91e..32db094 100644 --- a/main.cpp +++ b/main.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -31,9 +32,6 @@ #include #include #include -#include -#include -#include #include #include @@ -66,15 +64,12 @@ struct options { }; template -void create_dirs(In begin, In end, const std::string *) - throw (flacsplit::Unix_error); +void create_dirs(In begin, In end, const std::string *); std::string escape_cue_string(const std::string &); bool extension(const std::string &, std::string &, std::string &); FILE *find_file(const std::string &, std::string &, bool); -std::string frametime(uint32_t); void get_cue_extra(const std::string &, std::string &out_genre, - std::string &out_date, unsigned &out_offset) - throw (flacsplit::Unix_error); + std::string &out_date, unsigned &out_offset); void make_album_path(const flacsplit::Music_info &album, std::vector &, std::string &); void make_track_name(const flacsplit::Music_info &track, @@ -111,7 +106,7 @@ class Cuetools_cd { class File_handle { public: File_handle() : - _fp(0) + _fp(nullptr) {} File_handle(FILE *fp) : _fp(fp) @@ -122,36 +117,43 @@ class File_handle { if (_fp) fclose(_fp); } - File_handle &operator=(FILE *fp) throw (flacsplit::Unix_error) - { + //! \throw flacsplit::Unix_error + File_handle &operator=(FILE *fp) { close(); _fp = fp; return *this; } - void close() throw (flacsplit::Unix_error) - { + //! \throw flacsplit::Unix_error + void close() { if (_fp) { if (fclose(_fp) != 0) throw Unix_error("closing file"); - _fp = 0; + _fp = nullptr; } } - operator FILE *() - { return _fp; } - operator bool() const - { return _fp; } + FILE *release() { + FILE *fp = _fp; + _fp = nullptr; + return fp; + } + + operator FILE *() { + return _fp; + } + + operator bool() const { + return _fp; + } private: FILE *_fp; }; +//! \throw flacsplit::Unix_error template -void -create_dirs(In begin, In end, const std::string *out_dir) - throw (flacsplit::Unix_error) -{ +void create_dirs(In begin, In end, const std::string *out_dir) { std::ostringstream out; bool first = true; while (begin != end) { @@ -269,6 +271,7 @@ find_file(const std::string &path, std::string &out_path, bool use_flac) return 0; } +#if 0 std::string frametime(uint32_t frames) { @@ -287,12 +290,11 @@ frametime(uint32_t frames) << std::setw(2) << frames; return out.str(); } +#endif -void -get_cue_extra(const std::string &path, - std::string &out_genre, std::string &out_date, unsigned &out_offset) - throw (flacsplit::Unix_error) -{ +//! \throw flacsplit::Unix_error +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; @@ -407,7 +409,7 @@ once(const std::string &cue_path, const struct options *options) album_info.genre(genre); album_info.date(date); - std::vector > track_info; + std::vector> track_info; std::vector begin; std::vector end; std::vector pregap; @@ -443,9 +445,9 @@ once(const std::string &cue_path, const struct options *options) pregap_ = 0; } - track_info.push_back(boost::shared_ptr( - new Music_info(track_get_cdtext(track), album_info, - offset + i + 1))); + track_info.push_back(std::make_shared( + track_get_cdtext(track), album_info, + offset + i + 1)); begin.push_back(begin_); end.push_back(end_); @@ -485,18 +487,17 @@ once(const std::string &cue_path, const struct options *options) std::string path; std::string derived_path; - File_handle in_file; - boost::scoped_ptr decoder; + std::unique_ptr decoder; std::vector out_paths; // for replaygain analysis replaygain::Sample_accum rg_accum; - boost::scoped_ptr rg_analyzer; - boost::scoped_array rg_samples; + std::unique_ptr rg_analyzer; + std::unique_ptr rg_samples; double *double_samples[] = { 0, 0 }; unsigned dimens[] = { 0, 0 }; - boost::scoped_array gain_stats( + std::unique_ptr gain_stats( new Replaygain_stats[begin.size()]); for (unsigned i = 0; i < track_numbers.size(); i++) { @@ -508,11 +509,11 @@ once(const std::string &cue_path, const struct options *options) cur_path += '/'; cur_path += track_get_filename(track); - if (!in_file || cur_path != path) { + if (!decoder || cur_path != path) { // switch file path = cur_path; - in_file = find_file(path, derived_path, + File_handle in_file = find_file(path, derived_path, options->use_flac); if (!in_file) { std::cerr << prog << ": open `" @@ -527,7 +528,8 @@ once(const std::string &cue_path, const struct options *options) try { decoder.reset(new Decoder(derived_path, in_file)); - } catch (Bad_format) { + in_file.release(); + } catch (const Bad_format &) { std::cerr << prog << ": unknown format in file `" << derived_path << "'\n"; @@ -562,7 +564,7 @@ once(const std::string &cue_path, const struct options *options) throw Unix_error(out.str()); } - boost::shared_ptr encoder; + std::shared_ptr encoder; // transcode struct Frame frame; @@ -625,22 +627,21 @@ once(const std::string &cue_path, const struct options *options) replaygain::Sample rg_sample; rg_analyzer->pop(rg_sample); rg_accum += rg_sample; - gain_stats[i].track_gain(rg_sample.adjustment()); - gain_stats[i].track_peak(rg_sample.peak()); + gain_stats.get()[i].track_gain(rg_sample.adjustment()); + gain_stats.get()[i].track_peak(rg_sample.peak()); if (!encoder->finish()) { std::cerr << prog << ": finish() failed\n"; return false; } } - in_file.close(); double album_gain = rg_accum.adjustment(); double album_peak = rg_accum.peak(); for (unsigned i = 0; i < tracks; i++) { - gain_stats[i].album_gain(album_gain); - gain_stats[i].album_peak(album_peak); + gain_stats.get()[i].album_gain(album_gain); + gain_stats.get()[i].album_peak(album_peak); // I hate these stupid mode strings; "r+b" = O_RDWR, binary File_handle outfp(fopen(out_paths[i].c_str(), "r+b")); @@ -651,7 +652,7 @@ once(const std::string &cue_path, const struct options *options) } Replaygain_writer writer(outfp); - writer.add_replaygain(gain_stats[i]); + writer.add_replaygain(gain_stats.get()[i]); if (writer.check_if_tempfile_needed()) std::cerr << prog << ": padding exhausted for `" << out_paths[i] << "', using temp file\n"; @@ -770,7 +771,7 @@ main(int argc, char **argv) cuefiles = opt.as >(); } - boost::scoped_ptr out_dir; + std::unique_ptr out_dir; { const po::variable_value &opt = var_map["outdir"]; if (!opt.empty()) diff --git a/replaygain_writer.cpp b/replaygain_writer.cpp index 1ae72b5..140ffba 100644 --- a/replaygain_writer.cpp +++ b/replaygain_writer.cpp @@ -49,10 +49,9 @@ class Metadata_editor { virtual ~Metadata_editor() {} - std::auto_ptr iterator() + std::unique_ptr iterator() { - std::auto_ptr iter( - new FLAC::Metadata::Iterator); + auto iter = std::make_unique(); iter->init(_chain); return iter; } @@ -232,14 +231,14 @@ flacsplit::Replaygain_writer::save() FLAC::Metadata::VorbisComment * flacsplit::Replaygain_writer_impl::find_comment() { - std::auto_ptr i = iterator(); + auto iter = iterator(); do { FLAC::Metadata::VorbisComment *comment = dynamic_cast( - i->get_block()); + iter->get_block()); if (comment) return comment; - } while (i->next()); + } while (iter->next()); return 0; } diff --git a/replaygain_writer.hpp b/replaygain_writer.hpp index 53bb683..05986ae 100644 --- a/replaygain_writer.hpp +++ b/replaygain_writer.hpp @@ -1,7 +1,7 @@ #ifndef FLACSPLIT_REPLAYGAIN_WRITER_HPP #define FLACSPLIT_REPLAYGAIN_WRITER_HPP -#include +#include namespace FLAC { namespace Metadata { @@ -72,7 +72,7 @@ class Replaygain_writer { void save(); private: - boost::scoped_ptr _impl; + std::unique_ptr _impl; }; void append_replaygain_tags(FLAC::Metadata::VorbisComment &comment, diff --git a/transcode.cpp b/transcode.cpp index 96ee57e..323da94 100644 --- a/transcode.cpp +++ b/transcode.cpp @@ -13,6 +13,7 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include +#include #include #include @@ -24,10 +25,10 @@ flacsplit::Music_info::Music_info() : _track(0) {} -boost::shared_ptr +std::shared_ptr flacsplit::Music_info::create_hidden(const Music_info &parent) { - boost::shared_ptr info(new Music_info); + auto info = std::shared_ptr(); info->_parent = &parent; info->_title = "[hidden]"; return info; diff --git a/transcode.hpp b/transcode.hpp index 0fbc653..b4c09b7 100644 --- a/transcode.hpp +++ b/transcode.hpp @@ -16,11 +16,10 @@ #define TRANSCODE_HPP #include +#include #include #include -#include - struct Cdtext; namespace flacsplit { @@ -42,7 +41,7 @@ class Music_info { Music_info(const Cdtext *cdtext, const Music_info &parent, uint8_t track); - static boost::shared_ptr create_hidden( + static std::shared_ptr create_hidden( const Music_info &parent); const std::string &album() const