ncmpc  0.29
playlist.h
Go to the documentation of this file.
1 /* ncmpc (Ncurses MPD Client)
2  * (c) 2004-2017 The Music Player Daemon Project
3  * Project homepage: http://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 MPDCLIENT_PLAYLIST_H
21 #define MPDCLIENT_PLAYLIST_H
22 
23 #include "Compiler.h"
24 
25 #include <mpd/client.h>
26 
27 #include <assert.h>
28 #include <glib.h>
29 
31  /* queue version number (obtained from mpd_status) */
32  unsigned version;
33 
34  /* the list */
35  GPtrArray *list;
36 };
37 
38 void
39 playlist_init(struct mpdclient_playlist *playlist);
40 
42 void
43 playlist_clear(struct mpdclient_playlist *playlist);
44 
45 /* free a playlist */
46 gint
48 
49 static inline guint
50 playlist_length(const struct mpdclient_playlist *playlist)
51 {
52  assert(playlist != NULL);
53  assert(playlist->list != NULL);
54 
55  return playlist->list->len;
56 }
57 
58 static inline gboolean
59 playlist_is_empty(const struct mpdclient_playlist *playlist)
60 {
61  return playlist_length(playlist) == 0;
62 }
63 
64 static inline struct mpd_song *
65 playlist_get(const struct mpdclient_playlist *playlist, guint idx)
66 {
67  assert(idx < playlist_length(playlist));
68 
69  return g_ptr_array_index(playlist->list, idx);
70 }
71 
72 static inline void
73 playlist_append(struct mpdclient_playlist *playlist, const struct mpd_song *song)
74 {
75  g_ptr_array_add(playlist->list, mpd_song_dup(song));
76 }
77 
78 static inline void
79 playlist_set(const struct mpdclient_playlist *playlist, guint idx,
80  const struct mpd_song *song)
81 {
82  assert(idx < playlist_length(playlist));
83 
84  g_ptr_array_index(playlist->list, idx) = mpd_song_dup(song);
85 }
86 
87 static inline void
88 playlist_replace(struct mpdclient_playlist *playlist, guint idx,
89  const struct mpd_song *song)
90 {
91  mpd_song_free(playlist_get(playlist, idx));
92  playlist_set(playlist, idx, song);
93 }
94 
95 static inline struct mpd_song *
96 playlist_remove_reuse(struct mpdclient_playlist *playlist, guint idx)
97 {
98  return g_ptr_array_remove_index(playlist->list, idx);
99 }
100 
101 static inline void
102 playlist_remove(struct mpdclient_playlist *playlist, guint idx)
103 {
104  mpd_song_free(playlist_remove_reuse(playlist, idx));
105 }
106 
107 void
108 playlist_move(struct mpdclient_playlist *playlist,
109  unsigned dest, unsigned src);
110 
111 const struct mpd_song *
112 playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id);
113 
114 const struct mpd_song *
115 playlist_get_song(const struct mpdclient_playlist *playlist, gint index);
116 
117 gint
118 playlist_get_index(const struct mpdclient_playlist *playlist,
119  const struct mpd_song *song);
120 
121 gint
122 playlist_get_index_from_id(const struct mpdclient_playlist *playlist,
123  unsigned id);
124 
125 gint
126 playlist_get_index_from_file(const struct mpdclient_playlist *playlist,
127  const gchar *filename);
128 
129 static inline gint
130 playlist_get_index_from_same_song(const struct mpdclient_playlist *playlist,
131  const struct mpd_song *song)
132 {
133  return playlist_get_index_from_file(playlist, mpd_song_get_uri(song));
134 }
135 
136 gcc_pure
137 gint
138 playlist_get_id_from_uri(const struct mpdclient_playlist *playlist,
139  const gchar *uri);
140 
141 gcc_pure
142 static inline gint
143 playlist_get_id_from_same_song(const struct mpdclient_playlist *playlist,
144  const struct mpd_song *song)
145 {
146  return playlist_get_id_from_uri(playlist, mpd_song_get_uri(song));
147 }
148 
149 #endif
unsigned version
Definition: playlist.h:32
gint mpdclient_playlist_free(struct mpdclient_playlist *playlist)
const struct mpd_song * playlist_lookup_song(const struct mpdclient_playlist *playlist, unsigned id)
void playlist_init(struct mpdclient_playlist *playlist)
gcc_pure gint playlist_get_id_from_uri(const struct mpdclient_playlist *playlist, const gchar *uri)
gint playlist_get_index_from_file(const struct mpdclient_playlist *playlist, const gchar *filename)
GPtrArray * list
Definition: playlist.h:35
void playlist_move(struct mpdclient_playlist *playlist, unsigned dest, unsigned src)
gint playlist_get_index_from_id(const struct mpdclient_playlist *playlist, unsigned id)
void playlist_clear(struct mpdclient_playlist *playlist)
const struct mpd_song * playlist_get_song(const struct mpdclient_playlist *playlist, gint index)
#define gcc_pure
Definition: Compiler.h:100
gint playlist_get_index(const struct mpdclient_playlist *playlist, const struct mpd_song *song)
Definition: playlist.h:30