diff options
-rw-r--r-- | callbacks.c | 6 | ||||
-rw-r--r-- | gtkplaylist.c | 84 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rwxr-xr-x | mktarball.sh | 2 | ||||
-rw-r--r-- | playlist.c | 38 | ||||
-rw-r--r-- | playlist.h | 6 |
6 files changed, 90 insertions, 50 deletions
diff --git a/callbacks.c b/callbacks.c index 1d689564..eb99458c 100644 --- a/callbacks.c +++ b/callbacks.c @@ -43,11 +43,11 @@ on_playpos_value_changed (GtkRange *range, if (g_disable_seekbar_handler) { return; } - if (playlist_current && playlist_current->codec) { - if (playlist_current->codec->info.duration > 0) { + if (playlist_current.codec) { + if (playlist_current.codec->info.duration > 0) { int val = gtk_range_get_value (range); int upper = gtk_adjustment_get_upper (gtk_range_get_adjustment (range)); - float time = playlist_current->codec->info.duration / (float)upper * (float)val; + float time = playlist_current.codec->info.duration / (float)upper * (float)val; messagepump_push (M_SONGSEEK, 0, (int)time * 1000, 0); } } diff --git a/gtkplaylist.c b/gtkplaylist.c index eb44eb76..143e4353 100644 --- a/gtkplaylist.c +++ b/gtkplaylist.c @@ -122,7 +122,7 @@ void draw_ps_row (GdkDrawable *drawable, cairo_t *cr, int row, playItem_t *it) { int width, height; gdk_drawable_get_size (drawable, &width, &height); - if (it == playlist_current) { + if (it == playlist_current_ptr) { cairo_set_source_rgb (cr, 1, 1, 1); cairo_rectangle (cr, 3, row * rowheight - scrollpos * rowheight + 3, rowheight-6, rowheight-6); cairo_fill (cr); @@ -251,38 +251,38 @@ gtkps_playsong (void) { printf ("unpause\n"); psdl_unpause (); } - else if (playlist_current) { + else if (playlist_current_ptr) { printf ("restart\n"); codec_lock (); psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); codec_unlock (); GtkWidget *widget = lookup_widget (mainwin, "playlist"); - redraw_ps_row (widget, ps_get_idx_of (playlist_current)); + redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } else if (playlist_row != -1) { printf ("start under cursor\n"); playItem_t *it = ps_get_for_idx (playlist_row); if (it) { codec_lock (); + ps_set_current (it); psdl_stop (); psdl_play (it); codec_unlock (); - playlist_current = it; } GtkWidget *widget = lookup_widget (mainwin, "playlist"); redraw_ps_row (widget, playlist_row); } else { printf ("play 1st in list\n"); - playlist_current = playlist_head; - if (playlist_current) { + ps_set_current (playlist_head); + if (playlist_current_ptr) { codec_lock (); psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); codec_unlock (); GtkWidget *widget = lookup_widget (mainwin, "playlist"); - redraw_ps_row (widget, ps_get_idx_of (playlist_current)); + redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } } } @@ -290,24 +290,24 @@ gtkps_playsong (void) { void gtkps_prevsong (void) { GtkWidget *widget = lookup_widget (mainwin, "playlist"); - playItem_t *prev = playlist_current; + playItem_t *prev = playlist_current_ptr; - if (playlist_current) { - playlist_current = playlist_current->prev; + if (playlist_current_ptr) { + ps_set_current (playlist_current_ptr->prev); } - if (!playlist_current) { - playlist_current = playlist_tail; + if (!playlist_current_ptr) { + ps_set_current (playlist_tail); } - if (playlist_current) { + if (playlist_current_ptr) { psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); } - if (playlist_current != prev) { + if (playlist_current_ptr != prev) { if (prev) { redraw_ps_row (widget, ps_get_idx_of (prev)); } - if (playlist_current) { - redraw_ps_row (widget, ps_get_idx_of (playlist_current)); + if (playlist_current_ptr) { + redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } } } @@ -315,25 +315,25 @@ gtkps_prevsong (void) { void gtkps_nextsong (void) { GtkWidget *widget = lookup_widget (mainwin, "playlist"); - playItem_t *prev = playlist_current; - if (playlist_current) { - playlist_current = playlist_current->next; + playItem_t *prev = playlist_current_ptr; + if (playlist_current_ptr) { + ps_set_current (playlist_current_ptr->next); } - if (!playlist_current) { - playlist_current = playlist_head; + if (!playlist_current_ptr) { + ps_set_current (playlist_head); } - if (playlist_current) { + if (playlist_current_ptr) { codec_lock (); psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); codec_unlock (); } - if (playlist_current != prev) { + if (playlist_current_ptr != prev) { if (prev) { redraw_ps_row (widget, ps_get_idx_of (prev)); } - if (playlist_current) { - redraw_ps_row (widget, ps_get_idx_of (playlist_current)); + if (playlist_current_ptr) { + redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } } } @@ -344,27 +344,27 @@ gtkps_randomsong (void) { return; } GtkWidget *widget = lookup_widget (mainwin, "playlist"); - playItem_t *prev = playlist_current; + playItem_t *prev = playlist_current_ptr; int r = rand () % ps_getcount (); playItem_t *it = ps_get_for_idx (r); if (it) { - playlist_current = it; + ps_set_current (it); } else { - playlist_current = NULL; + ps_set_current (NULL); } - if (playlist_current) { + if (playlist_current_ptr) { codec_lock (); psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); codec_unlock (); } - if (playlist_current != prev) { + if (playlist_current_ptr != prev) { if (prev) { redraw_ps_row (widget, ps_get_idx_of (prev)); } - if (playlist_current) { - redraw_ps_row (widget, ps_get_idx_of (playlist_current)); + if (playlist_current_ptr) { + redraw_ps_row (widget, ps_get_idx_of (playlist_current_ptr)); } } } @@ -388,13 +388,13 @@ void gtkps_playsongnum (int idx) { playItem_t *it = ps_get_for_idx (playlist_row); if (it) { - if (it != playlist_current) { + if (it != playlist_current_ptr) { GtkWidget *widget = lookup_widget (mainwin, "playlist"); int prev = -1; - if (playlist_current) { - prev = ps_get_idx_of (playlist_current); + if (playlist_current_ptr) { + prev = ps_get_idx_of (playlist_current_ptr); } - playlist_current = it; + ps_set_current (it); if (prev != -1) { redraw_ps_row (widget, prev); } @@ -402,7 +402,7 @@ gtkps_playsongnum (int idx) { } codec_lock (); psdl_stop (); - psdl_play (playlist_current); + psdl_play (playlist_current_ptr); codec_unlock (); } } @@ -69,10 +69,10 @@ psdl_thread (uintptr_t ctx) { GDK_THREADS_LEAVE(); break; case M_SONGSEEK: - if (playlist_current && playlist_current->codec) { + if (playlist_current.codec) { psdl_pause (); codec_lock (); - playlist_current->codec->seek (p1 / 1000.f); + playlist_current.codec->seek (p1 / 1000.f); codec_unlock (); psdl_unpause (); } diff --git a/mktarball.sh b/mktarball.sh index d4db5b0d..3860c9b8 100755 --- a/mktarball.sh +++ b/mktarball.sh @@ -1,2 +1,2 @@ #!/bin/sh -tar jcvf deadbeef-prealpha.tar.bz2 *.c *.h Jamfile +tar jcvf deadbeef-prealpha.tar.bz2 *.c *.h gme/*.cpp gme/*.h gme/Jamfile Jamfile @@ -15,7 +15,8 @@ playItem_t *playlist_head; playItem_t *playlist_tail; -playItem_t *playlist_current; +playItem_t playlist_current; +playItem_t *playlist_current_ptr; static int ps_count = 0; void @@ -373,3 +374,38 @@ ps_append_item (playItem_t *it) { } ps_count++; } + +void +ps_item_copy (playItem_t *out, playItem_t *it) { + out->fname = strdup (it->fname); + out->displayname = strdup (it->displayname); + out->codec = it->codec; + out->tracknum = it->tracknum; + out->timestart = it->timestart; + out->timeend = it->timeend; + out->next = it->next; + out->prev = it->prev; +} + +void +ps_item_free (playItem_t *it) { + if (it) { + if (it->fname) { + free (it->fname); + } + if (it->displayname) { + free (it->displayname); + } + memset (it, 0, sizeof (playItem_t)); + } +} + +void +ps_set_current (playItem_t *it) { + ps_item_free (&playlist_current); + if (it) { + ps_item_copy (&playlist_current, it); + } + playlist_current_ptr = it; +} + @@ -14,7 +14,8 @@ typedef struct playItem_s { extern playItem_t *playlist_head; // head of linked list extern playItem_t *playlist_tail; // tail of linked list -extern playItem_t *playlist_current; +extern playItem_t *playlist_current_ptr; // pointer to a real current playlist item +extern playItem_t playlist_current; // copy of playlist item being played (stays in memory even if removed from playlist) int ps_add_file (const char *fname); @@ -43,4 +44,7 @@ ps_get_idx_of (playItem_t *it); int ps_add_cue (const char *cuename); +void +ps_set_current (playItem_t *it); + #endif // __PLAYLIST_H |