changeset 1710:5dfa4fc721b0

Add dockalbumart plugin for MacOS. (this could also be ported to GNOME's AWN too.)
author William Pitcock <nenolod@atheme.org>
date Thu, 13 Sep 2007 12:09:38 -0500
parents 85788238cbf5
children 1359a81e4674
files configure.ac src/dockalbumart/Makefile src/dockalbumart/audacious_player.xpm src/dockalbumart/dockalbumart.c
diffstat 4 files changed, 385 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/configure.ac	Sun Sep 02 22:18:43 2007 -0500
+++ b/configure.ac	Thu Sep 13 12:09:38 2007 -0500
@@ -280,6 +280,24 @@
 	have_coreaudio=no
 fi
 
+dnl *** Dock Album Art (MacOS)
+
+AC_ARG_ENABLE(dockalbumart,
+    [  --disable-dockalbumart  disable MacOS dock albumart plugin (default=guess)],
+    [enable_dockalbumart=$enableval],
+    [enable_dockalbumart="yes"]
+)
+
+if test "$enable_dockalbumart" = "yes"; then
+	AC_CHECK_HEADERS([Carbon/Carbon.h],
+		[have_dockalbumart=yes
+		 GENERAL_PLUGINS="$GENERAL_PLUGINS dockalbumart"],
+		[have_dockalbumart=no])
+else
+	AC_MSG_RESULT([*** DockAlbumArt plugin disabled per user request ***])
+	have_dockalbumart=no
+fi
+
 dnl *** AltiVec
 
 AC_ARG_ENABLE(altivec,
@@ -1548,6 +1566,7 @@
 echo "  LIRC:                                   $have_lirc"
 echo "  AudioScrobbler Client:                  $scrobbler"
 echo "  Upload to MTP device:                   $have_mtp_up"
+echo "  MacOS Dock Album Art plugin:            $have_dockalbumart"
 echo
 echo "  Effect"
 echo "  ------"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dockalbumart/Makefile	Thu Sep 13 12:09:38 2007 -0500
@@ -0,0 +1,16 @@
+include ../../mk/rules.mk
+include ../../mk/init.mk
+
+OBJECTIVE_LIBS = libdockalbumart$(SHARED_SUFFIX)
+
+LIBDIR = $(plugindir)/$(GENERAL_PLUGIN_DIR)
+
+LIBADD = $(GTK_LIBS) $(GDKX11_LIBS) $(GLIB_LIBS) $(PANGO_LIBS)
+SOURCES = dockalbumart.c
+
+OBJECTS = ${SOURCES:.c=.o}
+
+CFLAGS += $(PICFLAGS) $(GTK_CFLAGS) $(GLIB_CFLAGS) $(PANGO_CFLAGS) \
+	-I../../intl -I../.. -I..
+
+include ../../mk/objective.mk
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dockalbumart/audacious_player.xpm	Thu Sep 13 12:09:38 2007 -0500
@@ -0,0 +1,176 @@
+/* XPM */
+static char * audacious_player_xpm[] = {
+"48 48 125 2",
+"  	c None",
+". 	c #000000",
+"+ 	c #090909",
+"@ 	c #313131",
+"# 	c #505050",
+"$ 	c #5A5A5A",
+"% 	c #4F4F4F",
+"& 	c #0D0D0D",
+"* 	c #5C5C5C",
+"= 	c #A8A8A8",
+"- 	c #D6D6D6",
+"; 	c #D9D9D9",
+"> 	c #D5D5D5",
+", 	c #A5A5A5",
+"' 	c #595959",
+") 	c #0B0B0B",
+"! 	c #060606",
+"~ 	c #6A6A6A",
+"{ 	c #CCCCCC",
+"] 	c #CBCBCB",
+"^ 	c #696969",
+"/ 	c #2B2B2B",
+"( 	c #BABABA",
+"_ 	c #B8B8B8",
+": 	c #2A2A2A",
+"< 	c #484848",
+"[ 	c #D4D4D4",
+"} 	c #D3D3D3",
+"| 	c #474747",
+"1 	c #494949",
+"2 	c #D7D7D7",
+"3 	c #2D2D2D",
+"4 	c #2E2E2E",
+"5 	c #080808",
+"6 	c #BBBBBB",
+"7 	c #C5C5C5",
+"8 	c #A3A3A3",
+"9 	c #949494",
+"0 	c #6E6E6E",
+"a 	c #4D4D4D",
+"b 	c #858585",
+"c 	c #C6C6C6",
+"d 	c #BEBEBE",
+"e 	c #6C6C6C",
+"f 	c #777777",
+"g 	c #030303",
+"h 	c #515151",
+"i 	c #6B6B6B",
+"j 	c #CDCDCD",
+"k 	c #A7A7A7",
+"l 	c #141414",
+"m 	c #0E0E0E",
+"n 	c #5E5E5E",
+"o 	c #9A9A9A",
+"p 	c #393939",
+"q 	c #626262",
+"r 	c #ACACAC",
+"s 	c #717171",
+"t 	c #3E3E3E",
+"u 	c #5F5F5F",
+"v 	c #040404",
+"w 	c #BCBCBC",
+"x 	c #AFAFAF",
+"y 	c #121212",
+"z 	c #D8D8D8",
+"A 	c #333333",
+"B 	c #8C8C8C",
+"C 	c #3D3D3D",
+"D 	c #ABABAB",
+"E 	c #7B7B7B",
+"F 	c #373737",
+"G 	c #111111",
+"H 	c #606060",
+"I 	c #3B3B3B",
+"J 	c #919191",
+"K 	c #424242",
+"L 	c #585858",
+"M 	c #656565",
+"N 	c #7C7C7C",
+"O 	c #676767",
+"P 	c #020202",
+"Q 	c #6D6D6D",
+"R 	c #5D5D5D",
+"S 	c #353535",
+"T 	c #2C2C2C",
+"U 	c #1F1F1F",
+"V 	c #878787",
+"W 	c #5B5B5B",
+"X 	c #525252",
+"Y 	c #272727",
+"Z 	c #A2A2A2",
+"` 	c #404040",
+" .	c #1A1A1A",
+"..	c #303030",
+"+.	c #343434",
+"@.	c #A9A9A9",
+"#.	c #B9B9B9",
+"$.	c #666666",
+"%.	c #808080",
+"&.	c #7E7E7E",
+"*.	c #181818",
+"=.	c #969696",
+"-.	c #212121",
+";.	c #1B1B1B",
+">.	c #C9C9C9",
+",.	c #7F7F7F",
+"'.	c #464646",
+").	c #070707",
+"!.	c #3F3F3F",
+"~.	c #959595",
+"{.	c #D0D0D0",
+"].	c #CACACA",
+"^.	c #757575",
+"/.	c #444444",
+"(.	c #636363",
+"_.	c #C8C8C8",
+":.	c #7D7D7D",
+"<.	c #C4C4C4",
+"[.	c #0F0F0F",
+"}.	c #868686",
+"|.	c #848484",
+"1.	c #1E1E1E",
+"2.	c #C2C2C2",
+"3.	c #BFBFBF",
+"4.	c #747474",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . + @ # $ $ % @ + . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . & * = - ; ; ; ; ; ; > , ' ) . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . ! ~ { ; ; ; ; ; ; ; ; ; ; ; ; ] ^ ! . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . / ( ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; _ : . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . < [ ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; } | . . . . . . . . . . . . . ",
+". . . . . . . . . . . . 1 2 ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; 2 | . . . . . . . . . . . . ",
+". . . . . . . . . . . 3 [ ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; } 4 . . . . . . . . . . . ",
+". . . . . . . . . . 5 6 ; ; ; ; ; ; ; 7 8 9 0 a | $ b c ; ; ; ; ; ; ; ; d 5 . . . . . . . . . . ",
+". . . . . . . . . . e ; ; ; ; ; ; ; f g . . . . . . . g h 7 ; ; ; ; ; ; ; i . . . . . . . . . . ",
+". . . . . . . . . & j ; ; ; ; ; ; k . . . . . . . . . . . l ( ; ; ; ; ; ; j m . . . . . . . . . ",
+". . . . . . . . . n ; ; ; ; ; ; ; o . . . . . . . . . . . . p ; ; ; ; ; ; ; q . . . . . . . . . ",
+". . . . . . . . . r ; ; ; ; ; ; ; ; s t $ u u # v . . . . . . w ; ; ; ; ; ; x . . . . . . . . . ",
+". . . . . . . . y z ; ; ; ; ; ; ; ; ; ; ; ; ; z A . . . . . . B ; ; ; ; ; ; z y . . . . . . . . ",
+". . . . . . . . C ; ; ; ; ; ; ; ; ; ; - D E F G . . . . . . . H ; ; ; ; ; ; ; I . . . . . . . . ",
+". . . . . . . . $ ; ; ; ; ; ; ; ; ; J y . . . . . . . . . . . K ; ; ; ; ; ; ; L . . . . . . . . ",
+". . . . . . . . M ; ; ; ; ; ; ; ; N . . . . . . . . . . . . . C ; ; ; ; ; ; ; O . . . . . . . . ",
+". . . . . . . . O ; ; ; ; ; ; ; , P . . . . . . . . . . . . . Q ; ; ; ; ; ; ; ^ . . . . . . . . ",
+". . . . . . . . R ; ; ; ; ; ; ; S . . . . . T ( ( U . . . . . V ; ; ; ; ; ; ; W . . . . . . . . ",
+". . . . . . . . K ; ; ; ; ; ; ; / . . . . . X ; 2 Y . . . . . Z ; ; ; ; ; ; ; ` . . . . . . . . ",
+". . . . . . . .  .; ; ; ; ; ; ; ... . . . . g p +.. . . . . . @.; ; ; ; ; ; ;  .. . . . . . . . ",
+". . . . . . . . . #.; ; ; ; ; ; $.. . . . . . . . . . . . . . %.; ; ; ; ; ; w . . . . . . . . . ",
+". . . . . . . . . Q ; ; ; ; ; ; 6 ! . . . . . . . . . . . . . &.; ; ; ; ; ; s . . . . . . . . . ",
+". . . . . . . . . *.[ ; ; ; ; ; ; =.) . . . . . g -.+ . . . ;.>.; ; ; ; ; [  .. . . . . . . . . ",
+". . . . . . . . . . ,.; ; ; ; ; ; ; ( '.).. !.~.{.; ].^./.(._.; ; ; ; ; ; :.. . . . . . . . . . ",
+". . . . . . . . . . m c ; ; ; ; ; ; ; ; {.<.; ; ; ; ; ; ; ; ; ; ; ; ; ; _.[.. . . . . . . . . . ",
+". . . . . . . . . . . t z ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; z t . . . . . . . . . . . ",
+". . . . . . . . . . . . H ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; n . . . . . . . . . . . . ",
+". . . . . . . . . . . . . q z ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; z u . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . K >.; ; ; ; ; ; ; ; ; ; ; ; ; ; ; ; _.` . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . y }.- ; ; ; ; ; ; ; ; ; ; ; ; - |.G . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . 1.f 2.; ; ; ; ; ; ; ; 3.4.;.. . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . -.1 M 4.4.M 1 U . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ",
+". . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . "};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/dockalbumart/dockalbumart.c	Thu Sep 13 12:09:38 2007 -0500
@@ -0,0 +1,174 @@
+/*
+ * dockalbumart: An audacious plugin to change the MacOS dock tile to the
+ *     album art.
+ * dockalbumart.c: Plugin implementation
+ *
+ * Copyright (c) 2007 William Pitcock <nenolod -at- sacredspiral.co.uk>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice is present in all copies.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <glib.h>
+#include <audacious/i18n.h>
+
+#include <Carbon/Carbon.h>
+
+#include <audacious/plugin.h>
+#include <audacious/util.h>
+#include <audacious/playlist.h>
+#include <audacious/tuple.h>
+
+#include "audacious_player.xpm"
+
+extern gchar *fileinfo_recursive_get_image(const gchar* path, const gchar* file_name, gint depth);
+
+/* utility functions */
+static void
+dock_set_icon_from_pixbuf(const GdkPixbuf *in)
+{
+    GdkPixbuf *pixbuf;
+    CGColorSpaceRef colorspace;
+    CGDataProviderRef data_provider;
+    CGImageRef image;
+    gpointer data;
+    gint rowstride, pixbuf_width, pixbuf_height;
+    gboolean has_alpha;
+         
+    pixbuf = gdk_pixbuf_scale_simple(in, 128, 128, GDK_INTERP_BILINEAR);
+    
+    data = gdk_pixbuf_get_pixels(pixbuf);
+    pixbuf_width = gdk_pixbuf_get_width(pixbuf);
+    pixbuf_height = gdk_pixbuf_get_height(pixbuf);
+    rowstride = gdk_pixbuf_get_rowstride(pixbuf);
+    has_alpha = gdk_pixbuf_get_has_alpha(pixbuf);
+        
+    /* create the colourspace for the CGImage. */
+    colorspace = CGColorSpaceCreateDeviceRGB();
+    data_provider = CGDataProviderCreateWithData(NULL, data, pixbuf_height * rowstride, NULL);
+    image = CGImageCreate(pixbuf_width, pixbuf_height, 8,
+        has_alpha ? 32 : 24, rowstride, colorspace,
+        has_alpha ? kCGImageAlphaLast : 0,
+        data_provider, NULL, FALSE,   
+        kCGRenderingIntentDefault);
+    
+    /* release the colourspace and data provider, we have what we want. */
+    CGDataProviderRelease(data_provider);
+    CGColorSpaceRelease(colorspace);
+
+    /* set the dock tile images */
+    SetApplicationDockTileImage(image);
+
+    /* and release */
+    CGImageRelease(image);
+    g_object_unref(pixbuf);
+}
+
+static void
+pixbuf_find_and_load(Tuple *tuple)
+{
+    static gchar *last_artwork = NULL;
+    GdkPixbuf *out;
+    gchar *tmp;
+    const gchar *file_path, *file_name;
+
+    file_name = tuple_get_string(tuple, FIELD_FILE_NAME, NULL);
+    file_path = tuple_get_string(tuple, FIELD_FILE_PATH, NULL);
+
+    if (file_name != NULL && file_path != NULL)
+    {
+        tmp = fileinfo_recursive_get_image(file_path, file_name, 0);
+        if (tmp)
+        {
+            if (!last_artwork || strcmp(last_artwork, tmp))
+            {
+                GdkPixbuf *new = gdk_pixbuf_new_from_file(tmp, NULL);
+                if (last_artwork) g_free(last_artwork);
+                last_artwork = tmp;
+                dock_set_icon_from_pixbuf(new);
+                g_object_unref(new);                
+            }                              
+        }
+        else
+        {
+            GdkPixbuf *new = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm);
+            if (last_artwork) g_free(last_artwork);
+            last_artwork = NULL;
+            dock_set_icon_from_pixbuf(new);
+            g_object_unref(new);
+        }
+    }
+}
+
+/* trigger functions */
+
+static void
+dockart_trigger_func_pb_start_cb(gpointer plentry_p, gpointer unused)
+{
+    PlaylistEntry *entry = (PlaylistEntry *) plentry_p;
+    Tuple *tuple;
+
+    if (entry == NULL)
+        return;
+
+    tuple = entry->tuple;
+
+    if (tuple == NULL)
+        return;
+
+    pixbuf_find_and_load(tuple);
+}
+
+static void
+dockart_trigger_func_pb_end_cb(gpointer plentry_p, gpointer unused)
+{
+    GdkPixbuf *new;
+
+    new = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm);
+    dock_set_icon_from_pixbuf(new);
+    g_object_unref(new);
+}
+
+static void
+dockart_init(void)
+{
+    hook_associate("playback begin", dockart_trigger_func_pb_start_cb, NULL);
+    hook_associate("playback end", dockart_trigger_func_pb_end_cb, NULL);
+}
+
+static void
+dockart_cleanup(void)
+{
+    GdkPixbuf *new;
+
+    hook_dissociate("playback begin", dockart_trigger_func_pb_start_cb);
+    hook_dissociate("playback end", dockart_trigger_func_pb_end_cb);
+
+    /* reset dock tile */
+    new = gdk_pixbuf_new_from_xpm_data((const gchar **) audacious_player_xpm);
+    dock_set_icon_from_pixbuf(new);
+    g_object_unref(new);
+}
+
+GeneralPlugin dockart_gp =
+{
+    .description = "Dock Album Art",
+    .init = dockart_init,
+    .cleanup = dockart_cleanup
+};
+
+GeneralPlugin *dockart_gplist[] = { &dockart_gp, NULL };
+SIMPLE_GENERAL_PLUGIN(dockart, dockart_gplist);