diff --git a/plugins/cocoaui/AppDelegate.m b/plugins/cocoaui/AppDelegate.m index 4af317cdeb..853840b50d 100644 --- a/plugins/cocoaui/AppDelegate.m +++ b/plugins/cocoaui/AppDelegate.m @@ -510,7 +510,7 @@ - (IBAction)addFoldersAction:(id)sender { NSArray* files = openDlg.URLs; ddb_playlist_t *plt = deadbeef->plt_alloc ("add-folders"); ddb_playlist_t *plt_curr = deadbeef->plt_get_curr (); - if (!deadbeef->plt_add_files_begin (plt, 0)) { + if (!deadbeef->plt_add_files_begin (plt_curr, 0)) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ for (NSUInteger i = 0; i < files.count; i++) { NSString *fileName = [files[i] path]; @@ -527,13 +527,13 @@ - (IBAction)addFoldersAction:(id)sender { } deadbeef->pl_save_current(); ddb_undo->set_action_name ("Add Folders"); - deadbeef->plt_add_files_end (plt, 0); + deadbeef->plt_add_files_end (plt_curr, 0); deadbeef->plt_unref (plt); deadbeef->plt_unref (plt_curr); }); } else { - deadbeef->plt_add_files_end (plt, 0); + deadbeef->plt_add_files_end (plt_curr, 0); deadbeef->plt_unref (plt); deadbeef->plt_unref (plt_curr); } diff --git a/src/playlist.h b/src/playlist.h index acd53c96c5..b029351b7c 100644 --- a/src/playlist.h +++ b/src/playlist.h @@ -423,9 +423,6 @@ plt_search_process2 (playlist_t *plt, const char *text, int select_results); void plt_sort (playlist_t *plt, int iter, int id, const char *format, int order); -void -plt_sort_random (playlist_t *plt, int iter); - void pl_items_copy_junk (struct playItem_s *from, struct playItem_s *first, struct playItem_s *last); diff --git a/src/sort.c b/src/sort.c index 5b36f9534c..81aaec61e5 100644 --- a/src/sort.c +++ b/src/sort.c @@ -39,10 +39,10 @@ #define trace(fmt,...) static void -plt_sort_internal (playlist_t *playlist, int iter, int id, const char *format, int order, int version); +plt_sort_internal (playlist_t *playlist, int iter, int id, const char *format, int order, int version, int is_autosorting); -void -plt_sort_v2 (playlist_t *plt, int iter, int id, const char *format, int order) { +static void +plt_sort_v2_internal (playlist_t *plt, int iter, int id, const char *format, int order, int is_autosorting) { ddb_undobuffer_t *undobuffer = ddb_undomanager_get_buffer (ddb_undomanager_shared ()); if (plt->undo_enabled) { pl_lock (); @@ -58,7 +58,7 @@ plt_sort_v2 (playlist_t *plt, int iter, int id, const char *format, int order) { } } - plt_sort_internal (plt, iter, id, format, order, 1); + plt_sort_internal (plt, iter, id, format, order, 1, is_autosorting); if (plt->undo_enabled) { int count = plt->count[PL_MAIN]; @@ -75,10 +75,15 @@ plt_sort_v2 (playlist_t *plt, int iter, int id, const char *format, int order) { } } +void +plt_sort_v2 (playlist_t *plt, int iter, int id, const char *format, int order) { + plt_sort_v2_internal(plt, iter, id, format, order, 0); +} + // sort for title formatting v1 void plt_sort (playlist_t *playlist, int iter, int id, const char *format, int order) { - plt_sort_internal (playlist, iter, id, format, order, 0); + plt_sort_internal (playlist, iter, id, format, order, 0, 0); } static int pl_sort_is_duration; @@ -171,9 +176,8 @@ qsort_cmp_func (const void *a, const void *b) { return pl_sort_compare_str (aa, bb); } -void +static void plt_sort_random (playlist_t *playlist, int iter) { - plt_replace_meta (playlist, "autosort_mode", "random"); if (!playlist->head[iter] || !playlist->head[iter]->next[iter]) { return; } @@ -225,17 +229,23 @@ plt_sort_random (playlist_t *playlist, int iter) { // version 0: title formatting v1 // version 1: title formatting v2 -void -plt_sort_internal (playlist_t *playlist, int iter, int id, const char *format, int order, int version) { +static void +plt_sort_internal (playlist_t *playlist, int iter, int id, const char *format, int order, int version, int is_autosorting) { if (order == DDB_SORT_RANDOM) { + if (!is_autosorting) { + plt_replace_meta (playlist, "autosort_mode", "random"); + } plt_sort_random (playlist, iter); return; } int ascending = order == DDB_SORT_DESCENDING ? 0 : 1; - plt_set_meta_int (playlist, "autosort_ascending", ascending); - if (version != 0 && format != NULL) { - plt_replace_meta (playlist, "autosort_mode", "tf"); - plt_replace_meta (playlist, "autosort_tf", format); + if (!is_autosorting) + { + plt_set_meta_int (playlist, "autosort_ascending", ascending); + if (version != 0 && format != NULL) { + plt_replace_meta (playlist, "autosort_mode", "tf"); + plt_replace_meta (playlist, "autosort_tf", format); + } } if (format == NULL || id == DB_COLUMN_FILENUMBER || !playlist->head[iter] || !playlist->head[iter]->next[iter]) { @@ -409,10 +419,10 @@ plt_autosort (playlist_t *plt) { if (!fmt) { return; } - plt_sort_v2 (plt, PL_MAIN, -1, fmt, ascending ? DDB_SORT_ASCENDING : DDB_SORT_DESCENDING); + plt_sort_v2_internal (plt, PL_MAIN, -1, fmt, ascending ? DDB_SORT_ASCENDING : DDB_SORT_DESCENDING, 1); } else if (!strcmp (autosort_mode, "random")) { - plt_sort_v2 (plt, PL_MAIN, -1, NULL, DDB_SORT_RANDOM); + plt_sort_v2_internal (plt, PL_MAIN, -1, NULL, DDB_SORT_RANDOM, 1); } plt_save_config (plt);