summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-06 13:55:27 +0100
committerGravatar Alexey Yakovenko <wakeroid@gmail.com>2010-03-06 13:55:27 +0100
commit94b26d102e282a415980083866048aaf6bd9f4c1 (patch)
tree39fdce79f8ac0633922fc18b339e7c0aee0cc8c1
parent9c98bebdb84ab663c79cbf3e81e366c0efc19225 (diff)
fixed removing 1st column;
few albumart code improvements
-rw-r--r--plugins/gtkui/coverart.c106
-rw-r--r--plugins/gtkui/ddblistview.c1
-rw-r--r--plugins/gtkui/mainplaylist.c8
-rw-r--r--threading_pthread.c2
4 files changed, 63 insertions, 54 deletions
diff --git a/plugins/gtkui/coverart.c b/plugins/gtkui/coverart.c
index 653acc1b..7d79a1e5 100644
--- a/plugins/gtkui/coverart.c
+++ b/plugins/gtkui/coverart.c
@@ -49,6 +49,7 @@ typedef struct load_query_s {
static cached_pixbuf_t cache[CACHE_SIZE];
static int terminate = 0;
static uintptr_t mutex;
+static uintptr_t cond;
static uintptr_t tid;
load_query_t *queue;
load_query_t *tail;
@@ -75,6 +76,7 @@ queue_add (const char *fname, int width) {
queue = tail = q;
}
deadbeef->mutex_unlock (mutex);
+ deadbeef->cond_signal (cond);
}
static void
@@ -101,62 +103,67 @@ redraw_playlist_cb (gpointer dt) {
void
loading_thread (void *none) {
- while (!terminate) {
- if (!queue) {
- usleep (300000);
- continue;
- }
- int cache_min = 0;
- for (int i = 0; i < CACHE_SIZE; i++) {
- if (!cache[i].pixbuf) {
- cache_min = i;
- break;
- }
- if (cache[cache_min].pixbuf && cache[i].pixbuf) {
- if (cache[cache_min].tm.tv_sec > cache[i].tm.tv_sec) {
+ for (;;) {
+ trace ("covercache: waiting for signal\n");
+ deadbeef->cond_wait (cond, mutex);
+ trace ("covercache: signal received\n");
+ deadbeef->mutex_unlock (mutex);
+ while (!terminate && queue) {
+ int cache_min = 0;
+ for (int i = 0; i < CACHE_SIZE; i++) {
+ if (!cache[i].pixbuf) {
cache_min = i;
+ break;
+ }
+ if (cache[cache_min].pixbuf && cache[i].pixbuf) {
+ if (cache[cache_min].tm.tv_sec > cache[i].tm.tv_sec) {
+ cache_min = i;
+ }
}
}
- }
- trace ("loading image %s\n", queue->fname);
+ trace ("loading image %s\n", queue->fname);
- GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL);
- if (!pixbuf) {
- trace ("GDK failed to load pixbuf from file %s\n", queue->fname);
- }
+ GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file (queue->fname, NULL);
+ if (!pixbuf) {
+ trace ("GDK failed to load pixbuf from file %s\n", queue->fname);
+ }
- int w, h;
- w = gdk_pixbuf_get_width (pixbuf);
- h = gdk_pixbuf_get_height (pixbuf);
- int width = queue->width;
- if (w != width) {
- int height;
- if (w > h) {
- height = width * h / w;
+ int w, h;
+ w = gdk_pixbuf_get_width (pixbuf);
+ h = gdk_pixbuf_get_height (pixbuf);
+ int width = queue->width;
+ if (w != width) {
+ int height;
+ if (w > h) {
+ height = width * h / w;
+ }
+ else if (h > w) {
+ height = width;
+ width = height * w / h;
+ }
+ else {
+ height = width;
+ }
+ GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
+ g_object_unref (pixbuf);
+ pixbuf = scaled;
}
- else if (h > w) {
- height = width;
- width = height * w / h;
+ if (cache[cache_min].pixbuf) {
+ g_object_unref (cache[cache_min].pixbuf);
}
- else {
- height = width;
+ if (cache[cache_min].fname) {
+ free (cache[cache_min].fname);
}
- GdkPixbuf *scaled = gdk_pixbuf_scale_simple (pixbuf, width, height, GDK_INTERP_BILINEAR);
- g_object_unref (pixbuf);
- pixbuf = scaled;
+ cache[cache_min].pixbuf = pixbuf;
+ cache[cache_min].fname = strdup (queue->fname);
+ gettimeofday (&cache[cache_min].tm, NULL);
+ cache[cache_min].width = queue->width;
+ queue_pop ();
+ g_idle_add (redraw_playlist_cb, NULL);
}
- if (cache[cache_min].pixbuf) {
- g_object_unref (cache[cache_min].pixbuf);
+ if (terminate) {
+ break;
}
- if (cache[cache_min].fname) {
- free (cache[cache_min].fname);
- }
- cache[cache_min].pixbuf = pixbuf;
- cache[cache_min].fname = strdup (queue->fname);
- gettimeofday (&cache[cache_min].tm, NULL);
- cache[cache_min].width = queue->width;
- queue_pop ();
- g_idle_add (redraw_playlist_cb, NULL);
}
tid = 0;
}
@@ -236,20 +243,23 @@ reset_cover_art_cache (void) {
void
cover_art_init (void) {
terminate = 0;
- mutex = deadbeef->mutex_create ();
+ mutex = deadbeef->mutex_create_nonrecursive ();
+ cond = deadbeef->cond_create ();
tid = deadbeef->thread_start (loading_thread, NULL);
}
void
cover_art_free (void) {
trace ("terminating cover art loader thread\n");
- terminate = 1;
if (tid) {
+ terminate = 1;
+ deadbeef->cond_signal (cond);
deadbeef->thread_join (tid);
}
while (queue) {
queue_pop ();
}
+ deadbeef->mutex_free (cond);
deadbeef->mutex_free (mutex);
}
diff --git a/plugins/gtkui/ddblistview.c b/plugins/gtkui/ddblistview.c
index 70d81ab3..568e9321 100644
--- a/plugins/gtkui/ddblistview.c
+++ b/plugins/gtkui/ddblistview.c
@@ -2409,6 +2409,7 @@ ddb_listview_column_remove (DdbListview *listview, int idx) {
assert (c);
listview->columns = c->next;
ddb_listview_column_free (listview, c);
+ listview->binding->columns_changed (listview);
return;
}
c = listview->columns;
diff --git a/plugins/gtkui/mainplaylist.c b/plugins/gtkui/mainplaylist.c
index 4fe48817..f6568131 100644
--- a/plugins/gtkui/mainplaylist.c
+++ b/plugins/gtkui/mainplaylist.c
@@ -214,7 +214,7 @@ void
on_edit_column_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- if (!active_column)
+ if (active_column == -1)
return;
GtkWidget *dlg = create_editcolumndlg ();
gtk_window_set_title (GTK_WINDOW (dlg), "Edit column");
@@ -263,7 +263,7 @@ void
on_remove_column_activate (GtkMenuItem *menuitem,
gpointer user_data)
{
- if (!active_column)
+ if (active_column == -1)
return;
ddb_listview_column_remove (last_playlist, active_column);
@@ -303,7 +303,7 @@ void main_draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbLis
else {
sy = group_y - 5;
}
- if (art_width > 0 && group_y < art_width - 10) {
+ if (art_width > 0) {
if (group_it) {
int h = cwidth - group_y;
h = min (height, art_h);
@@ -314,7 +314,7 @@ void main_draw_column_data (DdbListview *listview, GdkDrawable *drawable, DdbLis
if (pixbuf) {
int pw = gdk_pixbuf_get_width (pixbuf);
int ph = gdk_pixbuf_get_height (pixbuf);
- if (group_y < ph) {
+ if (sy < ph) {
pw = min (art_width, pw);
if (group_y + h >= ph) {
ph = ph - group_y;
diff --git a/threading_pthread.c b/threading_pthread.c
index 3b04e7c8..96e464b6 100644
--- a/threading_pthread.c
+++ b/threading_pthread.c
@@ -90,8 +90,6 @@ mutex_create (void) {
void
mutex_free (uintptr_t _mtx) {
pthread_mutex_t *mtx = (pthread_mutex_t *)_mtx;
- mutex_lock (_mtx);
- mutex_unlock (_mtx);
pthread_mutex_destroy (mtx);
free (mtx);
}