decoder/DecoderPlugin: container_scan() returns forward_list<DetachedSong>
Speed up container_scan() again, by eliminating the need to call scan_file() for each item.
This commit is contained in:
@@ -23,13 +23,13 @@
|
||||
#include "Compiler.h"
|
||||
|
||||
#include <forward_list>
|
||||
#include <string>
|
||||
|
||||
struct ConfigBlock;
|
||||
class InputStream;
|
||||
struct TagHandler;
|
||||
class Path;
|
||||
class DecoderClient;
|
||||
class DetachedSong;
|
||||
|
||||
struct DecoderPlugin {
|
||||
const char *name;
|
||||
@@ -93,7 +93,7 @@ struct DecoderPlugin {
|
||||
* a filename for every single track;
|
||||
* do not include full pathname here, just the "virtual" file
|
||||
*/
|
||||
std::forward_list<std::string> (*container_scan)(Path path_fs);
|
||||
std::forward_list<DetachedSong> (*container_scan)(Path path_fs);
|
||||
|
||||
/* last element in these arrays must always be a nullptr: */
|
||||
const char *const*suffixes;
|
||||
|
@@ -22,7 +22,9 @@
|
||||
#include "../DecoderAPI.hxx"
|
||||
#include "config/Block.cxx"
|
||||
#include "CheckAudioFormat.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "tag/TagHandler.hxx"
|
||||
#include "tag/TagBuilder.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "util/ScopeExit.hxx"
|
||||
@@ -266,10 +268,10 @@ gme_scan_file(Path path_fs,
|
||||
return ScanMusicEmu(emu, container.track, handler, handler_ctx);
|
||||
}
|
||||
|
||||
static std::forward_list<std::string>
|
||||
static std::forward_list<DetachedSong>
|
||||
gme_container_scan(Path path_fs)
|
||||
{
|
||||
std::forward_list<std::string> list;
|
||||
std::forward_list<DetachedSong> list;
|
||||
|
||||
Music_Emu *emu;
|
||||
const char *gme_err = gme_open_file(path_fs.c_str(), &emu,
|
||||
@@ -279,20 +281,27 @@ gme_container_scan(Path path_fs)
|
||||
return list;
|
||||
}
|
||||
|
||||
AtScopeExit(emu) { gme_delete(emu); };
|
||||
|
||||
const unsigned num_songs = gme_track_count(emu);
|
||||
gme_delete(emu);
|
||||
/* if it only contains a single tune, don't treat as container */
|
||||
if (num_songs < 2)
|
||||
return list;
|
||||
|
||||
const char *subtune_suffix = uri_get_suffix(path_fs.c_str());
|
||||
|
||||
TagBuilder tag_builder;
|
||||
|
||||
auto tail = list.before_begin();
|
||||
for (unsigned i = 1; i <= num_songs; ++i) {
|
||||
ScanMusicEmu(emu, i,
|
||||
add_tag_handler, &tag_builder);
|
||||
|
||||
char track_name[64];
|
||||
snprintf(track_name, sizeof(track_name),
|
||||
SUBTUNE_PREFIX "%03u.%s", i, subtune_suffix);
|
||||
tail = list.emplace_after(tail, track_name);
|
||||
tail = list.emplace_after(tail, track_name,
|
||||
tag_builder.Commit());
|
||||
}
|
||||
|
||||
return list;
|
||||
|
@@ -21,6 +21,8 @@
|
||||
#include "SidplayDecoderPlugin.hxx"
|
||||
#include "../DecoderAPI.hxx"
|
||||
#include "tag/TagHandler.hxx"
|
||||
#include "tag/TagBuilder.hxx"
|
||||
#include "DetachedSong.hxx"
|
||||
#include "fs/Path.hxx"
|
||||
#include "fs/AllocatedPath.hxx"
|
||||
#include "util/Macros.hxx"
|
||||
@@ -467,12 +469,16 @@ sidplay_scan_file(Path path_fs,
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::forward_list<std::string>
|
||||
static std::forward_list<DetachedSong>
|
||||
sidplay_container_scan(Path path_fs)
|
||||
{
|
||||
std::forward_list<std::string> list;
|
||||
std::forward_list<DetachedSong> list;
|
||||
|
||||
SidTune tune(path_fs.c_str(), nullptr, true);
|
||||
#ifdef HAVE_SIDPLAYFP
|
||||
SidTune tune(path_fs.c_str());
|
||||
#else
|
||||
SidTuneMod tune(path_fs.c_str());
|
||||
#endif
|
||||
if (!tune.getStatus())
|
||||
return list;
|
||||
|
||||
@@ -489,13 +495,21 @@ sidplay_container_scan(Path path_fs)
|
||||
if(!all_files_are_containers && n_tracks < 2)
|
||||
return list;
|
||||
|
||||
TagBuilder tag_builder;
|
||||
|
||||
auto tail = list.before_begin();
|
||||
for (unsigned i = 1; i <= n_tracks; ++i) {
|
||||
tune.selectSong(i);
|
||||
|
||||
ScanSidTuneInfo(info, i, n_tracks,
|
||||
add_tag_handler, &tag_builder);
|
||||
|
||||
char track_name[32];
|
||||
/* Construct container/tune path names, eg.
|
||||
Delta.sid/tune_001.sid */
|
||||
sprintf(track_name, SUBTUNE_PREFIX "%03u.sid", i);
|
||||
tail = list.emplace_after(tail, track_name);
|
||||
tail = list.emplace_after(tail, track_name,
|
||||
tag_builder.Commit());
|
||||
}
|
||||
|
||||
return list;
|
||||
|
Reference in New Issue
Block a user