aboutsummaryrefslogtreecommitdiffstats
path: root/src/song.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/song.h')
-rw-r--r--src/song.h71
1 files changed, 57 insertions, 14 deletions
diff --git a/src/song.h b/src/song.h
index 8b97d45d0..119d89ccd 100644
--- a/src/song.h
+++ b/src/song.h
@@ -21,7 +21,9 @@
#define MPD_SONG_H
#include "util/list.h"
+#include "gcc.h"
+#include <assert.h>
#include <stddef.h>
#include <stdbool.h>
#include <sys/time.h>
@@ -41,7 +43,7 @@ struct song {
struct list_head siblings;
struct tag *tag;
- struct directory *parent;
+ struct Directory *parent;
time_t mtime;
/**
@@ -58,13 +60,21 @@ struct song {
char uri[sizeof(int)];
};
+/**
+ * A dummy #directory instance that is used for "detached" song
+ * copies.
+ */
+extern struct Directory detached_root;
+
+G_BEGIN_DECLS
+
/** allocate a new song with a remote URL */
struct song *
song_remote_new(const char *uri);
/** allocate a new song with a local file name */
struct song *
-song_file_new(const char *path, struct directory *parent);
+song_file_new(const char *path, struct Directory *parent);
/**
* allocate a new song structure with a local file name and attempt to
@@ -72,7 +82,7 @@ song_file_new(const char *path, struct directory *parent);
* data, NULL is returned.
*/
struct song *
-song_file_load(const char *path, struct directory *parent);
+song_file_load(const char *path, struct Directory *parent);
/**
* Replaces the URI of a song object. The given song object is
@@ -83,9 +93,52 @@ song_file_load(const char *path, struct directory *parent);
struct song *
song_replace_uri(struct song *song, const char *uri);
+/**
+ * Creates a "detached" song object.
+ */
+struct song *
+song_detached_new(const char *uri);
+
+/**
+ * Creates a duplicate of the song object. If the object is in the
+ * database, it creates a "detached" copy of this song, see
+ * song_is_detached().
+ */
+gcc_malloc
+struct song *
+song_dup_detached(const struct song *src);
+
void
song_free(struct song *song);
+static inline bool
+song_in_database(const struct song *song)
+{
+ return song->parent != NULL;
+}
+
+static inline bool
+song_is_file(const struct song *song)
+{
+ return song_in_database(song) || song->uri[0] == '/';
+}
+
+static inline bool
+song_is_detached(const struct song *song)
+{
+ assert(song != NULL);
+ assert(song_in_database(song));
+
+ return song->parent == &detached_root;
+}
+
+/**
+ * Returns true if both objects refer to the same physical song.
+ */
+gcc_pure
+bool
+song_equals(const struct song *a, const struct song *b);
+
bool
song_file_update(struct song *song);
@@ -105,16 +158,6 @@ song_get_uri(const struct song *song);
double
song_get_duration(const struct song *song);
-static inline bool
-song_in_database(const struct song *song)
-{
- return song->parent != NULL;
-}
-
-static inline bool
-song_is_file(const struct song *song)
-{
- return song_in_database(song) || song->uri[0] == '/';
-}
+G_END_DECLS
#endif