Commit 071cacc9 authored by Max Kellermann's avatar Max Kellermann

decoder/sidplay: pass SidTuneMod to get_song_length()

Eliminate duplicate SidTune construction.
parent 33f33323
...@@ -130,19 +130,12 @@ ParseContainerPath(Path path_fs) ...@@ -130,19 +130,12 @@ ParseContainerPath(Path path_fs)
/* get the song length in seconds */ /* get the song length in seconds */
static SignedSongTime static SignedSongTime
get_song_length(const SidplayContainerPath &container) get_song_length(SidTuneMod &tune)
{ {
if (songlength_database == nullptr) assert(tune);
return SignedSongTime::Negative();
SidTuneMod tune(container.path.c_str()); if (songlength_database == nullptr)
if(!tune) {
LogWarning(sidplay_domain,
"failed to load file for calculating md5 sum");
return SignedSongTime::Negative(); return SignedSongTime::Negative();
}
tune.selectSong(container.track);
const auto length = songlength_database->length(tune); const auto length = songlength_database->length(tune);
if (length < 0) if (length < 0)
...@@ -159,7 +152,7 @@ sidplay_file_decode(Decoder &decoder, Path path_fs) ...@@ -159,7 +152,7 @@ sidplay_file_decode(Decoder &decoder, Path path_fs)
/* load the tune */ /* load the tune */
const auto container = ParseContainerPath(path_fs); const auto container = ParseContainerPath(path_fs);
SidTune tune(container.path.c_str(), nullptr, true); SidTuneMod tune(container.path.c_str());
if (!tune) { if (!tune) {
LogWarning(sidplay_domain, "failed to load file"); LogWarning(sidplay_domain, "failed to load file");
return; return;
...@@ -168,7 +161,7 @@ sidplay_file_decode(Decoder &decoder, Path path_fs) ...@@ -168,7 +161,7 @@ sidplay_file_decode(Decoder &decoder, Path path_fs)
const int song_num = container.track; const int song_num = container.track;
tune.selectSong(song_num); tune.selectSong(song_num);
auto duration = get_song_length(container); auto duration = get_song_length(tune);
if (duration.IsNegative() && default_songlength > 0) if (duration.IsNegative() && default_songlength > 0)
duration = SongTime::FromS(default_songlength); duration = SongTime::FromS(default_songlength);
...@@ -298,10 +291,12 @@ sidplay_scan_file(Path path_fs, ...@@ -298,10 +291,12 @@ sidplay_scan_file(Path path_fs,
const auto container = ParseContainerPath(path_fs); const auto container = ParseContainerPath(path_fs);
const unsigned song_num = container.track; const unsigned song_num = container.track;
SidTune tune(container.path.c_str(), nullptr, true); SidTuneMod tune(container.path.c_str());
if (!tune) if (!tune)
return false; return false;
tune.selectSong(song_num);
const SidTuneInfo &info = tune.getInfo(); const SidTuneInfo &info = tune.getInfo();
/* title */ /* title */
...@@ -332,7 +327,7 @@ sidplay_scan_file(Path path_fs, ...@@ -332,7 +327,7 @@ sidplay_scan_file(Path path_fs,
tag_handler_invoke_tag(handler, handler_ctx, TAG_TRACK, track); tag_handler_invoke_tag(handler, handler_ctx, TAG_TRACK, track);
/* time */ /* time */
const auto duration = get_song_length(container); const auto duration = get_song_length(tune);
if (!duration.IsNegative()) if (!duration.IsNegative())
tag_handler_invoke_duration(handler, handler_ctx, tag_handler_invoke_duration(handler, handler_ctx,
SongTime(duration)); SongTime(duration));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment