2002-06-04 21:43:38 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by wavey@wavey.org
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-06-04 21:43:38 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
Dynamic playlist design (based on design originally proposed by ricII)
|
|
|
|
|
|
|
|
There are two files associated with a dynamic playlist:
|
|
|
|
1. Playlist file : This file contains the initial songs in the playlist.
|
|
|
|
The file is created by the user and stored on the hard
|
|
|
|
drive. NOTE: If we are playing the contents of a
|
|
|
|
directory, there will be no playlist file.
|
|
|
|
2. Control file : This file is automatically created when a playlist is
|
|
|
|
started and contains all the commands done to it.
|
|
|
|
|
|
|
|
The first non-comment line in a control file must begin with
|
|
|
|
"P:VERSION:DIR:FILE" where VERSION is the playlist control file version,
|
|
|
|
DIR is the directory where the playlist is located and FILE is the
|
|
|
|
playlist filename. For dirplay, FILE will be empty. An empty playlist
|
|
|
|
will have both entries as null.
|
|
|
|
|
|
|
|
Control file commands:
|
|
|
|
a. Add track (A:<position>:<last position>:<path to track>)
|
|
|
|
- Insert a track at the specified position in the current
|
|
|
|
playlist. Last position is used to specify where last insertion
|
|
|
|
occurred.
|
|
|
|
b. Queue track (Q:<position>:<last position>:<path to track>)
|
|
|
|
- Queue a track at the specified position in the current
|
|
|
|
playlist. Queued tracks differ from added tracks in that they
|
|
|
|
are deleted from the playlist as soon as they are played and
|
|
|
|
they are not saved to disk as part of the playlist.
|
|
|
|
c. Delete track (D:<position>)
|
|
|
|
- Delete track from specified position in the current playlist.
|
|
|
|
d. Shuffle playlist (S:<seed>:<index>)
|
|
|
|
- Shuffle entire playlist with specified seed. The index
|
|
|
|
identifies the first index in the newly shuffled playlist
|
|
|
|
(needed for repeat mode).
|
|
|
|
e. Unshuffle playlist (U:<index>)
|
|
|
|
- Unshuffle entire playlist. The index identifies the first index
|
|
|
|
in the newly unshuffled playlist.
|
|
|
|
f. Reset last insert position (R)
|
|
|
|
- Needed so that insertions work properly after resume
|
|
|
|
|
|
|
|
Resume:
|
|
|
|
The only resume info that needs to be saved is the current index in the
|
|
|
|
playlist and the position in the track. When resuming, all the commands
|
|
|
|
in the control file will be reapplied so that the playlist indices are
|
2004-01-26 17:05:21 +00:00
|
|
|
exactly the same as before shutdown. To avoid unnecessary disk
|
|
|
|
accesses, the shuffle mode settings are also saved in settings and only
|
|
|
|
flushed to disk when required.
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
|
|
|
|
2002-06-04 21:43:38 +00:00
|
|
|
#include <stdio.h>
|
2010-05-06 21:04:40 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "string-extra.h"
|
2002-06-04 21:43:38 +00:00
|
|
|
#include "playlist.h"
|
2008-04-30 09:23:12 +00:00
|
|
|
#include "ata_idle_notify.h"
|
2003-01-09 00:55:00 +00:00
|
|
|
#include "file.h"
|
2006-08-15 12:27:07 +00:00
|
|
|
#include "action.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
#include "dir.h"
|
2002-06-04 21:43:38 +00:00
|
|
|
#include "debug.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
#include "audio.h"
|
2002-06-13 15:16:41 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "kernel.h"
|
2002-06-27 10:10:30 +00:00
|
|
|
#include "settings.h"
|
2002-08-07 10:35:26 +00:00
|
|
|
#include "status.h"
|
2002-08-15 12:28:52 +00:00
|
|
|
#include "applimits.h"
|
2003-03-18 23:11:12 +00:00
|
|
|
#include "screens.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
#include "misc.h"
|
2010-08-01 16:15:27 +00:00
|
|
|
#include "filefuncs.h"
|
2003-07-01 21:05:43 +00:00
|
|
|
#include "button.h"
|
2005-01-17 11:39:46 +00:00
|
|
|
#include "filetree.h"
|
2005-08-21 23:01:12 +00:00
|
|
|
#include "abrepeat.h"
|
2005-11-17 19:31:29 +00:00
|
|
|
#include "thread.h"
|
|
|
|
#include "usb.h"
|
2007-04-18 13:03:01 +00:00
|
|
|
#include "filetypes.h"
|
2002-08-07 10:35:26 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2002-08-20 19:39:55 +00:00
|
|
|
#include "icons.h"
|
|
|
|
#endif
|
2009-03-08 16:10:40 +00:00
|
|
|
#include "system.h"
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2002-09-18 14:08:05 +00:00
|
|
|
#include "lang.h"
|
2004-03-14 21:33:53 +00:00
|
|
|
#include "talk.h"
|
2005-11-06 17:30:53 +00:00
|
|
|
#include "splash.h"
|
2006-11-29 19:22:44 +00:00
|
|
|
#include "rbunicode.h"
|
2007-10-12 04:20:20 +00:00
|
|
|
#include "root_menu.h"
|
2011-07-21 06:40:21 +00:00
|
|
|
#include "plugin.h" /* To borrow a temp buffer to rewrite a .m3u8 file */
|
2002-09-18 14:08:05 +00:00
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
#define PLAYLIST_CONTROL_FILE_VERSION 2
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Each playlist index has a flag associated with it which identifies what
|
2005-10-21 06:40:45 +00:00
|
|
|
type of track it is. These flags are stored in the 4 high order bits of
|
2003-07-01 21:05:43 +00:00
|
|
|
the index.
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
NOTE: This limits the playlist file size to a max of 256M.
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
Bits 31-30:
|
|
|
|
00 = Playlist track
|
|
|
|
01 = Track was prepended into playlist
|
|
|
|
10 = Track was inserted into playlist
|
|
|
|
11 = Track was appended into playlist
|
|
|
|
Bit 29:
|
|
|
|
0 = Added track
|
|
|
|
1 = Queued track
|
2005-10-21 06:40:45 +00:00
|
|
|
Bit 28:
|
|
|
|
0 = Track entry is valid
|
|
|
|
1 = Track does not exist on disk and should be skipped
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
2005-10-21 07:25:19 +00:00
|
|
|
#define PLAYLIST_SEEK_MASK 0x0FFFFFFF
|
2003-07-01 21:05:43 +00:00
|
|
|
#define PLAYLIST_INSERT_TYPE_MASK 0xC0000000
|
|
|
|
#define PLAYLIST_QUEUE_MASK 0x20000000
|
|
|
|
|
|
|
|
#define PLAYLIST_INSERT_TYPE_PREPEND 0x40000000
|
|
|
|
#define PLAYLIST_INSERT_TYPE_INSERT 0x80000000
|
|
|
|
#define PLAYLIST_INSERT_TYPE_APPEND 0xC0000000
|
2003-03-07 14:38:51 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
#define PLAYLIST_QUEUED 0x20000000
|
2005-10-21 06:40:45 +00:00
|
|
|
#define PLAYLIST_SKIPPED 0x10000000
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
struct directory_search_context {
|
|
|
|
struct playlist_info* playlist;
|
|
|
|
int position;
|
|
|
|
bool queue;
|
|
|
|
int count;
|
|
|
|
};
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
static struct playlist_info current_playlist;
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
static void empty_playlist(struct playlist_info* playlist, bool resume);
|
2004-08-18 01:09:31 +00:00
|
|
|
static void new_playlist(struct playlist_info* playlist, const char *dir,
|
|
|
|
const char *file);
|
2004-01-26 17:05:21 +00:00
|
|
|
static void create_control(struct playlist_info* playlist);
|
|
|
|
static int check_control(struct playlist_info* playlist);
|
2006-02-09 09:09:32 +00:00
|
|
|
static int recreate_control(struct playlist_info* playlist);
|
2004-01-26 17:05:21 +00:00
|
|
|
static void update_playlist_filename(struct playlist_info* playlist,
|
2004-08-18 01:09:31 +00:00
|
|
|
const char *dir, const char *file);
|
2004-01-26 17:05:21 +00:00
|
|
|
static int add_indices_to_playlist(struct playlist_info* playlist,
|
2006-11-06 18:07:30 +00:00
|
|
|
char* buffer, size_t buflen);
|
2004-01-26 17:05:21 +00:00
|
|
|
static int add_track_to_playlist(struct playlist_info* playlist,
|
2005-07-01 11:25:16 +00:00
|
|
|
const char *filename, int position,
|
2004-08-18 01:09:31 +00:00
|
|
|
bool queue, int seek_pos);
|
2006-07-18 13:54:12 +00:00
|
|
|
static int directory_search_callback(char* filename, void* context);
|
2004-01-26 17:05:21 +00:00
|
|
|
static int remove_track_from_playlist(struct playlist_info* playlist,
|
|
|
|
int position, bool write);
|
|
|
|
static int randomise_playlist(struct playlist_info* playlist,
|
|
|
|
unsigned int seed, bool start_current,
|
2003-07-01 21:05:43 +00:00
|
|
|
bool write);
|
2004-01-26 17:05:21 +00:00
|
|
|
static int sort_playlist(struct playlist_info* playlist, bool start_current,
|
|
|
|
bool write);
|
2005-06-25 06:28:55 +00:00
|
|
|
static int get_next_index(const struct playlist_info* playlist, int steps,
|
2005-06-25 04:46:25 +00:00
|
|
|
int repeat_mode);
|
2004-01-26 17:05:21 +00:00
|
|
|
static void find_and_set_playlist_index(struct playlist_info* playlist,
|
|
|
|
unsigned int seek);
|
2003-07-01 21:05:43 +00:00
|
|
|
static int compare(const void* p1, const void* p2);
|
2005-11-17 19:31:29 +00:00
|
|
|
static int get_filename(struct playlist_info* playlist, int index, int seek,
|
2004-01-26 17:05:21 +00:00
|
|
|
bool control_file, char *buf, int buf_length);
|
2005-07-01 11:25:16 +00:00
|
|
|
static int get_next_directory(char *dir);
|
2005-11-02 22:32:04 +00:00
|
|
|
static int get_next_dir(char *dir, bool is_forward, bool recursion);
|
|
|
|
static int get_previous_directory(char *dir);
|
2008-10-08 16:32:01 +00:00
|
|
|
static int check_subdir_for_music(char *dir, const char *subdir, bool recurse);
|
2003-07-01 21:05:43 +00:00
|
|
|
static int format_track_path(char *dest, char *src, int buf_length, int max,
|
2008-05-12 17:52:50 +00:00
|
|
|
const char *dir);
|
2007-08-06 13:08:36 +00:00
|
|
|
static void display_playlist_count(int count, const unsigned char *fmt,
|
|
|
|
bool final);
|
2003-07-01 21:05:43 +00:00
|
|
|
static void display_buffer_full(void);
|
2006-02-05 18:17:41 +00:00
|
|
|
static int flush_cached_control(struct playlist_info* playlist);
|
|
|
|
static int update_control(struct playlist_info* playlist,
|
|
|
|
enum playlist_command command, int i1, int i2,
|
|
|
|
const char* s1, const char* s2, void* data);
|
|
|
|
static void sync_control(struct playlist_info* playlist, bool force);
|
2004-08-18 01:09:31 +00:00
|
|
|
static int rotate_index(const struct playlist_info* playlist, int index);
|
2003-04-24 17:31:36 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
#define PLAYLIST_LOAD_POINTERS 1
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
static struct event_queue playlist_queue SHAREDBSS_ATTR;
|
2006-11-30 19:42:41 +00:00
|
|
|
static long playlist_stack[(DEFAULT_STACK_SIZE + 0x800)/sizeof(long)];
|
2005-11-17 19:31:29 +00:00
|
|
|
static const char playlist_thread_name[] = "playlist cachectrl";
|
|
|
|
#endif
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
static struct mutex current_playlist_mutex SHAREDBSS_ATTR;
|
|
|
|
static struct mutex created_playlist_mutex SHAREDBSS_ATTR;
|
|
|
|
|
2007-11-13 18:49:20 +00:00
|
|
|
/* Check if the filename suggests M3U or M3U8 format. */
|
|
|
|
static bool is_m3u8(const char* filename)
|
|
|
|
{
|
|
|
|
int len = strlen(filename);
|
|
|
|
|
|
|
|
/* Default to M3U8 unless explicitly told otherwise. */
|
|
|
|
return !(len > 4 && strcasecmp(&filename[len - 4], ".m3u") == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Convert a filename in an M3U playlist to UTF-8.
|
|
|
|
*
|
|
|
|
* buf - the filename to convert; can contain more than one line from the
|
|
|
|
* playlist.
|
|
|
|
* buf_len - amount of buf that is used.
|
|
|
|
* buf_max - total size of buf.
|
|
|
|
* temp - temporary conversion buffer, at least buf_max bytes.
|
|
|
|
*
|
|
|
|
* Returns the length of the converted filename.
|
|
|
|
*/
|
|
|
|
static int convert_m3u(char* buf, int buf_len, int buf_max, char* temp)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
char* dest;
|
|
|
|
|
|
|
|
/* Locate EOL. */
|
|
|
|
while ((buf[i] != '\n') && (buf[i] != '\r') && (i < buf_len))
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Work back killing white space. */
|
|
|
|
while ((i > 0) && isspace(buf[i - 1]))
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf_len = i;
|
|
|
|
dest = temp;
|
|
|
|
|
|
|
|
/* Convert char by char, so as to not overflow temp (iso_decode should
|
|
|
|
* preferably handle this). No more than 4 bytes should be generated for
|
|
|
|
* each input char.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < buf_len && dest < (temp + buf_max - 4); i++)
|
|
|
|
{
|
|
|
|
dest = iso_decode(&buf[i], dest, -1, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
*dest = 0;
|
|
|
|
strcpy(buf, temp);
|
|
|
|
return dest - temp;
|
|
|
|
}
|
|
|
|
|
2003-01-09 00:55:00 +00:00
|
|
|
/*
|
|
|
|
* remove any files and indices associated with the playlist
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static void empty_playlist(struct playlist_info* playlist, bool resume)
|
2002-08-06 13:09:48 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->filename[0] = '\0';
|
2006-11-29 19:22:44 +00:00
|
|
|
playlist->utf8 = true;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if(playlist->fd >= 0)
|
2003-04-23 18:45:51 +00:00
|
|
|
/* If there is an already open playlist, close it. */
|
2004-01-26 17:05:21 +00:00
|
|
|
close(playlist->fd);
|
|
|
|
playlist->fd = -1;
|
|
|
|
|
|
|
|
if(playlist->control_fd >= 0)
|
|
|
|
close(playlist->control_fd);
|
|
|
|
playlist->control_fd = -1;
|
|
|
|
playlist->control_created = false;
|
|
|
|
|
|
|
|
playlist->in_ram = false;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->buffer)
|
|
|
|
playlist->buffer[0] = 0;
|
|
|
|
|
|
|
|
playlist->buffer_end_pos = 0;
|
|
|
|
|
|
|
|
playlist->index = 0;
|
|
|
|
playlist->first_index = 0;
|
|
|
|
playlist->amount = 0;
|
|
|
|
playlist->last_insert_pos = -1;
|
|
|
|
playlist->seed = 0;
|
|
|
|
playlist->shuffle_modified = false;
|
|
|
|
playlist->deleted = false;
|
|
|
|
playlist->num_inserted_tracks = 0;
|
2006-04-19 02:22:23 +00:00
|
|
|
playlist->started = false;
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
playlist->num_cached = 0;
|
|
|
|
playlist->pending_control_sync = false;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
if (!resume && playlist->current)
|
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
/* start with fresh playlist control file when starting new
|
|
|
|
playlist */
|
2004-01-26 17:05:21 +00:00
|
|
|
create_control(playlist);
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2002-08-06 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/*
|
|
|
|
* Initialize a new playlist for viewing/editing/playing. dir is the
|
|
|
|
* directory where the playlist is located and file is the filename.
|
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static void new_playlist(struct playlist_info* playlist, const char *dir,
|
|
|
|
const char *file)
|
2004-01-26 17:05:21 +00:00
|
|
|
{
|
2008-05-12 17:52:50 +00:00
|
|
|
const char *fileused = file;
|
|
|
|
const char *dirused = dir;
|
2004-01-26 17:05:21 +00:00
|
|
|
empty_playlist(playlist, false);
|
|
|
|
|
2008-05-12 17:52:50 +00:00
|
|
|
if (!fileused)
|
2004-01-26 17:05:21 +00:00
|
|
|
{
|
2008-05-12 17:52:50 +00:00
|
|
|
fileused = "";
|
2004-01-26 17:05:21 +00:00
|
|
|
|
2008-05-12 17:52:50 +00:00
|
|
|
if (dirused && playlist->current) /* !current cannot be in_ram */
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->in_ram = true;
|
|
|
|
else
|
2008-05-12 17:52:50 +00:00
|
|
|
dirused = ""; /* empty playlist */
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
2008-05-12 17:52:50 +00:00
|
|
|
update_playlist_filename(playlist, dirused, fileused);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
update_control(playlist, PLAYLIST_COMMAND_PLAYLIST,
|
2008-05-12 17:52:50 +00:00
|
|
|
PLAYLIST_CONTROL_FILE_VERSION, -1, dirused, fileused, NULL);
|
2006-02-05 18:17:41 +00:00
|
|
|
sync_control(playlist, false);
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* create control file for playlist
|
|
|
|
*/
|
|
|
|
static void create_control(struct playlist_info* playlist)
|
|
|
|
{
|
2005-01-20 16:24:26 +00:00
|
|
|
playlist->control_fd = open(playlist->control_filename,
|
2010-05-06 17:35:13 +00:00
|
|
|
O_CREAT|O_RDWR|O_TRUNC, 0666);
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->control_fd < 0)
|
2004-08-02 05:11:20 +00:00
|
|
|
{
|
2004-09-10 20:51:12 +00:00
|
|
|
if (check_rockboxdir())
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
cond_talk_ids_fq(LANG_PLAYLIST_CONTROL_ACCESS_ERROR);
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(HZ*2, (unsigned char *)"%s (%d)",
|
2005-12-05 22:44:42 +00:00
|
|
|
str(LANG_PLAYLIST_CONTROL_ACCESS_ERROR),
|
|
|
|
playlist->control_fd);
|
2004-09-10 20:51:12 +00:00
|
|
|
}
|
|
|
|
playlist->control_created = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playlist->control_created = true;
|
2004-08-02 05:11:20 +00:00
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* validate the control file. This may include creating/initializing it if
|
|
|
|
* necessary;
|
|
|
|
*/
|
|
|
|
static int check_control(struct playlist_info* playlist)
|
|
|
|
{
|
|
|
|
if (!playlist->control_created)
|
|
|
|
{
|
|
|
|
create_control(playlist);
|
|
|
|
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
{
|
|
|
|
char* dir = playlist->filename;
|
|
|
|
char* file = playlist->filename+playlist->dirlen;
|
|
|
|
char c = playlist->filename[playlist->dirlen-1];
|
|
|
|
|
|
|
|
playlist->filename[playlist->dirlen-1] = '\0';
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
update_control(playlist, PLAYLIST_COMMAND_PLAYLIST,
|
|
|
|
PLAYLIST_CONTROL_FILE_VERSION, -1, dir, file, NULL);
|
|
|
|
sync_control(playlist, false);
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->filename[playlist->dirlen-1] = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playlist->control_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-09 09:09:32 +00:00
|
|
|
/*
|
|
|
|
* recreate the control file based on current playlist entries
|
|
|
|
*/
|
|
|
|
static int recreate_control(struct playlist_info* playlist)
|
|
|
|
{
|
|
|
|
char temp_file[MAX_PATH+1];
|
|
|
|
int temp_fd = -1;
|
|
|
|
int i;
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if(playlist->control_fd >= 0)
|
|
|
|
{
|
|
|
|
char* dir = playlist->filename;
|
|
|
|
char* file = playlist->filename+playlist->dirlen;
|
|
|
|
char c = playlist->filename[playlist->dirlen-1];
|
|
|
|
|
|
|
|
close(playlist->control_fd);
|
|
|
|
|
|
|
|
snprintf(temp_file, sizeof(temp_file), "%s_temp",
|
|
|
|
playlist->control_filename);
|
|
|
|
|
|
|
|
if (rename(playlist->control_filename, temp_file) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
temp_fd = open(temp_file, O_RDONLY);
|
|
|
|
if (temp_fd < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
playlist->control_fd = open(playlist->control_filename,
|
2010-05-06 17:35:13 +00:00
|
|
|
O_CREAT|O_RDWR|O_TRUNC, 0666);
|
2006-02-09 09:09:32 +00:00
|
|
|
if (playlist->control_fd < 0)
|
2011-08-25 19:39:01 +00:00
|
|
|
{
|
|
|
|
close(temp_fd);
|
2006-02-09 09:09:32 +00:00
|
|
|
return -1;
|
2011-08-25 19:39:01 +00:00
|
|
|
}
|
2006-02-09 09:09:32 +00:00
|
|
|
|
|
|
|
playlist->filename[playlist->dirlen-1] = '\0';
|
2011-08-25 19:39:01 +00:00
|
|
|
|
2006-02-09 09:09:32 +00:00
|
|
|
/* cannot call update_control() because of mutex */
|
|
|
|
result = fdprintf(playlist->control_fd, "P:%d:%s:%s\n",
|
|
|
|
PLAYLIST_CONTROL_FILE_VERSION, dir, file);
|
|
|
|
|
|
|
|
playlist->filename[playlist->dirlen-1] = c;
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
{
|
|
|
|
close(temp_fd);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist->seed = 0;
|
|
|
|
playlist->shuffle_modified = false;
|
|
|
|
playlist->deleted = false;
|
|
|
|
playlist->num_inserted_tracks = 0;
|
|
|
|
|
|
|
|
for (i=0; i<playlist->amount; i++)
|
|
|
|
{
|
|
|
|
if (playlist->indices[i] & PLAYLIST_INSERT_TYPE_MASK)
|
|
|
|
{
|
|
|
|
bool queue = playlist->indices[i] & PLAYLIST_QUEUE_MASK;
|
|
|
|
char inserted_file[MAX_PATH+1];
|
|
|
|
|
|
|
|
lseek(temp_fd, playlist->indices[i] & PLAYLIST_SEEK_MASK,
|
|
|
|
SEEK_SET);
|
|
|
|
read_line(temp_fd, inserted_file, sizeof(inserted_file));
|
|
|
|
|
|
|
|
result = fdprintf(playlist->control_fd, "%c:%d:%d:",
|
|
|
|
queue?'Q':'A', i, playlist->last_insert_pos);
|
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
/* save the position in file where name is written */
|
|
|
|
int seek_pos = lseek(playlist->control_fd, 0, SEEK_CUR);
|
|
|
|
|
|
|
|
result = fdprintf(playlist->control_fd, "%s\n",
|
|
|
|
inserted_file);
|
|
|
|
|
|
|
|
playlist->indices[i] =
|
|
|
|
(playlist->indices[i] & ~PLAYLIST_SEEK_MASK) | seek_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
playlist->num_inserted_tracks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(temp_fd);
|
|
|
|
remove(temp_file);
|
|
|
|
fsync(playlist->control_fd);
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* store directory and name of playlist file
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static void update_playlist_filename(struct playlist_info* playlist,
|
2004-08-18 01:09:31 +00:00
|
|
|
const char *dir, const char *file)
|
2002-08-06 13:09:48 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
char *sep="";
|
|
|
|
int dirlen = strlen(dir);
|
2006-11-29 19:22:44 +00:00
|
|
|
|
2007-11-13 18:49:20 +00:00
|
|
|
playlist->utf8 = is_m3u8(file);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* If the dir does not end in trailing slash, we use a separator.
|
|
|
|
Otherwise we don't. */
|
|
|
|
if('/' != dir[dirlen-1])
|
|
|
|
{
|
|
|
|
sep="/";
|
|
|
|
dirlen++;
|
|
|
|
}
|
2004-09-01 21:34:20 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->dirlen = dirlen;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
snprintf(playlist->filename, sizeof(playlist->filename),
|
2005-07-01 11:25:16 +00:00
|
|
|
"%s%s%s", dir, sep, file);
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* calculate track offsets within a playlist file
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static int add_indices_to_playlist(struct playlist_info* playlist,
|
2006-11-06 18:07:30 +00:00
|
|
|
char* buffer, size_t buflen)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
unsigned int nread;
|
|
|
|
unsigned int i = 0;
|
|
|
|
unsigned int count = 0;
|
2003-01-09 00:55:00 +00:00
|
|
|
bool store_index;
|
2003-07-01 21:05:43 +00:00
|
|
|
unsigned char *p;
|
2006-04-03 14:25:47 +00:00
|
|
|
int result = 0;
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if(-1 == playlist->fd)
|
2008-08-02 20:39:03 +00:00
|
|
|
playlist->fd = open_utf8(playlist->filename, O_RDONLY);
|
2004-01-26 17:05:21 +00:00
|
|
|
if(playlist->fd < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1; /* failure */
|
2008-08-09 11:43:56 +00:00
|
|
|
if((i = lseek(playlist->fd, 0, SEEK_CUR)) > 0)
|
2008-08-02 20:39:03 +00:00
|
|
|
playlist->utf8 = true; /* Override any earlier indication. */
|
2008-08-09 11:43:56 +00:00
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_WAIT));
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!buffer)
|
|
|
|
{
|
|
|
|
/* use mp3 buffer for maximum load speed */
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_stop();
|
2011-08-14 15:13:00 +00:00
|
|
|
buffer = audio_get_buffer(false, &buflen);
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
2008-08-09 11:43:56 +00:00
|
|
|
|
2003-01-09 00:55:00 +00:00
|
|
|
store_index = true;
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
nread = read(playlist->fd, buffer, buflen);
|
2003-07-01 21:05:43 +00:00
|
|
|
/* Terminate on EOF */
|
2003-01-09 00:55:00 +00:00
|
|
|
if(nread <= 0)
|
|
|
|
break;
|
2008-08-09 11:43:56 +00:00
|
|
|
|
2005-12-05 22:44:42 +00:00
|
|
|
p = (unsigned char *)buffer;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
for(count=0; count < nread; count++,p++) {
|
|
|
|
|
|
|
|
/* Are we on a new line? */
|
|
|
|
if((*p == '\n') || (*p == '\r'))
|
|
|
|
{
|
2003-01-09 00:55:00 +00:00
|
|
|
store_index = true;
|
2005-07-01 11:25:16 +00:00
|
|
|
}
|
|
|
|
else if(store_index)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
|
|
|
store_index = false;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if(*p != '#')
|
|
|
|
{
|
2006-04-03 14:25:47 +00:00
|
|
|
if ( playlist->amount >= playlist->max_playlist_size ) {
|
|
|
|
display_buffer_full();
|
|
|
|
result = -1;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* Store a new entry */
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->indices[ playlist->amount ] = i+count;
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
if (playlist->filenames)
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames[ playlist->amount ] = -1;
|
2005-11-17 19:31:29 +00:00
|
|
|
#endif
|
|
|
|
playlist->amount++;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
i+= count;
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-04-03 14:25:47 +00:00
|
|
|
exit:
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2006-04-03 14:25:47 +00:00
|
|
|
return result;
|
2002-08-06 13:09:48 +00:00
|
|
|
}
|
|
|
|
|
2007-10-25 19:18:20 +00:00
|
|
|
/*
|
|
|
|
* Utility function to create a new playlist, fill it with the next or
|
|
|
|
* previous directory, shuffle it if needed, and start playback.
|
|
|
|
* If play_last is true and direction zero or negative, start playing
|
|
|
|
* the last file in the directory, otherwise start playing the first.
|
|
|
|
*/
|
|
|
|
static int create_and_play_dir(int direction, bool play_last)
|
|
|
|
{
|
|
|
|
char dir[MAX_PATH + 1];
|
|
|
|
int res;
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
if(direction > 0)
|
|
|
|
res = get_next_directory(dir);
|
|
|
|
else
|
|
|
|
res = get_previous_directory(dir);
|
|
|
|
|
|
|
|
if (!res)
|
|
|
|
{
|
|
|
|
if (playlist_create(dir, NULL) != -1)
|
|
|
|
{
|
|
|
|
ft_build_playlist(tree_get_context(), 0);
|
|
|
|
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
playlist_shuffle(current_tick, -1);
|
|
|
|
|
|
|
|
if (play_last && direction <= 0)
|
|
|
|
index = current_playlist.amount - 1;
|
|
|
|
else
|
|
|
|
index = 0;
|
|
|
|
|
2011-04-09 13:07:08 +00:00
|
|
|
#if (CONFIG_CODEC == SWCODEC)
|
|
|
|
current_playlist.started = true;
|
|
|
|
#else
|
2007-10-25 19:18:20 +00:00
|
|
|
playlist_start(index, 0);
|
|
|
|
#endif
|
|
|
|
}
|
2008-01-09 20:37:36 +00:00
|
|
|
|
|
|
|
/* we've overwritten the dircache when getting the next/previous dir,
|
|
|
|
so the tree browser context will need to be reloaded */
|
|
|
|
reload_directory();
|
2007-10-25 19:18:20 +00:00
|
|
|
}
|
2008-01-09 20:37:36 +00:00
|
|
|
|
2007-10-25 19:18:20 +00:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2006-12-26 13:31:04 +00:00
|
|
|
/*
|
|
|
|
* Removes all tracks, from the playlist, leaving the presently playing
|
|
|
|
* track queued.
|
|
|
|
*/
|
2008-04-20 11:19:50 +00:00
|
|
|
int playlist_remove_all_tracks(struct playlist_info *playlist)
|
2006-12-26 13:31:04 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
if (playlist == NULL)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
while (playlist->index > 0)
|
|
|
|
if ((result = remove_track_from_playlist(playlist, 0, true)) < 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
while (playlist->amount > 1)
|
|
|
|
if ((result = remove_track_from_playlist(playlist, 1, true)) < 0)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (playlist->amount == 1) {
|
|
|
|
playlist->indices[0] |= PLAYLIST_QUEUED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
2009-10-28 22:27:38 +00:00
|
|
|
* Add track to playlist at specified position. There are seven special
|
2003-07-01 21:05:43 +00:00
|
|
|
* positions that can be specified:
|
2009-10-28 22:27:38 +00:00
|
|
|
* PLAYLIST_PREPEND - Add track at beginning of playlist
|
|
|
|
* PLAYLIST_INSERT - Add track after current song. NOTE: If
|
|
|
|
* there are already inserted tracks then track
|
|
|
|
* is added to the end of the insertion list
|
|
|
|
* PLAYLIST_INSERT_FIRST - Add track immediately after current song, no
|
|
|
|
* matter what other tracks have been inserted
|
|
|
|
* PLAYLIST_INSERT_LAST - Add track to end of playlist
|
|
|
|
* PLAYLIST_INSERT_SHUFFLED - Add track at some random point between the
|
|
|
|
* current playing track and end of playlist
|
|
|
|
* PLAYLIST_INSERT_LAST_SHUFFLED - Add tracks in random order to the end of
|
|
|
|
* the playlist.
|
|
|
|
* PLAYLIST_REPLACE - Erase current playlist, Cue the current track
|
|
|
|
* and inster this track at the end.
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static int add_track_to_playlist(struct playlist_info* playlist,
|
2004-08-18 01:09:31 +00:00
|
|
|
const char *filename, int position,
|
|
|
|
bool queue, int seek_pos)
|
2002-08-28 09:22:44 +00:00
|
|
|
{
|
2006-09-18 20:47:27 +00:00
|
|
|
int insert_position, orig_position;
|
2005-02-12 12:57:16 +00:00
|
|
|
unsigned long flags = PLAYLIST_INSERT_TYPE_INSERT;
|
2003-07-01 21:05:43 +00:00
|
|
|
int i;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2006-09-18 20:47:27 +00:00
|
|
|
insert_position = orig_position = position;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount >= playlist->max_playlist_size)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
display_buffer_full();
|
|
|
|
return -1;
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
switch (position)
|
2002-10-04 08:48:20 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
case PLAYLIST_PREPEND:
|
2006-06-12 23:06:51 +00:00
|
|
|
position = insert_position = playlist->first_index;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case PLAYLIST_INSERT:
|
|
|
|
/* if there are already inserted tracks then add track to end of
|
|
|
|
insertion list else add after current playing track */
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->last_insert_pos >= 0 &&
|
|
|
|
playlist->last_insert_pos < playlist->amount &&
|
|
|
|
(playlist->indices[playlist->last_insert_pos]&
|
2003-07-01 21:05:43 +00:00
|
|
|
PLAYLIST_INSERT_TYPE_MASK) == PLAYLIST_INSERT_TYPE_INSERT)
|
2004-01-26 17:05:21 +00:00
|
|
|
position = insert_position = playlist->last_insert_pos+1;
|
|
|
|
else if (playlist->amount > 0)
|
|
|
|
position = insert_position = playlist->index + 1;
|
2002-10-06 05:50:41 +00:00
|
|
|
else
|
2003-07-01 21:05:43 +00:00
|
|
|
position = insert_position = 0;
|
|
|
|
|
Fix playlist "Insert" a bit.
If insert was used to create a new playlist (e.g. inserting without audio playing), the insert position wasn't updated. Thus, the playlist created was in reversed order (except for the first song).
This was the reason "Insert last" was actually used as Insert in this case. BUT, this one doesn't update the insert position eiterh, but the order of the songs is fine, at least (due to appending).
Now, insert always updates the insert position properly, so that the aforementioned bugs are fixed. Insert is always used now.
Other impact: If you create a playlist using insert, every subsequent insert will append songs at the end of the playlist,if you start playback pressing select on songs, every subsequent insert will insert after the current track.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20241 a1c6a512-1295-4272-9138-f99709370657
2009-03-08 17:18:18 +00:00
|
|
|
playlist->last_insert_pos = position;
|
2002-10-04 08:48:20 +00:00
|
|
|
break;
|
2003-07-01 21:05:43 +00:00
|
|
|
case PLAYLIST_INSERT_FIRST:
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount > 0)
|
|
|
|
position = insert_position = playlist->index + 1;
|
2003-07-01 21:05:43 +00:00
|
|
|
else
|
|
|
|
position = insert_position = 0;
|
2002-10-04 08:48:20 +00:00
|
|
|
|
2009-03-08 19:03:53 +00:00
|
|
|
playlist->last_insert_pos = position;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case PLAYLIST_INSERT_LAST:
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->first_index > 0)
|
2006-06-12 23:06:51 +00:00
|
|
|
position = insert_position = playlist->first_index;
|
2003-01-09 00:55:00 +00:00
|
|
|
else
|
2006-06-12 23:06:51 +00:00
|
|
|
position = insert_position = playlist->amount;
|
2009-03-08 19:03:53 +00:00
|
|
|
|
|
|
|
playlist->last_insert_pos = position;
|
2002-10-04 08:48:20 +00:00
|
|
|
break;
|
2005-06-25 04:46:25 +00:00
|
|
|
case PLAYLIST_INSERT_SHUFFLED:
|
|
|
|
{
|
2006-04-19 02:22:23 +00:00
|
|
|
if (playlist->started)
|
2006-04-18 16:44:51 +00:00
|
|
|
{
|
|
|
|
int offset;
|
|
|
|
int n = playlist->amount -
|
|
|
|
rotate_index(playlist, playlist->index);
|
|
|
|
|
|
|
|
if (n > 0)
|
|
|
|
offset = rand() % n;
|
|
|
|
else
|
|
|
|
offset = 0;
|
|
|
|
|
|
|
|
position = playlist->index + offset + 1;
|
|
|
|
if (position >= playlist->amount)
|
|
|
|
position -= playlist->amount;
|
|
|
|
|
|
|
|
insert_position = position;
|
|
|
|
}
|
2005-06-25 04:46:25 +00:00
|
|
|
else
|
2006-04-19 02:22:23 +00:00
|
|
|
position = insert_position = (rand() % (playlist->amount+1));
|
2005-06-25 04:46:25 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-10-28 22:27:38 +00:00
|
|
|
case PLAYLIST_INSERT_LAST_SHUFFLED:
|
|
|
|
{
|
|
|
|
position = insert_position = playlist->last_shuffled_start +
|
|
|
|
rand() % (playlist->amount - playlist->last_shuffled_start + 1);
|
|
|
|
break;
|
|
|
|
}
|
2006-12-26 13:31:04 +00:00
|
|
|
case PLAYLIST_REPLACE:
|
2008-04-20 11:19:50 +00:00
|
|
|
if (playlist_remove_all_tracks(playlist) < 0)
|
2006-12-26 13:31:04 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-03-08 19:03:53 +00:00
|
|
|
playlist->last_insert_pos = position = insert_position = playlist->index + 1;
|
2006-12-26 13:31:04 +00:00
|
|
|
break;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (queue)
|
|
|
|
flags |= PLAYLIST_QUEUED;
|
2002-10-04 08:48:20 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* shift indices so that track can be added */
|
2004-01-26 17:05:21 +00:00
|
|
|
for (i=playlist->amount; i>insert_position; i--)
|
2005-11-17 19:31:29 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->indices[i] = playlist->indices[i-1];
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
if (playlist->filenames)
|
|
|
|
playlist->filenames[i] = playlist->filenames[i-1];
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* update stored indices if needed */
|
|
|
|
|
2010-01-21 07:28:37 +00:00
|
|
|
if (orig_position < 0)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
2010-01-21 07:28:37 +00:00
|
|
|
if (playlist->amount > 0 && insert_position <= playlist->index &&
|
|
|
|
playlist->started)
|
|
|
|
playlist->index++;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2010-01-21 07:28:37 +00:00
|
|
|
if (playlist->amount > 0 && insert_position <= playlist->first_index &&
|
|
|
|
orig_position != PLAYLIST_PREPEND && playlist->started)
|
|
|
|
playlist->first_index++;
|
2003-12-09 08:18:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (insert_position < playlist->last_insert_pos ||
|
|
|
|
(insert_position == playlist->last_insert_pos && position < 0))
|
|
|
|
playlist->last_insert_pos++;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (seek_pos < 0 && playlist->control_fd >= 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
int result = update_control(playlist,
|
|
|
|
(queue?PLAYLIST_COMMAND_QUEUE:PLAYLIST_COMMAND_ADD), position,
|
|
|
|
playlist->last_insert_pos, filename, NULL, &seek_pos);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return result;
|
2002-08-28 09:22:44 +00:00
|
|
|
}
|
2002-10-04 08:48:20 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->indices[insert_position] = flags | seek_pos;
|
2002-10-04 08:48:20 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
if (playlist->filenames)
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames[insert_position] = -1;
|
2005-11-17 19:31:29 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->amount++;
|
|
|
|
playlist->num_inserted_tracks++;
|
2011-04-07 20:33:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return insert_position;
|
2002-10-11 09:14:30 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
2006-07-18 13:54:12 +00:00
|
|
|
* Callback for playlist_directory_tracksearch to insert track into
|
|
|
|
* playlist.
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
2006-07-18 13:54:12 +00:00
|
|
|
static int directory_search_callback(char* filename, void* context)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-07-18 13:54:12 +00:00
|
|
|
struct directory_search_context* c =
|
|
|
|
(struct directory_search_context*) context;
|
|
|
|
int insert_pos;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
insert_pos = add_track_to_playlist(c->playlist, filename, c->position,
|
|
|
|
c->queue, -1);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
if (insert_pos < 0)
|
2005-02-04 13:20:25 +00:00
|
|
|
return -1;
|
2006-07-18 13:54:12 +00:00
|
|
|
|
|
|
|
(c->count)++;
|
|
|
|
|
|
|
|
/* Make sure tracks are inserted in correct order if user requests
|
|
|
|
INSERT_FIRST */
|
|
|
|
if (c->position == PLAYLIST_INSERT_FIRST || c->position >= 0)
|
|
|
|
c->position = insert_pos + 1;
|
|
|
|
|
|
|
|
if (((c->count)%PLAYLIST_DISPLAY_COUNT) == 0)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-07-18 13:54:12 +00:00
|
|
|
unsigned char* count_str;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
if (c->queue)
|
2007-08-06 13:08:36 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_QUEUE_COUNT);
|
2006-07-18 13:54:12 +00:00
|
|
|
else
|
2007-08-06 13:08:36 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_INSERT_COUNT);
|
2002-10-17 09:34:48 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(c->count, count_str, false);
|
2006-07-18 13:54:12 +00:00
|
|
|
|
|
|
|
if ((c->count) == PLAYLIST_DISPLAY_COUNT &&
|
|
|
|
(audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
c->playlist->started)
|
|
|
|
audio_flush_and_reload_tracks();
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2002-10-15 11:49:15 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
return 0;
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* remove track at specified position
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static int remove_track_from_playlist(struct playlist_info* playlist,
|
|
|
|
int position, bool write)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
int i;
|
2004-01-14 00:13:04 +00:00
|
|
|
bool inserted;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount <= 0)
|
2003-01-09 00:55:00 +00:00
|
|
|
return -1;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
inserted = playlist->indices[position] & PLAYLIST_INSERT_TYPE_MASK;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* shift indices now that track has been removed */
|
2004-01-26 17:05:21 +00:00
|
|
|
for (i=position; i<playlist->amount; i++)
|
2005-11-17 19:31:29 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->indices[i] = playlist->indices[i+1];
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
if (playlist->filenames)
|
|
|
|
playlist->filenames[i] = playlist->filenames[i+1];
|
|
|
|
#endif
|
|
|
|
}
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->amount--;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
if (inserted)
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->num_inserted_tracks--;
|
2004-01-14 00:13:04 +00:00
|
|
|
else
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->deleted = true;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* update stored indices if needed */
|
2004-01-26 17:05:21 +00:00
|
|
|
if (position < playlist->index)
|
|
|
|
playlist->index--;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (position < playlist->first_index)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->first_index--;
|
2003-12-09 08:18:03 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (position <= playlist->last_insert_pos)
|
|
|
|
playlist->last_insert_pos--;
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (write && playlist->control_fd >= 0)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
int result = update_control(playlist, PLAYLIST_COMMAND_DELETE,
|
|
|
|
position, -1, NULL, NULL, NULL);
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (result < 0)
|
|
|
|
return result;
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
sync_control(playlist, false);
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2011-04-07 20:33:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return 0;
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* randomly rearrange the array of indices for the playlist. If start_current
|
|
|
|
* is true then update the index to the new index of the current playing track
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static int randomise_playlist(struct playlist_info* playlist,
|
|
|
|
unsigned int seed, bool start_current,
|
|
|
|
bool write)
|
2002-10-04 08:48:20 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
int count;
|
|
|
|
int candidate;
|
2006-03-30 21:43:24 +00:00
|
|
|
long store;
|
2004-01-26 17:05:21 +00:00
|
|
|
unsigned int current = playlist->indices[playlist->index];
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
/* seed 0 is used to identify sorted playlist for resume purposes */
|
|
|
|
if (seed == 0)
|
|
|
|
seed = 1;
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* seed with the given seed */
|
|
|
|
srand(seed);
|
2002-10-04 08:48:20 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* randomise entire indices list */
|
2004-01-26 17:05:21 +00:00
|
|
|
for(count = playlist->amount - 1; count >= 0; count--)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
/* the rand is from 0 to RAND_MAX, so adjust to our value range */
|
2004-11-06 23:37:21 +00:00
|
|
|
candidate = rand() % (count + 1);
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* now swap the values at the 'count' and 'candidate' positions */
|
2004-01-26 17:05:21 +00:00
|
|
|
store = playlist->indices[candidate];
|
|
|
|
playlist->indices[candidate] = playlist->indices[count];
|
|
|
|
playlist->indices[count] = store;
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
if (playlist->filenames)
|
|
|
|
{
|
2011-06-20 20:12:42 +00:00
|
|
|
store = playlist->filenames[candidate];
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->filenames[candidate] = playlist->filenames[count];
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames[count] = store;
|
2005-11-17 19:31:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if (start_current)
|
2004-01-26 17:05:21 +00:00
|
|
|
find_and_set_playlist_index(playlist, current);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* indices have been moved so last insert position is no longer valid */
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->last_insert_pos = -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->seed = seed;
|
|
|
|
if (playlist->num_inserted_tracks > 0 || playlist->deleted)
|
|
|
|
playlist->shuffle_modified = true;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
if (write)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
update_control(playlist, PLAYLIST_COMMAND_SHUFFLE, seed,
|
|
|
|
playlist->first_index, NULL, NULL, NULL);
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2011-04-07 20:33:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return 0;
|
2002-08-28 09:22:44 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* Sort the array of indices for the playlist. If start_current is true then
|
|
|
|
* set the index to the new index of the current song.
|
2010-02-05 23:33:31 +00:00
|
|
|
* Also while going to unshuffled mode set the first_index to 0.
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static int sort_playlist(struct playlist_info* playlist, bool start_current,
|
|
|
|
bool write)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
unsigned int current = playlist->indices[playlist->index];
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount > 0)
|
2011-08-30 14:01:45 +00:00
|
|
|
qsort((void*)playlist->indices, playlist->amount,
|
2005-07-01 11:25:16 +00:00
|
|
|
sizeof(playlist->indices[0]), compare);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
/** We need to re-check the song names from disk because qsort can't
|
|
|
|
* sort two arrays at once :/
|
|
|
|
* FIXME: Please implement a better way to do this. */
|
2011-08-30 14:01:45 +00:00
|
|
|
memset((void*)playlist->filenames, 0xff, playlist->max_playlist_size * sizeof(int));
|
2005-11-17 19:31:29 +00:00
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (start_current)
|
2004-01-26 17:05:21 +00:00
|
|
|
find_and_set_playlist_index(playlist, current);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* indices have been moved so last insert position is no longer valid */
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->last_insert_pos = -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist->num_inserted_tracks && !playlist->deleted)
|
|
|
|
playlist->shuffle_modified = false;
|
|
|
|
if (write && playlist->control_fd >= 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2010-02-05 23:33:31 +00:00
|
|
|
playlist->first_index = 0;
|
2006-02-05 18:17:41 +00:00
|
|
|
update_control(playlist, PLAYLIST_COMMAND_UNSHUFFLE,
|
|
|
|
playlist->first_index, -1, NULL, NULL, NULL);
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2011-04-07 20:33:00 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return 0;
|
2003-04-11 00:29:15 +00:00
|
|
|
}
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
/* Calculate how many steps we have to really step when skipping entries
|
|
|
|
* marked as bad.
|
|
|
|
*/
|
|
|
|
static int calculate_step_count(const struct playlist_info *playlist, int steps)
|
|
|
|
{
|
|
|
|
int i, count, direction;
|
|
|
|
int index;
|
|
|
|
int stepped_count = 0;
|
|
|
|
|
|
|
|
if (steps < 0)
|
2005-11-21 13:23:06 +00:00
|
|
|
{
|
2005-10-21 06:40:45 +00:00
|
|
|
direction = -1;
|
2005-11-21 13:23:06 +00:00
|
|
|
count = -steps;
|
|
|
|
}
|
2005-10-21 06:40:45 +00:00
|
|
|
else
|
2005-11-21 13:23:06 +00:00
|
|
|
{
|
2005-10-21 06:40:45 +00:00
|
|
|
direction = 1;
|
2005-11-21 13:23:06 +00:00
|
|
|
count = steps;
|
|
|
|
}
|
2005-10-21 06:40:45 +00:00
|
|
|
|
|
|
|
index = playlist->index;
|
|
|
|
i = 0;
|
2005-11-21 11:14:51 +00:00
|
|
|
do {
|
2005-10-21 06:40:45 +00:00
|
|
|
/* Boundary check */
|
|
|
|
if (index < 0)
|
|
|
|
index += playlist->amount;
|
|
|
|
if (index >= playlist->amount)
|
|
|
|
index -= playlist->amount;
|
|
|
|
|
|
|
|
/* Check if we found a bad entry. */
|
|
|
|
if (playlist->indices[index] & PLAYLIST_SKIPPED)
|
|
|
|
{
|
|
|
|
steps += direction;
|
|
|
|
/* Are all entries bad? */
|
|
|
|
if (stepped_count++ > playlist->amount)
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i++;
|
2005-11-21 11:14:51 +00:00
|
|
|
|
|
|
|
index += direction;
|
2005-11-21 11:31:15 +00:00
|
|
|
} while (i <= count);
|
2005-10-21 06:40:45 +00:00
|
|
|
|
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2005-12-01 18:44:11 +00:00
|
|
|
/* Marks the index of the track to be skipped that is "steps" away from
|
|
|
|
* current playing track.
|
|
|
|
*/
|
|
|
|
void playlist_skip_entry(struct playlist_info *playlist, int steps)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (playlist == NULL)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
2006-05-05 08:32:07 +00:00
|
|
|
/* need to account for already skipped tracks */
|
|
|
|
steps = calculate_step_count(playlist, steps);
|
|
|
|
|
|
|
|
index = playlist->index + steps;
|
|
|
|
if (index < 0)
|
|
|
|
index += playlist->amount;
|
|
|
|
else if (index >= playlist->amount)
|
|
|
|
index -= playlist->amount;
|
|
|
|
|
2005-12-01 18:44:11 +00:00
|
|
|
playlist->indices[index] |= PLAYLIST_SKIPPED;
|
|
|
|
}
|
2005-10-21 06:40:45 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* returns the index of the track that is "steps" away from current playing
|
|
|
|
* track.
|
|
|
|
*/
|
2005-06-25 06:28:55 +00:00
|
|
|
static int get_next_index(const struct playlist_info* playlist, int steps,
|
2005-06-25 04:46:25 +00:00
|
|
|
int repeat_mode)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
int current_index = playlist->index;
|
2003-07-01 21:05:43 +00:00
|
|
|
int next_index = -1;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount <= 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2005-06-25 04:46:25 +00:00
|
|
|
if (repeat_mode == -1)
|
|
|
|
repeat_mode = global_settings.repeat_mode;
|
|
|
|
|
2006-12-27 01:51:33 +00:00
|
|
|
if (repeat_mode == REPEAT_SHUFFLE && playlist->amount <= 1)
|
2005-06-25 04:46:25 +00:00
|
|
|
repeat_mode = REPEAT_ALL;
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
steps = calculate_step_count(playlist, steps);
|
2005-06-25 04:46:25 +00:00
|
|
|
switch (repeat_mode)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2005-06-25 04:46:25 +00:00
|
|
|
case REPEAT_SHUFFLE:
|
|
|
|
/* Treat repeat shuffle just like repeat off. At end of playlist,
|
|
|
|
play will be resumed in playlist_next() */
|
2003-07-01 21:05:43 +00:00
|
|
|
case REPEAT_OFF:
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
current_index = rotate_index(playlist, current_index);
|
2003-07-01 21:05:43 +00:00
|
|
|
next_index = current_index+steps;
|
2004-01-26 17:05:21 +00:00
|
|
|
if ((next_index < 0) || (next_index >= playlist->amount))
|
2003-07-01 21:05:43 +00:00
|
|
|
next_index = -1;
|
|
|
|
else
|
2004-01-26 17:05:21 +00:00
|
|
|
next_index = (next_index+playlist->first_index) %
|
|
|
|
playlist->amount;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case REPEAT_ONE:
|
2007-02-17 23:07:39 +00:00
|
|
|
#ifdef AB_REPEAT_ENABLE
|
2005-08-21 23:01:12 +00:00
|
|
|
case REPEAT_AB:
|
|
|
|
#endif
|
2003-07-01 21:05:43 +00:00
|
|
|
next_index = current_index;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case REPEAT_ALL:
|
|
|
|
default:
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
next_index = (current_index+steps) % playlist->amount;
|
2003-07-01 21:05:43 +00:00
|
|
|
while (next_index < 0)
|
2004-01-26 17:05:21 +00:00
|
|
|
next_index += playlist->amount;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (steps >= playlist->amount)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
int i, index;
|
|
|
|
|
|
|
|
index = next_index;
|
|
|
|
next_index = -1;
|
|
|
|
|
|
|
|
/* second time around so skip the queued files */
|
2004-01-26 17:05:21 +00:00
|
|
|
for (i=0; i<playlist->amount; i++)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->indices[index] & PLAYLIST_QUEUE_MASK)
|
|
|
|
index = (index+1) % playlist->amount;
|
2003-07-01 21:05:43 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
next_index = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
/* No luck if the whole playlist was bad. */
|
|
|
|
if (playlist->indices[next_index] & PLAYLIST_SKIPPED)
|
|
|
|
return -1;
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return next_index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Search for the seek track and set appropriate indices. Used after shuffle
|
|
|
|
* to make sure the current index is still pointing to correct track.
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
static void find_and_set_playlist_index(struct playlist_info* playlist,
|
|
|
|
unsigned int seek)
|
2002-06-04 21:43:38 +00:00
|
|
|
{
|
2002-06-17 10:17:50 +00:00
|
|
|
int i;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* Set the index to the current song */
|
2004-01-26 17:05:21 +00:00
|
|
|
for (i=0; i<playlist->amount; i++)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->indices[i] == seek)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = playlist->first_index = i;
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* used to sort track indices. Sort order is as follows:
|
|
|
|
* 1. Prepended tracks (in prepend order)
|
|
|
|
* 2. Playlist/directory tracks (in playlist order)
|
|
|
|
* 3. Inserted/Appended tracks (in insert order)
|
|
|
|
*/
|
|
|
|
static int compare(const void* p1, const void* p2)
|
|
|
|
{
|
2005-02-12 12:57:16 +00:00
|
|
|
unsigned long* e1 = (unsigned long*) p1;
|
|
|
|
unsigned long* e2 = (unsigned long*) p2;
|
|
|
|
unsigned long flags1 = *e1 & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
unsigned long flags2 = *e2 & PLAYLIST_INSERT_TYPE_MASK;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if (flags1 == flags2)
|
|
|
|
return (*e1 & PLAYLIST_SEEK_MASK) - (*e2 & PLAYLIST_SEEK_MASK);
|
|
|
|
else if (flags1 == PLAYLIST_INSERT_TYPE_PREPEND ||
|
|
|
|
flags2 == PLAYLIST_INSERT_TYPE_APPEND)
|
|
|
|
return -1;
|
|
|
|
else if (flags1 == PLAYLIST_INSERT_TYPE_APPEND ||
|
|
|
|
flags2 == PLAYLIST_INSERT_TYPE_PREPEND)
|
|
|
|
return 1;
|
|
|
|
else if (flags1 && flags2)
|
|
|
|
return (*e1 & PLAYLIST_SEEK_MASK) - (*e2 & PLAYLIST_SEEK_MASK);
|
|
|
|
else
|
|
|
|
return *e1 - *e2;
|
|
|
|
}
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
/**
|
|
|
|
* Thread to update filename pointers to dircache on background
|
2006-02-05 18:17:41 +00:00
|
|
|
* without affecting playlist load up performance. This thread also flushes
|
|
|
|
* any pending control commands when the disk spins up.
|
2005-11-17 19:31:29 +00:00
|
|
|
*/
|
2009-10-20 21:54:44 +00:00
|
|
|
static void playlist_flush_callback(void *param)
|
2008-04-30 09:23:12 +00:00
|
|
|
{
|
2009-10-20 21:54:44 +00:00
|
|
|
(void)param;
|
2008-04-30 09:23:12 +00:00
|
|
|
struct playlist_info *playlist;
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
{
|
|
|
|
if (playlist->num_cached > 0)
|
|
|
|
{
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2008-04-30 09:23:12 +00:00
|
|
|
flush_cached_control(playlist);
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2008-04-30 09:23:12 +00:00
|
|
|
}
|
|
|
|
sync_control(playlist, true);
|
|
|
|
}
|
|
|
|
}
|
2011-06-21 17:42:31 +00:00
|
|
|
|
|
|
|
static bool is_dircache_pointers_intact(void)
|
|
|
|
{
|
|
|
|
return dircache_get_appflag(DIRCACHE_APPFLAG_PLAYLIST) ? true : false;
|
|
|
|
}
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
static void playlist_thread(void)
|
|
|
|
{
|
2007-10-16 01:25:17 +00:00
|
|
|
struct queue_event ev;
|
2005-11-17 19:31:29 +00:00
|
|
|
bool dirty_pointers = false;
|
|
|
|
static char tmp[MAX_PATH+1];
|
|
|
|
|
|
|
|
struct playlist_info *playlist;
|
|
|
|
int index;
|
|
|
|
int seek;
|
|
|
|
bool control_file;
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
int sleep_time = 5;
|
|
|
|
|
2008-10-07 19:37:33 +00:00
|
|
|
#ifdef HAVE_DISK_STORAGE
|
2006-02-05 18:17:41 +00:00
|
|
|
if (global_settings.disk_spindown > 1 &&
|
|
|
|
global_settings.disk_spindown <= 5)
|
|
|
|
sleep_time = global_settings.disk_spindown - 1;
|
2007-08-01 08:50:44 +00:00
|
|
|
#endif
|
2006-02-05 18:17:41 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
queue_wait_w_tmo(&playlist_queue, &ev, HZ*sleep_time);
|
2005-11-17 19:31:29 +00:00
|
|
|
|
|
|
|
switch (ev.id)
|
|
|
|
{
|
|
|
|
case PLAYLIST_LOAD_POINTERS:
|
|
|
|
dirty_pointers = true;
|
|
|
|
break ;
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
/* Start the background scanning after either the disk spindown
|
|
|
|
timeout or 5s, whichever is less */
|
2005-11-17 19:31:29 +00:00
|
|
|
case SYS_TIMEOUT:
|
2011-06-21 17:42:31 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
playlist = ¤t_playlist;
|
2008-04-30 09:23:12 +00:00
|
|
|
if (playlist->control_fd >= 0)
|
2006-02-05 18:17:41 +00:00
|
|
|
{
|
|
|
|
if (playlist->num_cached > 0)
|
2008-11-01 16:14:28 +00:00
|
|
|
register_storage_idle_func(playlist_flush_callback);
|
2006-02-05 18:17:41 +00:00
|
|
|
}
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
if (!dircache_is_enabled() || !playlist->filenames
|
|
|
|
|| playlist->amount <= 0)
|
2011-06-21 17:42:31 +00:00
|
|
|
{
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if previously loaded pointers are intact. */
|
|
|
|
if (is_dircache_pointers_intact() && !dirty_pointers)
|
2005-11-17 19:31:29 +00:00
|
|
|
break ;
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
cpu_boost(true);
|
|
|
|
#endif
|
|
|
|
for (index = 0; index < playlist->amount
|
|
|
|
&& queue_empty(&playlist_queue); index++)
|
|
|
|
{
|
|
|
|
/* Process only pointers that are not already loaded. */
|
2011-06-21 17:42:31 +00:00
|
|
|
if (is_dircache_pointers_intact() && playlist->filenames[index] >= 0)
|
2005-11-17 19:31:29 +00:00
|
|
|
continue ;
|
|
|
|
|
|
|
|
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
|
|
|
|
|
|
/* Load the filename from playlist file. */
|
|
|
|
if (get_filename(playlist, index, seek, control_file, tmp,
|
|
|
|
sizeof(tmp)) < 0)
|
2011-06-21 17:42:31 +00:00
|
|
|
{
|
2005-11-17 19:31:29 +00:00
|
|
|
break ;
|
2011-06-21 17:42:31 +00:00
|
|
|
}
|
2005-11-17 19:31:29 +00:00
|
|
|
|
|
|
|
/* Set the dircache entry pointer. */
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames[index] = dircache_get_entry_id(tmp);
|
2005-11-17 19:31:29 +00:00
|
|
|
|
|
|
|
/* And be on background so user doesn't notice any delays. */
|
|
|
|
yield();
|
|
|
|
}
|
2011-06-21 17:42:31 +00:00
|
|
|
|
|
|
|
if (dircache_is_enabled())
|
|
|
|
dircache_set_appflag(DIRCACHE_APPFLAG_PLAYLIST);
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
cpu_boost(false);
|
|
|
|
#endif
|
2011-06-21 17:42:31 +00:00
|
|
|
if (index == playlist->amount)
|
|
|
|
dirty_pointers = false;
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
break ;
|
2011-06-21 17:42:31 +00:00
|
|
|
}
|
2005-11-17 19:31:29 +00:00
|
|
|
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
usb_wait_for_disconnect(&playlist_queue);
|
|
|
|
break ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* gets pathname for track at seek index
|
|
|
|
*/
|
2005-11-17 19:31:29 +00:00
|
|
|
static int get_filename(struct playlist_info* playlist, int index, int seek,
|
2004-01-26 17:05:21 +00:00
|
|
|
bool control_file, char *buf, int buf_length)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2003-04-23 18:45:51 +00:00
|
|
|
int fd;
|
2003-07-01 21:05:43 +00:00
|
|
|
int max = -1;
|
|
|
|
char tmp_buf[MAX_PATH+1];
|
2002-08-01 11:37:26 +00:00
|
|
|
char dir_buf[MAX_PATH+1];
|
2007-11-13 18:49:20 +00:00
|
|
|
bool utf8 = playlist->utf8;
|
2002-06-07 14:48:06 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (buf_length > MAX_PATH+1)
|
|
|
|
buf_length = MAX_PATH+1;
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-06-21 17:42:31 +00:00
|
|
|
if (is_dircache_pointers_intact() && playlist->filenames)
|
2005-11-17 19:31:29 +00:00
|
|
|
{
|
2011-06-20 20:12:42 +00:00
|
|
|
if (playlist->filenames[index] >= 0)
|
2005-11-17 19:31:29 +00:00
|
|
|
{
|
2011-06-20 20:12:15 +00:00
|
|
|
max = dircache_copy_path(playlist->filenames[index],
|
|
|
|
tmp_buf, sizeof(tmp_buf)-1);
|
2005-11-17 19:31:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
(void)index;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (playlist->in_ram && !control_file && max < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
max = strlcpy(tmp_buf, (char*)&playlist->buffer[seek], sizeof(tmp_buf));
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2005-11-17 19:31:29 +00:00
|
|
|
else if (max < 0)
|
2002-08-06 13:09:48 +00:00
|
|
|
{
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2006-02-09 09:09:32 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (control_file)
|
2007-11-13 18:49:20 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
fd = playlist->control_fd;
|
2007-11-13 18:49:20 +00:00
|
|
|
utf8 = true;
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
else
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if(-1 == playlist->fd)
|
|
|
|
playlist->fd = open(playlist->filename, O_RDONLY);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
fd = playlist->fd;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
2002-08-06 13:09:48 +00:00
|
|
|
if(-1 != fd)
|
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2005-01-20 16:24:26 +00:00
|
|
|
if (lseek(fd, seek, SEEK_SET) != seek)
|
|
|
|
max = -1;
|
|
|
|
else
|
2006-11-29 19:22:44 +00:00
|
|
|
{
|
|
|
|
max = read(fd, tmp_buf, MIN((size_t) buf_length, sizeof(tmp_buf)));
|
|
|
|
|
2007-11-13 18:49:20 +00:00
|
|
|
if ((max > 0) && !utf8)
|
2006-11-29 19:22:44 +00:00
|
|
|
{
|
2007-11-13 18:49:20 +00:00
|
|
|
/* Use dir_buf as a temporary buffer. Note that dir_buf must
|
|
|
|
* be as large as tmp_buf.
|
2006-11-29 19:22:44 +00:00
|
|
|
*/
|
2007-11-13 18:49:20 +00:00
|
|
|
max = convert_m3u(tmp_buf, max, sizeof(tmp_buf), dir_buf);
|
2006-11-29 19:22:44 +00:00
|
|
|
}
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2006-02-09 09:09:32 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (max < 0)
|
|
|
|
{
|
|
|
|
if (control_file)
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
else
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
return max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(dir_buf, playlist->filename, playlist->dirlen);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
return (format_track_path(buf, tmp_buf, buf_length, max, dir_buf));
|
|
|
|
}
|
|
|
|
|
2005-11-02 22:32:04 +00:00
|
|
|
static int get_next_directory(char *dir){
|
|
|
|
return get_next_dir(dir,true,false);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int get_previous_directory(char *dir){
|
|
|
|
return get_next_dir(dir,false,false);
|
|
|
|
}
|
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
/*
|
|
|
|
* search through all the directories (starting with the current) to find
|
|
|
|
* one that has tracks to play
|
|
|
|
*/
|
2005-11-02 22:32:04 +00:00
|
|
|
static int get_next_dir(char *dir, bool is_forward, bool recursion)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
int result = -1;
|
|
|
|
char *start_dir = NULL;
|
|
|
|
bool exit = false;
|
|
|
|
struct tree_context* tc = tree_get_context();
|
2008-10-08 16:32:01 +00:00
|
|
|
int saved_dirfilter = *(tc->dirfilter);
|
|
|
|
|
|
|
|
/* process random folder advance */
|
2006-10-09 10:54:17 +00:00
|
|
|
if (global_settings.next_folder == FOLDER_ADVANCE_RANDOM)
|
|
|
|
{
|
2010-12-06 22:26:31 +00:00
|
|
|
int fd = open(ROCKBOX_DIR "/folder_advance_list.dat", O_RDONLY);
|
2006-10-09 10:54:17 +00:00
|
|
|
if (fd >= 0)
|
|
|
|
{
|
2008-10-08 16:32:01 +00:00
|
|
|
char buffer[MAX_PATH];
|
|
|
|
int folder_count = 0;
|
|
|
|
srand(current_tick);
|
|
|
|
*(tc->dirfilter) = SHOW_MUSIC;
|
|
|
|
tc->sort_dir = global_settings.sort_dir;
|
2006-10-09 10:54:17 +00:00
|
|
|
read(fd,&folder_count,sizeof(int));
|
2008-06-29 02:19:53 +00:00
|
|
|
if (!folder_count)
|
|
|
|
exit = true;
|
2006-10-09 10:54:17 +00:00
|
|
|
while (!exit)
|
|
|
|
{
|
2011-10-15 19:35:02 +00:00
|
|
|
int i = rand()%folder_count;
|
2006-10-09 10:54:17 +00:00
|
|
|
lseek(fd,sizeof(int) + (MAX_PATH*i),SEEK_SET);
|
|
|
|
read(fd,buffer,MAX_PATH);
|
2008-07-02 09:16:26 +00:00
|
|
|
if (check_subdir_for_music(buffer, "", false) ==0)
|
2006-10-09 10:54:17 +00:00
|
|
|
exit = true;
|
|
|
|
}
|
2008-06-29 02:19:53 +00:00
|
|
|
if (folder_count)
|
|
|
|
strcpy(dir,buffer);
|
2006-10-09 10:54:17 +00:00
|
|
|
close(fd);
|
2008-10-08 16:32:01 +00:00
|
|
|
*(tc->dirfilter) = saved_dirfilter;
|
|
|
|
tc->sort_dir = global_settings.sort_dir;
|
2007-05-15 06:42:02 +00:00
|
|
|
reload_directory();
|
2006-10-09 10:54:17 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2008-10-08 16:32:01 +00:00
|
|
|
|
|
|
|
/* not random folder advance (or random folder advance unavailable) */
|
|
|
|
if (recursion)
|
|
|
|
{
|
2005-11-02 22:32:04 +00:00
|
|
|
/* start with root */
|
|
|
|
dir[0] = '\0';
|
|
|
|
}
|
2008-10-08 16:32:01 +00:00
|
|
|
else
|
|
|
|
{
|
2005-11-02 22:32:04 +00:00
|
|
|
/* start with current directory */
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(dir, playlist->filename, playlist->dirlen);
|
2005-11-02 22:32:04 +00:00
|
|
|
}
|
2005-07-01 11:25:16 +00:00
|
|
|
|
|
|
|
/* use the tree browser dircache to load files */
|
2006-04-18 16:24:12 +00:00
|
|
|
*(tc->dirfilter) = SHOW_ALL;
|
2005-07-01 11:25:16 +00:00
|
|
|
|
2008-10-08 16:32:01 +00:00
|
|
|
/* set up sorting/direction */
|
|
|
|
tc->sort_dir = global_settings.sort_dir;
|
|
|
|
if (!is_forward)
|
|
|
|
{
|
2008-10-08 17:23:59 +00:00
|
|
|
static const char sortpairs[] =
|
2008-10-08 16:32:01 +00:00
|
|
|
{
|
2008-10-08 17:23:59 +00:00
|
|
|
[SORT_ALPHA] = SORT_ALPHA_REVERSED,
|
|
|
|
[SORT_DATE] = SORT_DATE_REVERSED,
|
|
|
|
[SORT_TYPE] = SORT_TYPE_REVERSED,
|
|
|
|
[SORT_ALPHA_REVERSED] = SORT_ALPHA,
|
|
|
|
[SORT_DATE_REVERSED] = SORT_DATE,
|
|
|
|
[SORT_TYPE_REVERSED] = SORT_TYPE,
|
2008-10-08 16:32:01 +00:00
|
|
|
};
|
2008-10-08 17:23:59 +00:00
|
|
|
|
|
|
|
if ((unsigned)tc->sort_dir < sizeof(sortpairs))
|
|
|
|
tc->sort_dir = sortpairs[tc->sort_dir];
|
2005-11-02 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
while (!exit)
|
|
|
|
{
|
|
|
|
struct entry *files;
|
|
|
|
int num_files = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (ft_load(tc, (dir[0]=='\0')?"/":dir) < 0)
|
|
|
|
{
|
|
|
|
exit = true;
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
files = tree_get_entries(tc);
|
2005-07-01 11:25:16 +00:00
|
|
|
num_files = tc->filesindir;
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_lock_cache(tc);
|
2005-07-01 11:25:16 +00:00
|
|
|
for (i=0; i<num_files; i++)
|
|
|
|
{
|
|
|
|
/* user abort */
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (files[i].attr & ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
if (!start_dir)
|
|
|
|
{
|
2008-07-02 09:16:26 +00:00
|
|
|
result = check_subdir_for_music(dir, files[i].name, true);
|
2005-07-01 11:25:16 +00:00
|
|
|
if (result != -1)
|
|
|
|
{
|
|
|
|
exit = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!strcmp(start_dir, files[i].name))
|
|
|
|
start_dir = NULL;
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(tc);
|
2005-07-01 11:25:16 +00:00
|
|
|
|
|
|
|
if (!exit)
|
|
|
|
{
|
|
|
|
/* move down to parent directory. current directory name is
|
|
|
|
stored as the starting point for the search in parent */
|
|
|
|
start_dir = strrchr(dir, '/');
|
|
|
|
if (start_dir)
|
|
|
|
{
|
|
|
|
*start_dir = '\0';
|
|
|
|
start_dir++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-08 16:32:01 +00:00
|
|
|
/* restore dirfilter */
|
|
|
|
*(tc->dirfilter) = saved_dirfilter;
|
|
|
|
tc->sort_dir = global_settings.sort_dir;
|
2005-11-02 22:32:04 +00:00
|
|
|
|
|
|
|
/* special case if nothing found: try start searching again from root */
|
|
|
|
if (result == -1 && !recursion){
|
2008-10-08 16:32:01 +00:00
|
|
|
result = get_next_dir(dir, is_forward, true);
|
2005-11-02 22:32:04 +00:00
|
|
|
}
|
2005-07-01 11:25:16 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checks if there are any music files in the dir or any of its
|
|
|
|
* subdirectories. May be called recursively.
|
|
|
|
*/
|
2008-10-08 16:32:01 +00:00
|
|
|
static int check_subdir_for_music(char *dir, const char *subdir, bool recurse)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
int result = -1;
|
|
|
|
int dirlen = strlen(dir);
|
|
|
|
int num_files = 0;
|
|
|
|
int i;
|
|
|
|
struct entry *files;
|
|
|
|
bool has_music = false;
|
|
|
|
bool has_subdir = false;
|
|
|
|
struct tree_context* tc = tree_get_context();
|
|
|
|
|
|
|
|
snprintf(dir+dirlen, MAX_PATH-dirlen, "/%s", subdir);
|
|
|
|
|
|
|
|
if (ft_load(tc, dir) < 0)
|
|
|
|
{
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
files = tree_get_entries(tc);
|
2005-07-01 11:25:16 +00:00
|
|
|
num_files = tc->filesindir;
|
|
|
|
|
|
|
|
for (i=0; i<num_files; i++)
|
|
|
|
{
|
|
|
|
if (files[i].attr & ATTR_DIRECTORY)
|
|
|
|
has_subdir = true;
|
2007-04-18 13:03:01 +00:00
|
|
|
else if ((files[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
has_music = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_music)
|
|
|
|
return 0;
|
2008-07-02 09:16:26 +00:00
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_lock_cache(tc);
|
2008-07-02 09:16:26 +00:00
|
|
|
if (has_subdir && recurse)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
for (i=0; i<num_files; i++)
|
|
|
|
{
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
|
|
|
result = -2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (files[i].attr & ATTR_DIRECTORY)
|
|
|
|
{
|
2008-07-02 09:16:26 +00:00
|
|
|
result = check_subdir_for_music(dir, files[i].name, true);
|
2005-07-01 11:25:16 +00:00
|
|
|
if (!result)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
tree_unlock_cache(tc);
|
2005-07-01 11:25:16 +00:00
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
{
|
2005-07-30 18:12:25 +00:00
|
|
|
if (dirlen)
|
|
|
|
{
|
|
|
|
dir[dirlen] = '\0';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strcpy(dir, "/");
|
|
|
|
}
|
2005-07-01 11:25:16 +00:00
|
|
|
|
|
|
|
/* we now need to reload our current directory */
|
|
|
|
if(ft_load(tc, dir) < 0)
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
|
2005-07-01 11:25:16 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* Returns absolute path of track
|
|
|
|
*/
|
|
|
|
static int format_track_path(char *dest, char *src, int buf_length, int max,
|
2008-05-12 17:52:50 +00:00
|
|
|
const char *dir)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
int j;
|
|
|
|
char *temp_ptr;
|
|
|
|
|
2011-02-18 21:56:48 +00:00
|
|
|
/* Look for the end of the string */
|
2011-02-18 21:21:50 +00:00
|
|
|
while((i < max) &&
|
|
|
|
(src[i] != '\n') &&
|
2011-02-18 21:56:48 +00:00
|
|
|
(src[i] != '\r') &&
|
|
|
|
(src[i] != '\0'))
|
2003-07-01 21:05:43 +00:00
|
|
|
i++;
|
|
|
|
|
|
|
|
/* Now work back killing white space */
|
2011-02-18 21:39:59 +00:00
|
|
|
while((i > 0) &&
|
|
|
|
((src[i-1] == ' ') ||
|
|
|
|
(src[i-1] == '\t')))
|
2003-07-01 21:05:43 +00:00
|
|
|
i--;
|
|
|
|
|
2011-02-18 21:56:48 +00:00
|
|
|
/* Zero-terminate the file name */
|
2003-07-01 21:05:43 +00:00
|
|
|
src[i]=0;
|
2011-02-18 21:39:59 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* replace backslashes with forward slashes */
|
|
|
|
for ( j=0; j<i; j++ )
|
|
|
|
if ( src[j] == '\\' )
|
|
|
|
src[j] = '/';
|
|
|
|
|
|
|
|
if('/' == src[0])
|
|
|
|
{
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(dest, src, buf_length);
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* handle dos style drive letter */
|
|
|
|
if (':' == src[1])
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(dest, &src[2], buf_length);
|
2004-08-31 23:44:24 +00:00
|
|
|
else if (!strncmp(src, "../", 3))
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* handle relative paths */
|
|
|
|
i=3;
|
2004-08-31 23:44:24 +00:00
|
|
|
while(!strncmp(&src[i], "../", 3))
|
2003-07-01 21:05:43 +00:00
|
|
|
i += 3;
|
|
|
|
for (j=0; j<i/3; j++) {
|
|
|
|
temp_ptr = strrchr(dir, '/');
|
|
|
|
if (temp_ptr)
|
|
|
|
*temp_ptr = '\0';
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
snprintf(dest, buf_length, "%s/%s", dir, &src[i]);
|
|
|
|
}
|
|
|
|
else if ( '.' == src[0] && '/' == src[1] ) {
|
|
|
|
snprintf(dest, buf_length, "%s/%s", dir, &src[2]);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
snprintf(dest, buf_length, "%s/%s", dir, src);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display splash message showing progress of playlist/directory insertion or
|
|
|
|
* save.
|
|
|
|
*/
|
2007-08-06 13:08:36 +00:00
|
|
|
static void display_playlist_count(int count, const unsigned char *fmt,
|
|
|
|
bool final)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
static long talked_tick = 0;
|
|
|
|
long id = P2ID(fmt);
|
2007-10-19 15:31:42 +00:00
|
|
|
if(global_settings.talk_menu && id>=0)
|
2007-08-06 13:08:36 +00:00
|
|
|
{
|
|
|
|
if(final || (count && (talked_tick == 0
|
|
|
|
|| TIME_AFTER(current_tick, talked_tick+5*HZ))))
|
|
|
|
{
|
|
|
|
talked_tick = current_tick;
|
|
|
|
talk_number(count, false);
|
|
|
|
talk_id(id, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt = P2STR(fmt);
|
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(0, fmt, count, str(LANG_OFF_ABORT));
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Display buffer full message
|
|
|
|
*/
|
|
|
|
static void display_buffer_full(void)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_BUFFER_FULL));
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
/*
|
2006-02-05 18:17:41 +00:00
|
|
|
* Flush any cached control commands to disk. Called when playlist is being
|
2003-12-09 08:18:03 +00:00
|
|
|
* modified. Returns 0 on success and -1 on failure.
|
|
|
|
*/
|
2006-02-05 18:17:41 +00:00
|
|
|
static int flush_cached_control(struct playlist_info* playlist)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
|
|
|
int result = 0;
|
2006-02-05 18:17:41 +00:00
|
|
|
int i;
|
|
|
|
|
2006-05-11 19:14:18 +00:00
|
|
|
if (!playlist->num_cached)
|
|
|
|
return 0;
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
lseek(playlist->control_fd, 0, SEEK_END);
|
|
|
|
|
|
|
|
for (i=0; i<playlist->num_cached; i++)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
struct playlist_control_cache* cache =
|
|
|
|
&(playlist->control_cache[i]);
|
|
|
|
|
|
|
|
switch (cache->command)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_PLAYLIST:
|
|
|
|
result = fdprintf(playlist->control_fd, "P:%d:%s:%s\n",
|
|
|
|
cache->i1, cache->s1, cache->s2);
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_ADD:
|
|
|
|
case PLAYLIST_COMMAND_QUEUE:
|
|
|
|
result = fdprintf(playlist->control_fd, "%c:%d:%d:",
|
|
|
|
(cache->command == PLAYLIST_COMMAND_ADD)?'A':'Q',
|
|
|
|
cache->i1, cache->i2);
|
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
/* save the position in file where name is written */
|
|
|
|
int* seek_pos = (int *)cache->data;
|
|
|
|
*seek_pos = lseek(playlist->control_fd, 0, SEEK_CUR);
|
|
|
|
result = fdprintf(playlist->control_fd, "%s\n",
|
|
|
|
cache->s1);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_DELETE:
|
|
|
|
result = fdprintf(playlist->control_fd, "D:%d\n", cache->i1);
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_SHUFFLE:
|
2005-02-22 12:19:12 +00:00
|
|
|
result = fdprintf(playlist->control_fd, "S:%d:%d\n",
|
2006-02-05 18:17:41 +00:00
|
|
|
cache->i1, cache->i2);
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_UNSHUFFLE:
|
|
|
|
result = fdprintf(playlist->control_fd, "U:%d\n", cache->i1);
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_RESET:
|
|
|
|
result = fdprintf(playlist->control_fd, "R\n");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-12-09 08:18:03 +00:00
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
if (result <= 0)
|
|
|
|
break;
|
|
|
|
}
|
2003-12-09 08:18:03 +00:00
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
if (result > 0)
|
|
|
|
{
|
|
|
|
playlist->num_cached = 0;
|
|
|
|
playlist->pending_control_sync = true;
|
|
|
|
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-05-11 19:14:18 +00:00
|
|
|
result = -1;
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_UPDATE_ERROR));
|
2003-12-09 08:18:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
/*
|
|
|
|
* Update control data with new command. Depending on the command, it may be
|
|
|
|
* cached or flushed to disk.
|
|
|
|
*/
|
|
|
|
static int update_control(struct playlist_info* playlist,
|
|
|
|
enum playlist_command command, int i1, int i2,
|
|
|
|
const char* s1, const char* s2, void* data)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
struct playlist_control_cache* cache;
|
|
|
|
bool flush = false;
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
cache = &(playlist->control_cache[playlist->num_cached++]);
|
|
|
|
|
|
|
|
cache->command = command;
|
|
|
|
cache->i1 = i1;
|
|
|
|
cache->i2 = i2;
|
|
|
|
cache->s1 = s1;
|
|
|
|
cache->s2 = s2;
|
|
|
|
cache->data = data;
|
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case PLAYLIST_COMMAND_PLAYLIST:
|
|
|
|
case PLAYLIST_COMMAND_ADD:
|
|
|
|
case PLAYLIST_COMMAND_QUEUE:
|
|
|
|
#ifndef HAVE_DIRCACHE
|
|
|
|
case PLAYLIST_COMMAND_DELETE:
|
|
|
|
case PLAYLIST_COMMAND_RESET:
|
|
|
|
#endif
|
|
|
|
flush = true;
|
|
|
|
break;
|
|
|
|
case PLAYLIST_COMMAND_SHUFFLE:
|
|
|
|
case PLAYLIST_COMMAND_UNSHUFFLE:
|
|
|
|
default:
|
|
|
|
/* only flush when needed */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flush || playlist->num_cached == PLAYLIST_MAX_CACHE)
|
|
|
|
result = flush_cached_control(playlist);
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* sync control file to disk
|
|
|
|
*/
|
|
|
|
static void sync_control(struct playlist_info* playlist, bool force)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_DIRCACHE
|
2006-04-20 01:43:16 +00:00
|
|
|
if (playlist->started && force)
|
|
|
|
#else
|
|
|
|
(void) force;
|
|
|
|
|
|
|
|
if (playlist->started)
|
2006-02-05 18:17:41 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if (playlist->pending_control_sync)
|
|
|
|
{
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
fsync(playlist->control_fd);
|
|
|
|
playlist->pending_control_sync = false;
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
/*
|
|
|
|
* Rotate indices such that first_index is index 0
|
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
static int rotate_index(const struct playlist_info* playlist, int index)
|
2003-12-10 00:11:25 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
index -= playlist->first_index;
|
2003-12-10 00:11:25 +00:00
|
|
|
if (index < 0)
|
2004-01-26 17:05:21 +00:00
|
|
|
index += playlist->amount;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
/*
|
|
|
|
* Need no movement protection since all 3 allocations are not passed to
|
|
|
|
* other functions which can yield().
|
|
|
|
*/
|
|
|
|
static int move_callback(int handle, void* current, void* new)
|
|
|
|
{
|
|
|
|
(void)handle;
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
if (current == playlist->indices)
|
|
|
|
playlist->indices = new;
|
|
|
|
else if (current == playlist->filenames)
|
|
|
|
playlist->filenames = new;
|
|
|
|
/* buffer can possibly point to a new buffer temporarily (playlist_save()).
|
|
|
|
* just don't overwrite the pointer to that temp buffer */
|
|
|
|
else if (current == playlist->buffer)
|
|
|
|
playlist->buffer = new;
|
|
|
|
|
|
|
|
return BUFLIB_CB_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct buflib_callbacks ops = {
|
|
|
|
.move_callback = move_callback,
|
|
|
|
.shrink_callback = NULL,
|
|
|
|
};
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* Initialize playlist entries at startup
|
|
|
|
*/
|
|
|
|
void playlist_init(void)
|
|
|
|
{
|
2011-08-30 14:01:33 +00:00
|
|
|
int handle;
|
2004-01-26 17:05:21 +00:00
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_init(¤t_playlist_mutex);
|
|
|
|
mutex_init(&created_playlist_mutex);
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->current = true;
|
2010-12-06 22:26:31 +00:00
|
|
|
strlcpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
|
2008-09-24 20:03:53 +00:00
|
|
|
sizeof(playlist->control_filename));
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->fd = -1;
|
|
|
|
playlist->control_fd = -1;
|
|
|
|
playlist->max_playlist_size = global_settings.max_files_in_playlist;
|
2011-08-30 14:01:45 +00:00
|
|
|
handle = core_alloc_ex("playlist idx",
|
|
|
|
playlist->max_playlist_size * sizeof(int), &ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
playlist->indices = core_get_data(handle);
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->buffer_size =
|
2003-07-01 21:05:43 +00:00
|
|
|
AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
|
2011-08-30 14:01:45 +00:00
|
|
|
handle = core_alloc_ex("playlist buf",
|
|
|
|
playlist->buffer_size, &ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
playlist->buffer = core_get_data(handle);
|
2011-02-14 11:27:45 +00:00
|
|
|
playlist->control_mutex = ¤t_playlist_mutex;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
empty_playlist(playlist, true);
|
2005-11-17 19:31:29 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-08-30 14:01:45 +00:00
|
|
|
handle = core_alloc_ex("playlist dc",
|
|
|
|
playlist->max_playlist_size * sizeof(int), &ops);
|
2011-08-30 14:01:33 +00:00
|
|
|
playlist->filenames = core_get_data(handle);
|
2011-08-30 14:01:45 +00:00
|
|
|
memset((void*)playlist->filenames, 0xff,
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->max_playlist_size * sizeof(int));
|
|
|
|
create_thread(playlist_thread, playlist_stack, sizeof(playlist_stack),
|
2007-10-16 01:25:17 +00:00
|
|
|
0, playlist_thread_name IF_PRIO(, PRIORITY_BACKGROUND)
|
2007-11-13 18:49:20 +00:00
|
|
|
IF_COP(, CPU));
|
2006-09-16 16:18:11 +00:00
|
|
|
queue_init(&playlist_queue, true);
|
2005-11-17 19:31:29 +00:00
|
|
|
#endif
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
/*
|
|
|
|
* Clean playlist at shutdown
|
|
|
|
*/
|
|
|
|
void playlist_shutdown(void)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
{
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
if (playlist->num_cached > 0)
|
|
|
|
flush_cached_control(playlist);
|
|
|
|
|
|
|
|
close(playlist->control_fd);
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2006-02-05 18:17:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* Create new playlist
|
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_create(const char *dir, const char *file)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
new_playlist(playlist, dir, file);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (file)
|
|
|
|
/* load the playlist file */
|
|
|
|
add_indices_to_playlist(playlist, NULL, 0);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PLAYLIST_COMMAND_SIZE (MAX_PATH+12)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the playlist state based on control file commands. Called to
|
|
|
|
* resume playback after shutdown.
|
|
|
|
*/
|
|
|
|
int playlist_resume(void)
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
char *buffer;
|
2006-11-06 18:07:30 +00:00
|
|
|
size_t buflen;
|
2003-07-01 21:05:43 +00:00
|
|
|
int nread;
|
|
|
|
int total_read = 0;
|
2004-07-14 18:02:38 +00:00
|
|
|
int control_file_size = 0;
|
2003-07-01 21:05:43 +00:00
|
|
|
bool first = true;
|
2003-12-09 08:18:03 +00:00
|
|
|
bool sorted = true;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* use mp3 buffer for maximum load speed */
|
2006-11-06 18:07:30 +00:00
|
|
|
buffer = (char *)audio_get_buffer(false, &buflen);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
empty_playlist(playlist, true);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(0, ID2P(LANG_WAIT));
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->control_fd = open(playlist->control_filename, O_RDWR);
|
|
|
|
if (playlist->control_fd < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->control_created = true;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-07-14 18:02:38 +00:00
|
|
|
control_file_size = filesize(playlist->control_fd);
|
|
|
|
if (control_file_size <= 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2004-07-14 18:02:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* read a small amount first to get the header */
|
2004-01-26 17:05:21 +00:00
|
|
|
nread = read(playlist->control_fd, buffer,
|
2003-07-01 21:05:43 +00:00
|
|
|
PLAYLIST_COMMAND_SIZE<buflen?PLAYLIST_COMMAND_SIZE:buflen);
|
|
|
|
if(nread <= 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-04-30 05:29:04 +00:00
|
|
|
playlist->started = true;
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
int count;
|
2006-02-05 18:17:41 +00:00
|
|
|
enum playlist_command current_command = PLAYLIST_COMMAND_COMMENT;
|
2003-07-01 21:05:43 +00:00
|
|
|
int last_newline = 0;
|
|
|
|
int str_count = -1;
|
|
|
|
bool newline = true;
|
|
|
|
bool exit_loop = false;
|
|
|
|
char *p = buffer;
|
|
|
|
char *str1 = NULL;
|
|
|
|
char *str2 = NULL;
|
|
|
|
char *str3 = NULL;
|
2006-08-12 11:00:39 +00:00
|
|
|
unsigned long last_tick = current_tick;
|
2008-08-11 13:57:26 +00:00
|
|
|
bool useraborted = false;
|
2006-08-12 11:00:39 +00:00
|
|
|
|
2008-08-11 13:57:26 +00:00
|
|
|
for(count=0; count<nread && !exit_loop && !useraborted; count++,p++)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2006-08-12 11:00:39 +00:00
|
|
|
/* So a splash while we are loading. */
|
2008-10-12 16:47:59 +00:00
|
|
|
if (TIME_AFTER(current_tick, last_tick + HZ/4))
|
2006-08-12 11:00:39 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splashf(0, str(LANG_LOADING_PERCENT),
|
|
|
|
(total_read+count)*100/control_file_size,
|
|
|
|
str(LANG_OFF_ABORT));
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2006-08-12 11:00:39 +00:00
|
|
|
{
|
2008-08-11 13:57:26 +00:00
|
|
|
useraborted = true;
|
|
|
|
break;
|
2006-08-12 11:00:39 +00:00
|
|
|
}
|
|
|
|
last_tick = current_tick;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* Are we on a new line? */
|
|
|
|
if((*p == '\n') || (*p == '\r'))
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
|
|
|
|
/* save last_newline in case we need to load more data */
|
|
|
|
last_newline = count;
|
|
|
|
|
|
|
|
switch (current_command)
|
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_PLAYLIST:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* str1=version str2=dir str3=file */
|
|
|
|
int version;
|
2004-09-01 21:34:20 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (!str1)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!str2)
|
|
|
|
str2 = "";
|
|
|
|
|
|
|
|
if (!str3)
|
|
|
|
str3 = "";
|
|
|
|
|
|
|
|
version = atoi(str1);
|
|
|
|
|
|
|
|
if (version != PLAYLIST_CONTROL_FILE_VERSION)
|
2003-12-09 08:18:03 +00:00
|
|
|
return -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
update_playlist_filename(playlist, str2, str3);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if (str3[0] != '\0')
|
|
|
|
{
|
|
|
|
/* NOTE: add_indices_to_playlist() overwrites the
|
2005-04-05 11:33:58 +00:00
|
|
|
audiobuf so we need to reload control file
|
2003-07-01 21:05:43 +00:00
|
|
|
data */
|
2004-01-26 17:05:21 +00:00
|
|
|
add_indices_to_playlist(playlist, NULL, 0);
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
|
|
|
else if (str2[0] != '\0')
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->in_ram = true;
|
2003-07-01 21:05:43 +00:00
|
|
|
resume_directory(str2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* load the rest of the data */
|
|
|
|
first = false;
|
|
|
|
exit_loop = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_ADD:
|
|
|
|
case PLAYLIST_COMMAND_QUEUE:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* str1=position str2=last_position str3=file */
|
|
|
|
int position, last_position;
|
|
|
|
bool queue;
|
|
|
|
|
|
|
|
if (!str1 || !str2 || !str3)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = atoi(str1);
|
|
|
|
last_position = atoi(str2);
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
queue = (current_command == PLAYLIST_COMMAND_ADD)?
|
|
|
|
false:true;
|
2004-09-01 21:34:20 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* seek position is based on str3's position in
|
|
|
|
buffer */
|
2004-01-26 17:05:21 +00:00
|
|
|
if (add_track_to_playlist(playlist, str3, position,
|
|
|
|
queue, total_read+(str3-buffer)) < 0)
|
2005-11-21 11:14:51 +00:00
|
|
|
return -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->last_insert_pos = last_position;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_DELETE:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* str1=position */
|
|
|
|
int position;
|
|
|
|
|
|
|
|
if (!str1)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
position = atoi(str1);
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (remove_track_from_playlist(playlist, position,
|
|
|
|
false) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_SHUFFLE:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* str1=seed str2=first_index */
|
|
|
|
int seed;
|
|
|
|
|
|
|
|
if (!str1 || !str2)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
if (!sorted)
|
|
|
|
{
|
|
|
|
/* Always sort list before shuffling */
|
2004-01-26 17:05:21 +00:00
|
|
|
sort_playlist(playlist, false, false);
|
2003-12-09 08:18:03 +00:00
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
seed = atoi(str1);
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->first_index = atoi(str2);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (randomise_playlist(playlist, seed, false,
|
|
|
|
false) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
2003-12-09 08:18:03 +00:00
|
|
|
sorted = false;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_UNSHUFFLE:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* str1=first_index */
|
|
|
|
if (!str1)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->first_index = atoi(str1);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (sort_playlist(playlist, false, false) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2003-12-09 08:18:03 +00:00
|
|
|
sorted = true;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_RESET:
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->last_insert_pos = -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
case PLAYLIST_COMMAND_COMMENT:
|
2003-07-01 21:05:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
newline = true;
|
|
|
|
|
|
|
|
/* to ignore any extra newlines */
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_COMMENT;
|
2005-07-01 11:25:16 +00:00
|
|
|
}
|
2004-09-01 21:34:20 +00:00
|
|
|
else if(newline)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
newline = false;
|
|
|
|
|
|
|
|
/* first non-comment line must always specify playlist */
|
|
|
|
if (first && *p != 'P' && *p != '#')
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (*p)
|
|
|
|
{
|
|
|
|
case 'P':
|
|
|
|
/* playlist can only be specified once */
|
|
|
|
if (!first)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_PLAYLIST;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'A':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_ADD;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'Q':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_QUEUE;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'D':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_DELETE;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_SHUFFLE;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'U':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_UNSHUFFLE;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case 'R':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_RESET;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
case '#':
|
2006-02-05 18:17:41 +00:00
|
|
|
current_command = PLAYLIST_COMMAND_COMMENT;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = -1;
|
|
|
|
exit_loop = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
str_count = -1;
|
|
|
|
str1 = NULL;
|
|
|
|
str2 = NULL;
|
|
|
|
str3 = NULL;
|
|
|
|
}
|
2006-02-05 18:17:41 +00:00
|
|
|
else if(current_command != PLAYLIST_COMMAND_COMMENT)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
/* all control file strings are separated with a colon.
|
|
|
|
Replace the colon with 0 to get proper strings that can be
|
|
|
|
used by commands above */
|
|
|
|
if (*p == ':')
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
str_count++;
|
|
|
|
|
|
|
|
if ((count+1) < nread)
|
|
|
|
{
|
|
|
|
switch (str_count)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
str1 = p+1;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
str2 = p+1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
str3 = p+1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* allow last string to contain colons */
|
|
|
|
*p = ':';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_INVALID));
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-08-11 13:57:26 +00:00
|
|
|
if (useraborted)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_CANCEL));
|
2008-08-11 13:57:26 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
if (!newline || (exit_loop && count<nread))
|
|
|
|
{
|
2004-07-14 18:02:38 +00:00
|
|
|
if ((total_read + count) >= control_file_size)
|
|
|
|
{
|
|
|
|
/* no newline at end of control file */
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_INVALID));
|
2004-07-14 18:02:38 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* We didn't end on a newline or we exited loop prematurely.
|
2004-07-14 18:02:38 +00:00
|
|
|
Either way, re-read the remainder. */
|
2003-07-01 21:05:43 +00:00
|
|
|
count = last_newline;
|
2004-01-26 17:05:21 +00:00
|
|
|
lseek(playlist->control_fd, total_read+count, SEEK_SET);
|
2002-08-06 13:09:48 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
total_read += count;
|
|
|
|
|
|
|
|
if (first)
|
|
|
|
/* still looking for header */
|
2004-01-26 17:05:21 +00:00
|
|
|
nread = read(playlist->control_fd, buffer,
|
2003-07-01 21:05:43 +00:00
|
|
|
PLAYLIST_COMMAND_SIZE<buflen?PLAYLIST_COMMAND_SIZE:buflen);
|
2002-08-06 13:09:48 +00:00
|
|
|
else
|
2004-01-26 17:05:21 +00:00
|
|
|
nread = read(playlist->control_fd, buffer, buflen);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* Terminate on EOF */
|
|
|
|
if(nread <= 0)
|
2003-12-09 08:18:03 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
2003-12-09 08:18:03 +00:00
|
|
|
}
|
2002-08-06 13:09:48 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2005-11-21 11:14:51 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
/*
|
2003-07-01 21:05:43 +00:00
|
|
|
* Add track to in_ram playlist. Used when playing directories.
|
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_add(const char *filename)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
int len = strlen(filename);
|
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
if((len+1 > playlist->buffer_size - playlist->buffer_end_pos) ||
|
2004-01-26 17:05:21 +00:00
|
|
|
(playlist->amount >= playlist->max_playlist_size))
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
display_buffer_full();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->indices[playlist->amount] = playlist->buffer_end_pos;
|
2005-11-17 19:41:16 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames[playlist->amount] = -1;
|
2005-11-17 19:41:16 +00:00
|
|
|
#endif
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->amount++;
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
strcpy((char*)&playlist->buffer[playlist->buffer_end_pos], filename);
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->buffer_end_pos += len;
|
|
|
|
playlist->buffer[playlist->buffer_end_pos++] = '\0';
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* shuffle newly created playlist using random seed. */
|
|
|
|
int playlist_shuffle(int random_seed, int start_index)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
bool start_current = false;
|
|
|
|
|
|
|
|
if (start_index >= 0 && global_settings.play_selected)
|
|
|
|
{
|
|
|
|
/* store the seek position before the shuffle */
|
2008-09-21 14:19:18 +00:00
|
|
|
playlist->index = playlist->first_index = start_index;
|
2004-01-26 17:05:21 +00:00
|
|
|
start_current = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
randomise_playlist(playlist, random_seed, start_current, true);
|
|
|
|
|
|
|
|
return playlist->index;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* start playing current playlist at specified index/offset */
|
2009-05-31 14:33:33 +00:00
|
|
|
void playlist_start(int start_index, int offset)
|
2004-01-26 17:05:21 +00:00
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
2007-10-12 04:20:20 +00:00
|
|
|
/* Cancel FM radio selection as previous music. For cases where we start
|
|
|
|
playback without going to the WPS, such as playlist insert.. or
|
|
|
|
playlist catalog. */
|
|
|
|
previous_music_is_wps();
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = start_index;
|
2006-04-20 01:43:16 +00:00
|
|
|
|
2006-04-19 02:22:23 +00:00
|
|
|
playlist->started = true;
|
2006-04-20 01:43:16 +00:00
|
|
|
sync_control(playlist, false);
|
|
|
|
audio_play(offset);
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns false if 'steps' is out of bounds, else true */
|
|
|
|
bool playlist_check(int steps)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
2005-11-02 22:32:04 +00:00
|
|
|
|
|
|
|
/* always allow folder navigation */
|
|
|
|
if (global_settings.next_folder && playlist->in_ram)
|
|
|
|
return true;
|
|
|
|
|
2005-06-25 04:46:25 +00:00
|
|
|
int index = get_next_index(playlist, steps, -1);
|
|
|
|
|
2005-11-02 22:32:04 +00:00
|
|
|
if (index < 0 && steps >= 0 && global_settings.repeat_mode == REPEAT_SHUFFLE)
|
2005-06-25 04:46:25 +00:00
|
|
|
index = get_next_index(playlist, steps, REPEAT_ALL);
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return (index >= 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get trackname of track that is "steps" away from current playing track.
|
|
|
|
NULL is used to identify end of playlist */
|
2010-08-11 19:01:50 +00:00
|
|
|
const char* playlist_peek(int steps, char* buf, size_t buf_size)
|
2004-01-26 17:05:21 +00:00
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
int seek;
|
|
|
|
char *temp_ptr;
|
|
|
|
int index;
|
|
|
|
bool control_file;
|
|
|
|
|
2005-06-25 04:46:25 +00:00
|
|
|
index = get_next_index(playlist, steps, -1);
|
2004-01-26 17:05:21 +00:00
|
|
|
if (index < 0)
|
|
|
|
return NULL;
|
|
|
|
|
2011-04-27 03:08:23 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
/* Just testing - don't care about the file name */
|
|
|
|
if (!buf || !buf_size)
|
|
|
|
return "";
|
|
|
|
#endif
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
|
|
|
|
2010-08-11 19:01:50 +00:00
|
|
|
if (get_filename(playlist, index, seek, control_file, buf,
|
|
|
|
buf_size) < 0)
|
2004-01-26 17:05:21 +00:00
|
|
|
return NULL;
|
|
|
|
|
2010-08-11 19:01:50 +00:00
|
|
|
temp_ptr = buf;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
if (!playlist->in_ram || control_file)
|
|
|
|
{
|
|
|
|
/* remove bogus dirs from beginning of path
|
|
|
|
(workaround for buggy playlist creation tools) */
|
|
|
|
while (temp_ptr)
|
|
|
|
{
|
2008-04-07 17:43:59 +00:00
|
|
|
if (file_exists(temp_ptr))
|
|
|
|
break;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
temp_ptr = strchr(temp_ptr+1, '/');
|
|
|
|
}
|
2008-04-07 17:43:59 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!temp_ptr)
|
|
|
|
{
|
|
|
|
/* Even though this is an invalid file, we still need to pass a
|
|
|
|
file name to the caller because NULL is used to indicate end
|
|
|
|
of playlist */
|
2010-08-11 19:01:50 +00:00
|
|
|
return buf;
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return temp_ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update indices as track has changed
|
|
|
|
*/
|
|
|
|
int playlist_next(int steps)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
int index;
|
|
|
|
|
2005-08-21 23:01:12 +00:00
|
|
|
if ( (steps > 0)
|
2007-02-17 23:07:39 +00:00
|
|
|
#ifdef AB_REPEAT_ENABLE
|
2005-08-21 23:01:12 +00:00
|
|
|
&& (global_settings.repeat_mode != REPEAT_AB)
|
|
|
|
#endif
|
|
|
|
&& (global_settings.repeat_mode != REPEAT_ONE) )
|
2004-01-26 17:05:21 +00:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
/* We need to delete all the queued songs */
|
|
|
|
for (i=0, j=steps; i<j; i++)
|
|
|
|
{
|
2005-06-25 04:46:25 +00:00
|
|
|
index = get_next_index(playlist, i, -1);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
if (playlist->indices[index] & PLAYLIST_QUEUE_MASK)
|
|
|
|
{
|
|
|
|
remove_track_from_playlist(playlist, index, true);
|
|
|
|
steps--; /* one less track */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-25 04:46:25 +00:00
|
|
|
index = get_next_index(playlist, steps, -1);
|
|
|
|
|
|
|
|
if (index < 0)
|
|
|
|
{
|
|
|
|
/* end of playlist... or is it */
|
2006-12-27 01:51:33 +00:00
|
|
|
if (global_settings.repeat_mode == REPEAT_SHUFFLE &&
|
2005-06-25 04:46:25 +00:00
|
|
|
playlist->amount > 1)
|
|
|
|
{
|
|
|
|
/* Repeat shuffle mode. Re-shuffle playlist and resume play */
|
2008-09-21 14:19:18 +00:00
|
|
|
playlist->first_index = 0;
|
2005-06-25 04:46:25 +00:00
|
|
|
sort_playlist(playlist, false, false);
|
|
|
|
randomise_playlist(playlist, current_tick, false, true);
|
2011-04-09 13:07:08 +00:00
|
|
|
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
playlist->started = true;
|
|
|
|
#else
|
2005-06-25 04:46:25 +00:00
|
|
|
playlist_start(0, 0);
|
2006-04-03 13:48:38 +00:00
|
|
|
#endif
|
|
|
|
playlist->index = 0;
|
2005-07-01 11:25:16 +00:00
|
|
|
index = 0;
|
|
|
|
}
|
2005-11-02 22:32:04 +00:00
|
|
|
else if (playlist->in_ram && global_settings.next_folder)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
2007-10-25 19:18:20 +00:00
|
|
|
index = create_and_play_dir(steps, true);
|
2005-07-01 11:25:16 +00:00
|
|
|
|
2007-10-25 19:18:20 +00:00
|
|
|
if (index >= 0)
|
2005-07-01 11:25:16 +00:00
|
|
|
{
|
2007-10-25 19:18:20 +00:00
|
|
|
playlist->index = index;
|
2005-11-10 22:31:47 +00:00
|
|
|
}
|
2005-06-25 04:46:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = index;
|
|
|
|
|
|
|
|
if (playlist->last_insert_pos >= 0 && steps > 0)
|
|
|
|
{
|
|
|
|
/* check to see if we've gone beyond the last inserted track */
|
|
|
|
int cur = rotate_index(playlist, index);
|
|
|
|
int last_pos = rotate_index(playlist, playlist->last_insert_pos);
|
|
|
|
|
|
|
|
if (cur > last_pos)
|
|
|
|
{
|
|
|
|
/* reset last inserted track */
|
|
|
|
playlist->last_insert_pos = -1;
|
|
|
|
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
{
|
2006-02-05 18:17:41 +00:00
|
|
|
int result = update_control(playlist, PLAYLIST_COMMAND_RESET,
|
|
|
|
-1, -1, NULL, NULL, NULL);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
if (result < 0)
|
|
|
|
return result;
|
2006-02-05 18:17:41 +00:00
|
|
|
|
|
|
|
sync_control(playlist, false);
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
2005-11-02 22:32:04 +00:00
|
|
|
/* try playing next or previous folder */
|
|
|
|
bool playlist_next_dir(int direction)
|
|
|
|
{
|
2005-11-10 22:31:47 +00:00
|
|
|
/* not to mess up real playlists */
|
|
|
|
if(!current_playlist.in_ram)
|
|
|
|
return false;
|
|
|
|
|
2007-10-25 19:18:20 +00:00
|
|
|
return create_and_play_dir(direction, false) >= 0;
|
2005-11-02 22:32:04 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* Get resume info for current playing song. If return value is -1 then
|
|
|
|
settings shouldn't be saved. */
|
|
|
|
int playlist_get_resume_info(int *resume_index)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
*resume_index = playlist->index;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-07-04 22:50:57 +00:00
|
|
|
/* Update resume info for current playing song. Returns -1 on error. */
|
|
|
|
int playlist_update_resume_info(const struct mp3entry* id3)
|
|
|
|
{
|
2011-04-07 21:38:51 +00:00
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
2011-04-27 03:08:23 +00:00
|
|
|
|
2005-07-04 22:50:57 +00:00
|
|
|
if (id3)
|
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
if (global_status.resume_index != playlist->index ||
|
2007-01-24 02:19:22 +00:00
|
|
|
global_status.resume_offset != id3->offset)
|
2005-07-04 22:50:57 +00:00
|
|
|
{
|
2011-04-27 03:08:23 +00:00
|
|
|
global_status.resume_index = playlist->index;
|
2007-01-24 02:19:22 +00:00
|
|
|
global_status.resume_offset = id3->offset;
|
|
|
|
status_save();
|
2005-07-04 22:50:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-06 19:11:40 +00:00
|
|
|
global_status.resume_index = -1;
|
2007-01-24 02:19:22 +00:00
|
|
|
global_status.resume_offset = -1;
|
|
|
|
status_save();
|
2005-07-04 22:50:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* Returns index of current playing track for display purposes. This value
|
|
|
|
should not be used for resume purposes as it doesn't represent the actual
|
|
|
|
index into the playlist */
|
|
|
|
int playlist_get_display_index(void)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
/* first_index should always be index 0 for display purposes */
|
|
|
|
int index = rotate_index(playlist, playlist->index);
|
|
|
|
|
|
|
|
return (index+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns number of tracks in current playlist */
|
|
|
|
int playlist_amount(void)
|
|
|
|
{
|
|
|
|
return playlist_amount_ex(NULL);
|
|
|
|
}
|
2009-10-28 22:27:38 +00:00
|
|
|
/* set playlist->last_shuffle_start to playlist->amount for
|
|
|
|
PLAYLIST_INSERT_LAST_SHUFFLED command purposes*/
|
|
|
|
void playlist_set_last_shuffled_start(void)
|
|
|
|
{
|
|
|
|
struct playlist_info* playlist = ¤t_playlist;
|
|
|
|
playlist->last_shuffled_start = playlist->amount;
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
/*
|
|
|
|
* Create a new playlist If playlist is not NULL then we're loading a
|
|
|
|
* playlist off disk for viewing/editing. The index_buffer is used to store
|
2011-07-17 13:30:48 +00:00
|
|
|
* playlist indices (required for and only used if !current playlist). The
|
|
|
|
* temp_buffer (if not NULL) is used as a scratchpad when loading indices.
|
2004-01-26 17:05:21 +00:00
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_create_ex(struct playlist_info* playlist,
|
|
|
|
const char* dir, const char* file,
|
2004-01-26 17:05:21 +00:00
|
|
|
void* index_buffer, int index_buffer_size,
|
|
|
|
void* temp_buffer, int temp_buffer_size)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Initialize playlist structure */
|
|
|
|
int r = rand() % 10;
|
|
|
|
playlist->current = false;
|
|
|
|
|
|
|
|
/* Use random name for control file */
|
|
|
|
snprintf(playlist->control_filename, sizeof(playlist->control_filename),
|
|
|
|
"%s.%d", PLAYLIST_CONTROL_FILE, r);
|
|
|
|
playlist->fd = -1;
|
|
|
|
playlist->control_fd = -1;
|
|
|
|
|
2011-07-17 13:30:48 +00:00
|
|
|
if (index_buffer)
|
|
|
|
{
|
|
|
|
int num_indices = index_buffer_size / sizeof(int);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-07-17 13:30:48 +00:00
|
|
|
num_indices /= 2;
|
2005-11-17 19:31:29 +00:00
|
|
|
#endif
|
2011-07-17 13:30:48 +00:00
|
|
|
if (num_indices > global_settings.max_files_in_playlist)
|
|
|
|
num_indices = global_settings.max_files_in_playlist;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
2011-07-17 13:30:48 +00:00
|
|
|
playlist->max_playlist_size = num_indices;
|
|
|
|
playlist->indices = index_buffer;
|
2005-11-17 19:31:29 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-06-20 20:12:42 +00:00
|
|
|
playlist->filenames = (int*)&playlist->indices[num_indices];
|
2005-11-17 19:31:29 +00:00
|
|
|
#endif
|
2011-07-17 13:30:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
playlist->max_playlist_size = current_playlist.max_playlist_size;
|
|
|
|
playlist->indices = current_playlist.indices;
|
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
playlist->filenames = current_playlist.filenames;
|
|
|
|
#endif
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
playlist->buffer_size = 0;
|
2011-08-30 14:01:45 +00:00
|
|
|
playlist->buffer_handle = -1;
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->buffer = NULL;
|
2011-02-14 11:27:45 +00:00
|
|
|
playlist->control_mutex = &created_playlist_mutex;
|
2004-01-26 17:05:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
new_playlist(playlist, dir, file);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (file)
|
|
|
|
/* load the playlist file */
|
|
|
|
add_indices_to_playlist(playlist, temp_buffer, temp_buffer_size);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/*
|
|
|
|
* Set the specified playlist as the current.
|
|
|
|
* NOTE: You will get undefined behaviour if something is already playing so
|
|
|
|
* remember to stop before calling this. Also, this call will
|
|
|
|
* effectively close your playlist, making it unusable.
|
|
|
|
*/
|
|
|
|
int playlist_set_current(struct playlist_info* playlist)
|
|
|
|
{
|
|
|
|
if (!playlist || (check_control(playlist) < 0))
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
empty_playlist(¤t_playlist, false);
|
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(current_playlist.filename, playlist->filename,
|
2004-01-26 17:05:21 +00:00
|
|
|
sizeof(current_playlist.filename));
|
|
|
|
|
2006-11-29 19:22:44 +00:00
|
|
|
current_playlist.utf8 = playlist->utf8;
|
2004-01-26 17:05:21 +00:00
|
|
|
current_playlist.fd = playlist->fd;
|
|
|
|
|
|
|
|
close(playlist->control_fd);
|
2006-04-20 01:43:16 +00:00
|
|
|
close(current_playlist.control_fd);
|
2004-01-26 17:05:21 +00:00
|
|
|
remove(current_playlist.control_filename);
|
|
|
|
if (rename(playlist->control_filename,
|
|
|
|
current_playlist.control_filename) < 0)
|
|
|
|
return -1;
|
|
|
|
current_playlist.control_fd = open(current_playlist.control_filename,
|
|
|
|
O_RDWR);
|
|
|
|
if (current_playlist.control_fd < 0)
|
|
|
|
return -1;
|
|
|
|
current_playlist.control_created = true;
|
|
|
|
|
|
|
|
current_playlist.dirlen = playlist->dirlen;
|
|
|
|
|
|
|
|
if (playlist->indices && playlist->indices != current_playlist.indices)
|
2005-11-17 19:31:29 +00:00
|
|
|
{
|
2011-08-30 14:01:45 +00:00
|
|
|
memcpy((void*)current_playlist.indices, (void*)playlist->indices,
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->max_playlist_size*sizeof(int));
|
|
|
|
#ifdef HAVE_DIRCACHE
|
2011-08-30 14:01:45 +00:00
|
|
|
memcpy((void*)current_playlist.filenames, (void*)playlist->filenames,
|
2005-11-17 19:31:29 +00:00
|
|
|
playlist->max_playlist_size*sizeof(int));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
current_playlist.first_index = playlist->first_index;
|
|
|
|
current_playlist.amount = playlist->amount;
|
|
|
|
current_playlist.last_insert_pos = playlist->last_insert_pos;
|
|
|
|
current_playlist.seed = playlist->seed;
|
|
|
|
current_playlist.shuffle_modified = playlist->shuffle_modified;
|
|
|
|
current_playlist.deleted = playlist->deleted;
|
|
|
|
current_playlist.num_inserted_tracks = playlist->num_inserted_tracks;
|
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
memcpy(current_playlist.control_cache, playlist->control_cache,
|
|
|
|
sizeof(current_playlist.control_cache));
|
|
|
|
current_playlist.num_cached = playlist->num_cached;
|
|
|
|
current_playlist.pending_control_sync = playlist->pending_control_sync;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2009-12-21 05:44:00 +00:00
|
|
|
struct playlist_info *playlist_get_current(void)
|
|
|
|
{
|
|
|
|
return ¤t_playlist;
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
/*
|
|
|
|
* Close files and delete control file for non-current playlist.
|
|
|
|
*/
|
|
|
|
void playlist_close(struct playlist_info* playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (playlist->fd >= 0)
|
|
|
|
close(playlist->fd);
|
|
|
|
|
|
|
|
if (playlist->control_fd >= 0)
|
|
|
|
close(playlist->control_fd);
|
|
|
|
|
|
|
|
if (playlist->control_created)
|
|
|
|
remove(playlist->control_filename);
|
|
|
|
}
|
|
|
|
|
2006-08-10 09:50:45 +00:00
|
|
|
void playlist_sync(struct playlist_info* playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
sync_control(playlist, false);
|
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started)
|
|
|
|
audio_flush_and_reload_tracks();
|
|
|
|
|
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/*
|
|
|
|
* Insert track into playlist at specified position (or one of the special
|
|
|
|
* positions). Returns position where track was inserted or -1 if error.
|
|
|
|
*/
|
2006-08-10 09:50:45 +00:00
|
|
|
int playlist_insert_track(struct playlist_info* playlist, const char *filename,
|
|
|
|
int position, bool queue, bool sync)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2003-07-06 16:05:44 +00:00
|
|
|
int result;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (check_control(playlist) < 0)
|
2003-07-06 16:05:44 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-06 16:05:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
result = add_track_to_playlist(playlist, filename, position, queue, -1);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-08-10 09:50:45 +00:00
|
|
|
/* Check if we want manually sync later. For example when adding
|
|
|
|
* bunch of files from tagcache, syncing after every file wouldn't be
|
|
|
|
* a good thing to do. */
|
|
|
|
if (sync && result >= 0)
|
|
|
|
playlist_sync(playlist);
|
2005-11-21 11:14:51 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Insert all tracks from specified directory into playlist.
|
|
|
|
*/
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_insert_directory(struct playlist_info* playlist,
|
|
|
|
const char *dirname, int position, bool queue,
|
|
|
|
bool recurse)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
int result;
|
2005-12-05 22:44:42 +00:00
|
|
|
unsigned char *count_str;
|
2006-07-18 13:54:12 +00:00
|
|
|
struct directory_search_context context;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (check_control(playlist) < 0)
|
2003-07-06 16:05:44 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-06 16:05:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-26 13:31:04 +00:00
|
|
|
if (position == PLAYLIST_REPLACE)
|
|
|
|
{
|
2008-04-20 11:19:50 +00:00
|
|
|
if (playlist_remove_all_tracks(playlist) == 0)
|
2006-12-26 13:31:04 +00:00
|
|
|
position = PLAYLIST_INSERT_LAST;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
if (queue)
|
2007-08-06 13:08:36 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_QUEUE_COUNT);
|
2003-07-01 21:05:43 +00:00
|
|
|
else
|
2008-07-29 13:32:47 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_INSERT_COUNT);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(0, count_str, false);
|
2006-07-18 13:54:12 +00:00
|
|
|
|
|
|
|
context.playlist = playlist;
|
|
|
|
context.position = position;
|
|
|
|
context.queue = queue;
|
|
|
|
context.count = 0;
|
2006-12-26 13:31:04 +00:00
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
result = playlist_directory_tracksearch(dirname, recurse,
|
|
|
|
directory_search_callback, &context);
|
2005-07-08 00:52:54 +00:00
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
sync_control(playlist, false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(context.count, count_str, true);
|
2005-07-08 00:52:54 +00:00
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started)
|
2005-07-08 00:52:54 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2005-11-21 11:14:51 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-26 17:05:21 +00:00
|
|
|
* Insert all tracks from specified playlist into dynamic playlist.
|
2003-07-01 21:05:43 +00:00
|
|
|
*/
|
2008-05-12 17:52:50 +00:00
|
|
|
int playlist_insert_playlist(struct playlist_info* playlist, const char *filename,
|
2004-01-26 17:05:21 +00:00
|
|
|
int position, bool queue)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int max;
|
|
|
|
char *temp_ptr;
|
2008-05-12 17:52:50 +00:00
|
|
|
const char *dir;
|
2005-12-05 22:44:42 +00:00
|
|
|
unsigned char *count_str;
|
2003-07-01 21:05:43 +00:00
|
|
|
char temp_buf[MAX_PATH+1];
|
|
|
|
char trackname[MAX_PATH+1];
|
|
|
|
int count = 0;
|
|
|
|
int result = 0;
|
2007-11-13 18:49:20 +00:00
|
|
|
bool utf8 = is_m3u8(filename);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (check_control(playlist) < 0)
|
2003-07-06 16:05:44 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-06 16:05:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-08-02 20:39:03 +00:00
|
|
|
fd = open_utf8(filename, O_RDONLY);
|
2003-07-01 21:05:43 +00:00
|
|
|
if (fd < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need the directory name for formatting purposes */
|
|
|
|
dir = filename;
|
|
|
|
|
|
|
|
temp_ptr = strrchr(filename+1,'/');
|
|
|
|
if (temp_ptr)
|
|
|
|
*temp_ptr = 0;
|
|
|
|
else
|
|
|
|
dir = "/";
|
|
|
|
|
|
|
|
if (queue)
|
2007-08-06 13:08:36 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_QUEUE_COUNT);
|
2003-01-09 00:55:00 +00:00
|
|
|
else
|
2007-08-06 13:08:36 +00:00
|
|
|
count_str = ID2P(LANG_PLAYLIST_INSERT_COUNT);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, count_str, false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-12-26 13:31:04 +00:00
|
|
|
if (position == PLAYLIST_REPLACE)
|
|
|
|
{
|
2008-04-20 11:19:50 +00:00
|
|
|
if (playlist_remove_all_tracks(playlist) == 0)
|
2006-12-26 13:31:04 +00:00
|
|
|
position = PLAYLIST_INSERT_LAST;
|
|
|
|
else return -1;
|
|
|
|
}
|
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
while ((max = read_line(fd, temp_buf, sizeof(temp_buf))) > 0)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
/* user abort */
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
2007-11-13 18:49:20 +00:00
|
|
|
|
2004-01-29 05:37:54 +00:00
|
|
|
if (temp_buf[0] != '#' && temp_buf[0] != '\0')
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
int insert_pos;
|
2007-11-13 18:49:20 +00:00
|
|
|
|
|
|
|
if (!utf8)
|
|
|
|
{
|
|
|
|
/* Use trackname as a temporay buffer. Note that trackname must
|
|
|
|
* be as large as temp_buf.
|
|
|
|
*/
|
|
|
|
max = convert_m3u(temp_buf, max, sizeof(temp_buf), trackname);
|
|
|
|
}
|
2003-04-23 18:45:51 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* we need to format so that relative paths are correctly
|
|
|
|
handled */
|
|
|
|
if (format_track_path(trackname, temp_buf, sizeof(trackname), max,
|
|
|
|
dir) < 0)
|
2003-01-09 00:55:00 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
result = -1;
|
|
|
|
break;
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
insert_pos = add_track_to_playlist(playlist, trackname, position,
|
|
|
|
queue, -1);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
if (insert_pos < 0)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure tracks are inserted in correct order if user
|
|
|
|
requests INSERT_FIRST */
|
|
|
|
if (position == PLAYLIST_INSERT_FIRST || position >= 0)
|
|
|
|
position = insert_pos + 1;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
|
|
|
if ((count%PLAYLIST_DISPLAY_COUNT) == 0)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, count_str, false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2005-07-08 00:52:54 +00:00
|
|
|
if (count == PLAYLIST_DISPLAY_COUNT &&
|
2006-05-09 14:43:49 +00:00
|
|
|
(audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
playlist->started)
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2005-07-01 11:25:16 +00:00
|
|
|
}
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* let the other threads work */
|
|
|
|
yield();
|
2003-01-09 00:55:00 +00:00
|
|
|
}
|
2002-08-16 14:41:47 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
close(fd);
|
2005-07-08 00:52:54 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (temp_ptr)
|
|
|
|
*temp_ptr = '/';
|
2002-06-27 08:20:09 +00:00
|
|
|
|
2006-02-05 18:17:41 +00:00
|
|
|
sync_control(playlist, false);
|
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, count_str, true);
|
2005-07-08 00:52:54 +00:00
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started)
|
2005-07-08 00:52:54 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2005-11-21 11:14:51 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
/*
|
2003-12-10 00:11:25 +00:00
|
|
|
* Delete track at specified index. If index is PLAYLIST_DELETE_CURRENT then
|
|
|
|
* we want to delete the current playing track.
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_delete(struct playlist_info* playlist, int index)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2003-12-10 00:11:25 +00:00
|
|
|
int result = 0;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (check_control(playlist) < 0)
|
2003-07-06 16:05:44 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2003-07-06 16:05:44 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
if (index == PLAYLIST_DELETE_CURRENT)
|
2004-01-26 17:05:21 +00:00
|
|
|
index = playlist->index;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
result = remove_track_from_playlist(playlist, index, true);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if (result != -1 && (audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
playlist->started)
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2003-01-09 00:18:47 +00:00
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
/*
|
|
|
|
* Move track at index to new_index. Tracks between the two are shifted
|
|
|
|
* appropriately. Returns 0 on success and -1 on failure.
|
|
|
|
*/
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_move(struct playlist_info* playlist, int index, int new_index)
|
2003-12-10 00:11:25 +00:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int seek;
|
|
|
|
bool control_file;
|
|
|
|
bool queue;
|
|
|
|
bool current = false;
|
2004-01-26 17:05:21 +00:00
|
|
|
int r;
|
2003-12-10 00:11:25 +00:00
|
|
|
char filename[MAX_PATH];
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (check_control(playlist) < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_CONTROL_ACCESS_ERROR));
|
2004-01-26 17:05:21 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
if (index == new_index)
|
|
|
|
return -1;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (index == playlist->index)
|
2003-12-10 00:11:25 +00:00
|
|
|
/* Moving the current track */
|
|
|
|
current = true;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
|
|
|
|
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
if (get_filename(playlist, index, seek, control_file, filename,
|
2004-01-26 17:05:21 +00:00
|
|
|
sizeof(filename)) < 0)
|
2003-12-10 00:11:25 +00:00
|
|
|
return -1;
|
|
|
|
|
2009-07-08 00:30:23 +00:00
|
|
|
/* We want to insert the track at the position that was specified by
|
|
|
|
new_index. This may be different then new_index because of the
|
|
|
|
shifting that will occur after the delete.
|
|
|
|
We calculate this before we do the remove as it depends on the
|
|
|
|
size of the playlist before the track removal */
|
|
|
|
r = rotate_index(playlist, new_index);
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
/* Delete track from original position */
|
2004-01-26 17:05:21 +00:00
|
|
|
result = remove_track_from_playlist(playlist, index, true);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
if (result != -1)
|
|
|
|
{
|
|
|
|
if (r == 0)
|
|
|
|
/* First index */
|
|
|
|
new_index = PLAYLIST_PREPEND;
|
2004-01-26 17:05:21 +00:00
|
|
|
else if (r == playlist->amount)
|
2003-12-10 00:11:25 +00:00
|
|
|
/* Append */
|
|
|
|
new_index = PLAYLIST_INSERT_LAST;
|
|
|
|
else
|
|
|
|
/* Calculate index of desired position */
|
2004-01-26 17:05:21 +00:00
|
|
|
new_index = (r+playlist->first_index)%playlist->amount;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
result = add_track_to_playlist(playlist, filename, new_index, queue,
|
|
|
|
-1);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
if (result != -1)
|
|
|
|
{
|
|
|
|
if (current)
|
|
|
|
{
|
|
|
|
/* Moved the current track */
|
|
|
|
switch (new_index)
|
|
|
|
{
|
|
|
|
case PLAYLIST_PREPEND:
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = playlist->first_index;
|
2003-12-10 00:11:25 +00:00
|
|
|
break;
|
|
|
|
case PLAYLIST_INSERT_LAST:
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = playlist->first_index - 1;
|
|
|
|
if (playlist->index < 0)
|
|
|
|
playlist->index += playlist->amount;
|
2003-12-10 00:11:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-01-26 17:05:21 +00:00
|
|
|
playlist->index = new_index;
|
2003-12-10 00:11:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if ((audio_status() & AUDIO_STATUS_PLAY) && playlist->started)
|
2005-07-08 00:52:54 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2003-12-10 00:11:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-21 11:14:51 +00:00
|
|
|
#ifdef HAVE_DIRCACHE
|
|
|
|
queue_post(&playlist_queue, PLAYLIST_LOAD_POINTERS, 0);
|
|
|
|
#endif
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* shuffle currently playing playlist */
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_randomise(struct playlist_info* playlist, unsigned int seed,
|
|
|
|
bool start_current)
|
2002-06-04 21:43:38 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
int result;
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2002-08-07 06:04:24 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
check_control(playlist);
|
2002-08-20 19:39:55 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
result = randomise_playlist(playlist, seed, start_current, true);
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if (result != -1 && (audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
playlist->started)
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2002-08-06 13:09:48 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2002-06-12 07:07:45 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* sort currently playing playlist */
|
|
|
|
int playlist_sort(struct playlist_info* playlist, bool start_current)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
int result;
|
2002-08-19 12:45:01 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2002-08-21 15:08:01 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
check_control(playlist);
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
result = sort_playlist(playlist, start_current, true);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-05-09 14:43:49 +00:00
|
|
|
if (result != -1 && (audio_status() & AUDIO_STATUS_PLAY) &&
|
|
|
|
playlist->started)
|
2005-04-04 12:06:29 +00:00
|
|
|
audio_flush_and_reload_tracks();
|
2003-01-09 00:55:00 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return result;
|
2002-06-04 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns true if playlist has been modified */
|
2004-08-18 01:09:31 +00:00
|
|
|
bool playlist_modified(const struct playlist_info* playlist)
|
2002-06-04 21:43:38 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->shuffle_modified ||
|
|
|
|
playlist->deleted ||
|
|
|
|
playlist->num_inserted_tracks > 0)
|
|
|
|
return true;
|
2002-06-11 07:30:31 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns index of first track in playlist */
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_get_first_index(const struct playlist_info* playlist)
|
2004-01-14 00:13:04 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
return playlist->first_index;
|
2004-01-14 00:13:04 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns shuffle seed of playlist */
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_get_seed(const struct playlist_info* playlist)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return playlist->seed;
|
2002-06-04 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns number of tracks in playlist (includes queued/inserted tracks) */
|
2004-08-18 01:09:31 +00:00
|
|
|
int playlist_amount_ex(const struct playlist_info* playlist)
|
2002-06-04 21:43:38 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2002-06-04 21:43:38 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return playlist->amount;
|
2003-07-01 21:05:43 +00:00
|
|
|
}
|
2002-09-10 08:50:40 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns full path of playlist (minus extension) */
|
2004-08-18 01:09:31 +00:00
|
|
|
char *playlist_name(const struct playlist_info* playlist, char *buf,
|
|
|
|
int buf_size)
|
2003-12-10 00:11:25 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
char *sep;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(buf, playlist->filename+playlist->dirlen, buf_size);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
if (!buf[0])
|
|
|
|
return NULL;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* Remove extension */
|
|
|
|
sep = strrchr(buf, '.');
|
|
|
|
if (sep)
|
|
|
|
*sep = 0;
|
2004-01-14 00:13:04 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
return buf;
|
2002-06-04 21:43:38 +00:00
|
|
|
}
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
/* returns the playlist filename */
|
2004-08-18 01:09:31 +00:00
|
|
|
char *playlist_get_name(const struct playlist_info* playlist, char *buf,
|
2004-01-26 17:05:21 +00:00
|
|
|
int buf_size)
|
2002-08-02 13:20:03 +00:00
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2009-07-14 13:57:45 +00:00
|
|
|
strlcpy(buf, playlist->filename, buf_size);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
if (!buf[0])
|
2003-07-01 21:05:43 +00:00
|
|
|
return NULL;
|
2002-08-02 13:20:03 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return buf;
|
2002-08-02 13:20:03 +00:00
|
|
|
}
|
|
|
|
|
2005-07-01 11:25:16 +00:00
|
|
|
/* Fills info structure with information about track at specified index.
|
2003-12-10 00:11:25 +00:00
|
|
|
Returns 0 on success and -1 on failure */
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_get_track_info(struct playlist_info* playlist, int index,
|
|
|
|
struct playlist_track_info* info)
|
2003-12-10 00:11:25 +00:00
|
|
|
{
|
|
|
|
int seek;
|
|
|
|
bool control_file;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
|
|
|
|
|
|
|
if (index < 0 || index >= playlist->amount)
|
2003-12-10 00:11:25 +00:00
|
|
|
return -1;
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
2005-11-17 19:31:29 +00:00
|
|
|
if (get_filename(playlist, index, seek, control_file, info->filename,
|
2003-12-10 00:11:25 +00:00
|
|
|
sizeof(info->filename)) < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
info->attr = 0;
|
|
|
|
|
|
|
|
if (control_file)
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->indices[index] & PLAYLIST_QUEUE_MASK)
|
2003-12-10 00:11:25 +00:00
|
|
|
info->attr |= PLAYLIST_ATTR_QUEUED;
|
|
|
|
else
|
|
|
|
info->attr |= PLAYLIST_ATTR_INSERTED;
|
2005-10-21 06:40:45 +00:00
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
}
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
if (playlist->indices[index] & PLAYLIST_SKIPPED)
|
|
|
|
info->attr |= PLAYLIST_ATTR_SKIPPED;
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
info->index = index;
|
2004-01-26 17:05:21 +00:00
|
|
|
info->display_index = rotate_index(playlist, index) + 1;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
/* save the current dynamic playlist to specified file */
|
2004-01-26 17:05:21 +00:00
|
|
|
int playlist_save(struct playlist_info* playlist, char *filename)
|
2002-08-02 13:20:03 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
int fd;
|
|
|
|
int i, index;
|
|
|
|
int count = 0;
|
2006-02-09 09:09:32 +00:00
|
|
|
char path[MAX_PATH+1];
|
2003-07-01 21:05:43 +00:00
|
|
|
char tmp_buf[MAX_PATH+1];
|
|
|
|
int result = 0;
|
2006-02-09 09:09:32 +00:00
|
|
|
bool overwrite_current = false;
|
2011-08-30 14:01:45 +00:00
|
|
|
int old_handle = -1;
|
2011-07-21 06:40:21 +00:00
|
|
|
char* old_buffer = NULL;
|
|
|
|
size_t old_buffer_size = 0;
|
2002-08-26 08:25:52 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
playlist = ¤t_playlist;
|
2003-07-06 16:05:44 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
if (playlist->amount <= 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* use current working directory as base for pathname */
|
2006-02-09 09:09:32 +00:00
|
|
|
if (format_track_path(path, filename, sizeof(tmp_buf),
|
2004-01-14 00:13:04 +00:00
|
|
|
strlen(filename)+1, getcwd(NULL, -1)) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
return -1;
|
|
|
|
|
2006-02-09 09:09:32 +00:00
|
|
|
if (!strncmp(playlist->filename, path, strlen(path)))
|
|
|
|
{
|
|
|
|
/* Attempting to overwrite current playlist file.*/
|
|
|
|
|
|
|
|
if (playlist->buffer_size < (int)(playlist->amount * sizeof(int)))
|
|
|
|
{
|
|
|
|
/* not enough buffer space to store updated indices */
|
2011-07-21 06:40:21 +00:00
|
|
|
/* Try to get a buffer */
|
2011-08-30 14:01:45 +00:00
|
|
|
old_handle = playlist->buffer_handle;
|
|
|
|
/* can ignore volatile here, because core_get_data() is called later */
|
|
|
|
old_buffer = (char*)playlist->buffer;
|
2011-07-21 06:40:21 +00:00
|
|
|
old_buffer_size = playlist->buffer_size;
|
|
|
|
playlist->buffer = plugin_get_buffer((size_t*)&playlist->buffer_size);
|
|
|
|
if (playlist->buffer_size < (int)(playlist->amount * sizeof(int)))
|
|
|
|
{
|
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
|
2011-08-30 14:01:45 +00:00
|
|
|
result = -1;
|
|
|
|
goto reset_old_buffer;
|
2011-07-21 06:40:21 +00:00
|
|
|
}
|
2006-02-09 09:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* use temporary pathname */
|
|
|
|
snprintf(path, sizeof(path), "%s_temp", playlist->filename);
|
|
|
|
overwrite_current = true;
|
|
|
|
}
|
|
|
|
|
2008-08-02 20:39:03 +00:00
|
|
|
if (is_m3u8(path))
|
|
|
|
{
|
|
|
|
fd = open_utf8(path, O_CREAT|O_WRONLY|O_TRUNC);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* some applications require a BOM to read the file properly */
|
2010-05-06 17:35:13 +00:00
|
|
|
fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0666);
|
2008-08-02 20:39:03 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
if (fd < 0)
|
2002-08-02 13:20:03 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
|
2011-08-30 14:01:45 +00:00
|
|
|
result = -1;
|
|
|
|
goto reset_old_buffer;
|
2002-08-02 13:20:03 +00:00
|
|
|
}
|
2002-08-26 08:25:52 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(true);
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
index = playlist->first_index;
|
|
|
|
for (i=0; i<playlist->amount; i++)
|
2002-08-26 08:25:52 +00:00
|
|
|
{
|
2003-07-01 21:05:43 +00:00
|
|
|
bool control_file;
|
|
|
|
bool queue;
|
|
|
|
int seek;
|
|
|
|
|
|
|
|
/* user abort */
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2006-02-09 09:09:32 +00:00
|
|
|
{
|
|
|
|
result = -1;
|
2003-07-01 21:05:43 +00:00
|
|
|
break;
|
2006-02-09 09:09:32 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
control_file = playlist->indices[index] & PLAYLIST_INSERT_TYPE_MASK;
|
|
|
|
queue = playlist->indices[index] & PLAYLIST_QUEUE_MASK;
|
|
|
|
seek = playlist->indices[index] & PLAYLIST_SEEK_MASK;
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
/* Don't save queued files */
|
|
|
|
if (!queue)
|
2002-08-26 08:25:52 +00:00
|
|
|
{
|
2005-11-17 19:31:29 +00:00
|
|
|
if (get_filename(playlist, index, seek, control_file, tmp_buf,
|
2004-01-26 17:05:21 +00:00
|
|
|
MAX_PATH+1) < 0)
|
2003-07-01 21:05:43 +00:00
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-02-09 09:09:32 +00:00
|
|
|
if (overwrite_current)
|
2011-08-30 14:01:33 +00:00
|
|
|
playlist->seek_buf[count] = lseek(fd, 0, SEEK_CUR);
|
2006-02-09 09:09:32 +00:00
|
|
|
|
2005-02-22 12:19:12 +00:00
|
|
|
if (fdprintf(fd, "%s\n", tmp_buf) < 0)
|
2002-08-26 08:25:52 +00:00
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_ACCESS_ERROR));
|
2003-07-01 21:05:43 +00:00
|
|
|
result = -1;
|
2002-08-26 08:25:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
count++;
|
|
|
|
|
2004-01-14 00:13:04 +00:00
|
|
|
if ((count % PLAYLIST_DISPLAY_COUNT) == 0)
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT),
|
|
|
|
false);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
yield();
|
2002-08-26 08:25:52 +00:00
|
|
|
}
|
2003-07-01 21:05:43 +00:00
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
index = (index+1)%playlist->amount;
|
2002-08-26 08:25:52 +00:00
|
|
|
}
|
2002-09-10 08:50:40 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
display_playlist_count(count, ID2P(LANG_PLAYLIST_SAVE_COUNT), true);
|
2003-07-01 21:05:43 +00:00
|
|
|
|
|
|
|
close(fd);
|
|
|
|
|
2006-02-09 09:09:32 +00:00
|
|
|
if (overwrite_current && result >= 0)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_lock(playlist->control_mutex);
|
2006-02-09 09:09:32 +00:00
|
|
|
|
|
|
|
/* Replace the current playlist with the new one and update indices */
|
|
|
|
close(playlist->fd);
|
|
|
|
if (remove(playlist->filename) >= 0)
|
|
|
|
{
|
|
|
|
if (rename(path, playlist->filename) >= 0)
|
|
|
|
{
|
2008-08-02 20:39:03 +00:00
|
|
|
playlist->fd = open_utf8(playlist->filename, O_RDONLY);
|
2006-02-09 09:09:32 +00:00
|
|
|
if (playlist->fd >= 0)
|
|
|
|
{
|
|
|
|
index = playlist->first_index;
|
|
|
|
for (i=0, count=0; i<playlist->amount; i++)
|
|
|
|
{
|
|
|
|
if (!(playlist->indices[index] & PLAYLIST_QUEUE_MASK))
|
|
|
|
{
|
2011-08-30 14:01:33 +00:00
|
|
|
playlist->indices[index] = playlist->seek_buf[count];
|
2006-02-09 09:09:32 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
index = (index+1)%playlist->amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we need to recreate control because inserted tracks are
|
|
|
|
now part of the playlist and shuffle has been
|
|
|
|
invalidated */
|
|
|
|
result = recreate_control(playlist);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-14 11:27:45 +00:00
|
|
|
mutex_unlock(playlist->control_mutex);
|
2006-02-09 09:09:32 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-12-05 20:01:48 +00:00
|
|
|
cpu_boost(false);
|
2011-08-30 14:01:45 +00:00
|
|
|
|
|
|
|
reset_old_buffer:
|
|
|
|
if (old_handle > 0)
|
|
|
|
old_buffer = core_get_data(old_handle);
|
|
|
|
playlist->buffer = old_buffer;
|
|
|
|
playlist->buffer_size = old_buffer_size;
|
2006-05-15 19:15:04 +00:00
|
|
|
|
2003-07-01 21:05:43 +00:00
|
|
|
return result;
|
2002-08-02 13:20:03 +00:00
|
|
|
}
|
2006-07-18 13:54:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Search specified directory for tracks and notify via callback. May be
|
|
|
|
* called recursively.
|
|
|
|
*/
|
|
|
|
int playlist_directory_tracksearch(const char* dirname, bool recurse,
|
|
|
|
int (*callback)(char*, void*),
|
|
|
|
void* context)
|
|
|
|
{
|
|
|
|
char buf[MAX_PATH+1];
|
|
|
|
int result = 0;
|
|
|
|
int num_files = 0;
|
2011-08-30 14:01:45 +00:00
|
|
|
int i;;
|
2006-07-18 13:54:12 +00:00
|
|
|
struct tree_context* tc = tree_get_context();
|
2011-08-30 14:01:45 +00:00
|
|
|
struct tree_cache* cache = &tc->cache;
|
2006-07-18 13:54:12 +00:00
|
|
|
int old_dirfilter = *(tc->dirfilter);
|
|
|
|
|
|
|
|
if (!callback)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* use the tree browser dircache to load files */
|
|
|
|
*(tc->dirfilter) = SHOW_ALL;
|
|
|
|
|
|
|
|
if (ft_load(tc, dirname) < 0)
|
|
|
|
{
|
2008-08-15 08:27:39 +00:00
|
|
|
splash(HZ*2, ID2P(LANG_PLAYLIST_DIRECTORY_ACCESS_ERROR));
|
2006-07-18 13:54:12 +00:00
|
|
|
*(tc->dirfilter) = old_dirfilter;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
num_files = tc->filesindir;
|
|
|
|
|
|
|
|
/* we've overwritten the dircache so tree browser will need to be
|
|
|
|
reloaded */
|
|
|
|
reload_directory();
|
|
|
|
|
|
|
|
for (i=0; i<num_files; i++)
|
|
|
|
{
|
|
|
|
/* user abort */
|
2006-08-15 12:27:07 +00:00
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
2006-07-18 13:54:12 +00:00
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-08-30 14:01:45 +00:00
|
|
|
struct entry *files = core_get_data(cache->entries_handle);
|
2006-07-18 13:54:12 +00:00
|
|
|
if (files[i].attr & ATTR_DIRECTORY)
|
|
|
|
{
|
|
|
|
if (recurse)
|
|
|
|
{
|
|
|
|
/* recursively add directories */
|
2010-11-29 12:51:44 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s",
|
|
|
|
dirname[1]? dirname: "", files[i].name);
|
2006-07-18 13:54:12 +00:00
|
|
|
result = playlist_directory_tracksearch(buf, recurse,
|
|
|
|
callback, context);
|
|
|
|
if (result < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* we now need to reload our current directory */
|
|
|
|
if(ft_load(tc, dirname) < 0)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
2011-08-30 14:01:45 +00:00
|
|
|
|
2006-07-18 13:54:12 +00:00
|
|
|
num_files = tc->filesindir;
|
|
|
|
if (!num_files)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
2007-04-18 13:03:01 +00:00
|
|
|
else if ((files[i].attr & FILE_ATTR_MASK) == FILE_ATTR_AUDIO)
|
2006-07-18 13:54:12 +00:00
|
|
|
{
|
2010-11-29 12:51:44 +00:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s",
|
|
|
|
dirname[1]? dirname: "", files[i].name);
|
2006-07-18 13:54:12 +00:00
|
|
|
|
|
|
|
if (callback(buf, context) != 0)
|
|
|
|
{
|
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* let the other threads work */
|
|
|
|
yield();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* restore dirfilter */
|
|
|
|
*(tc->dirfilter) = old_dirfilter;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|