DespotifyUtils: return Tag, not pointer

This commit is contained in:
Max Kellermann 2014-01-08 19:21:48 +01:00
parent 89a78a5f3c
commit 2071070f39
4 changed files with 12 additions and 12 deletions

View File

@ -83,8 +83,7 @@ void mpd_despotify_unregister_callback(void (*cb)(struct despotify_session *, in
} }
} }
Tag
Tag *
mpd_despotify_tag_from_track(const ds_track &track) mpd_despotify_tag_from_track(const ds_track &track)
{ {
char tracknum[20]; char tracknum[20];
@ -92,7 +91,7 @@ mpd_despotify_tag_from_track(const ds_track &track)
char date[20]; char date[20];
if (!track.has_meta_data) if (!track.has_meta_data)
return new Tag(); return Tag();
TagBuilder tag; TagBuilder tag;
snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber); snprintf(tracknum, sizeof(tracknum), "%d", track.tracknumber);
@ -108,7 +107,7 @@ mpd_despotify_tag_from_track(const ds_track &track)
tag.AddItem(TAG_COMMENT, comment); tag.AddItem(TAG_COMMENT, comment);
tag.SetTime(track.length / 1000); tag.SetTime(track.length / 1000);
return tag.CommitNew(); return tag.Commit();
} }
struct despotify_session *mpd_despotify_get_session(void) struct despotify_session *mpd_despotify_get_session(void)

View File

@ -42,9 +42,9 @@ struct despotify_session *mpd_despotify_get_session(void);
* *
* @param track the track to convert * @param track the track to convert
* *
* @return a pointer to the filled in tags structure * @return filled in #Tag structure
*/ */
Tag * Tag
mpd_despotify_tag_from_track(const ds_track &track); mpd_despotify_tag_from_track(const ds_track &track);
/** /**

View File

@ -41,7 +41,7 @@ class DespotifyInputStream {
struct despotify_session *session; struct despotify_session *session;
struct ds_track *track; struct ds_track *track;
Tag *tag; Tag tag;
struct ds_pcm_data pcm; struct ds_pcm_data pcm;
size_t len_available; size_t len_available;
bool eof; bool eof;
@ -64,8 +64,6 @@ class DespotifyInputStream {
public: public:
~DespotifyInputStream() { ~DespotifyInputStream() {
delete tag;
despotify_free_track(track); despotify_free_track(track);
} }
@ -79,8 +77,11 @@ public:
size_t Read(void *ptr, size_t size, Error &error); size_t Read(void *ptr, size_t size, Error &error);
Tag *ReadTag() { Tag *ReadTag() {
Tag *result = tag; if (tag.IsEmpty())
tag = nullptr; return nullptr;
Tag *result = new Tag(std::move(tag));
tag.Clear();
return result; return result;
} }

View File

@ -53,7 +53,7 @@ add_song(std::forward_list<SongPointer> &songs, ds_track &track)
} }
song = Song::NewRemote(uri); song = Song::NewRemote(uri);
song->tag = mpd_despotify_tag_from_track(track); song->tag = new Tag(mpd_despotify_tag_from_track(track));
songs.emplace_front(song); songs.emplace_front(song);
} }