db/simple/Song: add attribute "target"
Will be used for Song objects representing tracks inside a CUE file.
This commit is contained in:
parent
91c1274ac6
commit
5fdb804a50
@ -53,6 +53,9 @@ song_save(BufferedOutputStream &os, const Song &song)
|
|||||||
{
|
{
|
||||||
os.Format(SONG_BEGIN "%s\n", song.filename.c_str());
|
os.Format(SONG_BEGIN "%s\n", song.filename.c_str());
|
||||||
|
|
||||||
|
if (!song.target.empty())
|
||||||
|
os.Format("Target: %s\n", song.target.c_str());
|
||||||
|
|
||||||
range_save(os, song.start_time.ToMS(), song.end_time.ToMS());
|
range_save(os, song.start_time.ToMS(), song.end_time.ToMS());
|
||||||
|
|
||||||
tag_save(os, song.tag);
|
tag_save(os, song.tag);
|
||||||
@ -83,6 +86,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song)
|
|||||||
|
|
||||||
DetachedSong
|
DetachedSong
|
||||||
song_load(TextFile &file, const char *uri,
|
song_load(TextFile &file, const char *uri,
|
||||||
|
std::string *target_r,
|
||||||
AudioFormat *audio_format_r)
|
AudioFormat *audio_format_r)
|
||||||
{
|
{
|
||||||
DetachedSong song(uri);
|
DetachedSong song(uri);
|
||||||
@ -105,6 +109,9 @@ song_load(TextFile &file, const char *uri,
|
|||||||
tag.AddItem(type, value);
|
tag.AddItem(type, value);
|
||||||
} else if (StringIsEqual(line, "Time")) {
|
} else if (StringIsEqual(line, "Time")) {
|
||||||
tag.SetDuration(SignedSongTime::FromS(ParseDouble(value)));
|
tag.SetDuration(SignedSongTime::FromS(ParseDouble(value)));
|
||||||
|
} else if (StringIsEqual(line, "Target")) {
|
||||||
|
if (target_r != nullptr)
|
||||||
|
*target_r = value;
|
||||||
} else if (StringIsEqual(line, "Format")) {
|
} else if (StringIsEqual(line, "Format")) {
|
||||||
if (audio_format_r != nullptr) {
|
if (audio_format_r != nullptr) {
|
||||||
try {
|
try {
|
||||||
|
@ -44,6 +44,7 @@ song_save(BufferedOutputStream &os, const DetachedSong &song);
|
|||||||
*/
|
*/
|
||||||
DetachedSong
|
DetachedSong
|
||||||
song_load(TextFile &file, const char *uri,
|
song_load(TextFile &file, const char *uri,
|
||||||
|
std::string *target_r=nullptr,
|
||||||
AudioFormat *audio_format_r=nullptr);
|
AudioFormat *audio_format_r=nullptr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -161,12 +161,15 @@ directory_load(TextFile &file, Directory &directory)
|
|||||||
if (directory.FindSong(name) != nullptr)
|
if (directory.FindSong(name) != nullptr)
|
||||||
throw FormatRuntimeError("Duplicate song '%s'", name);
|
throw FormatRuntimeError("Duplicate song '%s'", name);
|
||||||
|
|
||||||
|
std::string target;
|
||||||
auto audio_format = AudioFormat::Undefined();
|
auto audio_format = AudioFormat::Undefined();
|
||||||
auto detached_song = song_load(file, name,
|
auto detached_song = song_load(file, name,
|
||||||
|
&target,
|
||||||
&audio_format);
|
&audio_format);
|
||||||
|
|
||||||
auto song = std::make_unique<Song>(std::move(detached_song),
|
auto song = std::make_unique<Song>(std::move(detached_song),
|
||||||
directory);
|
directory);
|
||||||
|
song->target = std::move(target);
|
||||||
song->audio_format = audio_format;
|
song->audio_format = audio_format;
|
||||||
|
|
||||||
directory.AddSong(std::move(song));
|
directory.AddSong(std::move(song));
|
||||||
|
@ -51,6 +51,8 @@ Song::Export() const noexcept
|
|||||||
LightSong dest(filename.c_str(), tag);
|
LightSong dest(filename.c_str(), tag);
|
||||||
if (!parent.IsRoot())
|
if (!parent.IsRoot())
|
||||||
dest.directory = parent.GetPath();
|
dest.directory = parent.GetPath();
|
||||||
|
if (!target.empty())
|
||||||
|
dest.real_uri = target.c_str();
|
||||||
dest.mtime = mtime;
|
dest.mtime = mtime;
|
||||||
dest.start_time = start_time;
|
dest.start_time = start_time;
|
||||||
dest.end_time = end_time;
|
dest.end_time = end_time;
|
||||||
|
@ -93,6 +93,15 @@ struct Song {
|
|||||||
*/
|
*/
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If non-empty, then this object does not describe a file
|
||||||
|
* within the `music_directory`, but some sort of symbolic
|
||||||
|
* link pointing to this value. It can be an absolute URI
|
||||||
|
* (i.e. with URI scheme) or a URI relative to this object
|
||||||
|
* (which may begin with one or more "../").
|
||||||
|
*/
|
||||||
|
std::string target;
|
||||||
|
|
||||||
template<typename F>
|
template<typename F>
|
||||||
Song(F &&_filename, Directory &_parent) noexcept
|
Song(F &&_filename, Directory &_parent) noexcept
|
||||||
:parent(_parent), filename(std::forward<F>(_filename)) {}
|
:parent(_parent), filename(std::forward<F>(_filename)) {}
|
||||||
|
Loading…
Reference in New Issue
Block a user