Skip to content

Commit

Permalink
When input has an embeded cuesheet, split output by the cuesheet by d…
Browse files Browse the repository at this point in the history
…efault
  • Loading branch information
nu774 committed Jun 25, 2015
1 parent 09f73e6 commit 76bb83f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 42 deletions.
5 changes: 4 additions & 1 deletion cuesheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ void CueSheet::parse(std::wstreambuf *src)

void CueSheet::loadTracks(playlist::Playlist &tracks,
const std::wstring &cuedir,
const std::wstring &fname_format)
const std::wstring &fname_format,
const wchar_t *embedder_fname)
{
std::shared_ptr<ISeekableSource> src;
std::for_each(begin(), end(), [&](const CueTrack &track) {
Expand All @@ -163,6 +164,8 @@ void CueSheet::loadTracks(playlist::Playlist &tracks,
if (seg.m_filename == L"__GAP__") {
if (src.get())
src.reset(new NullSource(src->getSampleFormat()));
} else if (embedder_fname) {
src = input::factory()->open(embedder_fname);
} else {
std::wstring ifilename =
win32::PathCombineX(cuedir, seg.m_filename);
Expand Down
3 changes: 2 additions & 1 deletion cuesheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class CueSheet {
void parse(std::wstreambuf *src);
void loadTracks(playlist::Playlist &tracks,
const std::wstring &cuedir,
const std::wstring &fname_format);
const std::wstring &fname_format,
const wchar_t *embedder_fname=0);
void asChapters(double duration, /* total duration in sec. */
std::vector<chapters::entry_t> *chapters) const;
void getTags(std::map<std::string, std::string> *tags) const;
Expand Down
14 changes: 1 addition & 13 deletions flacsrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,8 @@ void FLACSource::handleVorbisComment(
if (sscanf(value, "%i", &mask) == 1)
chanmap::getChannels(mask, &m_chanmap);
} else if (value) {
if (!strcasecmp(key, "cuesheet"))
cuesheet = strutil::us2w(value);
else
tags[key] = value;
tags[key] = value;
}
}
if (cuesheet.size()) {
std::map<std::string, std::string> ctags;
Cue::CueSheetToChapters(cuesheet,
m_length / m_asbd.mSampleRate,
&m_chapters, &ctags);
std::map<std::string, std::string>::const_iterator it;
for (it = ctags.begin(); it != ctags.end(); ++it)
tags[it->first] = it->second;
}
TextBasedTag::normalizeTags(tags, &m_tags);
}
26 changes: 25 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,32 @@ int wmain1(int argc, wchar_t **argv)
ifilename = argv[i];
if (strutil::wslower(PathFindExtensionW(ifilename)) == L".cue")
load_cue_sheet(ifilename, opts, tracks);
else
else {
load_track(ifilename, opts, tracks);
auto src = tracks.back().source;
auto parser = dynamic_cast<ITagParser*>(src.get());
do {
if (!parser) break;
auto &tags = parser->getTags();
auto ti = tags.begin();
for (; ti != tags.end(); ++ti)
if (strcasecmp(ti->first.c_str(), "cuesheet") == 0)
break;
if (ti == tags.end())
break;
try {
std::wstringbuf wsb(strutil::us2w(ti->second));
CueSheet cue;
cue.parse(&wsb);
tracks.pop_back();
cue.loadTracks(tracks, L"",
opts.fname_format
? opts.fname_format
: L"${tracknumber}${title& }${title}",
ifilename);
} catch (...) {}
} while (0);
}
}
SetConsoleCtrlHandler(console_interrupt_handler, TRUE);
if (!opts.concat) {
Expand Down
14 changes: 1 addition & 13 deletions taksrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,7 @@ void TakSource::fetchTags()
continue;
std::string key = it->first.toCString();
std::wstring value = it->second.toString().toWString();
if (strutil::slower(key) == "cuesheet")
cuesheet = value;
else
tags[key] = strutil::w2us(value);
}
if (cuesheet.size()) {
std::map<std::string, std::string> ctags;
Cue::CueSheetToChapters(cuesheet,
m_length / m_asbd.mSampleRate,
&m_chapters, &ctags);
std::map<std::string, std::string>::const_iterator it;
for (it = ctags.begin(); it != ctags.end(); ++it)
tags[it->first] = it->second;
tags[key] = strutil::w2us(value);
}
TextBasedTag::normalizeTags(tags, &m_tags);
}
14 changes: 1 addition & 13 deletions wvpacksrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,7 @@ void WavpackSource::fetchTags()
size = m_module.GetTagItem(wpc, &name[0], 0, 0);
std::vector<char> value(size + 1);
m_module.GetTagItem(wpc, &name[0], &value[0], value.size());
if (!strcasecmp(&name[0], "cuesheet"))
cuesheet = strutil::us2w(&value[0]);
else
tags[&name[0]] = &value[0];
}
if (cuesheet.size()) {
std::map<std::string, std::string> ctags;
Cue::CueSheetToChapters(cuesheet,
m_length / m_asbd.mSampleRate,
&m_chapters, &ctags);
std::map<std::string, std::string>::const_iterator it;
for (it = ctags.begin(); it != ctags.end(); ++it)
tags[it->first] = it->second;
tags[&name[0]] = &value[0];
}
TextBasedTag::normalizeTags(tags, &m_tags);
}
Expand Down

0 comments on commit 76bb83f

Please sign in to comment.