changeset 1251:5f09d64c61e2 trunk

[svn] - sort by Artist
author nenolod
date Thu, 15 Jun 2006 05:07:23 -0700
parents 4c9cc4f67818
children ece68ef26b94
files ChangeLog audacious/playlist.c audacious/playlist.h audacious/ui_playlist.c
diffstat 4 files changed, 76 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Jun 15 04:54:42 2006 -0700
+++ b/ChangeLog	Thu Jun 15 05:07:23 2006 -0700
@@ -1,3 +1,12 @@
+2006-06-15 11:54:42 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [1414]
+  - use tuplecache to optimise title sorts
+  
+
+  Changes:        Modified:
+  +11 -3          trunk/audacious/playlist.c  
+
+
 2006-06-15 11:05:23 +0000  William Pitcock <nenolod@nenolod.net>
   revision [1412]
   - tuple builder for wma
--- a/audacious/playlist.c	Thu Jun 15 04:54:42 2006 -0700
+++ b/audacious/playlist.c	Thu Jun 15 05:07:23 2006 -0700
@@ -57,7 +57,7 @@
 
 #include "debug.h"
 
-typedef gint (*PlaylistCompareFunc) (const PlaylistEntry * a, const PlaylistEntry * b);
+typedef gint (*PlaylistCompareFunc) (PlaylistEntry * a, PlaylistEntry * b);
 typedef void (*PlaylistSaveFunc) (FILE * file);
 
 PlaylistEntry *playlist_position;
@@ -101,19 +101,21 @@
 
 
 static gint path_compare(const gchar * a, const gchar * b);
-static gint playlist_compare_path(const PlaylistEntry * a, const PlaylistEntry * b);
-static gint playlist_compare_filename(const PlaylistEntry * a, const PlaylistEntry * b);
-static gint playlist_compare_title(const PlaylistEntry * a, const PlaylistEntry * b);
-static gint playlist_compare_date(const PlaylistEntry * a, const PlaylistEntry * b);
-
-static gint playlist_dupscmp_path( const PlaylistEntry * a, const PlaylistEntry * b);
-static gint playlist_dupscmp_filename( const PlaylistEntry * a, const PlaylistEntry * b);
-static gint playlist_dupscmp_title( const PlaylistEntry * a, const PlaylistEntry * b);
+static gint playlist_compare_path(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_compare_filename(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_compare_title(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_compare_artist(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_compare_date(PlaylistEntry * a, PlaylistEntry * b);
+
+static gint playlist_dupscmp_path(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_dupscmp_filename(PlaylistEntry * a, PlaylistEntry * b);
+static gint playlist_dupscmp_title(PlaylistEntry * a, PlaylistEntry * b);
 
 static PlaylistCompareFunc playlist_compare_func_table[] = {
     playlist_compare_path,
     playlist_compare_filename,
     playlist_compare_title,
+    playlist_compare_artist,
     playlist_compare_date
 };
 
@@ -1748,8 +1750,8 @@
 }
 
 static gint
-playlist_compare_title(const PlaylistEntry * a,
-                       const PlaylistEntry * b)
+playlist_compare_title(PlaylistEntry * a,
+                       PlaylistEntry * b)
 {
     const gchar *a_title = NULL, *b_title = NULL;
 
@@ -1761,7 +1763,7 @@
     if (b->tuple != NULL && b->tuple->track_name != NULL)
         b_title = b->tuple->track_name;
 
-    if (a->title != NULL && b->title != NULL)
+    if (a_title != NULL && b_title != NULL)
         return strcasecmp(a_title, b_title);
 
     if (a->title != NULL)
@@ -1786,8 +1788,34 @@
 }
 
 static gint
-playlist_compare_filename(const PlaylistEntry * a,
-                          const PlaylistEntry * b)
+playlist_compare_artist(PlaylistEntry * a,
+                        PlaylistEntry * b)
+{
+    const gchar *a_artist = NULL, *b_artist = NULL;
+
+    g_return_val_if_fail(a != NULL, 0);
+    g_return_val_if_fail(b != NULL, 0);
+
+    if (a->tuple != NULL)
+        playlist_entry_get_info(a);
+
+    if (b->tuple != NULL)
+        playlist_entry_get_info(b);
+
+    if (a->tuple->performer != NULL)
+        a_artist = a->tuple->performer;
+    if (b->tuple->performer != NULL)
+        b_artist = b->tuple->performer;
+
+    if (a_artist != NULL && b_artist != NULL)
+        return strcasecmp(a_artist, b_artist);
+
+    return -1;
+}
+
+static gint
+playlist_compare_filename(PlaylistEntry * a,
+                          PlaylistEntry * b)
 {
     gchar *a_filename, *b_filename;
 
@@ -1836,15 +1864,15 @@
 }
 
 static gint
-playlist_compare_path(const PlaylistEntry * a,
-                      const PlaylistEntry * b)
+playlist_compare_path(PlaylistEntry * a,
+                      PlaylistEntry * b)
 {
     return path_compare(a->filename, b->filename);
 }
 
 static gint
-playlist_compare_date(const PlaylistEntry * a,
-                      const PlaylistEntry * b)
+playlist_compare_date(PlaylistEntry * a,
+                      PlaylistEntry * b)
 {
     struct stat buf;
     time_t modtime;
@@ -2310,7 +2338,8 @@
 
 
 static gint
-playlist_dupscmp_title( const PlaylistEntry * a , const PlaylistEntry * b )
+playlist_dupscmp_title(PlaylistEntry * a,
+                       PlaylistEntry * b)
 {
     const gchar *a_title, *b_title;
 
@@ -2339,7 +2368,8 @@
 }
 
 static gint
-playlist_dupscmp_filename( const PlaylistEntry * a , const PlaylistEntry * b )
+playlist_dupscmp_filename(PlaylistEntry * a,
+                          PlaylistEntry * b )
 {
     gchar *a_filename, *b_filename;
 
@@ -2360,7 +2390,8 @@
 }
 
 static gint
-playlist_dupscmp_path( const PlaylistEntry * a , const PlaylistEntry * b )
+playlist_dupscmp_path(PlaylistEntry * a,
+                      PlaylistEntry * b)
 {
     /* simply compare the entire filename string */
     return strcmp(a->filename, b->filename);
@@ -2371,7 +2402,7 @@
 {
     GList *node, *next_node;
     GList *node_cmp, *next_node_cmp;
-    gint (*dups_compare_func)( const PlaylistEntry * , const PlaylistEntry * );
+    gint (*dups_compare_func)(PlaylistEntry * , PlaylistEntry *);
 
     switch ( type )
     {
--- a/audacious/playlist.h	Thu Jun 15 04:54:42 2006 -0700
+++ b/audacious/playlist.h	Thu Jun 15 05:07:23 2006 -0700
@@ -32,6 +32,7 @@
     PLAYLIST_SORT_PATH,
     PLAYLIST_SORT_FILENAME,
     PLAYLIST_SORT_TITLE,
+    PLAYLIST_SORT_ARTIST,
     PLAYLIST_SORT_DATE
 } PlaylistSortType;
 
--- a/audacious/ui_playlist.c	Thu Jun 15 04:54:42 2006 -0700
+++ b/audacious/ui_playlist.c	Thu Jun 15 05:07:23 2006 -0700
@@ -80,6 +80,7 @@
 enum {
     PLAYLISTWIN_SORT_BYTITLE, PLAYLISTWIN_SORT_BYFILENAME,
     PLAYLISTWIN_SORT_BYPATH, PLAYLISTWIN_SORT_BYDATE,
+    PLAYLISTWIN_SORT_BYARTIST, PLAYLISTWIN_SORT_SEL_BYARTIST,
     PLAYLISTWIN_SORT_SEL_BYTITLE, PLAYLISTWIN_SORT_SEL_BYFILENAME,
     PLAYLISTWIN_SORT_SEL_BYPATH, PLAYLISTWIN_SORT_SEL_BYDATE,
     PLAYLISTWIN_SORT_RANDOMIZE, PLAYLISTWIN_SORT_REVERSE
@@ -250,6 +251,8 @@
     {N_("/Sort List"), NULL, NULL, 0, "<Branch>", NULL},
     {N_("/Sort List/By Title"), NULL, plsort_menu_callback,
      PLAYLISTWIN_SORT_BYTITLE, "<ImageItem>", sortbytitle_pixbuf},
+    {N_("/Sort List/By Artist"), NULL, plsort_menu_callback,
+     PLAYLISTWIN_SORT_BYARTIST, "<ImageItem>", sortbytitle_pixbuf},
     {N_("/Sort List/By Filename"), NULL, plsort_menu_callback,
      PLAYLISTWIN_SORT_BYFILENAME, "<ImageItem>", sortbyfilename_pixbuf},
     {N_("/Sort List/By Path + Filename"), NULL, plsort_menu_callback,
@@ -259,6 +262,8 @@
     {N_("/Sort Selection"), NULL, NULL, 0, "<Branch>", NULL},
     {N_("/Sort Selection/By Title"), NULL, plsort_menu_callback,
      PLAYLISTWIN_SORT_SEL_BYTITLE, "<ImageItem>", sortbytitle_pixbuf},
+    {N_("/Sort Selection/By Artist"), NULL, plsort_menu_callback,
+     PLAYLISTWIN_SORT_SEL_BYARTIST, "<ImageItem>", sortbytitle_pixbuf},
     {N_("/Sort Selection/By Filename"), NULL, plsort_menu_callback,
      PLAYLISTWIN_SORT_SEL_BYFILENAME, "<ImageItem>", sortbyfilename_pixbuf},
     {N_("/Sort Selection/By Path + Filename"), NULL, plsort_menu_callback,
@@ -1823,6 +1828,10 @@
         playlist_sort(PLAYLIST_SORT_TITLE);
         playlistwin_update_list();
         break;
+    case PLAYLISTWIN_SORT_BYARTIST:
+        playlist_sort(PLAYLIST_SORT_ARTIST);
+        playlistwin_update_list();
+        break;
     case PLAYLISTWIN_SORT_BYPATH:
         playlist_sort(PLAYLIST_SORT_PATH);
         playlistwin_update_list();
@@ -1839,6 +1848,10 @@
         playlist_sort_selected(PLAYLIST_SORT_TITLE);
         playlistwin_update_list();
         break;
+    case PLAYLISTWIN_SORT_SEL_BYARTIST:
+        playlist_sort_selected(PLAYLIST_SORT_ARTIST);
+        playlistwin_update_list();
+        break;
     case PLAYLISTWIN_SORT_SEL_BYFILENAME:
         playlist_sort_selected(PLAYLIST_SORT_FILENAME);
         playlistwin_update_list();