MPD  0.20.18
Song.hxx
Go to the documentation of this file.
1 /*
2  * Copyright 2003-2017 The Music Player Daemon Project
3  * http://www.musicpd.org
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef MPD_SONG_HXX
21 #define MPD_SONG_HXX
22 
23 #include "check.h"
24 #include "Chrono.hxx"
25 #include "tag/Tag.hxx"
26 #include "Compiler.h"
27 
28 #include <boost/intrusive/list.hpp>
29 
30 #include <string>
31 
32 #include <time.h>
33 
34 struct LightSong;
35 struct Directory;
36 class DetachedSong;
37 class Storage;
38 class ArchiveFile;
39 
44 struct Song {
45  static constexpr auto link_mode = boost::intrusive::normal_link;
46  typedef boost::intrusive::link_mode<link_mode> LinkMode;
47  typedef boost::intrusive::list_member_hook<LinkMode> Hook;
48 
49  struct Disposer {
50  void operator()(Song *song) const {
51  song->Free();
52  }
53  };
54 
63  Hook siblings;
64 
66 
71  Directory *const parent;
72 
73  time_t mtime;
74 
79 
85 
89  char uri[sizeof(int)];
90 
91  Song(const char *_uri, size_t uri_length, Directory &parent);
92  ~Song();
93 
95  static Song *NewFrom(DetachedSong &&other, Directory &parent);
96 
99  static Song *NewFile(const char *path_utf8, Directory &parent);
100 
106  gcc_malloc
107  static Song *LoadFile(Storage &storage, const char *name_utf8,
108  Directory &parent);
109 
110  void Free();
111 
112  bool UpdateFile(Storage &storage);
113 
114 #ifdef ENABLE_ARCHIVE
115  static Song *LoadFromArchive(ArchiveFile &archive,
116  const char *name_utf8,
117  Directory &parent);
118  bool UpdateFileInArchive(ArchiveFile &archive);
119 #endif
120 
125  gcc_pure
126  std::string GetURI() const noexcept;
127 
128  gcc_pure
129  LightSong Export() const noexcept;
130 };
131 
132 typedef boost::intrusive::list<Song,
133  boost::intrusive::member_hook<Song, Song::Hook,
134  &Song::siblings>,
135  boost::intrusive::constant_time_size<false>> SongList;
136 
137 #endif
Hook siblings
Pointers to the siblings of this directory within the parent directory.
Definition: Song.hxx:63
gcc_pure LightSong Export() const noexcept
void Free()
The meta information about a song file.
Definition: Tag.hxx:34
boost::intrusive::list< Song, boost::intrusive::member_hook< Song, Song::Hook,&Song::siblings >, boost::intrusive::constant_time_size< false > > SongList
Definition: Song.hxx:135
boost::intrusive::link_mode< link_mode > LinkMode
Definition: Song.hxx:46
A time stamp within a song.
Definition: Chrono.hxx:31
#define gcc_malloc
Definition: Compiler.h:112
SongTime start_time
Start of this sub-song within the file.
Definition: Song.hxx:78
const Storage const char const char * path_utf8
static gcc_malloc Song * LoadFile(Storage &storage, const char *name_utf8, Directory &parent)
allocate a new song structure with a local file name and attempt to load its metadata.
static gcc_malloc Song * NewFile(const char *path_utf8, Directory &parent)
allocate a new song with a local file name
bool UpdateFile(Storage &storage)
A song file inside the configured music directory.
Definition: Song.hxx:44
Tag tag
Definition: Song.hxx:65
boost::intrusive::list_member_hook< LinkMode > Hook
Definition: Song.hxx:47
const Storage & storage
SongTime end_time
End of this sub-song within the file.
Definition: Song.hxx:84
Song(const char *_uri, size_t uri_length, Directory &parent)
void operator()(Song *song) const
Definition: Song.hxx:50
Directory *const parent
The Directory that contains this song.
Definition: Song.hxx:71
time_t mtime
Definition: Song.hxx:73
static constexpr auto link_mode
Definition: Song.hxx:45
static gcc_malloc Song * NewFrom(DetachedSong &&other, Directory &parent)
char uri[sizeof(int)]
The file name.
Definition: Song.hxx:89
gcc_pure std::string GetURI() const noexcept
Returns the URI of the song in UTF-8 encoding, including its location within the music directory...
#define gcc_pure
Definition: Compiler.h:116
A reference to a song file.
Definition: LightSong.hxx:40