+#define DO_META_SORT_ADV( node, integer ) { \
+ char *psz_a = input_item_GetMeta( (*(playlist_item_t **)first)->p_input, vlc_meta_##node ); \
+ char *psz_b = input_item_GetMeta( (*(playlist_item_t **)second)->p_input, vlc_meta_##node ); \
+ /* Nodes go first */ \
+ if( (*(playlist_item_t **)first)->i_children == -1 && (*(playlist_item_t **)second)->i_children >= 0 ) \
+ i_test = 1;\
+ else if( (*(playlist_item_t **)first)->i_children >= 0 &&\
+ (*(playlist_item_t **)second)->i_children == -1 ) \
+ i_test = -1; \
+ /* Both are nodes, sort by name */ \
+ else if( (*(playlist_item_t **)first)->i_children >= 0 && \
+ (*(playlist_item_t **)second)->i_children >= 0 ) \
+ { \
+ META_STRCASECMP_NAME( ) \
+ } \
+ /* Both are items */ \
+ else if( psz_a == NULL && psz_b != NULL ) \
+ i_test = 1; \
+ else if( psz_a != NULL && psz_b == NULL ) \
+ i_test = -1;\
+ /* No meta, sort by name */ \
+ else if( psz_a == NULL && psz_b == NULL ) \
+ { \
+ META_STRCASECMP_NAME( ); \
+ } \
+ else \
+ { \
+ if( !integer ) i_test = strcmp( psz_a, psz_b ); \
+ else i_test = atoi( psz_a ) - atoi( psz_b ); \
+ } \
+ free( psz_a ); \
+ free( psz_b ); \
+}
+#define DO_META_SORT( node ) DO_META_SORT_ADV( node, false )
+
+ int i_test = 0;
+
+ if( sort_mode == SORT_TITLE )
+ {
+ META_STRCASECMP_NAME( );
+ }
+ else if( sort_mode == SORT_TITLE_NUMERIC )
+ {
+ char *psz_i = input_item_GetName( (*(playlist_item_t **)first)->p_input );
+ char *psz_ismall =
+ input_item_GetName( (*(playlist_item_t **)second)->p_input );
+ i_test = atoi( psz_i ) - atoi( psz_ismall );
+ free( psz_i );
+ free( psz_ismall );
+ }
+ else if( sort_mode == SORT_DURATION )
+ {
+ i_test = input_item_GetDuration( (*(playlist_item_t **)first)->p_input ) -
+ input_item_GetDuration( (*(playlist_item_t **)second)->p_input );
+ }
+ else if( sort_mode == SORT_ARTIST )
+ {
+ DO_META_SORT( Artist );
+ /* sort by artist, album, tracknumber */
+ if( i_test == 0 )
+ DO_META_SORT( Album );
+ if( i_test == 0 )
+ DO_META_SORT_ADV( TrackNumber, true );
+ }
+ else if( sort_mode == SORT_GENRE )
+ {
+ DO_META_SORT( Genre );
+ }
+ else if( sort_mode == SORT_ALBUM )