2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2008-10-31 09:19:53 +01:00
|
|
|
#ifndef MPD_SONG_H
|
|
|
|
#define MPD_SONG_H
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2012-01-24 21:33:09 +01:00
|
|
|
#include "util/list.h"
|
|
|
|
|
2008-10-08 11:03:39 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdbool.h>
|
2008-10-08 10:49:29 +02:00
|
|
|
#include <sys/time.h>
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-10-28 01:07:34 +02:00
|
|
|
#define SONG_FILE "file: "
|
|
|
|
#define SONG_TIME "Time: "
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
struct song {
|
2012-01-24 21:33:09 +01: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.
|
|
|
|
*/
|
|
|
|
struct list_head siblings;
|
|
|
|
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag *tag;
|
2008-10-08 11:05:34 +02:00
|
|
|
struct directory *parent;
|
2004-02-24 00:41:20 +01:00
|
|
|
time_t mtime;
|
2009-12-25 22:59:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start of this sub-song within the file in milliseconds.
|
|
|
|
*/
|
|
|
|
unsigned start_ms;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* End of this sub-song within the file in milliseconds.
|
|
|
|
* Unused if zero.
|
|
|
|
*/
|
|
|
|
unsigned end_ms;
|
|
|
|
|
2009-10-13 18:01:06 +02:00
|
|
|
char uri[sizeof(int)];
|
2008-10-08 10:49:11 +02:00
|
|
|
};
|
2008-10-06 18:46:52 +02:00
|
|
|
|
2012-08-08 20:12:20 +02:00
|
|
|
G_BEGIN_DECLS
|
|
|
|
|
2008-10-08 11:05:25 +02:00
|
|
|
/** allocate a new song with a remote URL */
|
2008-10-08 10:49:11 +02:00
|
|
|
struct song *
|
2009-10-13 18:01:06 +02:00
|
|
|
song_remote_new(const char *uri);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-10-08 11:05:25 +02:00
|
|
|
/** allocate a new song with a local file name */
|
2008-10-08 10:49:11 +02:00
|
|
|
struct song *
|
2008-10-08 11:05:25 +02:00
|
|
|
song_file_new(const char *path, struct directory *parent);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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, NULL is returned.
|
|
|
|
*/
|
|
|
|
struct song *
|
|
|
|
song_file_load(const char *path, struct directory *parent);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2012-02-12 19:47:22 +01:00
|
|
|
/**
|
|
|
|
* Replaces the URI of a song object. The given song object is
|
|
|
|
* destroyed, and a newly allocated one is returned. It does not
|
|
|
|
* update the reference within the parent directory; the caller is
|
|
|
|
* responsible for doing that.
|
|
|
|
*/
|
|
|
|
struct song *
|
|
|
|
song_replace_uri(struct song *song, const char *uri);
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
void
|
2008-10-08 11:05:34 +02:00
|
|
|
song_free(struct song *song);
|
2004-05-13 20:46:38 +02:00
|
|
|
|
2008-10-08 11:06:26 +02:00
|
|
|
bool
|
2008-10-08 11:05:34 +02:00
|
|
|
song_file_update(struct song *song);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2008-12-16 21:42:42 +01:00
|
|
|
bool
|
|
|
|
song_file_update_inarchive(struct song *song);
|
|
|
|
|
2009-01-04 19:09:34 +01:00
|
|
|
/**
|
|
|
|
* Returns the URI of the song in UTF-8 encoding, including its
|
|
|
|
* location within the music directory.
|
|
|
|
*
|
|
|
|
* The return value is allocated on the heap, and must be freed by the
|
|
|
|
* caller.
|
2008-04-12 06:08:18 +02:00
|
|
|
*/
|
2008-10-08 10:49:11 +02:00
|
|
|
char *
|
2009-01-04 19:09:34 +01:00
|
|
|
song_get_uri(const struct song *song);
|
2004-11-11 03:36:25 +01:00
|
|
|
|
2009-12-26 13:56:35 +01:00
|
|
|
double
|
|
|
|
song_get_duration(const struct song *song);
|
|
|
|
|
2008-10-08 11:03:39 +02:00
|
|
|
static inline bool
|
2008-10-15 22:34:47 +02:00
|
|
|
song_in_database(const struct song *song)
|
2008-10-06 18:52:13 +02:00
|
|
|
{
|
2008-10-08 11:05:34 +02:00
|
|
|
return song->parent != NULL;
|
2008-10-06 18:52:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-15 22:34:47 +02:00
|
|
|
static inline bool
|
|
|
|
song_is_file(const struct song *song)
|
|
|
|
{
|
2009-10-13 18:01:06 +02:00
|
|
|
return song_in_database(song) || song->uri[0] == '/';
|
2008-10-15 22:34:47 +02:00
|
|
|
}
|
|
|
|
|
2012-08-08 20:12:20 +02:00
|
|
|
G_END_DECLS
|
|
|
|
|
2004-02-24 00:41:20 +01:00
|
|
|
#endif
|