2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2014-01-13 22:30:36 +01:00
|
|
|
* Copyright (C) 2003-2014 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
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2013-07-28 13:25:12 +02:00
|
|
|
#include "Song.hxx"
|
2013-01-02 22:52:08 +01:00
|
|
|
#include "Directory.hxx"
|
2013-09-05 18:22:02 +02:00
|
|
|
#include "tag/Tag.hxx"
|
2014-01-18 19:24:55 +01:00
|
|
|
#include "util/VarSize.hxx"
|
2014-01-07 21:39:47 +01:00
|
|
|
#include "DetachedSong.hxx"
|
2014-01-19 10:51:34 +01:00
|
|
|
#include "LightSong.hxx"
|
2009-01-03 14:51:30 +01:00
|
|
|
|
2008-12-29 17:28:32 +01:00
|
|
|
#include <assert.h>
|
2013-07-30 20:11:57 +02:00
|
|
|
#include <string.h>
|
2014-01-07 23:33:46 +01:00
|
|
|
#include <stdlib.h>
|
2008-12-29 17:28:32 +01:00
|
|
|
|
2014-01-19 19:57:27 +01:00
|
|
|
inline Song::Song(const char *_uri, size_t uri_length, Directory &_parent)
|
|
|
|
:parent(&_parent), mtime(0), start_ms(0), end_ms(0)
|
2014-01-18 19:24:55 +01:00
|
|
|
{
|
|
|
|
memcpy(uri, _uri, uri_length + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline Song::~Song()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
static Song *
|
2014-01-19 19:57:27 +01:00
|
|
|
song_alloc(const char *uri, Directory &parent)
|
2008-10-06 18:46:52 +02:00
|
|
|
{
|
2009-10-13 18:01:06 +02:00
|
|
|
size_t uri_length;
|
2008-10-07 21:20:34 +02:00
|
|
|
|
2009-10-13 18:01:06 +02:00
|
|
|
assert(uri);
|
|
|
|
uri_length = strlen(uri);
|
|
|
|
assert(uri_length);
|
2008-10-06 18:46:52 +02:00
|
|
|
|
2014-01-18 19:24:55 +01:00
|
|
|
return NewVarSize<Song>(sizeof(Song::uri),
|
|
|
|
uri_length + 1,
|
|
|
|
uri, uri_length, parent);
|
2008-10-06 18:46:52 +02:00
|
|
|
}
|
2004-03-10 10:55:54 +01:00
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
Song *
|
2014-01-19 19:57:27 +01:00
|
|
|
Song::NewFrom(DetachedSong &&other, Directory &parent)
|
2008-10-08 11:05:25 +02:00
|
|
|
{
|
2014-01-07 21:39:47 +01:00
|
|
|
Song *song = song_alloc(other.GetURI(), parent);
|
2014-01-18 19:08:39 +01:00
|
|
|
song->tag = std::move(other.WritableTag());
|
2014-01-07 21:39:47 +01:00
|
|
|
song->mtime = other.GetLastModified();
|
|
|
|
song->start_ms = other.GetStartMS();
|
|
|
|
song->end_ms = other.GetEndMS();
|
|
|
|
return song;
|
2008-10-08 11:05:25 +02:00
|
|
|
}
|
|
|
|
|
2013-07-28 13:25:12 +02:00
|
|
|
Song *
|
2014-01-19 19:57:27 +01:00
|
|
|
Song::NewFile(const char *path, Directory &parent)
|
2008-10-08 11:05:25 +02:00
|
|
|
{
|
|
|
|
return song_alloc(path, parent);
|
|
|
|
}
|
|
|
|
|
2008-10-08 10:49:11 +02:00
|
|
|
void
|
2013-07-28 13:25:12 +02:00
|
|
|
Song::Free()
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2014-01-18 19:24:55 +01:00
|
|
|
DeleteVarSize(this);
|
2004-04-10 19:56:01 +02:00
|
|
|
}
|
|
|
|
|
2013-10-17 01:01:15 +02:00
|
|
|
std::string
|
2013-07-28 13:25:12 +02:00
|
|
|
Song::GetURI() const
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2013-07-28 13:25:12 +02:00
|
|
|
assert(*uri);
|
2008-08-26 08:27:11 +02:00
|
|
|
|
2014-01-19 19:57:27 +01:00
|
|
|
if (parent->IsRoot())
|
2013-10-17 01:01:15 +02:00
|
|
|
return std::string(uri);
|
|
|
|
else {
|
|
|
|
const char *path = parent->GetPath();
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
result.reserve(strlen(path) + 1 + strlen(uri));
|
|
|
|
result.assign(path);
|
|
|
|
result.push_back('/');
|
|
|
|
result.append(uri);
|
|
|
|
return result;
|
|
|
|
}
|
2004-11-11 03:36:25 +01:00
|
|
|
}
|
2009-12-26 13:56:35 +01:00
|
|
|
|
2014-01-19 10:51:34 +01:00
|
|
|
LightSong
|
|
|
|
Song::Export() const
|
2009-12-26 13:56:35 +01:00
|
|
|
{
|
2014-01-19 10:51:34 +01:00
|
|
|
LightSong dest;
|
|
|
|
dest.directory = parent->IsRoot()
|
|
|
|
? nullptr : parent->GetPath();
|
|
|
|
dest.uri = uri;
|
2014-02-04 00:38:52 +01:00
|
|
|
dest.real_uri = nullptr;
|
2014-01-19 10:51:34 +01:00
|
|
|
dest.tag = &tag;
|
|
|
|
dest.mtime = mtime;
|
|
|
|
dest.start_ms = start_ms;
|
|
|
|
dest.end_ms = end_ms;
|
|
|
|
return dest;
|
2009-12-26 13:56:35 +01:00
|
|
|
}
|