2 * Copyright 2006 Timo Hirvonen
10 struct editable pl_editable
;
11 struct simple_track
*pl_cur_track
= NULL
;
13 static LIST_HEAD(pl_shuffle_head
);
15 static void pl_free_track(struct list_head
*item
)
17 struct simple_track
*track
= to_simple_track(item
);
19 if (track
== pl_cur_track
)
22 list_del(&((struct shuffle_track
*)track
)->node
);
23 track_info_unref(track
->info
);
29 editable_init(&pl_editable
, pl_free_track
);
32 static int dummy_filter(const struct simple_track
*track
)
37 static struct track_info
*set_track(struct simple_track
*track
)
39 struct track_info
*ti
= NULL
;
45 pl_editable
.win
->changed
= 1;
50 struct track_info
*pl_set_next(void)
52 struct simple_track
*track
;
54 if (list_empty(&pl_editable
.head
))
58 track
= (struct simple_track
*)shuffle_list_get_next(&pl_shuffle_head
,
59 (struct shuffle_track
*)pl_cur_track
, dummy_filter
);
61 track
= simple_list_get_next(&pl_editable
.head
, pl_cur_track
, dummy_filter
);
63 return set_track(track
);
66 struct track_info
*pl_set_prev(void)
68 struct simple_track
*track
;
70 if (list_empty(&pl_editable
.head
))
74 track
= (struct simple_track
*)shuffle_list_get_prev(&pl_shuffle_head
,
75 (struct shuffle_track
*)pl_cur_track
, dummy_filter
);
77 track
= simple_list_get_prev(&pl_editable
.head
, pl_cur_track
, dummy_filter
);
79 return set_track(track
);
82 struct track_info
*pl_set_selected(void)
86 if (list_empty(&pl_editable
.head
))
89 window_get_sel(pl_editable
.win
, &sel
);
90 return set_track(iter_to_simple_track(&sel
));
93 void pl_sel_current(void)
98 editable_track_to_iter(&pl_editable
, pl_cur_track
, &iter
);
99 window_set_sel(pl_editable
.win
, &iter
);
103 void pl_add_track(struct track_info
*ti
)
105 struct shuffle_track
*track
= xnew(struct shuffle_track
, 1);
108 simple_track_init((struct simple_track
*)track
, ti
);
109 shuffle_list_add_track(&pl_shuffle_head
, &track
->node
, pl_editable
.nr_tracks
);
110 editable_add(&pl_editable
, (struct simple_track
*)track
);
113 void pl_reshuffle(void)
115 reshuffle(&pl_shuffle_head
);
118 int pl_for_each(int (*cb
)(void *data
, struct track_info
*ti
), void *data
)
120 struct simple_track
*track
;
123 list_for_each_entry(track
, &pl_editable
.head
, node
) {
124 rc
= cb(data
, track
->info
);