1 /* gmpc-dynamic-playlist (GMPC plugin)
2 * Copyright (C) 2009 Andre Klitzing <andre@incubo.de>
3 * Homepage: http://www.incubo.de
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.
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.
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.
22 #include <gmpc/plugin.h>
24 static gint m_song
= -1;
25 static gint m_artist
= -1;
26 static dbQueue m_list
= G_QUEUE_INIT
;
28 static void flush_played_list(gint l_max
)
32 const gint max
= (gint
)g_queue_get_length(&m_list
) - l_max
;
34 for(i
= 0; i
< max
; ++i
)
35 free_dbSong( (dbSong
*) g_queue_pop_tail(&m_list
) );
38 void add_played_song(dbSong
* l_song
)
40 g_assert(l_song
!= NULL
);
41 g_assert(l_song
->artist
!= NULL
);
42 g_assert(l_song
->title
!= NULL
);
43 g_assert(l_song
->artist
[0] != '\0');
44 g_assert(l_song
->title
[0] != '\0');
46 g_queue_push_head(&m_list
, l_song
);
47 flush_played_list( MAX(m_song
, m_artist
) );
50 static gboolean
is_played_song_current(const gchar
* l_artist
, const gchar
* l_title
)
52 mpd_Song
* curSong
= mpd_playlist_get_current_song(connection
);
53 if(curSong
!= NULL
&& curSong
->artist
!= NULL
&& fuzzy_match_artist(l_artist
, curSong
->artist
))
55 if(m_artist
> 0 || (l_title
!= NULL
&& curSong
->title
!= NULL
&& fuzzy_match_title(l_title
, curSong
->title
)))
62 gboolean
is_played_song(const gchar
* l_artist
, const gchar
* l_title
)
64 g_assert(l_artist
!= NULL
);
65 g_assert(l_artist
[0] != '\0');
67 g_assert(l_title
[0] != '\0');
69 if(is_played_song_current(l_artist
, l_title
))
72 if(!g_queue_is_empty(&m_list
))
74 dbList
* iter
= g_queue_peek_head_link(&m_list
);
76 for(i
= 0; iter
!= NULL
; iter
= g_list_next(iter
), ++i
)
78 dbSong
* song
= (dbSong
*) iter
->data
;
79 if(!fuzzy_match_artist(l_artist
, song
->artist
))
84 g_debug("Artist blocked: %s", l_artist
);
88 if(i
< m_song
&& l_title
!= NULL
&& fuzzy_match_title(l_title
, song
->title
))
90 g_debug("Song blocked: %s::%s", l_artist
, l_title
);
99 gboolean
is_played_artist(const gchar
* l_artist
)
101 return is_played_song(l_artist
, NULL
);
104 void set_played_limit_song(gint l_song
)
106 g_assert(l_song
>= 0);
108 cfg_set_single_value_as_int(config
, "dynamic-playlist", "block", m_song
);
111 void set_played_limit_artist(gint l_artist
)
113 g_assert(l_artist
>= 0);
115 cfg_set_single_value_as_int(config
, "dynamic-playlist", "block_artist", m_artist
);
118 gint
get_played_limit_song()
123 gint
get_played_limit_artist()
128 void init_played_list()
130 m_song
= cfg_get_single_value_as_int_with_default(config
, "dynamic-playlist", "block", 100);
131 m_artist
= cfg_get_single_value_as_int_with_default(config
, "dynamic-playlist", "block_artist", 0);
134 void free_played_list()
136 if(!g_queue_is_empty(&m_list
))
137 clear_dbQueue(&m_list
);
140 /* vim:set ts=4 sw=4: */