comparison src/audacious/playlist.c @ 3468:440877c9360e trunk

Changed PLAYLIST_{UN}LOCK() macros to use playlist itself as argument, not the mutex.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 09 Sep 2007 22:05:24 +0300
parents 5a6896b6000f
children 26910525cec8 a1d398a05b52
comparison
equal deleted inserted replaced
3467:5a6896b6000f 3468:440877c9360e
411 } 411 }
412 412
413 void 413 void
414 playlist_clear_only(Playlist *playlist) 414 playlist_clear_only(Playlist *playlist)
415 { 415 {
416 PLAYLIST_LOCK( playlist->mutex ); 416 PLAYLIST_LOCK(playlist);
417 417
418 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL); 418 g_list_foreach(playlist->entries, (GFunc) playlist_entry_free, NULL);
419 g_list_free(playlist->entries); 419 g_list_free(playlist->entries);
420 playlist->position = NULL; 420 playlist->position = NULL;
421 playlist->entries = NULL; 421 playlist->entries = NULL;
422 playlist->tail = NULL; 422 playlist->tail = NULL;
423 playlist->attribute = PLAYLIST_PLAIN; 423 playlist->attribute = PLAYLIST_PLAIN;
424 424
425 PLAYLIST_UNLOCK( playlist->mutex ); 425 PLAYLIST_UNLOCK(playlist);
426 } 426 }
427 427
428 void 428 void
429 playlist_clear(Playlist *playlist) 429 playlist_clear(Playlist *playlist)
430 { 430 {
457 457
458 if (playing_song == node) { 458 if (playing_song == node) {
459 *set_info_text = TRUE; 459 *set_info_text = TRUE;
460 460
461 if (playback_get_playing()) { 461 if (playback_get_playing()) {
462 PLAYLIST_UNLOCK(playlist->mutex); 462 PLAYLIST_UNLOCK(playlist);
463 ip_data.stop = TRUE; 463 ip_data.stop = TRUE;
464 playback_stop(); 464 playback_stop();
465 ip_data.stop = FALSE; 465 ip_data.stop = FALSE;
466 PLAYLIST_LOCK(playlist->mutex); 466 PLAYLIST_LOCK(playlist);
467 *restart_playing = TRUE; 467 *restart_playing = TRUE;
468 } 468 }
469 469
470 playing_song = find_playlist_position_list(playlist); 470 playing_song = find_playlist_position_list(playlist);
471 471
503 GList *node; 503 GList *node;
504 504
505 if (!playlist) 505 if (!playlist)
506 return; 506 return;
507 507
508 PLAYLIST_LOCK(playlist->mutex); 508 PLAYLIST_LOCK(playlist);
509 509
510 node = g_list_nth(playlist->entries, pos); 510 node = g_list_nth(playlist->entries, pos);
511 511
512 if (!node) { 512 if (!node) {
513 PLAYLIST_UNLOCK(playlist->mutex); 513 PLAYLIST_UNLOCK(playlist);
514 return; 514 return;
515 } 515 }
516 516
517 playlist_delete_node(playlist, node, &set_info_text, &restart_playing); 517 playlist_delete_node(playlist, node, &set_info_text, &restart_playing);
518 518
519 PLAYLIST_UNLOCK(playlist->mutex); 519 PLAYLIST_UNLOCK(playlist);
520 520
521 playlist_recalc_total_time(playlist); 521 playlist_recalc_total_time(playlist);
522 522
523 playlistwin_update_list(playlist); 523 playlistwin_update_list(playlist);
524 if (restart_playing) { 524 if (restart_playing) {
536 playlist_delete_filenames(Playlist * playlist, GList * filenames) 536 playlist_delete_filenames(Playlist * playlist, GList * filenames)
537 { 537 {
538 GList *node, *fnode; 538 GList *node, *fnode;
539 gboolean set_info_text = FALSE, restart_playing = FALSE; 539 gboolean set_info_text = FALSE, restart_playing = FALSE;
540 540
541 PLAYLIST_LOCK(playlist->mutex); 541 PLAYLIST_LOCK(playlist);
542 542
543 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) { 543 for (fnode = filenames; fnode; fnode = g_list_next(fnode)) {
544 node = playlist->entries; 544 node = playlist->entries;
545 545
546 while (node) { 546 while (node) {
552 552
553 node = next; 553 node = next;
554 } 554 }
555 } 555 }
556 556
557 PLAYLIST_UNLOCK(playlist->mutex); 557 PLAYLIST_UNLOCK(playlist);
558 558
559 playlist_recalc_total_time(playlist); 559 playlist_recalc_total_time(playlist);
560 playlistwin_update_list(playlist); 560 playlistwin_update_list(playlist);
561 561
562 if (restart_playing) { 562 if (restart_playing) {
577 GList *node, *next_node; 577 GList *node, *next_node;
578 PlaylistEntry *entry; 578 PlaylistEntry *entry;
579 579
580 g_return_if_fail(playlist != NULL); 580 g_return_if_fail(playlist != NULL);
581 581
582 PLAYLIST_LOCK(playlist->mutex); 582 PLAYLIST_LOCK(playlist);
583 583
584 node = playlist->entries; 584 node = playlist->entries;
585 585
586 while (node) { 586 while (node) {
587 entry = PLAYLIST_ENTRY(node->data); 587 entry = PLAYLIST_ENTRY(node->data);
593 } 593 }
594 594
595 node = next_node; 595 node = next_node;
596 } 596 }
597 597
598 PLAYLIST_UNLOCK(playlist->mutex); 598 PLAYLIST_UNLOCK(playlist);
599 599
600 playlist_recalc_total_time(playlist); 600 playlist_recalc_total_time(playlist);
601 601
602 if (restart_playing) { 602 if (restart_playing) {
603 if (playlist->position) 603 if (playlist->position)
619 gint len, 619 gint len,
620 InputPlugin * dec) 620 InputPlugin * dec)
621 { 621 {
622 g_return_if_fail(filename != NULL); 622 g_return_if_fail(filename != NULL);
623 623
624 PLAYLIST_LOCK( playlist->mutex ); 624 PLAYLIST_LOCK(playlist);
625 playlist->entries = g_list_insert(playlist->entries, 625 playlist->entries = g_list_insert(playlist->entries,
626 playlist_entry_new(filename, title, len, dec), 626 playlist_entry_new(filename, title, len, dec),
627 pos); 627 pos);
628 PLAYLIST_UNLOCK( playlist->mutex ); 628 PLAYLIST_UNLOCK(playlist);
629 629
630 g_mutex_lock(mutex_scan); 630 g_mutex_lock(mutex_scan);
631 playlist_get_info_scan_active = TRUE; 631 playlist_get_info_scan_active = TRUE;
632 g_mutex_unlock(mutex_scan); 632 g_mutex_unlock(mutex_scan);
633 g_cond_signal(cond_scan); 633 g_cond_signal(cond_scan);
647 647
648 entry = playlist_entry_new(filename, tuple ? tuple_get_string(tuple, "title") : NULL, tuple ? tuple_get_int(tuple, "length") : -1, dec); 648 entry = playlist_entry_new(filename, tuple ? tuple_get_string(tuple, "title") : NULL, tuple ? tuple_get_int(tuple, "length") : -1, dec);
649 if(!playlist->tail) 649 if(!playlist->tail)
650 playlist->tail = g_list_last(playlist->entries); 650 playlist->tail = g_list_last(playlist->entries);
651 651
652 PLAYLIST_LOCK( playlist->mutex ); 652 PLAYLIST_LOCK(playlist);
653
653 if(pos == -1) { // the common case 654 if(pos == -1) { // the common case
654 GList *element; 655 GList *element;
655 element = g_list_alloc(); 656 element = g_list_alloc();
656 element->data = entry; 657 element->data = entry;
657 element->prev = playlist->tail; // NULL is allowed here. 658 element->prev = playlist->tail; // NULL is allowed here.
669 } 670 }
670 else { 671 else {
671 playlist->entries = g_list_insert(playlist->entries, entry, pos); 672 playlist->entries = g_list_insert(playlist->entries, entry, pos);
672 } 673 }
673 674
674 PLAYLIST_UNLOCK( playlist->mutex ); 675 PLAYLIST_UNLOCK(playlist);
676
675 if (tuple != NULL) { 677 if (tuple != NULL) {
676 const gchar *formatter = tuple_get_string(tuple, "formatter"); 678 const gchar *formatter = tuple_get_string(tuple, "formatter");
677 entry->title = tuple_formatter_make_title_string(tuple, formatter ? 679 entry->title = tuple_formatter_make_title_string(tuple, formatter ?
678 formatter : get_gentitle_format()); 680 formatter : get_gentitle_format());
679 entry->length = tuple_get_int(tuple, "length"); 681 entry->length = tuple_get_int(tuple, "length");
1001 } 1003 }
1002 } 1004 }
1003 1005
1004 g_free(decoded); 1006 g_free(decoded);
1005 1007
1006 PLAYLIST_LOCK(playlist->mutex); 1008 PLAYLIST_LOCK(playlist);
1007 node = g_list_nth(playlist->entries, pos); 1009 node = g_list_nth(playlist->entries, pos);
1008 PLAYLIST_UNLOCK(playlist->mutex); 1010 PLAYLIST_UNLOCK(playlist);
1009 1011
1010 entries += i; 1012 entries += i;
1011 1013
1012 if (pos >= 0) 1014 if (pos >= 0)
1013 pos += i; 1015 pos += i;
1095 gint pos, row, bottom; 1097 gint pos, row, bottom;
1096 1098
1097 if (!playlist) 1099 if (!playlist)
1098 return; 1100 return;
1099 1101
1100 PLAYLIST_LOCK(playlist->mutex); 1102 PLAYLIST_LOCK(playlist);
1101 if (!playlist->position || !playlistwin_list) { 1103 if (!playlist->position || !playlistwin_list) {
1102 PLAYLIST_UNLOCK(playlist->mutex); 1104 PLAYLIST_UNLOCK(playlist);
1103 return; 1105 return;
1104 } 1106 }
1105 1107
1106 pos = g_list_index(playlist->entries, playlist->position); 1108 pos = g_list_index(playlist->entries, playlist->position);
1107 1109
1108 if (playlistwin_item_visible(pos)) { 1110 if (playlistwin_item_visible(pos)) {
1109 PLAYLIST_UNLOCK(playlist->mutex); 1111 PLAYLIST_UNLOCK(playlist);
1110 return; 1112 return;
1111 } 1113 }
1112 1114
1113 bottom = MAX(0, playlist_get_length(playlist) - 1115 bottom = MAX(0, playlist_get_length(playlist) -
1114 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible); 1116 UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible);
1115 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom); 1117 row = CLAMP(pos - UI_SKINNED_PLAYLIST(playlistwin_list)->num_visible / 2, 0, bottom);
1116 PLAYLIST_UNLOCK(playlist->mutex); 1118 PLAYLIST_UNLOCK(playlist);
1117 playlistwin_set_toprow(row); 1119 playlistwin_set_toprow(row);
1118 g_cond_signal(cond_scan); 1120 g_cond_signal(cond_scan);
1119 } 1121 }
1120 1122
1121 void 1123 void
1124 GList *plist_pos_list; 1126 GList *plist_pos_list;
1125 gboolean restart_playing = FALSE; 1127 gboolean restart_playing = FALSE;
1126 if (!playlist_get_length(playlist)) 1128 if (!playlist_get_length(playlist))
1127 return; 1129 return;
1128 1130
1129 PLAYLIST_LOCK(playlist->mutex); 1131 PLAYLIST_LOCK(playlist);
1130 1132
1131 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) 1133 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL)
1132 { 1134 {
1133 playlist->position = playlist_position_before_jump; 1135 playlist->position = playlist_position_before_jump;
1134 playlist_position_before_jump = NULL; 1136 playlist_position_before_jump = NULL;
1135 } 1137 }
1136 1138
1137 plist_pos_list = find_playlist_position_list(playlist); 1139 plist_pos_list = find_playlist_position_list(playlist);
1138 1140
1139 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) { 1141 if (!cfg.repeat && !g_list_next(plist_pos_list) && playlist->queue == NULL) {
1140 PLAYLIST_UNLOCK(playlist->mutex); 1142 PLAYLIST_UNLOCK(playlist);
1141 return; 1143 return;
1142 } 1144 }
1143 1145
1144 if (playback_get_playing()) { 1146 if (playback_get_playing()) {
1145 /* We need to stop before changing playlist_position */ 1147 /* We need to stop before changing playlist_position */
1146 PLAYLIST_UNLOCK(playlist->mutex); 1148 PLAYLIST_UNLOCK(playlist);
1147 ip_data.stop = TRUE; 1149 ip_data.stop = TRUE;
1148 playback_stop(); 1150 playback_stop();
1149 ip_data.stop = FALSE; 1151 ip_data.stop = FALSE;
1150 PLAYLIST_LOCK(playlist->mutex); 1152 PLAYLIST_LOCK(playlist);
1151 restart_playing = TRUE; 1153 restart_playing = TRUE;
1152 } 1154 }
1153 1155
1154 plist_pos_list = find_playlist_position_list(playlist); 1156 plist_pos_list = find_playlist_position_list(playlist);
1155 if (playlist->queue != NULL) 1157 if (playlist->queue != NULL)
1162 if (cfg.shuffle) 1164 if (cfg.shuffle)
1163 playlist->position = playlist->shuffle->data; 1165 playlist->position = playlist->shuffle->data;
1164 else 1166 else
1165 playlist->position = playlist->entries->data; 1167 playlist->position = playlist->entries->data;
1166 } 1168 }
1167 PLAYLIST_UNLOCK(playlist->mutex); 1169 PLAYLIST_UNLOCK(playlist);
1168 playlist_check_pos_current(playlist); 1170 playlist_check_pos_current(playlist);
1169 1171
1170 if (restart_playing) 1172 if (restart_playing)
1171 playback_initiate(); 1173 playback_initiate();
1172 1174
1180 gboolean restart_playing = FALSE; 1182 gboolean restart_playing = FALSE;
1181 1183
1182 if (!playlist_get_length(playlist)) 1184 if (!playlist_get_length(playlist))
1183 return; 1185 return;
1184 1186
1185 PLAYLIST_LOCK(playlist->mutex); 1187 PLAYLIST_LOCK(playlist);
1186 1188
1187 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) 1189 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL)
1188 { 1190 {
1189 playlist->position = playlist_position_before_jump; 1191 playlist->position = playlist_position_before_jump;
1190 playlist_position_before_jump = NULL; 1192 playlist_position_before_jump = NULL;
1191 } 1193 }
1192 1194
1193 plist_pos_list = find_playlist_position_list(playlist); 1195 plist_pos_list = find_playlist_position_list(playlist);
1194 1196
1195 if (!cfg.repeat && !g_list_previous(plist_pos_list)) { 1197 if (!cfg.repeat && !g_list_previous(plist_pos_list)) {
1196 PLAYLIST_UNLOCK(playlist->mutex); 1198 PLAYLIST_UNLOCK(playlist);
1197 return; 1199 return;
1198 } 1200 }
1199 1201
1200 if (playback_get_playing()) { 1202 if (playback_get_playing()) {
1201 /* We need to stop before changing playlist_position */ 1203 /* We need to stop before changing playlist_position */
1202 PLAYLIST_UNLOCK(playlist->mutex); 1204 PLAYLIST_UNLOCK(playlist);
1203 ip_data.stop = TRUE; 1205 ip_data.stop = TRUE;
1204 playback_stop(); 1206 playback_stop();
1205 ip_data.stop = FALSE; 1207 ip_data.stop = FALSE;
1206 PLAYLIST_LOCK(playlist->mutex); 1208 PLAYLIST_LOCK(playlist);
1207 restart_playing = TRUE; 1209 restart_playing = TRUE;
1208 } 1210 }
1209 1211
1210 plist_pos_list = find_playlist_position_list(playlist); 1212 plist_pos_list = find_playlist_position_list(playlist);
1211 if (g_list_previous(plist_pos_list)) { 1213 if (g_list_previous(plist_pos_list)) {
1221 node = g_list_last(playlist->entries); 1223 node = g_list_last(playlist->entries);
1222 if (node) 1224 if (node)
1223 playlist->position = node->data; 1225 playlist->position = node->data;
1224 } 1226 }
1225 1227
1226 PLAYLIST_UNLOCK(playlist->mutex); 1228 PLAYLIST_UNLOCK(playlist);
1227 1229
1228 playlist_check_pos_current(playlist); 1230 playlist_check_pos_current(playlist);
1229 1231
1230 if (restart_playing) 1232 if (restart_playing)
1231 playback_initiate(); 1233 playback_initiate();
1237 playlist_queue(Playlist *playlist) 1239 playlist_queue(Playlist *playlist)
1238 { 1240 {
1239 GList *list = playlist_get_selected(playlist); 1241 GList *list = playlist_get_selected(playlist);
1240 GList *it = list; 1242 GList *it = list;
1241 1243
1242 PLAYLIST_LOCK(playlist->mutex); 1244 PLAYLIST_LOCK(playlist);
1243 1245
1244 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) 1246 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1245 { 1247 {
1246 /* Shuffling and this is our first manual jump. */ 1248 /* Shuffling and this is our first manual jump. */
1247 playlist_position_before_jump = playlist->position; 1249 playlist_position_before_jump = playlist->position;
1263 it = next; 1265 it = next;
1264 } 1266 }
1265 1267
1266 playlist->queue = g_list_concat(playlist->queue, list); 1268 playlist->queue = g_list_concat(playlist->queue, list);
1267 1269
1268 PLAYLIST_UNLOCK(playlist->mutex); 1270 PLAYLIST_UNLOCK(playlist);
1269 1271
1270 playlist_recalc_total_time(playlist); 1272 playlist_recalc_total_time(playlist);
1271 playlistwin_update_list(playlist); 1273 playlistwin_update_list(playlist);
1272 } 1274 }
1273 1275
1275 playlist_queue_position(Playlist *playlist, guint pos) 1277 playlist_queue_position(Playlist *playlist, guint pos)
1276 { 1278 {
1277 GList *tmp; 1279 GList *tmp;
1278 PlaylistEntry *entry; 1280 PlaylistEntry *entry;
1279 1281
1280 PLAYLIST_LOCK(playlist->mutex); 1282 PLAYLIST_LOCK(playlist);
1281 1283
1282 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) 1284 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1283 { 1285 {
1284 /* Shuffling and this is our first manual jump. */ 1286 /* Shuffling and this is our first manual jump. */
1285 playlist_position_before_jump = playlist->position; 1287 playlist_position_before_jump = playlist->position;
1290 playlist->queue = g_list_remove_link(playlist->queue, tmp); 1292 playlist->queue = g_list_remove_link(playlist->queue, tmp);
1291 g_list_free_1(tmp); 1293 g_list_free_1(tmp);
1292 } 1294 }
1293 else 1295 else
1294 playlist->queue = g_list_append(playlist->queue, entry); 1296 playlist->queue = g_list_append(playlist->queue, entry);
1295 PLAYLIST_UNLOCK(playlist->mutex); 1297 PLAYLIST_UNLOCK(playlist);
1296 1298
1297 playlist_recalc_total_time(playlist); 1299 playlist_recalc_total_time(playlist);
1298 playlistwin_update_list(playlist); 1300 playlistwin_update_list(playlist);
1299 } 1301 }
1300 1302
1302 playlist_is_position_queued(Playlist *playlist, guint pos) 1304 playlist_is_position_queued(Playlist *playlist, guint pos)
1303 { 1305 {
1304 PlaylistEntry *entry; 1306 PlaylistEntry *entry;
1305 GList *tmp; 1307 GList *tmp;
1306 1308
1307 PLAYLIST_LOCK(playlist->mutex); 1309 PLAYLIST_LOCK(playlist);
1308 entry = g_list_nth_data(playlist->entries, pos); 1310 entry = g_list_nth_data(playlist->entries, pos);
1309 tmp = g_list_find(playlist->queue, entry); 1311 tmp = g_list_find(playlist->queue, entry);
1310 PLAYLIST_UNLOCK(playlist->mutex); 1312 PLAYLIST_UNLOCK(playlist);
1311 1313
1312 return tmp != NULL; 1314 return tmp != NULL;
1313 } 1315 }
1314 1316
1315 gint 1317 gint
1316 playlist_get_queue_position_number(Playlist *playlist, guint pos) 1318 playlist_get_queue_position_number(Playlist *playlist, guint pos)
1317 { 1319 {
1318 PlaylistEntry *entry; 1320 PlaylistEntry *entry;
1319 gint tmp; 1321 gint tmp;
1320 1322
1321 PLAYLIST_LOCK(playlist->mutex); 1323 PLAYLIST_LOCK(playlist);
1322 entry = g_list_nth_data(playlist->entries, pos); 1324 entry = g_list_nth_data(playlist->entries, pos);
1323 tmp = g_list_index(playlist->queue, entry); 1325 tmp = g_list_index(playlist->queue, entry);
1324 PLAYLIST_UNLOCK(playlist->mutex); 1326 PLAYLIST_UNLOCK(playlist);
1325 1327
1326 return tmp; 1328 return tmp;
1327 } 1329 }
1328 1330
1329 gint 1331 gint
1330 playlist_get_queue_qposition_number(Playlist *playlist, guint pos) 1332 playlist_get_queue_qposition_number(Playlist *playlist, guint pos)
1331 { 1333 {
1332 PlaylistEntry *entry; 1334 PlaylistEntry *entry;
1333 gint tmp; 1335 gint tmp;
1334 1336
1335 PLAYLIST_LOCK(playlist->mutex); 1337 PLAYLIST_LOCK(playlist);
1336 entry = g_list_nth_data(playlist->queue, pos); 1338 entry = g_list_nth_data(playlist->queue, pos);
1337 tmp = g_list_index(playlist->entries, entry); 1339 tmp = g_list_index(playlist->entries, entry);
1338 PLAYLIST_UNLOCK(playlist->mutex); 1340 PLAYLIST_UNLOCK(playlist);
1339 1341
1340 return tmp; 1342 return tmp;
1341 } 1343 }
1342 1344
1343 void 1345 void
1344 playlist_clear_queue(Playlist *playlist) 1346 playlist_clear_queue(Playlist *playlist)
1345 { 1347 {
1346 PLAYLIST_LOCK(playlist->mutex); 1348 PLAYLIST_LOCK(playlist);
1347 g_list_free(playlist->queue); 1349 g_list_free(playlist->queue);
1348 playlist->queue = NULL; 1350 playlist->queue = NULL;
1349 PLAYLIST_UNLOCK(playlist->mutex); 1351 PLAYLIST_UNLOCK(playlist);
1350 1352
1351 playlist_recalc_total_time(playlist); 1353 playlist_recalc_total_time(playlist);
1352 playlistwin_update_list(playlist); 1354 playlistwin_update_list(playlist);
1353 } 1355 }
1354 1356
1355 void 1357 void
1356 playlist_queue_remove(Playlist *playlist, guint pos) 1358 playlist_queue_remove(Playlist *playlist, guint pos)
1357 { 1359 {
1358 void *entry; 1360 void *entry;
1359 1361
1360 PLAYLIST_LOCK(playlist->mutex); 1362 PLAYLIST_LOCK(playlist);
1361 entry = g_list_nth_data(playlist->entries, pos); 1363 entry = g_list_nth_data(playlist->entries, pos);
1362 playlist->queue = g_list_remove(playlist->queue, entry); 1364 playlist->queue = g_list_remove(playlist->queue, entry);
1363 PLAYLIST_UNLOCK(playlist->mutex); 1365 PLAYLIST_UNLOCK(playlist);
1364 1366
1365 playlistwin_update_list(playlist); 1367 playlistwin_update_list(playlist);
1366 } 1368 }
1367 1369
1368 gint 1370 gint
1378 gboolean restart_playing = FALSE; 1380 gboolean restart_playing = FALSE;
1379 1381
1380 if (!playlist) 1382 if (!playlist)
1381 return; 1383 return;
1382 1384
1383 PLAYLIST_LOCK(playlist->mutex); 1385 PLAYLIST_LOCK(playlist);
1384 1386
1385 node = g_list_nth(playlist->entries, pos); 1387 node = g_list_nth(playlist->entries, pos);
1386 if (!node) { 1388 if (!node) {
1387 PLAYLIST_UNLOCK(playlist->mutex); 1389 PLAYLIST_UNLOCK(playlist);
1388 return; 1390 return;
1389 } 1391 }
1390 1392
1391 if (playback_get_playing()) { 1393 if (playback_get_playing()) {
1392 /* We need to stop before changing playlist_position */ 1394 /* We need to stop before changing playlist_position */
1393 PLAYLIST_UNLOCK(playlist->mutex); 1395 PLAYLIST_UNLOCK(playlist);
1394 ip_data.stop = TRUE; 1396 ip_data.stop = TRUE;
1395 playback_stop(); 1397 playback_stop();
1396 ip_data.stop = FALSE; 1398 ip_data.stop = FALSE;
1397 PLAYLIST_LOCK(playlist->mutex); 1399 PLAYLIST_LOCK(playlist);
1398 restart_playing = TRUE; 1400 restart_playing = TRUE;
1399 } 1401 }
1400 1402
1401 if ((cfg.shuffle) && (playlist_position_before_jump == NULL)) 1403 if ((cfg.shuffle) && (playlist_position_before_jump == NULL))
1402 { 1404 {
1403 /* Shuffling and this is our first manual jump. */ 1405 /* Shuffling and this is our first manual jump. */
1404 playlist_position_before_jump = playlist->position; 1406 playlist_position_before_jump = playlist->position;
1405 } 1407 }
1406 1408
1407 playlist->position = node->data; 1409 playlist->position = node->data;
1408 PLAYLIST_UNLOCK(playlist->mutex); 1410 PLAYLIST_UNLOCK(playlist);
1409 playlist_check_pos_current(playlist); 1411 playlist_check_pos_current(playlist);
1410 1412
1411 if (restart_playing) 1413 if (restart_playing)
1412 playback_initiate(); 1414 playback_initiate();
1413 else 1415 else
1425 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong) 1427 if ((cfg.no_playlist_advance && !cfg.repeat) || cfg.stopaftersong)
1426 ip_data.stop = FALSE; 1428 ip_data.stop = FALSE;
1427 1429
1428 hook_call("playback end", playlist->position); 1430 hook_call("playback end", playlist->position);
1429 1431
1430 PLAYLIST_LOCK(playlist->mutex); 1432 PLAYLIST_LOCK(playlist);
1431 1433
1432 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL) 1434 if ((playlist_position_before_jump != NULL) && playlist->queue == NULL)
1433 { 1435 {
1434 playlist->position = playlist_position_before_jump; 1436 playlist->position = playlist_position_before_jump;
1435 playlist_position_before_jump = NULL; 1437 playlist_position_before_jump = NULL;
1436 } 1438 }
1437 1439
1438 plist_pos_list = find_playlist_position_list(playlist); 1440 plist_pos_list = find_playlist_position_list(playlist);
1439 1441
1440 if (cfg.no_playlist_advance) { 1442 if (cfg.no_playlist_advance) {
1441 PLAYLIST_UNLOCK(playlist->mutex); 1443 PLAYLIST_UNLOCK(playlist);
1442 mainwin_clear_song_info(); 1444 mainwin_clear_song_info();
1443 if (cfg.repeat) 1445 if (cfg.repeat)
1444 playback_initiate(); 1446 playback_initiate();
1445 return; 1447 return;
1446 } 1448 }
1447 1449
1448 if (cfg.stopaftersong) { 1450 if (cfg.stopaftersong) {
1449 PLAYLIST_UNLOCK(playlist->mutex); 1451 PLAYLIST_UNLOCK(playlist);
1450 mainwin_clear_song_info(); 1452 mainwin_clear_song_info();
1451 mainwin_set_stopaftersong(FALSE); 1453 mainwin_set_stopaftersong(FALSE);
1452 return; 1454 return;
1453 } 1455 }
1454 1456
1462 } 1464 }
1463 else if (playlist->entries != NULL) 1465 else if (playlist->entries != NULL)
1464 playlist->position = playlist->entries->data; 1466 playlist->position = playlist->entries->data;
1465 1467
1466 if (!cfg.repeat) { 1468 if (!cfg.repeat) {
1467 PLAYLIST_UNLOCK(playlist->mutex); 1469 PLAYLIST_UNLOCK(playlist);
1468 hook_call("playlist end reached", playlist->position); 1470 hook_call("playlist end reached", playlist->position);
1469 mainwin_clear_song_info(); 1471 mainwin_clear_song_info();
1470 return; 1472 return;
1471 } 1473 }
1472 } 1474 }
1473 else 1475 else
1474 playlist->position = g_list_next(plist_pos_list)->data; 1476 playlist->position = g_list_next(plist_pos_list)->data;
1475 1477
1476 PLAYLIST_UNLOCK(playlist->mutex); 1478 PLAYLIST_UNLOCK(playlist);
1477 1479
1478 playlist_check_pos_current(playlist); 1480 playlist_check_pos_current(playlist);
1479 playback_initiate(); 1481 playback_initiate();
1480 playlistwin_update_list(playlist); 1482 playlistwin_update_list(playlist);
1481 } 1483 }
1483 gint 1485 gint
1484 playlist_queue_get_length(Playlist *playlist) 1486 playlist_queue_get_length(Playlist *playlist)
1485 { 1487 {
1486 gint length; 1488 gint length;
1487 1489
1488 PLAYLIST_LOCK(playlist->mutex); 1490 PLAYLIST_LOCK(playlist);
1489 length = g_list_length(playlist->queue); 1491 length = g_list_length(playlist->queue);
1490 PLAYLIST_UNLOCK(playlist->mutex); 1492 PLAYLIST_UNLOCK(playlist);
1491 1493
1492 return length; 1494 return length;
1493 } 1495 }
1494 1496
1495 gint 1497 gint
1503 { 1505 {
1504 gchar *text, *title, *numbers, *length; 1506 gchar *text, *title, *numbers, *length;
1505 1507
1506 g_return_val_if_fail(playlist != NULL, NULL); 1508 g_return_val_if_fail(playlist != NULL, NULL);
1507 1509
1508 PLAYLIST_LOCK(playlist->mutex); 1510 PLAYLIST_LOCK(playlist);
1509 if (!playlist->position) { 1511 if (!playlist->position) {
1510 PLAYLIST_UNLOCK(playlist->mutex); 1512 PLAYLIST_UNLOCK(playlist);
1511 return NULL; 1513 return NULL;
1512 } 1514 }
1513 1515
1514 /* FIXME: there should not be a need to do additional conversion, 1516 /* FIXME: there should not be a need to do additional conversion,
1515 * if playlist is properly maintained */ 1517 * if playlist is properly maintained */
1541 playlist->position->length / 60000, 1543 playlist->position->length / 60000,
1542 (playlist->position->length / 1000) % 60); 1544 (playlist->position->length / 1000) % 60);
1543 else 1545 else
1544 length = g_strdup(""); 1546 length = g_strdup("");
1545 1547
1546 PLAYLIST_UNLOCK(playlist->mutex); 1548 PLAYLIST_UNLOCK(playlist);
1547 1549
1548 text = convert_title_text(g_strconcat(numbers, title, length, NULL)); 1550 text = convert_title_text(g_strconcat(numbers, title, length, NULL));
1549 1551
1550 g_free(numbers); 1552 g_free(numbers);
1551 g_free(title); 1553 g_free(title);
1796 gint 1798 gint
1797 playlist_get_position(Playlist *playlist) 1799 playlist_get_position(Playlist *playlist)
1798 { 1800 {
1799 gint pos; 1801 gint pos;
1800 1802
1801 PLAYLIST_LOCK(playlist->mutex); 1803 PLAYLIST_LOCK(playlist);
1802 pos = playlist_get_position_nolock(playlist); 1804 pos = playlist_get_position_nolock(playlist);
1803 PLAYLIST_UNLOCK(playlist->mutex); 1805 PLAYLIST_UNLOCK(playlist);
1804 1806
1805 return pos; 1807 return pos;
1806 } 1808 }
1807 1809
1808 gchar * 1810 gchar *
1813 GList *node; 1815 GList *node;
1814 1816
1815 if (!playlist) 1817 if (!playlist)
1816 return NULL; 1818 return NULL;
1817 1819
1818 PLAYLIST_LOCK(playlist->mutex); 1820 PLAYLIST_LOCK(playlist);
1819 node = g_list_nth(playlist->entries, pos); 1821 node = g_list_nth(playlist->entries, pos);
1820 if (!node) { 1822 if (!node) {
1821 PLAYLIST_UNLOCK(playlist->mutex); 1823 PLAYLIST_UNLOCK(playlist);
1822 return NULL; 1824 return NULL;
1823 } 1825 }
1824 entry = node->data; 1826 entry = node->data;
1825 1827
1826 filename = g_strdup(entry->filename); 1828 filename = g_strdup(entry->filename);
1827 PLAYLIST_UNLOCK(playlist->mutex); 1829 PLAYLIST_UNLOCK(playlist);
1828 1830
1829 return filename; 1831 return filename;
1830 } 1832 }
1831 1833
1832 gchar * 1834 gchar *
1838 time_t mtime; 1840 time_t mtime;
1839 1841
1840 if (!playlist) 1842 if (!playlist)
1841 return NULL; 1843 return NULL;
1842 1844
1843 PLAYLIST_LOCK(playlist->mutex); 1845 PLAYLIST_LOCK(playlist);
1844 1846
1845 if (!(node = g_list_nth(playlist->entries, pos))) { 1847 if (!(node = g_list_nth(playlist->entries, pos))) {
1846 PLAYLIST_UNLOCK(playlist->mutex); 1848 PLAYLIST_UNLOCK(playlist);
1847 return NULL; 1849 return NULL;
1848 } 1850 }
1849 1851
1850 entry = node->data; 1852 entry = node->data;
1851 1853
1863 } 1865 }
1864 else { 1866 else {
1865 title = entry->title; 1867 title = entry->title;
1866 } 1868 }
1867 1869
1868 PLAYLIST_UNLOCK(playlist->mutex); 1870 PLAYLIST_UNLOCK(playlist);
1869 1871
1870 if (!title) { 1872 if (!title) {
1871 gchar *realfn = NULL; 1873 gchar *realfn = NULL;
1872 realfn = g_filename_from_uri(entry->filename, NULL, NULL); 1874 realfn = g_filename_from_uri(entry->filename, NULL, NULL);
1873 title = g_path_get_basename(realfn ? realfn : entry->filename); 1875 title = g_path_get_basename(realfn ? realfn : entry->filename);
2193 2195
2194 void 2196 void
2195 playlist_sort(Playlist *playlist, PlaylistSortType type) 2197 playlist_sort(Playlist *playlist, PlaylistSortType type)
2196 { 2198 {
2197 playlist_remove_dead_files(playlist); 2199 playlist_remove_dead_files(playlist);
2198 PLAYLIST_LOCK(playlist->mutex); 2200 PLAYLIST_LOCK(playlist);
2199 playlist->entries = 2201 playlist->entries =
2200 g_list_sort(playlist->entries, 2202 g_list_sort(playlist->entries,
2201 (GCompareFunc) playlist_compare_func_table[type]); 2203 (GCompareFunc) playlist_compare_func_table[type]);
2202 PLAYLIST_UNLOCK(playlist->mutex); 2204 PLAYLIST_UNLOCK(playlist);
2203 } 2205 }
2204 2206
2205 static GList * 2207 static GList *
2206 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc) 2208 playlist_sort_selected_generic(GList * list, GCompareFunc cmpfunc)
2207 { 2209 {
2252 } 2254 }
2253 2255
2254 void 2256 void
2255 playlist_sort_selected(Playlist *playlist, PlaylistSortType type) 2257 playlist_sort_selected(Playlist *playlist, PlaylistSortType type)
2256 { 2258 {
2257 PLAYLIST_LOCK(playlist->mutex); 2259 PLAYLIST_LOCK(playlist);
2258 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc) 2260 playlist->entries = playlist_sort_selected_generic(playlist->entries, (GCompareFunc)
2259 playlist_compare_func_table 2261 playlist_compare_func_table
2260 [type]); 2262 [type]);
2261 PLAYLIST_UNLOCK(playlist->mutex); 2263 PLAYLIST_UNLOCK(playlist);
2262 } 2264 }
2263 2265
2264 void 2266 void
2265 playlist_reverse(Playlist *playlist) 2267 playlist_reverse(Playlist *playlist)
2266 { 2268 {
2267 PLAYLIST_LOCK(playlist->mutex); 2269 PLAYLIST_LOCK(playlist);
2268 playlist->entries = g_list_reverse(playlist->entries); 2270 playlist->entries = g_list_reverse(playlist->entries);
2269 PLAYLIST_UNLOCK(playlist->mutex); 2271 PLAYLIST_UNLOCK(playlist);
2270 } 2272 }
2271 2273
2272 static GList * 2274 static GList *
2273 playlist_shuffle_list(Playlist *playlist, GList * list) 2275 playlist_shuffle_list(Playlist *playlist, GList * list)
2274 { 2276 {
2314 } 2316 }
2315 2317
2316 void 2318 void
2317 playlist_random(Playlist *playlist) 2319 playlist_random(Playlist *playlist)
2318 { 2320 {
2319 PLAYLIST_LOCK(playlist->mutex); 2321 PLAYLIST_LOCK(playlist);
2320 playlist->entries = playlist_shuffle_list(playlist, playlist->entries); 2322 playlist->entries = playlist_shuffle_list(playlist, playlist->entries);
2321 PLAYLIST_UNLOCK(playlist->mutex); 2323 PLAYLIST_UNLOCK(playlist);
2322 } 2324 }
2323 2325
2324 GList * 2326 GList *
2325 playlist_get_selected(Playlist *playlist) 2327 playlist_get_selected(Playlist *playlist)
2326 { 2328 {
2327 GList *node, *list = NULL; 2329 GList *node, *list = NULL;
2328 gint i = 0; 2330 gint i = 0;
2329 2331
2330 PLAYLIST_LOCK(playlist->mutex); 2332 PLAYLIST_LOCK(playlist);
2331 for (node = playlist->entries; node; node = g_list_next(node), i++) { 2333 for (node = playlist->entries; node; node = g_list_next(node), i++) {
2332 PlaylistEntry *entry = node->data; 2334 PlaylistEntry *entry = node->data;
2333 if (entry->selected) 2335 if (entry->selected)
2334 list = g_list_prepend(list, GINT_TO_POINTER(i)); 2336 list = g_list_prepend(list, GINT_TO_POINTER(i));
2335 } 2337 }
2336 PLAYLIST_UNLOCK(playlist->mutex); 2338 PLAYLIST_UNLOCK(playlist);
2337 return g_list_reverse(list); 2339 return g_list_reverse(list);
2338 } 2340 }
2339 2341
2340 void 2342 void
2341 playlist_clear_selected(Playlist *playlist) 2343 playlist_clear_selected(Playlist *playlist)
2342 { 2344 {
2343 GList *node = NULL; 2345 GList *node = NULL;
2344 gint i = 0; 2346 gint i = 0;
2345 2347
2346 PLAYLIST_LOCK(playlist->mutex); 2348 PLAYLIST_LOCK(playlist);
2347 for (node = playlist->entries; node; node = g_list_next(node), i++) { 2349 for (node = playlist->entries; node; node = g_list_next(node), i++) {
2348 PLAYLIST_ENTRY(node->data)->selected = FALSE; 2350 PLAYLIST_ENTRY(node->data)->selected = FALSE;
2349 } 2351 }
2350 PLAYLIST_UNLOCK(playlist->mutex); 2352 PLAYLIST_UNLOCK(playlist);
2351 playlist_recalc_total_time(playlist); 2353 playlist_recalc_total_time(playlist);
2352 playlist_manager_update(); 2354 playlist_manager_update();
2353 } 2355 }
2354 2356
2355 gint 2357 gint
2356 playlist_get_num_selected(Playlist *playlist) 2358 playlist_get_num_selected(Playlist *playlist)
2357 { 2359 {
2358 GList *node; 2360 GList *node;
2359 gint num = 0; 2361 gint num = 0;
2360 2362
2361 PLAYLIST_LOCK(playlist->mutex); 2363 PLAYLIST_LOCK(playlist);
2362 for (node = playlist->entries; node; node = g_list_next(node)) { 2364 for (node = playlist->entries; node; node = g_list_next(node)) {
2363 PlaylistEntry *entry = node->data; 2365 PlaylistEntry *entry = node->data;
2364 if (entry->selected) 2366 if (entry->selected)
2365 num++; 2367 num++;
2366 } 2368 }
2367 PLAYLIST_UNLOCK(playlist->mutex); 2369 PLAYLIST_UNLOCK(playlist);
2368 return num; 2370 return num;
2369 } 2371 }
2370 2372
2371 2373
2372 static void 2374 static void
2373 playlist_generate_shuffle_list(Playlist *playlist) 2375 playlist_generate_shuffle_list(Playlist *playlist)
2374 { 2376 {
2375 PLAYLIST_LOCK(playlist->mutex); 2377 PLAYLIST_LOCK(playlist);
2376 playlist_generate_shuffle_list_nolock(playlist); 2378 playlist_generate_shuffle_list_nolock(playlist);
2377 PLAYLIST_UNLOCK(playlist->mutex); 2379 PLAYLIST_UNLOCK(playlist);
2378 } 2380 }
2379 2381
2380 static void 2382 static void
2381 playlist_generate_shuffle_list_nolock(Playlist *playlist) 2383 playlist_generate_shuffle_list_nolock(Playlist *playlist)
2382 { 2384 {
2412 PlaylistEntry *entry = NULL; 2414 PlaylistEntry *entry = NULL;
2413 Tuple *tuple = NULL; 2415 Tuple *tuple = NULL;
2414 ProbeResult *pr = NULL; 2416 ProbeResult *pr = NULL;
2415 time_t mtime; 2417 time_t mtime;
2416 2418
2417 PLAYLIST_LOCK(playlist->mutex); 2419 PLAYLIST_LOCK(playlist);
2418 2420
2419 if ((node = g_list_nth(playlist->entries, pos))) 2421 if ((node = g_list_nth(playlist->entries, pos)))
2420 { 2422 {
2421 entry = node->data; 2423 entry = node->data;
2422 tuple = entry->tuple; 2424 tuple = entry->tuple;
2423 path = g_strdup(entry->filename); 2425 path = g_strdup(entry->filename);
2424 } 2426 }
2425 2427
2426 PLAYLIST_UNLOCK(playlist->mutex); 2428 PLAYLIST_UNLOCK(playlist);
2427 2429
2428 if (entry->tuple) 2430 if (entry->tuple)
2429 mtime = tuple_get_int(entry->tuple, "mtime"); 2431 mtime = tuple_get_int(entry->tuple, "mtime");
2430 else 2432 else
2431 mtime = 0; 2433 mtime = 0;
2470 playlist_fileinfo_current(Playlist *playlist) 2472 playlist_fileinfo_current(Playlist *playlist)
2471 { 2473 {
2472 gchar *path = NULL; 2474 gchar *path = NULL;
2473 Tuple *tuple = NULL; 2475 Tuple *tuple = NULL;
2474 2476
2475 PLAYLIST_LOCK(playlist->mutex); 2477 PLAYLIST_LOCK(playlist);
2476 2478
2477 if (playlist->entries && playlist->position) 2479 if (playlist->entries && playlist->position)
2478 { 2480 {
2479 path = g_strdup(playlist->position->filename); 2481 path = g_strdup(playlist->position->filename);
2480 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL )) 2482 if (( playlist->position->tuple == NULL ) || ( playlist->position->decoder == NULL ))
2481 playlist_entry_get_info(playlist->position); 2483 playlist_entry_get_info(playlist->position);
2482 tuple = playlist->position->tuple; 2484 tuple = playlist->position->tuple;
2483 } 2485 }
2484 2486
2485 PLAYLIST_UNLOCK(playlist->mutex); 2487 PLAYLIST_UNLOCK(playlist);
2486 2488
2487 if (tuple != NULL) 2489 if (tuple != NULL)
2488 { 2490 {
2489 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL) 2491 if (playlist->position->decoder != NULL && playlist->position->decoder->file_info_box == NULL)
2490 fileinfo_show_for_tuple(tuple); 2492 fileinfo_show_for_tuple(tuple);
2689 void 2691 void
2690 playlist_remove_dead_files(Playlist *playlist) 2692 playlist_remove_dead_files(Playlist *playlist)
2691 { 2693 {
2692 GList *node, *next_node; 2694 GList *node, *next_node;
2693 2695
2694 PLAYLIST_LOCK(playlist->mutex); 2696 PLAYLIST_LOCK(playlist);
2695 2697
2696 for (node = playlist->entries; node; node = next_node) { 2698 for (node = playlist->entries; node; node = next_node) {
2697 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); 2699 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
2698 next_node = g_list_next(node); 2700 next_node = g_list_next(node);
2699 2701
2724 2726
2725 playlist_entry_free(entry); 2727 playlist_entry_free(entry);
2726 playlist->entries = g_list_delete_link(playlist->entries, node); 2728 playlist->entries = g_list_delete_link(playlist->entries, node);
2727 } 2729 }
2728 2730
2729 PLAYLIST_UNLOCK(playlist->mutex); 2731 PLAYLIST_UNLOCK(playlist);
2730 2732
2731 playlist_generate_shuffle_list(playlist); 2733 playlist_generate_shuffle_list(playlist);
2732 playlistwin_update_list(playlist); 2734 playlistwin_update_list(playlist);
2733 playlist_recalc_total_time(playlist); 2735 playlist_recalc_total_time(playlist);
2734 playlist_manager_update(); 2736 playlist_manager_update();
2814 default: 2816 default:
2815 dups_compare_func = playlist_dupscmp_filename; 2817 dups_compare_func = playlist_dupscmp_filename;
2816 break; 2818 break;
2817 } 2819 }
2818 2820
2819 PLAYLIST_LOCK(playlist->mutex); 2821 PLAYLIST_LOCK(playlist);
2820 2822
2821 for (node = playlist->entries; node; node = next_node) { 2823 for (node = playlist->entries; node; node = next_node) {
2822 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data); 2824 PlaylistEntry *entry = PLAYLIST_ENTRY(node->data);
2823 next_node = g_list_next(node); 2825 next_node = g_list_next(node);
2824 2826
2859 playlist->entries = g_list_delete_link(playlist->entries, node_cmp); 2861 playlist->entries = g_list_delete_link(playlist->entries, node_cmp);
2860 } 2862 }
2861 } 2863 }
2862 } 2864 }
2863 2865
2864 PLAYLIST_UNLOCK(playlist->mutex); 2866 PLAYLIST_UNLOCK(playlist);
2865 2867
2866 playlistwin_update_list(playlist); 2868 playlistwin_update_list(playlist);
2867 playlist_recalc_total_time(playlist); 2869 playlist_recalc_total_time(playlist);
2868 2870
2869 playlist_manager_update(); 2871 playlist_manager_update();
2874 gulong * total_time, 2876 gulong * total_time,
2875 gulong * selection_time, 2877 gulong * selection_time,
2876 gboolean * total_more, 2878 gboolean * total_more,
2877 gboolean * selection_more) 2879 gboolean * selection_more)
2878 { 2880 {
2879 PLAYLIST_LOCK(playlist->mutex); 2881 PLAYLIST_LOCK(playlist);
2880 *total_time = playlist->pl_total_time; 2882 *total_time = playlist->pl_total_time;
2881 *selection_time = playlist->pl_selection_time; 2883 *selection_time = playlist->pl_selection_time;
2882 *total_more = playlist->pl_total_more; 2884 *total_more = playlist->pl_total_more;
2883 *selection_more = playlist->pl_selection_more; 2885 *selection_more = playlist->pl_selection_more;
2884 PLAYLIST_UNLOCK(playlist->mutex); 2886 PLAYLIST_UNLOCK(playlist);
2885 } 2887 }
2886 2888
2887 2889
2888 static void 2890 static void
2889 playlist_recalc_total_time_nolock(Playlist *playlist) 2891 playlist_recalc_total_time_nolock(Playlist *playlist)
2916 } 2918 }
2917 2919
2918 static void 2920 static void
2919 playlist_recalc_total_time(Playlist *playlist) 2921 playlist_recalc_total_time(Playlist *playlist)
2920 { 2922 {
2921 PLAYLIST_LOCK(playlist->mutex); 2923 PLAYLIST_LOCK(playlist);
2922 playlist_recalc_total_time_nolock(playlist); 2924 playlist_recalc_total_time_nolock(playlist);
2923 PLAYLIST_UNLOCK(playlist->mutex); 2925 PLAYLIST_UNLOCK(playlist);
2924 } 2926 }
2925 2927
2926 gint 2928 gint
2927 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action ) 2929 playlist_select_search( Playlist *playlist , Tuple *tuple , gint action )
2928 { 2930 {
2934 /* set encoding for Oniguruma regex to UTF-8 */ 2936 /* set encoding for Oniguruma regex to UTF-8 */
2935 reg_set_encoding( REG_POSIX_ENCODING_UTF8 ); 2937 reg_set_encoding( REG_POSIX_ENCODING_UTF8 );
2936 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC ); 2938 onig_set_default_syntax( ONIG_SYNTAX_POSIX_BASIC );
2937 #endif 2939 #endif
2938 2940
2939 PLAYLIST_LOCK(playlist->mutex); 2941 PLAYLIST_LOCK(playlist);
2940 2942
2941 if ( tuple_get_string(tuple, "title") != NULL ) 2943 if ( tuple_get_string(tuple, "title") != NULL )
2942 { 2944 {
2943 /* match by track_name */ 2945 /* match by track_name */
2944 const gchar *regex_pattern = tuple_get_string(tuple, "title"); 2946 const gchar *regex_pattern = tuple_get_string(tuple, "title");
3072 num_of_entries_found++; 3074 num_of_entries_found++;
3073 } 3075 }
3074 3076
3075 g_list_free( found_list ); 3077 g_list_free( found_list );
3076 3078
3077 PLAYLIST_UNLOCK(playlist->mutex); 3079 PLAYLIST_UNLOCK(playlist);
3078 playlist_recalc_total_time(playlist); 3080 playlist_recalc_total_time(playlist);
3079 3081
3080 return num_of_entries_found; 3082 return num_of_entries_found;
3081 } 3083 }
3082 3084
3083 void 3085 void
3084 playlist_select_all(Playlist *playlist, gboolean set) 3086 playlist_select_all(Playlist *playlist, gboolean set)
3085 { 3087 {
3086 GList *list; 3088 GList *list;
3087 3089
3088 PLAYLIST_LOCK(playlist->mutex); 3090 PLAYLIST_LOCK(playlist);
3089 3091
3090 for (list = playlist->entries; list; list = g_list_next(list)) { 3092 for (list = playlist->entries; list; list = g_list_next(list)) {
3091 PlaylistEntry *entry = list->data; 3093 PlaylistEntry *entry = list->data;
3092 entry->selected = set; 3094 entry->selected = set;
3093 } 3095 }
3094 3096
3095 PLAYLIST_UNLOCK(playlist->mutex); 3097 PLAYLIST_UNLOCK(playlist);
3096 playlist_recalc_total_time(playlist); 3098 playlist_recalc_total_time(playlist);
3097 } 3099 }
3098 3100
3099 void 3101 void
3100 playlist_select_invert_all(Playlist *playlist) 3102 playlist_select_invert_all(Playlist *playlist)
3101 { 3103 {
3102 GList *list; 3104 GList *list;
3103 3105
3104 PLAYLIST_LOCK(playlist->mutex); 3106 PLAYLIST_LOCK(playlist);
3105 3107
3106 for (list = playlist->entries; list; list = g_list_next(list)) { 3108 for (list = playlist->entries; list; list = g_list_next(list)) {
3107 PlaylistEntry *entry = list->data; 3109 PlaylistEntry *entry = list->data;
3108 entry->selected = !entry->selected; 3110 entry->selected = !entry->selected;
3109 } 3111 }
3110 3112
3111 PLAYLIST_UNLOCK(playlist->mutex); 3113 PLAYLIST_UNLOCK(playlist);
3112 playlist_recalc_total_time(playlist); 3114 playlist_recalc_total_time(playlist);
3113 } 3115 }
3114 3116
3115 gboolean 3117 gboolean
3116 playlist_select_invert(Playlist *playlist, guint pos) 3118 playlist_select_invert(Playlist *playlist, guint pos)
3117 { 3119 {
3118 GList *list; 3120 GList *list;
3119 gboolean invert_ok = FALSE; 3121 gboolean invert_ok = FALSE;
3120 3122
3121 PLAYLIST_LOCK(playlist->mutex); 3123 PLAYLIST_LOCK(playlist);
3122 3124
3123 if ((list = g_list_nth(playlist->entries, pos))) { 3125 if ((list = g_list_nth(playlist->entries, pos))) {
3124 PlaylistEntry *entry = list->data; 3126 PlaylistEntry *entry = list->data;
3125 entry->selected = !entry->selected; 3127 entry->selected = !entry->selected;
3126 invert_ok = TRUE; 3128 invert_ok = TRUE;
3127 } 3129 }
3128 3130
3129 PLAYLIST_UNLOCK(playlist->mutex); 3131 PLAYLIST_UNLOCK(playlist);
3130 playlist_recalc_total_time(playlist); 3132 playlist_recalc_total_time(playlist);
3131 3133
3132 return invert_ok; 3134 return invert_ok;
3133 } 3135 }
3134 3136
3140 gint i; 3142 gint i;
3141 3143
3142 if (min_pos > max_pos) 3144 if (min_pos > max_pos)
3143 SWAP(min_pos, max_pos); 3145 SWAP(min_pos, max_pos);
3144 3146
3145 PLAYLIST_LOCK(playlist->mutex); 3147 PLAYLIST_LOCK(playlist);
3146 3148
3147 list = g_list_nth(playlist->entries, min_pos); 3149 list = g_list_nth(playlist->entries, min_pos);
3148 for (i = min_pos; i <= max_pos && list; i++) { 3150 for (i = min_pos; i <= max_pos && list; i++) {
3149 PlaylistEntry *entry = list->data; 3151 PlaylistEntry *entry = list->data;
3150 entry->selected = select; 3152 entry->selected = select;
3151 list = g_list_next(list); 3153 list = g_list_next(list);
3152 } 3154 }
3153 3155
3154 PLAYLIST_UNLOCK(playlist->mutex); 3156 PLAYLIST_UNLOCK(playlist);
3155 3157
3156 playlist_recalc_total_time(playlist); 3158 playlist_recalc_total_time(playlist);
3157 } 3159 }
3158 3160
3159 gboolean 3161 gboolean
3160 playlist_read_info_selection(Playlist *playlist) 3162 playlist_read_info_selection(Playlist *playlist)
3161 { 3163 {
3162 GList *node; 3164 GList *node;
3163 gboolean retval = FALSE; 3165 gboolean retval = FALSE;
3164 3166
3165 PLAYLIST_LOCK(playlist->mutex); 3167 PLAYLIST_LOCK(playlist);
3166 3168
3167 for (node = playlist->entries; node; node = g_list_next(node)) { 3169 for (node = playlist->entries; node; node = g_list_next(node)) {
3168 PlaylistEntry *entry = node->data; 3170 PlaylistEntry *entry = node->data;
3169 if (!entry->selected) 3171 if (!entry->selected)
3170 continue; 3172 continue;
3183 /* Entry disappeared while we looked it up. Restart. */ 3185 /* Entry disappeared while we looked it up. Restart. */
3184 node = playlist->entries; 3186 node = playlist->entries;
3185 } 3187 }
3186 } 3188 }
3187 3189
3188 PLAYLIST_UNLOCK(playlist->mutex); 3190 PLAYLIST_UNLOCK(playlist);
3189 3191
3190 playlistwin_update_list(playlist); 3192 playlistwin_update_list(playlist);
3191 playlist_recalc_total_time(playlist); 3193 playlist_recalc_total_time(playlist);
3192 3194
3193 return retval; 3195 return retval;
3196 void 3198 void
3197 playlist_read_info(Playlist *playlist, guint pos) 3199 playlist_read_info(Playlist *playlist, guint pos)
3198 { 3200 {
3199 GList *node; 3201 GList *node;
3200 3202
3201 PLAYLIST_LOCK(playlist->mutex); 3203 PLAYLIST_LOCK(playlist);
3202 3204
3203 if ((node = g_list_nth(playlist->entries, pos))) { 3205 if ((node = g_list_nth(playlist->entries, pos))) {
3204 PlaylistEntry *entry = node->data; 3206 PlaylistEntry *entry = node->data;
3205 str_replace_in(&entry->title, NULL); 3207 str_replace_in(&entry->title, NULL);
3206 entry->length = -1; 3208 entry->length = -1;
3207 playlist_entry_get_info(entry); 3209 playlist_entry_get_info(entry);
3208 } 3210 }
3209 3211
3210 PLAYLIST_UNLOCK(playlist->mutex); 3212 PLAYLIST_UNLOCK(playlist);
3211 3213
3212 playlistwin_update_list(playlist); 3214 playlistwin_update_list(playlist);
3213 playlist_recalc_total_time(playlist); 3215 playlist_recalc_total_time(playlist);
3214 } 3216 }
3215 3217
3230 { 3232 {
3231 Playlist *playlist = playlist_get_active(); 3233 Playlist *playlist = playlist_get_active();
3232 if (!playlist) 3234 if (!playlist)
3233 return; 3235 return;
3234 3236
3235 PLAYLIST_LOCK(playlist->mutex); 3237 PLAYLIST_LOCK(playlist);
3236 3238
3237 playlist_position_before_jump = NULL; 3239 playlist_position_before_jump = NULL;
3238 3240
3239 cfg.shuffle = shuffle; 3241 cfg.shuffle = shuffle;
3240 playlist_generate_shuffle_list_nolock(playlist); 3242 playlist_generate_shuffle_list_nolock(playlist);
3241 3243
3242 PLAYLIST_UNLOCK(playlist->mutex); 3244 PLAYLIST_UNLOCK(playlist);
3243 } 3245 }
3244 3246
3245 Playlist * 3247 Playlist *
3246 playlist_new(void) 3248 playlist_new(void)
3247 { 3249 {
3272 Playlist *playlist = playlist_get_active(); 3274 Playlist *playlist = playlist_get_active();
3273 GList *list = playlist_get_selected(playlist); 3275 GList *list = playlist_get_selected(playlist);
3274 3276
3275 playlist_add_playlist( newpl ); 3277 playlist_add_playlist( newpl );
3276 3278
3277 PLAYLIST_LOCK(playlist->mutex); 3279 PLAYLIST_LOCK(playlist);
3278 3280
3279 while ( list != NULL ) 3281 while ( list != NULL )
3280 { 3282 {
3281 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data)); 3283 PlaylistEntry *entry = g_list_nth_data(playlist->entries, GPOINTER_TO_INT(list->data));
3282 if ( entry->filename != NULL ) /* paranoid? oh well... */ 3284 if ( entry->filename != NULL ) /* paranoid? oh well... */
3283 playlist_add( newpl , entry->filename ); 3285 playlist_add( newpl , entry->filename );
3284 list = g_list_next(list); 3286 list = g_list_next(list);
3285 } 3287 }
3286 3288
3287 PLAYLIST_UNLOCK(playlist->mutex); 3289 PLAYLIST_UNLOCK(playlist);
3288 3290
3289 playlist_recalc_total_time(newpl); 3291 playlist_recalc_total_time(newpl);
3290 playlistwin_update_list(playlist); 3292 playlistwin_update_list(playlist);
3291 3293
3292 return newpl; 3294 return newpl;
3298 const gchar *filename = NULL; 3300 const gchar *filename = NULL;
3299 3301
3300 if (!playlist) 3302 if (!playlist)
3301 return NULL; 3303 return NULL;
3302 3304
3303 PLAYLIST_LOCK(playlist->mutex); 3305 PLAYLIST_LOCK(playlist);
3304 3306
3305 if (!playlist->position) { 3307 if (!playlist->position) {
3306 if (cfg.shuffle) 3308 if (cfg.shuffle)
3307 playlist->position = playlist->shuffle->data; 3309 playlist->position = playlist->shuffle->data;
3308 else 3310 else
3309 playlist->position = playlist->entries->data; 3311 playlist->position = playlist->entries->data;
3310 } 3312 }
3311 3313
3312 filename = playlist->position->filename; 3314 filename = playlist->position->filename;
3313 3315
3314 PLAYLIST_UNLOCK(playlist->mutex); 3316 PLAYLIST_UNLOCK(playlist);
3315 3317
3316 return filename; 3318 return filename;
3317 } 3319 }
3318 3320
3319 PlaylistEntry * 3321 PlaylistEntry *
3320 playlist_get_entry_to_play(Playlist *playlist) 3322 playlist_get_entry_to_play(Playlist *playlist)
3321 { 3323 {
3322 if (!playlist) 3324 if (!playlist)
3323 return NULL; 3325 return NULL;
3324 3326
3325 PLAYLIST_LOCK(playlist->mutex); 3327 PLAYLIST_LOCK(playlist);
3326 3328
3327 if (!playlist->position) { 3329 if (!playlist->position) {
3328 if (cfg.shuffle) 3330 if (cfg.shuffle)
3329 playlist->position = playlist->shuffle->data; 3331 playlist->position = playlist->shuffle->data;
3330 else 3332 else
3331 playlist->position = playlist->entries->data; 3333 playlist->position = playlist->entries->data;
3332 } 3334 }
3333 3335
3334 PLAYLIST_UNLOCK(playlist->mutex); 3336 PLAYLIST_UNLOCK(playlist);
3335 3337
3336 return playlist->position; 3338 return playlist->position;
3337 } 3339 }