summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-10 12:21:05 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-01-10 12:21:05 +0100
commit07c402bc06c7158b5669f622ff7d1896ce423ff7 (patch)
treeb50673ade6bc1b2a9dbfdf819434ee08b11f55f9
parent5e65f53c6064a6eb977cdcf8a735a22f9a0deb7a (diff)
playlist structural changes
-rw-r--r--playlist.c122
-rw-r--r--playlist.h30
-rw-r--r--streamer.c21
3 files changed, 97 insertions, 76 deletions
diff --git a/playlist.c b/playlist.c
index ed0917cc..532dfe34 100644
--- a/playlist.c
+++ b/playlist.c
@@ -49,10 +49,6 @@
#define min(x,y) ((x)<(y)?(x):(y))
-playItem_t *playlist_head[PL_MAX_ITERATORS];
-playItem_t *playlist_tail[PL_MAX_ITERATORS];
-int playlist_current_row[PL_MAX_ITERATORS];
-
static int pl_count[2];
static float pl_totaltime = 0;
@@ -60,16 +56,24 @@ static float pl_totaltime = 0;
static playItem_t *playqueue[100];
static int playqueue_count = 0;
+static playlist_t dummy_playlist;
+static playlist_t *playlist = &dummy_playlist;
+
+playlist_t *
+plt_get_curr (void) {
+ return playlist;
+}
+
void
pl_free (void) {
- while (playlist_head[PL_MAIN]) {
- pl_remove (playlist_head[PL_MAIN]);
+ while (playlist->head[PL_MAIN]) {
+ pl_remove (playlist->head[PL_MAIN]);
}
- if (playlist_current_row[PL_MAIN] >= pl_count[PL_MAIN]) {
- playlist_current_row[PL_MAIN] = pl_count[PL_MAIN]-1;
+ if (playlist->current_row[PL_MAIN] >= pl_count[PL_MAIN]) {
+ playlist->current_row[PL_MAIN] = pl_count[PL_MAIN]-1;
}
- if (playlist_current_row[PL_SEARCH] >= pl_count[PL_SEARCH]) {
- playlist_current_row[PL_SEARCH] = pl_count[PL_SEARCH]-1;
+ if (playlist->current_row[PL_SEARCH] >= pl_count[PL_SEARCH]) {
+ playlist->current_row[PL_SEARCH] = pl_count[PL_SEARCH]-1;
}
}
@@ -334,7 +338,7 @@ pl_insert_cue_from_buffer (playItem_t *after, playItem_t *origin, const uint8_t
pl_set_item_duration (after, (float)(after->endsample - after->startsample + 1) / samplerate);
}
// copy metadata from embedded tags
- playItem_t *first = ins ? ins->next[PL_MAIN] : playlist_head[PL_MAIN];
+ playItem_t *first = ins ? ins->next[PL_MAIN] : playlist->head[PL_MAIN];
junk_copy (origin, first, after);
return after;
}
@@ -705,7 +709,7 @@ pl_insert_dir (playItem_t *after, const char *dirname, int *pabort, int (*cb)(pl
int
pl_add_file (const char *fname, int (*cb)(playItem_t *it, void *data), void *user_data) {
int abort = 0;
- if (pl_insert_file (playlist_tail[PL_MAIN], fname, &abort, cb, user_data)) {
+ if (pl_insert_file (playlist->tail[PL_MAIN], fname, &abort, cb, user_data)) {
return 0;
}
return -1;
@@ -714,7 +718,7 @@ pl_add_file (const char *fname, int (*cb)(playItem_t *it, void *data), void *use
int
pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *user_data) {
int abort = 0;
- if (pl_insert_dir (playlist_tail[PL_MAIN], dirname, &abort, cb, user_data)) {
+ if (pl_insert_dir (playlist->tail[PL_MAIN], dirname, &abort, cb, user_data)) {
return 0;
}
return -1;
@@ -729,20 +733,20 @@ pl_remove (playItem_t *it) {
// remove from both lists list
for (int iter = PL_MAIN; iter <= PL_SEARCH; iter++) {
- if (it->prev[iter] || it->next[iter] || playlist_head[iter] == it || playlist_tail[iter] == it) {
+ if (it->prev[iter] || it->next[iter] || playlist->head[iter] == it || playlist->tail[iter] == it) {
pl_count[iter]--;
}
if (it->prev[iter]) {
it->prev[iter]->next[iter] = it->next[iter];
}
else {
- playlist_head[iter] = it->next[iter];
+ playlist->head[iter] = it->next[iter];
}
if (it->next[iter]) {
it->next[iter]->prev[iter] = it->prev[iter];
}
else {
- playlist_tail[iter] = it->prev[iter];
+ playlist->tail[iter] = it->prev[iter];
}
}
@@ -767,7 +771,7 @@ int
pl_getselcount (void) {
// FIXME: slow!
int cnt = 0;
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
if (it->selected) {
cnt++;
}
@@ -777,7 +781,7 @@ pl_getselcount (void) {
playItem_t *
pl_get_for_idx_and_iter (int idx, int iter) {
- playItem_t *it = playlist_head[iter];
+ playItem_t *it = playlist->head[iter];
while (idx--) {
if (!it)
return NULL;
@@ -793,7 +797,7 @@ pl_get_for_idx (int idx) {
int
pl_get_idx_of (playItem_t *it) {
- playItem_t *c = playlist_head[PL_MAIN];
+ playItem_t *c = playlist->head[PL_MAIN];
int idx = 0;
while (c && c != it) {
c = c->next[PL_MAIN];
@@ -808,15 +812,15 @@ pl_get_idx_of (playItem_t *it) {
playItem_t *
pl_insert_item (playItem_t *after, playItem_t *it) {
if (!after) {
- it->next[PL_MAIN] = playlist_head[PL_MAIN];
+ it->next[PL_MAIN] = playlist->head[PL_MAIN];
it->prev[PL_MAIN] = NULL;
- if (playlist_head[PL_MAIN]) {
- playlist_head[PL_MAIN]->prev[PL_MAIN] = it;
+ if (playlist->head[PL_MAIN]) {
+ playlist->head[PL_MAIN]->prev[PL_MAIN] = it;
}
else {
- playlist_tail[PL_MAIN] = it;
+ playlist->tail[PL_MAIN] = it;
}
- playlist_head[PL_MAIN] = it;
+ playlist->head[PL_MAIN] = it;
}
else {
it->prev[PL_MAIN] = after;
@@ -825,8 +829,8 @@ pl_insert_item (playItem_t *after, playItem_t *it) {
after->next[PL_MAIN]->prev[PL_MAIN] = it;
}
after->next[PL_MAIN] = it;
- if (after == playlist_tail[PL_MAIN]) {
- playlist_tail[PL_MAIN] = it;
+ if (after == playlist->tail[PL_MAIN]) {
+ playlist->tail[PL_MAIN] = it;
}
}
it->in_playlist = 1;
@@ -978,7 +982,7 @@ pl_delete_selected (void) {
int i = 0;
int ret = -1;
playItem_t *next = NULL;
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = next, i++) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = next, i++) {
next = it->next[PL_MAIN];
if (it->selected) {
if (ret == -1) {
@@ -993,7 +997,7 @@ pl_delete_selected (void) {
void
pl_crop_selected (void) {
playItem_t *next = NULL;
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = next) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = next) {
next = it->next[PL_MAIN];
if (!it->selected) {
pl_remove (it);
@@ -1023,7 +1027,7 @@ pl_save (const char *fname) {
if (fwrite (&cnt, 1, 4, fp) != 4) {
goto save_fail;
}
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
uint16_t l;
uint8_t ll;
l = strlen (it->fname);
@@ -1312,7 +1316,7 @@ pl_load (const char *fname) {
}
}
}
- pl_insert_item (playlist_tail[PL_MAIN], it);
+ pl_insert_item (playlist->tail[PL_MAIN], it);
}
fclose (fp);
return 0;
@@ -1328,7 +1332,7 @@ load_fail:
void
pl_select_all (void) {
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
it->selected = 1;
}
}
@@ -1338,7 +1342,7 @@ void
pl_reshuffle (playItem_t **ppmin, playItem_t **ppmax) {
playItem_t *pmin = NULL;
playItem_t *pmax = NULL;
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
it->shufflerating = rand ();
if (!pmin || it->shufflerating < pmin->shufflerating) {
pmin = it;
@@ -1617,7 +1621,7 @@ pl_sort (int iter, int id, const char *format, int ascending) {
do {
sorted = 1;
playItem_t *it;
- for (it = playlist_head[iter]; it; it = it->next[iter]) {
+ for (it = playlist->head[iter]; it; it = it->next[iter]) {
playItem_t *next = it->next[iter];
if (!next) {
break;
@@ -1655,7 +1659,7 @@ pl_sort (int iter, int id, const char *format, int ascending) {
// printf ("it->prev->next = it->next\n");
}
else {
- playlist_head[iter] = next;
+ playlist->head[iter] = next;
next->prev[iter] = NULL;
// printf ("head = it->next\n");
}
@@ -1664,7 +1668,7 @@ pl_sort (int iter, int id, const char *format, int ascending) {
// printf ("it->next->next->prev = it\n");
}
else {
- playlist_tail[iter] = it;
+ playlist->tail[iter] = it;
it->next[iter] = NULL;
// printf ("tail = it\n");
}
@@ -1683,7 +1687,7 @@ void
pl_reset_cursor (void) {
int i;
for (i = 0; i < PL_MAX_ITERATORS; i++) {
- playlist_current_row[i] = -1;
+ playlist->current_row[i] = -1;
}
}
@@ -1704,12 +1708,12 @@ pl_is_selected (playItem_t *it) {
playItem_t *
pl_get_first (int iter) {
- return playlist_head[iter];
+ return playlist->head[iter];
}
playItem_t *
pl_get_last (int iter) {
- return playlist_tail[iter];
+ return playlist->tail[iter];
}
playItem_t *
@@ -1724,12 +1728,12 @@ pl_get_prev (playItem_t *it, int iter) {
int
pl_get_cursor (int iter) {
- return playlist_current_row[iter];
+ return playlist->current_row[iter];
}
void
pl_set_cursor (int iter, int cursor) {
- playlist_current_row[iter] = cursor;
+ playlist->current_row[iter] = cursor;
}
// this function must move items in playlist
@@ -1743,20 +1747,20 @@ pl_move_items (int iter, playItem_t *drop_before, uint32_t *indexes, int count)
int processed = 0;
int idx = 0;
playItem_t *next = NULL;
- for (playItem_t *it = playlist_head[iter]; it && processed < count; it = next, idx++) {
+ for (playItem_t *it = playlist->head[iter]; it && processed < count; it = next, idx++) {
next = it->next[iter];
if (idx == indexes[processed]) {
if (it->prev[iter]) {
it->prev[iter]->next[iter] = it->next[iter];
}
else {
- playlist_head[iter] = it->next[iter];
+ playlist->head[iter] = it->next[iter];
}
if (it->next[iter]) {
it->next[iter]->prev[iter] = it->prev[iter];
}
else {
- playlist_tail[iter] = it->prev[iter];
+ playlist->tail[iter] = it->prev[iter];
}
if (tail) {
tail->next[iter] = it;
@@ -1776,7 +1780,7 @@ pl_move_items (int iter, playItem_t *drop_before, uint32_t *indexes, int count)
drop_after = drop_before->prev[iter];
}
else {
- drop_after = playlist_tail[iter];
+ drop_after = playlist->tail[iter];
}
// insert in between
head->prev[iter] = drop_after;
@@ -1784,34 +1788,34 @@ pl_move_items (int iter, playItem_t *drop_before, uint32_t *indexes, int count)
drop_after->next[iter] = head;
}
else {
- playlist_head[iter] = head;
+ playlist->head[iter] = head;
}
tail->next[iter] = drop_before;
if (drop_before) {
drop_before->prev[iter] = tail;
}
else {
- playlist_tail[iter] = tail;
+ playlist->tail[iter] = tail;
}
}
void
pl_search_reset (void) {
- while (playlist_head[PL_SEARCH]) {
- playItem_t *next = playlist_head[PL_SEARCH]->next[PL_SEARCH];
- playlist_head[PL_SEARCH]->selected = 0;
- playlist_head[PL_SEARCH]->next[PL_SEARCH] = NULL;
- playlist_head[PL_SEARCH]->prev[PL_SEARCH] = NULL;
- playlist_head[PL_SEARCH] = next;
- }
- playlist_tail[PL_SEARCH] = NULL;
+ while (playlist->head[PL_SEARCH]) {
+ playItem_t *next = playlist->head[PL_SEARCH]->next[PL_SEARCH];
+ playlist->head[PL_SEARCH]->selected = 0;
+ playlist->head[PL_SEARCH]->next[PL_SEARCH] = NULL;
+ playlist->head[PL_SEARCH]->prev[PL_SEARCH] = NULL;
+ playlist->head[PL_SEARCH] = next;
+ }
+ playlist->tail[PL_SEARCH] = NULL;
pl_count[PL_SEARCH] = 0;
}
void
pl_search_process (const char *text) {
pl_search_reset ();
- for (playItem_t *it = playlist_head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
+ for (playItem_t *it = playlist->head[PL_MAIN]; it; it = it->next[PL_MAIN]) {
it->selected = 0;
if (*text) {
for (metaInfo_t *m = it->meta; m; m = m->next) {
@@ -1820,12 +1824,12 @@ pl_search_process (const char *text) {
//fprintf (stderr, "%s -> %s match (%s.%s)\n", text, m->value, it->fname, m->key);
// add to list
it->next[PL_SEARCH] = NULL;
- if (playlist_tail[PL_SEARCH]) {
- playlist_tail[PL_SEARCH]->next[PL_SEARCH] = it;
- playlist_tail[PL_SEARCH] = it;
+ if (playlist->tail[PL_SEARCH]) {
+ playlist->tail[PL_SEARCH]->next[PL_SEARCH] = it;
+ playlist->tail[PL_SEARCH] = it;
}
else {
- playlist_head[PL_SEARCH] = playlist_tail[PL_SEARCH] = it;
+ playlist->head[PL_SEARCH] = playlist->tail[PL_SEARCH] = it;
}
it->selected = 1;
pl_count[PL_SEARCH]++;
diff --git a/playlist.h b/playlist.h
index 0276aea2..25d4cc26 100644
--- a/playlist.h
+++ b/playlist.h
@@ -53,17 +53,31 @@ typedef struct playItem_s {
unsigned in_playlist : 1; // 1 if item is in playlist
} playItem_t;
-typedef struct {
- playItem_t *playlist_head[PL_MAX_ITERATORS]; // head of linked list
- playItem_t *playlist_tail[PL_MAX_ITERATORS]; // tail of linked list
- int playlist_current_row[PL_MAX_ITERATORS]; // current row (cursor)
- playItem_t *playlist_current_ptr; // pointer to a real current playlist item (or NULL)
+typedef struct playlist_s{
+ char *fname;
+ playItem_t *head[PL_MAX_ITERATORS]; // head of linked list
+ playItem_t *tail[PL_MAX_ITERATORS]; // tail of linked list
+ int current_row[PL_MAX_ITERATORS]; // current row (cursor)
+ struct playlist_s *next;
} playlist_t;
-extern playItem_t *playlist_head[PL_MAX_ITERATORS]; // head of linked list
-extern playItem_t *playlist_tail[PL_MAX_ITERATORS]; // tail of linked list
-extern int playlist_current_row[PL_MAX_ITERATORS]; // current row (cursor)
+// playlist management functions
+int
+plt_get_count (void);
+
+void
+plt_add (int before);
+
+void
+plt_remove (int plt);
+
+void
+plt_set_curr (playlist_t *ptr);
+
+playlist_t *
+plt_get_curr (void);
+// playlist access functions
int
pl_add_dir (const char *dirname, int (*cb)(playItem_t *it, void *data), void *user_data);
diff --git a/streamer.c b/streamer.c
index 0a3ec188..f16109a4 100644
--- a/streamer.c
+++ b/streamer.c
@@ -928,12 +928,13 @@ streamer_configchanged (void) {
void
streamer_play_current_track (void) {
+ playlist_t *plt = plt_get_curr ();
if (p_ispaused ()) {
// unpause currently paused track
p_unpause ();
plug_trigger_event_paused (0);
}
- else if (playlist_current_row[PL_MAIN] != -1) {
+ else if (plt->current_row[PL_MAIN] != -1) {
// play currently selected track
p_stop ();
// get next song in queue
@@ -944,7 +945,7 @@ streamer_play_current_track (void) {
pl_playqueue_pop ();
}
else {
- idx = playlist_current_row[PL_MAIN];
+ idx = plt->current_row[PL_MAIN];
}
streamer_set_nextsong (idx, 1);
@@ -958,8 +959,9 @@ streamer_play_current_track (void) {
int
streamer_move_prevsong (void) {
+ playlist_t *plt = plt_get_curr ();
pl_playqueue_clear ();
- if (!playlist_head[PL_MAIN]) {
+ if (!plt->head[PL_MAIN]) {
streamer_set_nextsong (-2, 1);
return 0;
}
@@ -975,7 +977,7 @@ streamer_move_prevsong (void) {
int rating = orig_playing_song->shufflerating;
playItem_t *pmax = NULL; // played maximum
playItem_t *amax = NULL; // absolute maximum
- for (playItem_t *i = playlist_head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
+ for (playItem_t *i = plt->head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
if (i != orig_playing_song && i->played && (!amax || i->shufflerating > amax->shufflerating)) {
amax = i;
}
@@ -1012,7 +1014,7 @@ streamer_move_prevsong (void) {
}
if (!it) {
if (pl_loop_mode == PLAYBACK_MODE_LOOP_ALL) {
- it = playlist_tail[PL_MAIN];
+ it = plt->tail[PL_MAIN];
}
}
if (!it) {
@@ -1030,6 +1032,7 @@ streamer_move_prevsong (void) {
int
streamer_move_nextsong (int reason) {
+ playlist_t *plt = plt_get_curr ();
playItem_t *it = pl_playqueue_getnext ();
if (it) {
pl_playqueue_pop ();
@@ -1039,7 +1042,7 @@ streamer_move_nextsong (int reason) {
}
playItem_t *curr = streamer_get_streaming_track ();
- if (!playlist_head[PL_MAIN]) {
+ if (!plt->head[PL_MAIN]) {
streamer_set_nextsong (-2, 1);
return 0;
}
@@ -1049,7 +1052,7 @@ streamer_move_nextsong (int reason) {
if (!curr) {
// find minimal notplayed
playItem_t *pmin = NULL; // notplayed minimum
- for (playItem_t *i = playlist_head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
+ for (playItem_t *i = plt->head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
if (i->played) {
continue;
}
@@ -1081,7 +1084,7 @@ streamer_move_nextsong (int reason) {
// find minimal notplayed above current
int rating = curr->shufflerating;
playItem_t *pmin = NULL; // notplayed minimum
- for (playItem_t *i = playlist_head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
+ for (playItem_t *i = plt->head[PL_MAIN]; i; i = i->next[PL_MAIN]) {
if (i->played || i->shufflerating < rating) {
continue;
}
@@ -1118,7 +1121,7 @@ streamer_move_nextsong (int reason) {
if (!it) {
trace ("streamer_move_nextsong: was last track\n");
if (pl_loop_mode == PLAYBACK_MODE_LOOP_ALL) {
- it = playlist_head[PL_MAIN];
+ it = plt->head[PL_MAIN];
}
else {
streamer_set_nextsong (-2, 1);