2013-07-28 13:25:12 +02:00
|
|
|
/*
|
2018-10-31 17:54:59 +01:00
|
|
|
* Copyright 2003-2018 The Music Player Daemon Project
|
2013-07-28 13:25:12 +02:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPD_SONG_HXX
|
|
|
|
#define MPD_SONG_HXX
|
|
|
|
|
2014-08-28 12:49:29 +02:00
|
|
|
#include "Chrono.hxx"
|
2014-01-18 19:08:39 +01:00
|
|
|
#include "tag/Tag.hxx"
|
2018-07-06 13:22:17 +02:00
|
|
|
#include "AudioFormat.hxx"
|
2018-08-20 16:19:17 +02:00
|
|
|
#include "util/Compiler.h"
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2013-07-28 13:25:12 +02:00
|
|
|
|
2014-06-10 21:15:40 +02:00
|
|
|
#include <boost/intrusive/list.hpp>
|
|
|
|
|
2013-10-17 01:01:15 +02:00
|
|
|
#include <string>
|
|
|
|
|
2014-01-19 10:51:34 +01:00
|
|
|
struct LightSong;
|
2014-01-07 21:39:47 +01:00
|
|
|
struct Directory;
|
|
|
|
class DetachedSong;
|
2014-02-06 18:58:15 +01:00
|
|
|
class Storage;
|
2016-02-26 14:53:37 +01:00
|
|
|
class ArchiveFile;
|
2013-07-30 20:11:57 +02:00
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
/**
|
2014-02-25 22:16:20 +01:00
|
|
|
* A song file inside the configured music directory. Internal
|
|
|
|
* #SimpleDatabase class.
|
2013-07-28 13:25:12 +02:00
|
|
|
*/
|
|
|
|
struct Song {
|
2014-06-10 21:15:40 +02:00
|
|
|
static constexpr auto link_mode = boost::intrusive::normal_link;
|
|
|
|
typedef boost::intrusive::link_mode<link_mode> LinkMode;
|
|
|
|
typedef boost::intrusive::list_member_hook<LinkMode> Hook;
|
|
|
|
|
|
|
|
struct Disposer {
|
|
|
|
void operator()(Song *song) const {
|
|
|
|
song->Free();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
/**
|
|
|
|
* Pointers to the siblings of this directory within the
|
|
|
|
* parent directory. It is unused (undefined) if this song is
|
|
|
|
* not in the database.
|
|
|
|
*
|
|
|
|
* This attribute is protected with the global #db_mutex.
|
|
|
|
* Read access in the update thread does not need protection.
|
|
|
|
*/
|
2014-06-10 21:15:40 +02:00
|
|
|
Hook siblings;
|
2013-07-28 13:25:12 +02:00
|
|
|
|
2014-01-18 19:08:39 +01:00
|
|
|
Tag tag;
|
2014-01-07 21:39:47 +01:00
|
|
|
|
|
|
|
/**
|
2014-02-25 22:16:20 +01:00
|
|
|
* The #Directory that contains this song. Must be
|
2018-07-06 21:50:53 +02:00
|
|
|
* non-nullptr.
|
2014-01-07 21:39:47 +01:00
|
|
|
*/
|
2014-01-19 19:57:27 +01:00
|
|
|
Directory *const parent;
|
2014-01-07 21:39:47 +01:00
|
|
|
|
2017-01-18 13:19:13 +01:00
|
|
|
/**
|
|
|
|
* The time stamp of the last file modification. A negative
|
|
|
|
* value means that this is unknown/unavailable.
|
|
|
|
*/
|
2018-07-06 17:03:31 +02:00
|
|
|
std::chrono::system_clock::time_point mtime =
|
|
|
|
std::chrono::system_clock::time_point::min();
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
/**
|
2014-08-28 12:49:29 +02:00
|
|
|
* Start of this sub-song within the file.
|
2013-07-28 13:25:12 +02:00
|
|
|
*/
|
2018-07-06 17:03:31 +02:00
|
|
|
SongTime start_time = SongTime::zero();
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
/**
|
2014-08-28 12:49:29 +02:00
|
|
|
* End of this sub-song within the file.
|
2013-07-28 13:25:12 +02:00
|
|
|
* Unused if zero.
|
|
|
|
*/
|
2018-07-06 17:03:31 +02:00
|
|
|
SongTime end_time = SongTime::zero();
|
2013-07-28 13:25:12 +02:00
|
|
|
|
2018-07-06 13:22:17 +02:00
|
|
|
/**
|
|
|
|
* The audio format of the song, if given by the decoder
|
|
|
|
* plugin. May be undefined if unknown.
|
|
|
|
*/
|
|
|
|
AudioFormat audio_format = AudioFormat::Undefined();
|
|
|
|
|
2014-01-07 21:39:47 +01:00
|
|
|
/**
|
2014-02-25 22:16:20 +01:00
|
|
|
* The file name.
|
2014-01-07 21:39:47 +01:00
|
|
|
*/
|
2013-07-28 13:25:12 +02:00
|
|
|
char uri[sizeof(int)];
|
|
|
|
|
2014-01-19 19:57:27 +01:00
|
|
|
Song(const char *_uri, size_t uri_length, Directory &parent);
|
2014-01-18 19:24:55 +01:00
|
|
|
~Song();
|
|
|
|
|
2017-12-18 23:00:13 +01:00
|
|
|
gcc_malloc gcc_returns_nonnull
|
2014-01-19 19:57:27 +01:00
|
|
|
static Song *NewFrom(DetachedSong &&other, Directory &parent);
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
/** allocate a new song with a local file name */
|
2017-12-18 23:00:13 +01:00
|
|
|
gcc_malloc gcc_returns_nonnull
|
2014-01-19 19:57:27 +01:00
|
|
|
static Song *NewFile(const char *path_utf8, Directory &parent);
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* allocate a new song structure with a local file name and attempt to
|
|
|
|
* load its metadata. If all decoder plugin fail to read its meta
|
|
|
|
* data, nullptr is returned.
|
|
|
|
*/
|
|
|
|
gcc_malloc
|
2014-02-06 18:58:15 +01:00
|
|
|
static Song *LoadFile(Storage &storage, const char *name_utf8,
|
2018-01-21 11:40:42 +01:00
|
|
|
Directory &parent) noexcept;
|
2013-10-19 18:48:38 +02:00
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
void Free();
|
|
|
|
|
2018-01-21 11:40:42 +01:00
|
|
|
bool UpdateFile(Storage &storage) noexcept;
|
2015-03-01 00:25:30 +01:00
|
|
|
|
|
|
|
#ifdef ENABLE_ARCHIVE
|
2016-02-26 14:53:37 +01:00
|
|
|
static Song *LoadFromArchive(ArchiveFile &archive,
|
|
|
|
const char *name_utf8,
|
2018-01-21 11:40:42 +01:00
|
|
|
Directory &parent) noexcept;
|
|
|
|
bool UpdateFileInArchive(ArchiveFile &archive) noexcept;
|
2015-03-01 00:25:30 +01:00
|
|
|
#endif
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the URI of the song in UTF-8 encoding, including its
|
|
|
|
* location within the music directory.
|
|
|
|
*/
|
2013-10-17 01:01:15 +02:00
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
std::string GetURI() const noexcept;
|
2013-07-28 13:25:12 +02:00
|
|
|
|
|
|
|
gcc_pure
|
2017-05-08 14:44:49 +02:00
|
|
|
LightSong Export() const noexcept;
|
2013-07-28 13:25:12 +02:00
|
|
|
};
|
|
|
|
|
2014-06-10 21:15:40 +02:00
|
|
|
typedef boost::intrusive::list<Song,
|
|
|
|
boost::intrusive::member_hook<Song, Song::Hook,
|
|
|
|
&Song::siblings>,
|
|
|
|
boost::intrusive::constant_time_size<false>> SongList;
|
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
#endif
|