@@ -446,24 +446,26 @@ static bool tag_flac(ScanJob::Track &track, const Config &config)
446
446
447
447
template <typename T>
448
448
static bool tag_ogg (ScanJob::Track &track, const Config &config) {
449
- T file (track.path .string ().c_str ());
450
- TagLib::Ogg::XiphComment *tag = nullptr ;
451
- if constexpr (std::is_same_v<T, TagLib::FileRef>)
452
- tag = dynamic_cast <TagLib::Ogg::XiphComment*>(file.tag ());
453
- else
454
- tag = file.tag ();
455
- if (!tag)
456
- return false ;
457
- tag_clear<T>(tag);
458
- if (config.tag_mode == ' i' && (!std::is_same_v<T, TagLib::Ogg::Opus::File> ||
459
- (config.opus_mode != ' t' && config.opus_mode != ' a' )))
460
- tag_write<T>(tag, track.result , config);
461
-
462
- bool ret = file.save ();
463
- if (!std::is_same_v<T, TagLib::Ogg::Opus::File> || config.tag_mode == ' s' ||
464
- !(config.opus_mode == ' t' || config.opus_mode == ' a' ) || !ret)
465
- return ret;
449
+ {
450
+ T file (track.path .string ().c_str ());
451
+ TagLib::Ogg::XiphComment* tag = nullptr ;
452
+ if constexpr (std::is_same_v<T, TagLib::FileRef>)
453
+ tag = dynamic_cast <TagLib::Ogg::XiphComment*>(file.tag ());
454
+ else
455
+ tag = file.tag ();
456
+ if (!tag)
457
+ return false ;
458
+ tag_clear<T>(tag);
459
+ if (config.tag_mode == ' i' && (!std::is_same_v<T, TagLib::Ogg::Opus::File> ||
460
+ (config.opus_mode != ' t' && config.opus_mode != ' a' )))
461
+ tag_write<T>(tag, track.result , config);
466
462
463
+ bool ret = file.save ();
464
+ if (!std::is_same_v<T, TagLib::Ogg::Opus::File> || config.tag_mode == ' s' ||
465
+ !(config.opus_mode == ' t' || config.opus_mode == ' a' ) || !ret)
466
+ return ret;
467
+
468
+ }
467
469
int16_t gain = config.opus_mode == ' a' && config.do_album ?
468
470
GAIN_TO_Q78 (track.result .album_gain ) : GAIN_TO_Q78 (track.result .track_gain );
469
471
return set_opus_header_gain (track.path .string ().c_str (), gain);
@@ -722,13 +724,16 @@ static void tag_write(TagLib::ASF::Tag *tag, const ScanResult &result, const Con
722
724
}
723
725
724
726
static_assert (-1 == ~0 ); // 2's complement for signed integers
725
- bool set_opus_header_gain (const char * path, int16_t gain)
726
- {
727
+ bool set_opus_header_gain (const char * path, int16_t gain)
728
+ {
727
729
uint32_t crc;
728
- if constexpr (std::endian::native == std::endian::big)
730
+ if constexpr (std::endian::native == std::endian::big)
729
731
gain = static_cast <int16_t >((gain << 8 ) & 0xff00 ) | ((gain >> 8 ) & 0x00ff );
730
-
732
+
731
733
std::unique_ptr<std::FILE, int (*)(FILE*)> file (fopen (path, " rb+" ), fclose );
734
+ if (!file)
735
+ return false ;
736
+
732
737
char buffer[8 ];
733
738
size_t page_size = 0 ;
734
739
size_t opus_header_size = 0 ;
0 commit comments