core/playlist: Access playlists through a string
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
90e0b3ed78
commit
5e9b6bc975
|
@ -217,7 +217,7 @@ struct track *audio_eos()
|
|||
/* Mark current track as played */
|
||||
if (audio_track) {
|
||||
track_played(audio_track);
|
||||
playlist_update(PL_UNPLAYED);
|
||||
playlist_update("Unplayed");
|
||||
}
|
||||
|
||||
/* Check pause count and pick the next track */
|
||||
|
|
|
@ -56,7 +56,7 @@ static void __scan_path(struct scan_data *scan, const gchar *name)
|
|||
track = track_add(scan->sd_lib, path);
|
||||
if (track) {
|
||||
queue_add(&c_queue, track);
|
||||
playlist_add(PL_UNPLAYED, track);
|
||||
playlist_add("Unplayed", track);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -110,9 +110,11 @@ static bool __validate_library(void *data)
|
|||
if (collection_check_library(library) < 0)
|
||||
return true;
|
||||
queue_remove_all(&c_queue, track);
|
||||
playlist_remove(PL_UNPLAYED, track);
|
||||
playlist_remove(PL_MOST_PLAYED, track);
|
||||
playlist_remove(PL_LEAST_PLAYED, track);
|
||||
playlist_remove("Favorites", track);
|
||||
playlist_remove("Hidden", track);
|
||||
playlist_remove("Least Played", track);
|
||||
playlist_remove("Most Played", track);
|
||||
playlist_remove("Unplayed", track);
|
||||
track_remove(track);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ bool __collection_init_idle(void *data)
|
|||
|
||||
db_for_each(track, next, track_db_get()) {
|
||||
if (TRACK(track)->tr_library->li_enabled &&
|
||||
!playlist_has(PL_HIDDEN, TRACK(track)))
|
||||
!playlist_has("Hidden", TRACK(track)))
|
||||
queue_add(&c_queue, TRACK(track));
|
||||
}
|
||||
queue_unset_flag(&c_queue, Q_ADD_FRONT);
|
||||
|
@ -234,7 +236,7 @@ void collection_update_all()
|
|||
|
||||
bool collection_ban(struct track *track)
|
||||
{
|
||||
bool ret = playlist_add(PL_HIDDEN, track);
|
||||
bool ret = playlist_add("Hidden", track);
|
||||
if (ret)
|
||||
queue_remove_all(&c_queue, track);
|
||||
return ret;
|
||||
|
@ -242,7 +244,7 @@ bool collection_ban(struct track *track)
|
|||
|
||||
bool collection_unban(struct track *track)
|
||||
{
|
||||
bool ret = playlist_remove(PL_HIDDEN, track);
|
||||
bool ret = playlist_remove("Hidden", track);
|
||||
if (ret)
|
||||
queue_add(&c_queue, track);
|
||||
return ret;
|
||||
|
@ -265,7 +267,7 @@ void collection_set_enabled(struct library *library, bool enabled)
|
|||
track = TRACK(dbe);
|
||||
if (track->tr_library == library) {
|
||||
if (enabled) {
|
||||
if (!playlist_has(PL_HIDDEN, track))
|
||||
if (!playlist_has("Hidden", track))
|
||||
queue_add(&c_queue, track);
|
||||
} else
|
||||
queue_remove_all(&c_queue, track);
|
||||
|
|
|
@ -4,10 +4,6 @@
|
|||
#include <core/playlist.h>
|
||||
#include <core/playlists/system.h>
|
||||
|
||||
static enum playlist_t playlist_cur;
|
||||
static const gchar *playlist_names[5] =
|
||||
{ "Favorites", "Hidden", "Unplayed", "Most Played", "Least Played" };
|
||||
|
||||
|
||||
void playlist_init(struct queue_ops *ops)
|
||||
{
|
||||
|
@ -19,39 +15,34 @@ void playlist_deinit()
|
|||
pl_system_deinit();
|
||||
}
|
||||
|
||||
bool playlist_add(enum playlist_t plist, struct track *track)
|
||||
bool playlist_add(const gchar *name, struct track *track)
|
||||
{
|
||||
if (!track)
|
||||
return false;
|
||||
return pl_system.pl_add_track(playlist_names[plist], track);
|
||||
return pl_system.pl_add_track(name, track);
|
||||
}
|
||||
|
||||
bool playlist_remove(enum playlist_t plist, struct track *track)
|
||||
bool playlist_remove(const gchar *name, struct track *track)
|
||||
{
|
||||
if (!track)
|
||||
return false;
|
||||
return pl_system.pl_remove_track(playlist_names[plist], track);
|
||||
return pl_system.pl_remove_track(name, track);
|
||||
}
|
||||
|
||||
void playlist_update(enum playlist_t plist)
|
||||
void playlist_update(const gchar *name)
|
||||
{
|
||||
pl_system.pl_update(playlist_names[plist]);
|
||||
pl_system.pl_update(name);
|
||||
}
|
||||
|
||||
bool playlist_has(enum playlist_t plist, struct track *track)
|
||||
bool playlist_has(const gchar *name, struct track *track)
|
||||
{
|
||||
struct queue *queue = pl_system.pl_get_queue(playlist_names[plist]);
|
||||
struct queue *queue = pl_system.pl_get_queue(name);
|
||||
if (!track || !queue)
|
||||
return false;
|
||||
return queue_has(queue, track);
|
||||
}
|
||||
|
||||
void playlist_select(enum playlist_t plist)
|
||||
struct queue *playlist_get_queue(const gchar *name)
|
||||
{
|
||||
playlist_cur = plist;
|
||||
}
|
||||
|
||||
struct queue *playlist_get_queue(enum playlist_t plist)
|
||||
{
|
||||
return pl_system.pl_get_queue(playlist_names[plist]);
|
||||
return pl_system.pl_get_queue(name);
|
||||
}
|
||||
|
|
|
@ -102,9 +102,9 @@ static void __audio_load(struct track *track)
|
|||
__audio_set_time_label("o_duration", track->tr_length);
|
||||
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_hide")),
|
||||
playlist_has(PL_HIDDEN, track));
|
||||
playlist_has("Hidden", track));
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gui_builder_widget("o_favorite")),
|
||||
playlist_has(PL_FAVORITED, track));
|
||||
playlist_has("Favorites", track));
|
||||
|
||||
gui_view_scroll();
|
||||
__audio_set_cover();
|
||||
|
@ -141,9 +141,9 @@ void __audio_seek(GtkRange *range, GtkScrollType type, double value, gpointer da
|
|||
void __audio_favorite(GtkToggleButton *toggle, gpointer data)
|
||||
{
|
||||
if (gtk_toggle_button_get_active(toggle))
|
||||
playlist_add(PL_FAVORITED, audio_cur_track());
|
||||
playlist_add("Favorites", audio_cur_track());
|
||||
else
|
||||
playlist_remove(PL_FAVORITED, audio_cur_track());
|
||||
playlist_remove("Favorites", audio_cur_track());
|
||||
}
|
||||
|
||||
void __audio_hide(GtkToggleButton *toggle, gpointer data)
|
||||
|
|
|
@ -182,7 +182,7 @@ static void __collection_added(struct queue *queue, unsigned int pos)
|
|||
|
||||
static bool __collection_erase(struct queue *queue, struct track *track)
|
||||
{
|
||||
return playlist_add(PL_HIDDEN, track);
|
||||
return playlist_add("Hidden", track);
|
||||
}
|
||||
|
||||
static void __collection_removed(struct queue *queue, unsigned int pos)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright 2016 (c) Anna Schumaker.
|
||||
*/
|
||||
#include <core/collection.h>
|
||||
#include <core/string.h>
|
||||
#include <gui/builder.h>
|
||||
#include <gui/playlist.h>
|
||||
#include <gui/sidebar.h>
|
||||
|
@ -12,8 +13,8 @@ enum playlist_sidebar_columns {
|
|||
P_SB_PLAYLIST,
|
||||
};
|
||||
|
||||
static GtkTreeStore *p_store;
|
||||
static enum playlist_t p_cur;
|
||||
static GtkTreeStore *p_store;
|
||||
static gchar *p_name;
|
||||
|
||||
static void __playlist_set(GtkTreeIter *iter, const gchar *name,
|
||||
const gchar *image, enum playlist_t plist)
|
||||
|
@ -38,12 +39,11 @@ void __playlist_selection_changed(GtkTreeSelection *selection, gpointer data)
|
|||
GtkTreeIter iter;
|
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) {
|
||||
gtk_tree_model_get(model, &iter, P_SB_PLAYLIST, &p_cur, -1);
|
||||
gtk_tree_model_get(model, &iter, P_SB_NAME, &p_name, -1);
|
||||
|
||||
gtk_stack_set_visible_child_name(stack, "queues");
|
||||
gui_sidebar_selected(SB_PLAYLIST,
|
||||
gui_queue(playlist_get_queue(p_cur)));
|
||||
playlist_select(p_cur);
|
||||
gui_queue(playlist_get_queue(p_name)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -55,7 +55,7 @@ static void *__playlist_init(struct queue *queue)
|
|||
static bool __playlist_erase(struct queue *queue, struct track *track)
|
||||
{
|
||||
/* collection_unban() and playlist_remove() handle queue changes */
|
||||
if (gui_playlist_cur() == PL_HIDDEN)
|
||||
if (string_match(gui_playlist_cur(), "Hidden"))
|
||||
collection_unban(track);
|
||||
else
|
||||
playlist_remove(gui_playlist_cur(), track);
|
||||
|
@ -91,9 +91,9 @@ void gui_playlist_init()
|
|||
gtk_tree_store_insert(p_store, &parent, NULL, -1);
|
||||
}
|
||||
|
||||
enum playlist_t gui_playlist_cur()
|
||||
gchar *gui_playlist_cur()
|
||||
{
|
||||
return p_cur;
|
||||
return p_name;
|
||||
}
|
||||
|
||||
struct queue_ops playlist_ops = {
|
||||
|
|
|
@ -196,7 +196,7 @@ static void __view_add_to_queue(GtkTreeModel *model, GtkTreePath *path,
|
|||
static void __view_add_to_playlist(GtkTreeModel *model, GtkTreePath *path,
|
||||
GtkTreeIter *iter, gpointer data)
|
||||
{
|
||||
playlist_add(GPOINTER_TO_UINT(data), __view_filter_get_track(path));
|
||||
playlist_add((gchar *)data, __view_filter_get_track(path));
|
||||
}
|
||||
|
||||
static void __view_delete_selection(GtkTreeSelection *selection)
|
||||
|
@ -231,7 +231,7 @@ static void __view_process_selection(GtkTreeView *treeview, unsigned int keyval)
|
|||
case GDK_KEY_f:
|
||||
gtk_tree_selection_selected_foreach(selection,
|
||||
__view_add_to_playlist,
|
||||
GUINT_TO_POINTER(PL_FAVORITED));
|
||||
"Favorites");
|
||||
break;
|
||||
case GDK_KEY_r:
|
||||
flags = Q_RANDOM;
|
||||
|
|
|
@ -28,23 +28,20 @@ void playlist_deinit();
|
|||
|
||||
|
||||
/* Called to add a track to a playlist. */
|
||||
bool playlist_add(enum playlist_t, struct track *);
|
||||
bool playlist_add(const gchar *, struct track *);
|
||||
|
||||
/* Called to remove a track from a playlist. */
|
||||
bool playlist_remove(enum playlist_t, struct track *);
|
||||
bool playlist_remove(const gchar *, struct track *);
|
||||
|
||||
/* Called to update tracks on a playlist. */
|
||||
void playlist_update(enum playlist_t);
|
||||
void playlist_update(const gchar *);
|
||||
|
||||
|
||||
/* Called to check if a specific track is in the playlist. */
|
||||
bool playlist_has(enum playlist_t, struct track *);
|
||||
|
||||
/* Called to fill the queue with a specific playlist. */
|
||||
void playlist_select(enum playlist_t);
|
||||
bool playlist_has(const gchar *, struct track *);
|
||||
|
||||
|
||||
/* Called to access the playlist queue. */
|
||||
struct queue *playlist_get_queue(enum playlist_t);
|
||||
struct queue *playlist_get_queue(const gchar *);
|
||||
|
||||
#endif /* OCARINA_CORE_PLAYLIST_H */
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
void gui_playlist_init();
|
||||
|
||||
/* Called to get the currently selected playlist. */
|
||||
enum playlist_t gui_playlist_cur();
|
||||
gchar *gui_playlist_cur();
|
||||
|
||||
/* Playlist operations passed to core_init() */
|
||||
extern struct queue_ops playlist_ops;
|
||||
|
|
|
@ -133,10 +133,10 @@ static void test_ban()
|
|||
|
||||
db_for_each(dbe, next, track_db) {
|
||||
track = TRACK(dbe);
|
||||
test_loop_equal(playlist_has(PL_HIDDEN, track), (bool)false, i);
|
||||
test_loop_equal(playlist_has("Hidden", track), (bool)false, i);
|
||||
test_loop_equal(collection_ban(track), (bool)true, i);
|
||||
test_loop_equal(collection_ban(track), (bool)false, i);
|
||||
test_loop_equal(playlist_has(PL_HIDDEN, track), (bool)true, i);
|
||||
test_loop_equal(playlist_has("Hidden", track), (bool)true, i);
|
||||
test_loop_equal(queue_size(q), track_db->db_size - (i + 1), i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
|
@ -145,10 +145,10 @@ static void test_ban()
|
|||
i = 0;
|
||||
db_for_each(dbe, next, track_db) {
|
||||
track = TRACK(dbe);
|
||||
test_loop_equal(playlist_has(PL_HIDDEN, track), (bool)true, i);
|
||||
test_loop_equal(playlist_has("Hidden", track), (bool)true, i);
|
||||
test_loop_equal(collection_unban(track), (bool)true, i);
|
||||
test_loop_equal(collection_unban(track), (bool)false, i);
|
||||
test_loop_equal(playlist_has(PL_HIDDEN, track), (bool)false, i);
|
||||
test_loop_equal(playlist_has("Hidden", track), (bool)false, i);
|
||||
test_loop_equal(queue_size(q), i + 1, i);
|
||||
i++;
|
||||
} test_loop_passed();
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
static void test_init()
|
||||
{
|
||||
struct queue *q = playlist_get_queue(PL_MOST_PLAYED);
|
||||
struct queue *q = playlist_get_queue("Most Played");
|
||||
struct library *library;
|
||||
GSList *list;
|
||||
|
||||
|
@ -19,11 +19,11 @@ static void test_init()
|
|||
playlist_init(NULL);
|
||||
while (idle_run_task()) {};
|
||||
|
||||
test_not_equal((void *)playlist_get_queue(PL_FAVORITED), NULL);
|
||||
test_not_equal((void *)playlist_get_queue(PL_HIDDEN), NULL);
|
||||
test_not_equal((void *)playlist_get_queue(PL_UNPLAYED), NULL);
|
||||
test_not_equal((void *)playlist_get_queue(PL_MOST_PLAYED), NULL);
|
||||
test_not_equal((void *)playlist_get_queue(PL_LEAST_PLAYED), NULL);
|
||||
test_not_equal((void *)playlist_get_queue("Favorites"), NULL);
|
||||
test_not_equal((void *)playlist_get_queue("Hidden"), NULL);
|
||||
test_not_equal((void *)playlist_get_queue("Unplayed"), NULL);
|
||||
test_not_equal((void *)playlist_get_queue("Most Played"), NULL);
|
||||
test_not_equal((void *)playlist_get_queue("Least Played"), NULL);
|
||||
|
||||
test_not_equal((void *)q, NULL);
|
||||
test_equal(queue_has_flag(q, Q_ENABLED), (bool)true);
|
||||
|
@ -59,64 +59,61 @@ static void test_init()
|
|||
|
||||
static void test_add()
|
||||
{
|
||||
struct queue *q = playlist_get_queue(PL_FAVORITED);
|
||||
struct queue *q = playlist_get_queue("Favorites");
|
||||
struct track *track = track_get(0);
|
||||
|
||||
test_equal(playlist_add(PL_FAVORITED, NULL), (bool)false);
|
||||
test_equal(playlist_has(PL_FAVORITED, NULL), (bool)false);
|
||||
test_equal(playlist_add("Favorites", NULL), (bool)false);
|
||||
test_equal(playlist_has("Favorites", NULL), (bool)false);
|
||||
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(playlist_add(PL_FAVORITED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)true);
|
||||
q = playlist_get_queue(PL_FAVORITED);
|
||||
test_equal(playlist_has("Favorites", track), (bool)false);
|
||||
test_equal(playlist_add("Favorites", track), (bool)true);
|
||||
test_equal(playlist_has("Favorites", track), (bool)true);
|
||||
q = playlist_get_queue("Favorites");
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(playlist_add(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(playlist_add("Favorites", track), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(playlist_add(PL_FAVORITED, track_get(1)), (bool)true);
|
||||
test_equal(playlist_add("Favorites", track_get(1)), (bool)true);
|
||||
test_equal(queue_size(q), 2);
|
||||
|
||||
track = track_get(2);
|
||||
playlist_select(PL_HIDDEN);
|
||||
q = playlist_get_queue(PL_HIDDEN);
|
||||
test_equal(playlist_has(PL_HIDDEN, track), (bool)false);
|
||||
test_equal(playlist_add(PL_HIDDEN, track), (bool)true);
|
||||
test_equal(playlist_has(PL_HIDDEN, track), (bool)true);
|
||||
q = playlist_get_queue(PL_HIDDEN);
|
||||
q = playlist_get_queue("Hidden");
|
||||
test_equal(playlist_has("Hidden", track), (bool)false);
|
||||
test_equal(playlist_add("Hidden", track), (bool)true);
|
||||
test_equal(playlist_has("Hidden", track), (bool)true);
|
||||
q = playlist_get_queue("Hidden");
|
||||
test_equal(queue_size(q), 1);
|
||||
}
|
||||
|
||||
static void test_remove()
|
||||
{
|
||||
struct queue *q = playlist_get_queue(PL_FAVORITED);
|
||||
struct queue *q = playlist_get_queue("Favorites");
|
||||
struct track *track = track_get(0);
|
||||
|
||||
/* The important thing here is that we don't crash */
|
||||
test_equal(playlist_remove(PL_FAVORITED, NULL), (bool)false);
|
||||
test_equal(playlist_remove("Favorites", NULL), (bool)false);
|
||||
|
||||
playlist_select(PL_FAVORITED);
|
||||
test_equal(queue_size(q), 2);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)true);
|
||||
test_equal(playlist_remove(PL_FAVORITED, track), (bool)true);
|
||||
test_equal(playlist_has(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(playlist_has("Favorites", track), (bool)true);
|
||||
test_equal(playlist_remove("Favorites", track), (bool)true);
|
||||
test_equal(playlist_has("Favorites", track), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(playlist_remove(PL_FAVORITED, track), (bool)false);
|
||||
test_equal(playlist_remove("Favorites", track), (bool)false);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(playlist_remove(PL_FAVORITED, track_get(1)), (bool)true);
|
||||
test_equal(playlist_remove("Favorites", track_get(1)), (bool)true);
|
||||
test_equal(queue_size(q), 0);
|
||||
|
||||
q = playlist_get_queue(PL_HIDDEN);
|
||||
q = playlist_get_queue("Hidden");
|
||||
track = track_get(2);
|
||||
playlist_select(PL_HIDDEN);
|
||||
test_equal(queue_size(q), 1);
|
||||
test_equal(playlist_has(PL_HIDDEN, track), (bool)true);
|
||||
test_equal(playlist_remove(PL_HIDDEN, track), (bool)true);
|
||||
test_equal(playlist_has(PL_HIDDEN, track), (bool)false);
|
||||
test_equal(playlist_has("Hidden", track), (bool)true);
|
||||
test_equal(playlist_remove("Hidden", track), (bool)true);
|
||||
test_equal(playlist_has("Hidden", track), (bool)false);
|
||||
test_equal(queue_size(q), 0);
|
||||
}
|
||||
|
||||
static void test_deinit()
|
||||
{
|
||||
struct queue *q = playlist_get_queue(PL_UNPLAYED);
|
||||
struct queue *q = playlist_get_queue("Unplayed");
|
||||
|
||||
playlist_deinit();
|
||||
tags_deinit();
|
||||
|
|
|
@ -73,8 +73,8 @@ static void test_audio()
|
|||
while (idle_run_task()) {};
|
||||
|
||||
track = track_get(0);
|
||||
playlist_add(PL_FAVORITED, track);
|
||||
playlist_add(PL_HIDDEN, track);
|
||||
playlist_add("Favorites", track);
|
||||
playlist_add("Hidden", track);
|
||||
audio_load(track);
|
||||
|
||||
duration = string_sec2str(track->tr_length);
|
||||
|
|
|
@ -38,23 +38,23 @@ static void test_playlist_sidebar()
|
|||
|
||||
gtk_tree_path_down(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
test_equal(gui_playlist_cur(), PL_FAVORITED);
|
||||
test_equal(gui_playlist_cur(), "Favorites");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
test_equal(gui_playlist_cur(), PL_HIDDEN);
|
||||
test_equal(gui_playlist_cur(), "Hidden");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
test_equal(gui_playlist_cur(), PL_MOST_PLAYED);
|
||||
test_equal(gui_playlist_cur(), "Most Played");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
test_equal(gui_playlist_cur(), PL_LEAST_PLAYED);
|
||||
test_equal(gui_playlist_cur(), "Least Played");
|
||||
|
||||
gtk_tree_path_next(path);
|
||||
gtk_tree_selection_select_path(selection, path);
|
||||
test_equal(gui_playlist_cur(), PL_UNPLAYED);
|
||||
test_equal(gui_playlist_cur(), "Unplayed");
|
||||
|
||||
gtk_tree_path_free(path);
|
||||
gui_builder_deinit();
|
||||
|
|
Loading…
Reference in New Issue