2003-12-10 00:11:25 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
*
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2003 Hardeep Sidhu
|
|
|
|
|
*
|
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.
|
2003-12-10 00:11:25 +00:00
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2005-11-16 02:12:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* Kevin Ferrare 2005/10/16
|
|
|
|
|
* multi-screen support, rewrote a lot of code
|
|
|
|
|
*/
|
2003-12-10 00:11:25 +00:00
|
|
|
|
#include <string.h>
|
|
|
|
|
#include "playlist.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
|
#include "audio.h"
|
2003-12-10 00:11:25 +00:00
|
|
|
|
#include "screens.h"
|
|
|
|
|
#include "settings.h"
|
|
|
|
|
#include "icons.h"
|
|
|
|
|
#include "menu.h"
|
|
|
|
|
#include "plugin.h"
|
2004-01-26 17:05:21 +00:00
|
|
|
|
#include "keyboard.h"
|
2007-04-18 13:03:01 +00:00
|
|
|
|
#include "filetypes.h"
|
2004-01-26 17:05:21 +00:00
|
|
|
|
#include "onplay.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
|
#include "talk.h"
|
2004-07-26 16:06:59 +00:00
|
|
|
|
#include "misc.h"
|
2005-06-23 01:31:26 +00:00
|
|
|
|
#include "action.h"
|
2006-01-17 14:15:47 +00:00
|
|
|
|
#include "debug.h"
|
2006-03-05 00:16:34 +00:00
|
|
|
|
#include "backlight.h"
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
#include "lang.h"
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
#include "playlist_viewer.h"
|
2007-02-12 05:02:42 +00:00
|
|
|
|
#include "playlist_catalog.h"
|
2005-11-16 02:12:25 +00:00
|
|
|
|
#include "icon.h"
|
|
|
|
|
#include "list.h"
|
|
|
|
|
#include "splash.h"
|
2006-02-09 09:09:32 +00:00
|
|
|
|
#include "playlist_menu.h"
|
2014-01-11 09:46:37 +00:00
|
|
|
|
#include "menus/exported_menus.h"
|
2011-07-21 06:40:21 +00:00
|
|
|
|
#include "yesno.h"
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
/* Maximum number of tracks we can have loaded at one time */
|
2005-11-16 02:55:26 +00:00
|
|
|
|
#define MAX_PLAYLIST_ENTRIES 200
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
|
|
|
|
/* The number of items between the selected one and the end/start of
|
|
|
|
|
* the buffer under which the buffer must reload */
|
2008-09-07 20:09:11 +00:00
|
|
|
|
#define MIN_BUFFER_MARGIN (screens[0].getnblines()+1)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
/* Information about a specific track */
|
|
|
|
|
struct playlist_entry {
|
|
|
|
|
char *name; /* Formatted track name */
|
|
|
|
|
int index; /* Playlist index */
|
|
|
|
|
int display_index; /* Display index */
|
|
|
|
|
bool queued; /* Is track queued? */
|
2005-10-21 06:40:45 +00:00
|
|
|
|
bool skipped; /* Is track marked as bad? */
|
2003-12-10 00:11:25 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
enum direction
|
|
|
|
|
{
|
|
|
|
|
FORWARD,
|
|
|
|
|
BACKWARD
|
|
|
|
|
};
|
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
enum pv_onplay_result {
|
|
|
|
|
PV_ONPLAY_USB,
|
|
|
|
|
PV_ONPLAY_USB_CLOSED,
|
2022-11-19 15:15:22 +00:00
|
|
|
|
PV_ONPLAY_WPS_CLOSED,
|
2022-04-16 03:40:42 +00:00
|
|
|
|
PV_ONPLAY_CLOSED,
|
|
|
|
|
PV_ONPLAY_ITEM_REMOVED,
|
|
|
|
|
PV_ONPLAY_CHANGED,
|
|
|
|
|
PV_ONPLAY_UNCHANGED,
|
|
|
|
|
};
|
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
struct playlist_buffer
|
|
|
|
|
{
|
|
|
|
|
char *name_buffer; /* Buffer used to store track names */
|
|
|
|
|
int buffer_size; /* Size of name buffer */
|
|
|
|
|
|
|
|
|
|
int first_index; /* Real index of first track loaded inside
|
|
|
|
|
the buffer */
|
|
|
|
|
|
|
|
|
|
enum direction direction; /* Direction of the buffer (if the buffer
|
|
|
|
|
was loaded BACKWARD, the last track in
|
|
|
|
|
the buffer has a real index < to the
|
|
|
|
|
real index of the the first track)*/
|
|
|
|
|
|
|
|
|
|
struct playlist_entry tracks[MAX_PLAYLIST_ENTRIES];
|
|
|
|
|
int num_loaded; /* Number of track entries loaded in buffer */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Global playlist viewer settings */
|
|
|
|
|
struct playlist_viewer {
|
2022-11-21 02:15:03 +00:00
|
|
|
|
const char *title; /* Playlist Viewer list title */
|
|
|
|
|
struct playlist_info* playlist; /* Playlist being viewed */
|
2009-07-02 23:03:46 +00:00
|
|
|
|
int num_tracks; /* Number of tracks in playlist */
|
2022-11-22 19:37:47 +00:00
|
|
|
|
int *initial_selection; /* The initially selected track */
|
2009-07-02 23:03:46 +00:00
|
|
|
|
int current_playing_track; /* Index of current playing track */
|
|
|
|
|
int selected_track; /* The selected track, relative (first is 0) */
|
|
|
|
|
int moving_track; /* The track to move, relative (first is 0)
|
|
|
|
|
or -1 if nothing is currently being moved */
|
2021-10-21 20:42:01 +00:00
|
|
|
|
int moving_playlist_index; /* Playlist-relative index (as opposed to
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer-relative index) of moving track */
|
2005-11-16 02:12:25 +00:00
|
|
|
|
struct playlist_buffer buffer;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct playlist_viewer viewer;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* Used when viewing playlists on disk */
|
2005-11-19 18:19:46 +00:00
|
|
|
|
static struct playlist_info temp_playlist;
|
2023-01-21 21:05:02 +00:00
|
|
|
|
static bool temp_playlist_init = false;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
static bool dirty = false;
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
|
|
|
|
|
int names_buffer_size);
|
|
|
|
|
static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index,
|
|
|
|
|
enum direction direction);
|
|
|
|
|
static int playlist_entry_load(struct playlist_entry *entry, int index,
|
|
|
|
|
char* name_buffer, int remaining_size);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
|
|
|
|
|
int index);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
|
|
|
|
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
2022-11-22 19:37:47 +00:00
|
|
|
|
const char* filename, bool reload,
|
|
|
|
|
int *most_recent_selection);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2004-08-18 01:09:31 +00:00
|
|
|
|
static void format_name(char* dest, const char* src);
|
2005-11-19 18:19:46 +00:00
|
|
|
|
static void format_line(const struct playlist_entry* track, char* str,
|
|
|
|
|
int len);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2003-12-10 00:11:25 +00:00
|
|
|
|
static bool update_playlist(bool force);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
static enum pv_onplay_result onplay_menu(int index);
|
|
|
|
|
|
2022-12-14 08:06:04 +00:00
|
|
|
|
static void close_playlist_viewer(void);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer,
|
|
|
|
|
int names_buffer_size)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
pb->name_buffer = names_buffer;
|
|
|
|
|
pb->buffer_size = names_buffer_size;
|
|
|
|
|
pb->first_index = 0;
|
|
|
|
|
pb->num_loaded = 0;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
2005-11-19 18:19:46 +00:00
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
/*
|
|
|
|
|
* Loads the entries following 'index' in the playlist buffer
|
|
|
|
|
*/
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static void playlist_buffer_load_entries(struct playlist_buffer *pb, int index,
|
|
|
|
|
enum direction direction)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
int num_entries = viewer.num_tracks;
|
|
|
|
|
char* p = pb->name_buffer;
|
|
|
|
|
int remaining = pb->buffer_size;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
pb->first_index = index;
|
|
|
|
|
if (num_entries > MAX_PLAYLIST_ENTRIES)
|
|
|
|
|
num_entries = MAX_PLAYLIST_ENTRIES;
|
|
|
|
|
|
2011-04-08 13:39:56 +00:00
|
|
|
|
for (i = 0; i < num_entries; i++)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
int len = playlist_entry_load(&(pb->tracks[i]), index, p, remaining);
|
|
|
|
|
if (len < 0)
|
|
|
|
|
{
|
|
|
|
|
/* Out of name buffer space */
|
|
|
|
|
num_entries = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p += len;
|
|
|
|
|
remaining -= len;
|
|
|
|
|
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if(direction == FORWARD)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
index++;
|
|
|
|
|
else
|
|
|
|
|
index--;
|
2011-04-08 13:39:56 +00:00
|
|
|
|
index += viewer.num_tracks;
|
|
|
|
|
index %= viewer.num_tracks;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
pb->direction = direction;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
pb->num_loaded = i;
|
|
|
|
|
}
|
|
|
|
|
|
2012-06-18 09:37:22 +00:00
|
|
|
|
/* playlist_buffer_load_entries_screen()
|
|
|
|
|
* This function is called when the currently selected item gets too close
|
|
|
|
|
* to the start or the end of the loaded part of the playlis, or when
|
|
|
|
|
* the list callback requests a playlist item that has not been loaded yet
|
|
|
|
|
*
|
|
|
|
|
* reference_track is either the currently selected track, or the track that
|
|
|
|
|
* has been requested by the callback, and has not been loaded yet.
|
|
|
|
|
*/
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb,
|
2012-06-18 09:37:22 +00:00
|
|
|
|
enum direction direction,
|
|
|
|
|
int reference_track)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (direction == FORWARD)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2012-06-18 09:37:22 +00:00
|
|
|
|
int min_start = reference_track-2*screens[0].getnblines();
|
2011-04-08 13:39:56 +00:00
|
|
|
|
while (min_start < 0)
|
|
|
|
|
min_start += viewer.num_tracks;
|
2006-01-17 14:15:47 +00:00
|
|
|
|
min_start %= viewer.num_tracks;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
playlist_buffer_load_entries(pb, min_start, FORWARD);
|
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
else
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2012-06-18 09:37:22 +00:00
|
|
|
|
int max_start = reference_track+2*screens[0].getnblines();
|
2011-04-08 13:39:56 +00:00
|
|
|
|
max_start %= viewer.num_tracks;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
playlist_buffer_load_entries(pb, max_start, BACKWARD);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static int playlist_entry_load(struct playlist_entry *entry, int index,
|
|
|
|
|
char* name_buffer, int remaining_size)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
struct playlist_track_info info;
|
|
|
|
|
int len;
|
|
|
|
|
|
|
|
|
|
/* Playlist viewer orders songs based on display index. We need to
|
|
|
|
|
convert to real playlist index to access track */
|
|
|
|
|
index = (index + playlist_get_first_index(viewer.playlist)) %
|
|
|
|
|
viewer.num_tracks;
|
|
|
|
|
if (playlist_get_track_info(viewer.playlist, index, &info) < 0)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
len = strlen(info.filename) + 1;
|
|
|
|
|
|
|
|
|
|
if (len <= remaining_size)
|
|
|
|
|
{
|
|
|
|
|
strcpy(name_buffer, info.filename);
|
|
|
|
|
|
|
|
|
|
entry->name = name_buffer;
|
|
|
|
|
entry->index = info.index;
|
|
|
|
|
entry->display_index = info.display_index;
|
|
|
|
|
entry->queued = info.attr & PLAYLIST_ATTR_QUEUED;
|
|
|
|
|
entry->skipped = info.attr & PLAYLIST_ATTR_SKIPPED;
|
|
|
|
|
return len;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2008-04-09 21:47:43 +00:00
|
|
|
|
static int playlist_buffer_get_index(struct playlist_buffer *pb, int index)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
int buffer_index;
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (pb->direction == FORWARD)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (index >= pb->first_index)
|
|
|
|
|
buffer_index = index-pb->first_index;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
else /* rotation : track0 in buffer + requested track */
|
2011-04-08 13:39:56 +00:00
|
|
|
|
buffer_index = viewer.num_tracks-pb->first_index+index;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (index <= pb->first_index)
|
|
|
|
|
buffer_index = pb->first_index-index;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
else /* rotation : track0 in buffer + dist from the last track
|
|
|
|
|
to the requested track (num_tracks-requested track) */
|
2011-04-08 13:39:56 +00:00
|
|
|
|
buffer_index = pb->first_index+viewer.num_tracks-index;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
return buffer_index;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define distance(a, b) \
|
|
|
|
|
a>b? (a) - (b) : (b) - (a)
|
2008-04-09 21:47:43 +00:00
|
|
|
|
static bool playlist_buffer_needs_reload(struct playlist_buffer* pb,
|
|
|
|
|
int track_index)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (pb->num_loaded == viewer.num_tracks)
|
|
|
|
|
return false;
|
|
|
|
|
int selected_index = playlist_buffer_get_index(pb, track_index);
|
|
|
|
|
int first_buffer_index = playlist_buffer_get_index(pb, pb->first_index);
|
|
|
|
|
int distance_beginning = distance(selected_index, first_buffer_index);
|
|
|
|
|
if (distance_beginning < MIN_BUFFER_MARGIN)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (pb->num_loaded - distance_beginning < MIN_BUFFER_MARGIN)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
|
static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb,
|
|
|
|
|
int index)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
int buffer_index = playlist_buffer_get_index(pb, index);
|
2012-06-18 09:37:22 +00:00
|
|
|
|
/* Make sure that we are not returning an invalid pointer.
|
|
|
|
|
In some cases, when scrolling really fast, it could happen that a reqested track
|
|
|
|
|
has not been pre-loaded */
|
|
|
|
|
if (buffer_index < 0) {
|
|
|
|
|
playlist_buffer_load_entries_screen(&viewer.buffer,
|
|
|
|
|
pb->direction == FORWARD ? BACKWARD : FORWARD,
|
|
|
|
|
index);
|
|
|
|
|
|
|
|
|
|
} else if (buffer_index >= pb->num_loaded) {
|
|
|
|
|
playlist_buffer_load_entries_screen(&viewer.buffer,
|
|
|
|
|
pb->direction,
|
|
|
|
|
index);
|
|
|
|
|
}
|
|
|
|
|
buffer_index = playlist_buffer_get_index(pb, index);
|
|
|
|
|
if (buffer_index < 0 || buffer_index >= pb->num_loaded) {
|
|
|
|
|
/* This really shouldn't happen. If this happens, then
|
|
|
|
|
the name_buffer is probably too small to store enough
|
|
|
|
|
titles to fill the screen, and preload data in the short
|
|
|
|
|
direction.
|
2021-10-21 20:42:01 +00:00
|
|
|
|
|
2012-06-18 09:37:22 +00:00
|
|
|
|
If this happens then scrolling performance will probably
|
|
|
|
|
be quite low, but it's better then having Data Abort errors */
|
|
|
|
|
playlist_buffer_load_entries(pb, index, FORWARD);
|
|
|
|
|
buffer_index = playlist_buffer_get_index(pb, index);
|
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
return &(pb->tracks[buffer_index]);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* Initialize the playlist viewer. */
|
2005-11-16 02:12:25 +00:00
|
|
|
|
static bool playlist_viewer_init(struct playlist_viewer * viewer,
|
2022-11-22 19:37:47 +00:00
|
|
|
|
const char* filename, bool reload,
|
|
|
|
|
int *most_recent_selection)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
|
char* buffer;
|
2007-04-21 19:20:20 +00:00
|
|
|
|
size_t buffer_size;
|
2007-04-26 08:21:29 +00:00
|
|
|
|
bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE);
|
|
|
|
|
bool have_list = filename || is_playing;
|
2011-08-01 08:38:32 +00:00
|
|
|
|
if (!have_list && (global_status.resume_index != -1))
|
2007-04-26 08:21:29 +00:00
|
|
|
|
{
|
|
|
|
|
/* Try to restore the list from control file */
|
|
|
|
|
have_list = (playlist_resume() != -1);
|
|
|
|
|
}
|
2007-08-25 16:05:58 +00:00
|
|
|
|
if (!have_list && (playlist_amount() > 0))
|
|
|
|
|
{
|
2021-10-21 20:42:01 +00:00
|
|
|
|
/*If dynamic playlist still exists, view it anyway even
|
2007-08-25 16:05:58 +00:00
|
|
|
|
if playback has reached the end of the playlist */
|
|
|
|
|
have_list = true;
|
|
|
|
|
}
|
2007-04-26 08:21:29 +00:00
|
|
|
|
if (!have_list)
|
|
|
|
|
{
|
|
|
|
|
/* Nothing to view, exit */
|
2018-10-30 13:45:26 +00:00
|
|
|
|
splash(HZ, ID2P(LANG_CATALOG_NO_PLAYLISTS));
|
2003-12-10 00:11:25 +00:00
|
|
|
|
return false;
|
2007-04-26 08:21:29 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2007-04-21 19:20:20 +00:00
|
|
|
|
buffer = plugin_get_buffer(&buffer_size);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (!buffer)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (!filename)
|
2022-11-21 02:15:03 +00:00
|
|
|
|
{
|
2005-11-16 02:12:25 +00:00
|
|
|
|
viewer->playlist = NULL;
|
2022-11-21 02:15:03 +00:00
|
|
|
|
viewer->title = (char *) str(LANG_PLAYLIST);
|
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Viewing playlist on disk */
|
2008-05-12 17:52:50 +00:00
|
|
|
|
const char *dir, *file;
|
|
|
|
|
char *temp_ptr;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
char *index_buffer = NULL;
|
2007-04-21 18:38:25 +00:00
|
|
|
|
ssize_t index_buffer_size = 0;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2023-01-21 21:05:02 +00:00
|
|
|
|
/* Initialize temp playlist
|
|
|
|
|
* TODO - move this to playlist.c */
|
|
|
|
|
if (!temp_playlist_init)
|
|
|
|
|
{
|
|
|
|
|
mutex_init(&temp_playlist.mutex);
|
|
|
|
|
temp_playlist_init = true;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
viewer->playlist = &temp_playlist;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
|
|
/* Separate directory from filename */
|
|
|
|
|
temp_ptr = strrchr(filename+1,'/');
|
|
|
|
|
if (temp_ptr)
|
|
|
|
|
{
|
|
|
|
|
*temp_ptr = 0;
|
|
|
|
|
dir = filename;
|
|
|
|
|
file = temp_ptr + 1;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dir = "/";
|
|
|
|
|
file = filename+1;
|
|
|
|
|
}
|
2022-11-21 02:15:03 +00:00
|
|
|
|
viewer->title = file;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
|
|
if (is_playing)
|
|
|
|
|
{
|
2020-05-19 06:20:39 +00:00
|
|
|
|
/* Something is playing, try to accommodate
|
|
|
|
|
* global_settings.max_files_in_playlist entries */
|
|
|
|
|
index_buffer_size = playlist_get_required_bufsz(viewer->playlist,
|
|
|
|
|
false, global_settings.max_files_in_playlist);
|
|
|
|
|
|
|
|
|
|
if ((unsigned)index_buffer_size >= buffer_size - MAX_PATH)
|
|
|
|
|
index_buffer_size = buffer_size - (MAX_PATH + 1);
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
index_buffer = buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
playlist_create_ex(viewer->playlist, dir, file, index_buffer,
|
2004-01-26 17:05:21 +00:00
|
|
|
|
index_buffer_size, buffer+index_buffer_size,
|
|
|
|
|
buffer_size-index_buffer_size);
|
|
|
|
|
|
|
|
|
|
if (temp_ptr)
|
|
|
|
|
*temp_ptr = '/';
|
|
|
|
|
|
|
|
|
|
buffer += index_buffer_size;
|
|
|
|
|
buffer_size -= index_buffer_size;
|
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
playlist_buffer_init(&viewer->buffer, buffer, buffer_size);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer->moving_track = -1;
|
2009-07-07 22:40:47 +00:00
|
|
|
|
viewer->moving_playlist_index = -1;
|
2022-11-22 19:37:47 +00:00
|
|
|
|
viewer->initial_selection = most_recent_selection;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (!reload)
|
2005-11-19 18:19:46 +00:00
|
|
|
|
{
|
2006-01-17 12:30:03 +00:00
|
|
|
|
if (viewer->playlist)
|
2022-11-22 19:37:47 +00:00
|
|
|
|
viewer->selected_track = most_recent_selection ? *most_recent_selection : 0;
|
2006-01-17 12:30:03 +00:00
|
|
|
|
else
|
|
|
|
|
viewer->selected_track = playlist_get_display_index() - 1;
|
2005-11-19 18:19:46 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
if (!update_playlist(true))
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Format trackname for display purposes */
|
2004-08-18 01:09:31 +00:00
|
|
|
|
static void format_name(char* dest, const char* src)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
|
switch (global_settings.playlist_viewer_track_display)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
default:
|
|
|
|
|
{
|
2006-08-10 21:08:44 +00:00
|
|
|
|
/* Only display the filename */
|
2004-01-26 17:05:21 +00:00
|
|
|
|
char* p = strrchr(src, '/');
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
strcpy(dest, p+1);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* Remove the extension */
|
2007-11-18 14:12:01 +00:00
|
|
|
|
strrsplt(dest, '.');
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case 1:
|
|
|
|
|
/* Full path */
|
|
|
|
|
strcpy(dest, src);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Format display line */
|
2005-11-19 18:19:46 +00:00
|
|
|
|
static void format_line(const struct playlist_entry* track, char* str,
|
|
|
|
|
int len)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
{
|
|
|
|
|
char name[MAX_PATH];
|
2005-10-21 06:40:45 +00:00
|
|
|
|
char *skipped = "";
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
format_name(name, track->name);
|
|
|
|
|
|
2005-10-21 06:40:45 +00:00
|
|
|
|
if (track->skipped)
|
|
|
|
|
skipped = "(ERR) ";
|
2006-04-03 04:13:26 +00:00
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (global_settings.playlist_viewer_indices)
|
|
|
|
|
/* Display playlist index */
|
2005-10-21 06:40:45 +00:00
|
|
|
|
snprintf(str, len, "%d. %s%s", track->display_index, skipped, name);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
else
|
2005-10-21 06:40:45 +00:00
|
|
|
|
snprintf(str, len, "%s%s", skipped, name);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Update playlist in case something has changed or forced */
|
|
|
|
|
static bool update_playlist(bool force)
|
|
|
|
|
{
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (!viewer.playlist)
|
|
|
|
|
playlist_get_resume_info(&viewer.current_playing_track);
|
|
|
|
|
else
|
|
|
|
|
viewer.current_playing_track = -1;
|
2011-04-08 13:39:56 +00:00
|
|
|
|
int nb_tracks = playlist_amount_ex(viewer.playlist);
|
|
|
|
|
force = force || nb_tracks != viewer.num_tracks;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
if (force)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Reload tracks */
|
2005-11-16 02:12:25 +00:00
|
|
|
|
viewer.num_tracks = nb_tracks;
|
2006-04-20 07:30:28 +00:00
|
|
|
|
if (viewer.num_tracks <= 0)
|
2009-07-02 22:45:00 +00:00
|
|
|
|
{
|
|
|
|
|
global_status.resume_index = -1;
|
|
|
|
|
global_status.resume_offset = -1;
|
2013-07-14 11:59:39 +00:00
|
|
|
|
global_status.resume_elapsed = -1;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
return false;
|
2009-07-02 22:45:00 +00:00
|
|
|
|
}
|
2012-06-18 09:37:22 +00:00
|
|
|
|
playlist_buffer_load_entries_screen(&viewer.buffer, FORWARD,
|
|
|
|
|
viewer.selected_track);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
if (viewer.buffer.num_loaded <= 0)
|
2009-07-02 22:45:00 +00:00
|
|
|
|
{
|
|
|
|
|
global_status.resume_index = -1;
|
|
|
|
|
global_status.resume_offset = -1;
|
2013-07-14 11:59:39 +00:00
|
|
|
|
global_status.resume_elapsed = -1;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
return false;
|
2009-07-02 22:45:00 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
static enum pv_onplay_result show_track_info(const struct playlist_entry *current_track)
|
2021-12-28 07:56:16 +00:00
|
|
|
|
{
|
|
|
|
|
struct mp3entry id3;
|
|
|
|
|
bool id3_retrieval_successful = false;
|
|
|
|
|
|
2022-04-10 00:25:54 +00:00
|
|
|
|
int fd = open(current_track->name, O_RDONLY);
|
|
|
|
|
if (fd >= 0)
|
2021-12-28 07:56:16 +00:00
|
|
|
|
{
|
2022-04-10 00:25:54 +00:00
|
|
|
|
if (get_metadata(&id3, fd, current_track->name))
|
|
|
|
|
id3_retrieval_successful = true;
|
|
|
|
|
close(fd);
|
2021-12-28 07:56:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return id3_retrieval_successful &&
|
|
|
|
|
browse_id3(&id3, current_track->index + 1,
|
2023-04-12 18:19:58 +00:00
|
|
|
|
viewer.num_tracks, NULL, 1) ? PV_ONPLAY_USB : PV_ONPLAY_UNCHANGED;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 09:35:20 +00:00
|
|
|
|
|
2022-08-05 18:05:33 +00:00
|
|
|
|
#ifdef HAVE_HOTKEY
|
2022-04-18 09:35:20 +00:00
|
|
|
|
static enum pv_onplay_result open_with(const struct playlist_entry *current_track)
|
|
|
|
|
{
|
|
|
|
|
char selected_track[MAX_PATH];
|
2022-12-14 08:06:04 +00:00
|
|
|
|
close_playlist_viewer(); /* don't pop activity yet – relevant for plugin_load */
|
2022-11-14 15:01:14 +00:00
|
|
|
|
|
2022-11-14 16:32:34 +00:00
|
|
|
|
strmemccpy(selected_track, current_track->name, sizeof(selected_track));
|
2022-11-14 15:01:14 +00:00
|
|
|
|
|
2022-11-19 15:15:22 +00:00
|
|
|
|
int plugin_return = filetype_list_viewers(selected_track);
|
2022-12-14 08:06:04 +00:00
|
|
|
|
pop_current_activity_without_refresh();
|
2022-04-18 09:35:20 +00:00
|
|
|
|
|
2022-11-19 15:15:22 +00:00
|
|
|
|
switch (plugin_return)
|
|
|
|
|
{
|
|
|
|
|
case PLUGIN_USB_CONNECTED:
|
|
|
|
|
return PV_ONPLAY_USB_CLOSED;
|
|
|
|
|
case PLUGIN_GOTO_WPS:
|
|
|
|
|
return PV_ONPLAY_WPS_CLOSED;
|
|
|
|
|
default:
|
|
|
|
|
return PV_ONPLAY_CLOSED;
|
|
|
|
|
}
|
2022-04-18 09:35:20 +00:00
|
|
|
|
}
|
2022-08-05 18:05:33 +00:00
|
|
|
|
#endif /* HAVE_HOTKEY */
|
2022-04-18 09:35:20 +00:00
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
static enum pv_onplay_result open_pictureflow(const struct playlist_entry *current_track)
|
|
|
|
|
{
|
|
|
|
|
char selected_track[MAX_PATH];
|
2022-12-14 08:06:04 +00:00
|
|
|
|
close_playlist_viewer(); /* don't pop activity yet – relevant for plugin_load */
|
2022-11-14 15:01:14 +00:00
|
|
|
|
|
2022-11-14 16:32:34 +00:00
|
|
|
|
strmemccpy(selected_track, current_track->name, sizeof(selected_track));
|
2022-11-19 15:15:22 +00:00
|
|
|
|
int plugin_return = filetype_load_plugin((void *)"pictureflow", selected_track);
|
2022-12-14 08:06:04 +00:00
|
|
|
|
pop_current_activity_without_refresh();
|
2022-11-19 15:15:22 +00:00
|
|
|
|
|
|
|
|
|
switch (plugin_return)
|
|
|
|
|
{
|
|
|
|
|
case PLUGIN_USB_CONNECTED:
|
|
|
|
|
return PV_ONPLAY_USB_CLOSED;
|
|
|
|
|
case PLUGIN_GOTO_WPS:
|
|
|
|
|
return PV_ONPLAY_WPS_CLOSED;
|
|
|
|
|
default:
|
|
|
|
|
return PV_ONPLAY_CLOSED;
|
|
|
|
|
}
|
2021-12-28 07:56:16 +00:00
|
|
|
|
}
|
2022-04-16 03:40:42 +00:00
|
|
|
|
#endif
|
2021-12-28 07:56:16 +00:00
|
|
|
|
|
2022-04-18 09:35:20 +00:00
|
|
|
|
static enum pv_onplay_result delete_track(int current_track_index,
|
|
|
|
|
int index, bool current_was_playing)
|
|
|
|
|
{
|
|
|
|
|
playlist_delete(viewer.playlist, current_track_index);
|
|
|
|
|
if (current_was_playing)
|
|
|
|
|
{
|
|
|
|
|
if (playlist_amount_ex(viewer.playlist) <= 0)
|
|
|
|
|
audio_stop();
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Start playing new track except if it's the lasttrack
|
|
|
|
|
track in the playlist and repeat mode is disabled */
|
|
|
|
|
struct playlist_entry *current_track =
|
|
|
|
|
playlist_buffer_get_track(&viewer.buffer, index);
|
|
|
|
|
if (current_track->display_index != viewer.num_tracks ||
|
|
|
|
|
global_settings.repeat_mode == REPEAT_ALL)
|
|
|
|
|
{
|
|
|
|
|
audio_play(0, 0);
|
|
|
|
|
viewer.current_playing_track = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return PV_ONPLAY_ITEM_REMOVED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
/* Menu of playlist commands. Invoked via ON+PLAY on main viewer screen. */
|
|
|
|
|
static enum pv_onplay_result onplay_menu(int index)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2022-04-16 03:40:42 +00:00
|
|
|
|
int result, ret = PV_ONPLAY_UNCHANGED;
|
2011-04-08 13:39:56 +00:00
|
|
|
|
struct playlist_entry * current_track =
|
2005-11-16 02:12:25 +00:00
|
|
|
|
playlist_buffer_get_track(&viewer.buffer, index);
|
2021-03-11 17:40:02 +00:00
|
|
|
|
MENUITEM_STRINGLIST(menu_items, ID2P(LANG_PLAYLIST), NULL,
|
2022-11-27 22:37:26 +00:00
|
|
|
|
ID2P(LANG_PLAYING_NEXT), ID2P(LANG_ADD_TO_PL),
|
2021-12-28 07:56:16 +00:00
|
|
|
|
ID2P(LANG_REMOVE), ID2P(LANG_MOVE), ID2P(LANG_MENU_SHOW_ID3_INFO),
|
|
|
|
|
ID2P(LANG_SHUFFLE),
|
2021-09-29 04:21:05 +00:00
|
|
|
|
ID2P(LANG_SAVE),
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ID2P(LANG_PLAYLISTVIEWER_SETTINGS)
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
,ID2P(LANG_ONPLAY_PICTUREFLOW)
|
|
|
|
|
#endif
|
|
|
|
|
);
|
|
|
|
|
|
2022-04-18 09:35:20 +00:00
|
|
|
|
bool current_was_playing = (current_track->index == viewer.current_playing_track);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2008-03-26 03:35:24 +00:00
|
|
|
|
result = do_menu(&menu_items, NULL, NULL, false);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
if (result == MENU_ATTACHED_USB)
|
2007-02-12 05:02:42 +00:00
|
|
|
|
{
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_USB;
|
2007-02-12 05:02:42 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
else if (result >= 0)
|
|
|
|
|
{
|
|
|
|
|
/* Abort current move */
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer.moving_track = -1;
|
2009-07-07 22:40:47 +00:00
|
|
|
|
viewer.moving_playlist_index = -1;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
switch (result)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
2011-07-20 14:11:15 +00:00
|
|
|
|
/* playlist */
|
2023-05-26 01:24:45 +00:00
|
|
|
|
onplay_show_playlist_menu(current_track->name, FILE_ATTR_AUDIO, NULL);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_UNCHANGED;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
/* add to catalog */
|
2022-08-16 11:10:13 +00:00
|
|
|
|
onplay_show_playlist_cat_menu(current_track->name, FILE_ATTR_AUDIO, NULL);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_UNCHANGED;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
2022-04-18 09:35:20 +00:00
|
|
|
|
ret = delete_track(current_track->index, index, current_was_playing);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
break;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
case 3:
|
2003-12-10 00:11:25 +00:00
|
|
|
|
/* move track */
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer.moving_track = index;
|
|
|
|
|
viewer.moving_playlist_index = current_track->index;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_UNCHANGED;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
break;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
case 4:
|
2021-12-28 07:56:16 +00:00
|
|
|
|
ret = show_track_info(current_track);
|
|
|
|
|
break;
|
|
|
|
|
case 5:
|
2011-09-17 09:29:19 +00:00
|
|
|
|
/* shuffle */
|
|
|
|
|
playlist_randomise(viewer.playlist, current_tick, false);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_CHANGED;
|
2011-09-17 09:29:19 +00:00
|
|
|
|
break;
|
2021-12-28 07:56:16 +00:00
|
|
|
|
case 6:
|
2011-07-20 14:11:15 +00:00
|
|
|
|
/* save playlist */
|
2023-06-04 18:25:39 +00:00
|
|
|
|
if (!save_playlist_screen(viewer.playlist))
|
|
|
|
|
dirty = false;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = PV_ONPLAY_UNCHANGED;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
break;
|
2021-12-28 07:56:16 +00:00
|
|
|
|
case 7:
|
2014-01-11 09:46:37 +00:00
|
|
|
|
/* playlist viewer settings */
|
|
|
|
|
result = do_menu(&viewer_settings_menu, NULL, NULL, false);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
ret = (result == MENU_ATTACHED_USB) ? PV_ONPLAY_USB : PV_ONPLAY_UNCHANGED;
|
|
|
|
|
break;
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
case 8:
|
|
|
|
|
ret = open_pictureflow(current_track);
|
2014-01-11 09:46:37 +00:00
|
|
|
|
break;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
#endif
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* View current playlist */
|
2010-02-20 19:06:39 +00:00
|
|
|
|
enum playlist_viewer_result playlist_viewer(void)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2022-11-22 19:37:47 +00:00
|
|
|
|
return playlist_viewer_ex(NULL, NULL);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 13:39:56 +00:00
|
|
|
|
static int get_track_num(struct playlist_viewer *local_viewer,
|
|
|
|
|
int selected_item)
|
2007-10-15 20:34:02 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (local_viewer->moving_track >= 0)
|
2007-10-15 20:34:02 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (local_viewer->selected_track == selected_item)
|
2007-10-15 20:34:02 +00:00
|
|
|
|
{
|
2009-07-02 23:03:46 +00:00
|
|
|
|
return local_viewer->moving_track;
|
2007-10-15 20:34:02 +00:00
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
else if (local_viewer->selected_track > selected_item
|
|
|
|
|
&& selected_item >= local_viewer->moving_track)
|
2007-10-15 20:34:02 +00:00
|
|
|
|
{
|
2009-07-02 23:03:46 +00:00
|
|
|
|
return selected_item+1; /* move down */
|
2007-10-15 20:34:02 +00:00
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
else if (local_viewer->selected_track < selected_item
|
|
|
|
|
&& selected_item <= local_viewer->moving_track)
|
2007-10-15 20:34:02 +00:00
|
|
|
|
{
|
2009-07-02 23:03:46 +00:00
|
|
|
|
return selected_item-1; /* move up */
|
2007-10-15 20:34:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return selected_item;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
|
static const char* playlist_callback_name(int selected_item,
|
|
|
|
|
void *data,
|
|
|
|
|
char *buffer,
|
|
|
|
|
size_t buffer_len)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
struct playlist_viewer *local_viewer = (struct playlist_viewer *)data;
|
2008-04-09 21:47:43 +00:00
|
|
|
|
|
|
|
|
|
int track_num = get_track_num(local_viewer, selected_item);
|
|
|
|
|
struct playlist_entry *track =
|
2011-04-08 13:39:56 +00:00
|
|
|
|
playlist_buffer_get_track(&(local_viewer->buffer), track_num);
|
2008-04-09 21:47:43 +00:00
|
|
|
|
|
2008-04-09 15:25:17 +00:00
|
|
|
|
format_line(track, buffer, buffer_len);
|
2008-04-09 21:47:43 +00:00
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
return(buffer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2009-07-11 00:22:26 +00:00
|
|
|
|
static enum themable_icons playlist_callback_icons(int selected_item,
|
|
|
|
|
void *data)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
struct playlist_viewer *local_viewer = (struct playlist_viewer *)data;
|
2008-04-09 21:47:43 +00:00
|
|
|
|
|
|
|
|
|
int track_num = get_track_num(local_viewer, selected_item);
|
2011-04-08 13:39:56 +00:00
|
|
|
|
struct playlist_entry *track =
|
2008-04-09 21:47:43 +00:00
|
|
|
|
playlist_buffer_get_track(&(local_viewer->buffer), track_num);
|
|
|
|
|
|
2005-11-16 02:12:25 +00:00
|
|
|
|
if (track->index == local_viewer->current_playing_track)
|
|
|
|
|
{
|
|
|
|
|
/* Current playing track */
|
2007-04-16 09:14:36 +00:00
|
|
|
|
return Icon_Audio;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
2009-07-02 23:03:46 +00:00
|
|
|
|
else if (track->index == local_viewer->moving_playlist_index)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Track we are moving */
|
2007-04-16 09:14:36 +00:00
|
|
|
|
return Icon_Moving;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
else if (track->queued)
|
|
|
|
|
{
|
|
|
|
|
/* Queued track */
|
2007-04-16 09:14:36 +00:00
|
|
|
|
return Icon_Queued;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2007-04-16 09:14:36 +00:00
|
|
|
|
return Icon_NOICON;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-04-08 13:39:56 +00:00
|
|
|
|
static int playlist_callback_voice(int selected_item, void *data)
|
2011-04-08 13:10:32 +00:00
|
|
|
|
{
|
2011-04-08 13:39:56 +00:00
|
|
|
|
struct playlist_viewer *local_viewer = (struct playlist_viewer *)data;
|
2018-10-30 13:45:26 +00:00
|
|
|
|
struct playlist_entry *track=
|
|
|
|
|
playlist_buffer_get_track(&(local_viewer->buffer),
|
|
|
|
|
selected_item);
|
|
|
|
|
(void)selected_item;
|
|
|
|
|
if(global_settings.playlist_viewer_icons) {
|
|
|
|
|
if (track->index == local_viewer->current_playing_track)
|
|
|
|
|
talk_id(LANG_NOW_PLAYING, true);
|
|
|
|
|
if (track->index == local_viewer->moving_track)
|
|
|
|
|
talk_id(VOICE_TRACK_TO_MOVE, true);
|
|
|
|
|
if (track->queued)
|
|
|
|
|
talk_id(VOICE_QUEUED, true);
|
2011-04-08 13:10:32 +00:00
|
|
|
|
}
|
2018-10-30 13:45:26 +00:00
|
|
|
|
if (track->skipped)
|
|
|
|
|
talk_id(VOICE_BAD_TRACK, true);
|
|
|
|
|
if (global_settings.playlist_viewer_indices)
|
2011-04-08 13:10:32 +00:00
|
|
|
|
talk_number(track->display_index, true);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
|
|
|
|
|
if(global_settings.playlist_viewer_track_display)
|
|
|
|
|
talk_fullpath(track->name, true);
|
|
|
|
|
else talk_file_or_spell(NULL, track->name, NULL, true);
|
|
|
|
|
if (viewer.moving_track != -1)
|
|
|
|
|
talk_ids(true,VOICE_PAUSE, VOICE_MOVING_TRACK);
|
2011-04-08 13:10:32 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-18 09:35:20 +00:00
|
|
|
|
static void update_lists(struct gui_synclist * playlist_lists)
|
|
|
|
|
{
|
|
|
|
|
gui_synclist_set_voice_callback(playlist_lists,
|
|
|
|
|
global_settings.talk_file?
|
|
|
|
|
&playlist_callback_voice:NULL);
|
|
|
|
|
gui_synclist_set_icon_callback(playlist_lists,
|
|
|
|
|
global_settings.playlist_viewer_icons?
|
|
|
|
|
&playlist_callback_icons:NULL);
|
2022-11-21 02:15:03 +00:00
|
|
|
|
gui_synclist_set_title(playlist_lists, viewer.title, Icon_Playlist);
|
2022-04-18 09:35:20 +00:00
|
|
|
|
gui_synclist_draw(playlist_lists);
|
|
|
|
|
gui_synclist_speak_item(playlist_lists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool update_viewer_with_changes(struct gui_synclist *playlist_lists, enum pv_onplay_result res)
|
|
|
|
|
{
|
|
|
|
|
bool exit = false;
|
|
|
|
|
if (res == PV_ONPLAY_CHANGED ||
|
|
|
|
|
res == PV_ONPLAY_ITEM_REMOVED)
|
|
|
|
|
{
|
|
|
|
|
if (res == PV_ONPLAY_ITEM_REMOVED)
|
|
|
|
|
gui_synclist_del_item(playlist_lists);
|
|
|
|
|
update_playlist(true);
|
|
|
|
|
if (viewer.num_tracks <= 0)
|
|
|
|
|
exit = true;
|
|
|
|
|
if (viewer.selected_track >= viewer.num_tracks)
|
|
|
|
|
viewer.selected_track = viewer.num_tracks-1;
|
|
|
|
|
dirty = true;
|
|
|
|
|
}
|
|
|
|
|
/* the show_icons option in the playlist viewer settings
|
|
|
|
|
* menu might have changed */
|
|
|
|
|
update_lists(playlist_lists);
|
|
|
|
|
return exit;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
static void prepare_lists(struct gui_synclist * playlist_lists)
|
|
|
|
|
{
|
|
|
|
|
gui_synclist_init(playlist_lists, playlist_callback_name,
|
|
|
|
|
&viewer, false, 1, NULL);
|
|
|
|
|
gui_synclist_set_voice_callback(playlist_lists,
|
|
|
|
|
global_settings.talk_file ?
|
|
|
|
|
&playlist_callback_voice : NULL);
|
|
|
|
|
gui_synclist_set_icon_callback(playlist_lists,
|
|
|
|
|
global_settings.playlist_viewer_icons ?
|
|
|
|
|
&playlist_callback_icons : NULL);
|
|
|
|
|
gui_synclist_set_nb_items(playlist_lists, viewer.num_tracks);
|
2022-11-21 02:15:03 +00:00
|
|
|
|
gui_synclist_set_title(playlist_lists, viewer.title, Icon_Playlist);
|
2022-04-16 03:40:42 +00:00
|
|
|
|
gui_synclist_select_item(playlist_lists, viewer.selected_track);
|
|
|
|
|
gui_synclist_draw(playlist_lists);
|
|
|
|
|
gui_synclist_speak_item(playlist_lists);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool open_playlist_viewer(const char* filename,
|
|
|
|
|
struct gui_synclist *playlist_lists,
|
2022-11-22 19:37:47 +00:00
|
|
|
|
bool reload, int *most_recent_selection)
|
2022-04-16 03:40:42 +00:00
|
|
|
|
{
|
|
|
|
|
push_current_activity(ACTIVITY_PLAYLISTVIEWER);
|
|
|
|
|
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (!playlist_viewer_init(&viewer, filename, reload, most_recent_selection))
|
2022-04-16 03:40:42 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
prepare_lists(playlist_lists);
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* Main viewer function. Filename identifies playlist to be viewed. If NULL,
|
|
|
|
|
view current playlist. */
|
2022-11-22 19:37:47 +00:00
|
|
|
|
enum playlist_viewer_result playlist_viewer_ex(const char* filename,
|
|
|
|
|
int* most_recent_selection)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
{
|
2010-02-20 19:06:39 +00:00
|
|
|
|
enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK;
|
2011-04-08 13:39:56 +00:00
|
|
|
|
bool exit = false; /* exit viewer */
|
2006-08-15 12:27:07 +00:00
|
|
|
|
int button;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
struct gui_synclist playlist_lists;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (!open_playlist_viewer(filename, &playlist_lists, false, most_recent_selection))
|
2021-04-10 23:32:53 +00:00
|
|
|
|
{
|
|
|
|
|
ret = PLAYLIST_VIEWER_CANCEL;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
goto exit;
|
2021-04-10 23:32:53 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
while (!exit)
|
|
|
|
|
{
|
2004-01-14 00:13:04 +00:00
|
|
|
|
int track;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2007-08-21 23:50:26 +00:00
|
|
|
|
if (global_status.resume_index != -1 && !viewer.playlist)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_get_resume_info(&track);
|
|
|
|
|
else
|
|
|
|
|
track = -1;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
if (track != viewer.current_playing_track ||
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_amount_ex(viewer.playlist) != viewer.num_tracks)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Playlist has changed (new track started?) */
|
|
|
|
|
if (!update_playlist(false))
|
2004-04-15 06:12:02 +00:00
|
|
|
|
goto exit;
|
2007-08-21 23:50:26 +00:00
|
|
|
|
/*Needed because update_playlist gives wrong value when
|
|
|
|
|
playing is stopped*/
|
|
|
|
|
viewer.current_playing_track = track;
|
2005-11-16 02:12:25 +00:00
|
|
|
|
gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks);
|
2009-11-25 22:48:15 +00:00
|
|
|
|
|
2006-06-12 23:25:12 +00:00
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
gui_synclist_speak_item(&playlist_lists);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2004-04-15 06:12:02 +00:00
|
|
|
|
/* Timeout so we can determine if play status has changed */
|
2022-09-19 11:48:15 +00:00
|
|
|
|
bool res = list_do_action(CONTEXT_TREE, HZ/2, &playlist_lists, &button);
|
2010-10-02 20:15:35 +00:00
|
|
|
|
/* during moving, another redraw is going to be needed,
|
|
|
|
|
* since viewer.selected_track is updated too late (after the first draw)
|
|
|
|
|
* drawing the moving item needs it */
|
2010-09-20 23:10:19 +00:00
|
|
|
|
viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists);
|
|
|
|
|
if (res)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
{
|
2010-09-20 23:10:19 +00:00
|
|
|
|
bool reload = playlist_buffer_needs_reload(&viewer.buffer,
|
|
|
|
|
viewer.selected_track);
|
2010-10-02 20:15:35 +00:00
|
|
|
|
if (reload)
|
2005-11-16 02:12:25 +00:00
|
|
|
|
playlist_buffer_load_entries_screen(&viewer.buffer,
|
2012-06-18 09:37:22 +00:00
|
|
|
|
button == ACTION_STD_NEXT ? FORWARD : BACKWARD,
|
|
|
|
|
viewer.selected_track);
|
2010-10-02 20:15:35 +00:00
|
|
|
|
if (reload || viewer.moving_track >= 0)
|
2010-09-20 23:10:19 +00:00
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
2005-11-16 02:12:25 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
switch (button)
|
|
|
|
|
{
|
2007-04-12 21:28:58 +00:00
|
|
|
|
case ACTION_TREE_WPS:
|
2006-08-15 12:27:07 +00:00
|
|
|
|
case ACTION_STD_CANCEL:
|
2007-12-15 17:14:04 +00:00
|
|
|
|
{
|
2009-07-02 23:03:46 +00:00
|
|
|
|
if (viewer.moving_track >= 0)
|
2007-12-15 17:14:04 +00:00
|
|
|
|
{
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer.selected_track = viewer.moving_track;
|
|
|
|
|
gui_synclist_select_item(&playlist_lists, viewer.moving_track);
|
|
|
|
|
viewer.moving_track = -1;
|
2009-07-07 22:40:47 +00:00
|
|
|
|
viewer.moving_playlist_index = -1;
|
2007-12-15 17:14:04 +00:00
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
gui_synclist_speak_item(&playlist_lists);
|
2007-12-15 17:14:04 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2011-07-20 14:11:15 +00:00
|
|
|
|
{
|
2007-12-15 17:14:04 +00:00
|
|
|
|
exit = true;
|
2022-11-19 12:01:49 +00:00
|
|
|
|
ret = button == ACTION_TREE_WPS ?
|
|
|
|
|
PLAYLIST_VIEWER_OK : PLAYLIST_VIEWER_CANCEL;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
break;
|
2007-12-15 17:14:04 +00:00
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
|
case ACTION_STD_OK:
|
|
|
|
|
{
|
2005-11-19 18:19:46 +00:00
|
|
|
|
struct playlist_entry * current_track =
|
2010-09-20 23:10:19 +00:00
|
|
|
|
playlist_buffer_get_track(&viewer.buffer,
|
|
|
|
|
viewer.selected_track);
|
|
|
|
|
|
2009-07-02 23:03:46 +00:00
|
|
|
|
if (viewer.moving_track >= 0)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
|
|
|
|
/* Move track */
|
2007-04-26 10:28:32 +00:00
|
|
|
|
int ret_val;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2009-07-02 23:03:46 +00:00
|
|
|
|
ret_val = playlist_move(viewer.playlist,
|
|
|
|
|
viewer.moving_playlist_index,
|
|
|
|
|
current_track->index);
|
2007-04-26 10:28:32 +00:00
|
|
|
|
if (ret_val < 0)
|
2018-10-30 13:45:26 +00:00
|
|
|
|
{
|
|
|
|
|
cond_talk_ids_fq(LANG_MOVE, LANG_FAILED);
|
2008-08-15 08:27:39 +00:00
|
|
|
|
splashf(HZ, (unsigned char *)"%s %s", str(LANG_MOVE),
|
|
|
|
|
str(LANG_FAILED));
|
2018-10-30 13:45:26 +00:00
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
update_playlist(true);
|
2009-07-02 23:03:46 +00:00
|
|
|
|
viewer.moving_track = -1;
|
2009-07-07 22:40:47 +00:00
|
|
|
|
viewer.moving_playlist_index = -1;
|
2011-07-21 06:40:21 +00:00
|
|
|
|
dirty = true;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
|
else if (!viewer.playlist)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2005-06-23 17:31:44 +00:00
|
|
|
|
/* play new track */
|
2011-07-20 14:11:15 +00:00
|
|
|
|
if (!global_settings.party_mode)
|
|
|
|
|
{
|
2013-07-14 11:59:39 +00:00
|
|
|
|
playlist_start(current_track->index, 0, 0);
|
2011-07-20 14:11:15 +00:00
|
|
|
|
update_playlist(false);
|
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
2011-07-20 14:11:15 +00:00
|
|
|
|
else if (!global_settings.party_mode)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
{
|
2011-07-20 14:11:15 +00:00
|
|
|
|
int start_index = current_track->index;
|
|
|
|
|
if (!warn_on_pl_erase())
|
|
|
|
|
{
|
2021-12-20 19:12:03 +00:00
|
|
|
|
gui_synclist_set_title(&playlist_lists, playlist_lists.title, playlist_lists.title_icon);
|
2011-07-20 14:11:15 +00:00
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* New playlist */
|
|
|
|
|
if (playlist_set_current(viewer.playlist) < 0)
|
|
|
|
|
goto exit;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
if (global_settings.playlist_shuffle)
|
|
|
|
|
start_index = playlist_shuffle(current_tick, start_index);
|
2013-07-14 11:59:39 +00:00
|
|
|
|
playlist_start(start_index, 0, 0);
|
2023-01-22 13:35:27 +00:00
|
|
|
|
playlist_set_modified(NULL, false);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (viewer.initial_selection)
|
|
|
|
|
*(viewer.initial_selection) = viewer.selected_track;
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
/* Our playlist is now the current list */
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (!playlist_viewer_init(&viewer, NULL, true, NULL))
|
2004-01-26 17:05:21 +00:00
|
|
|
|
goto exit;
|
2011-07-20 14:11:15 +00:00
|
|
|
|
exit = true;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
}
|
2005-11-16 02:12:25 +00:00
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
gui_synclist_speak_item(&playlist_lists);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
|
|
|
|
break;
|
2006-08-15 12:27:07 +00:00
|
|
|
|
}
|
|
|
|
|
case ACTION_STD_CONTEXT:
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2022-04-16 03:40:42 +00:00
|
|
|
|
int pv_onplay_result = onplay_menu(viewer.selected_track);
|
2003-12-10 00:11:25 +00:00
|
|
|
|
|
2022-04-16 03:40:42 +00:00
|
|
|
|
if (pv_onplay_result == PV_ONPLAY_USB)
|
2004-01-26 17:05:21 +00:00
|
|
|
|
{
|
2010-02-20 19:06:39 +00:00
|
|
|
|
ret = PLAYLIST_VIEWER_USB;
|
2004-01-26 17:05:21 +00:00
|
|
|
|
goto exit;
|
|
|
|
|
}
|
2022-04-16 03:40:42 +00:00
|
|
|
|
else if (pv_onplay_result == PV_ONPLAY_USB_CLOSED)
|
|
|
|
|
return PLAYLIST_VIEWER_USB;
|
2022-11-19 15:15:22 +00:00
|
|
|
|
else if (pv_onplay_result == PV_ONPLAY_WPS_CLOSED)
|
|
|
|
|
return PLAYLIST_VIEWER_OK;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
else if (pv_onplay_result == PV_ONPLAY_CLOSED)
|
2003-12-10 00:11:25 +00:00
|
|
|
|
{
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (!open_playlist_viewer(filename, &playlist_lists, true, NULL))
|
2021-04-10 23:32:53 +00:00
|
|
|
|
{
|
|
|
|
|
ret = PLAYLIST_VIEWER_CANCEL;
|
2022-04-16 03:40:42 +00:00
|
|
|
|
goto exit;
|
2021-04-10 23:32:53 +00:00
|
|
|
|
}
|
2022-04-16 03:40:42 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2021-04-10 23:32:53 +00:00
|
|
|
|
if (update_viewer_with_changes(&playlist_lists, pv_onplay_result))
|
|
|
|
|
{
|
|
|
|
|
exit = true;
|
|
|
|
|
ret = PLAYLIST_VIEWER_CANCEL;
|
|
|
|
|
}
|
2003-12-10 00:11:25 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2006-08-15 12:27:07 +00:00
|
|
|
|
case ACTION_STD_MENU:
|
2010-02-20 19:06:39 +00:00
|
|
|
|
ret = PLAYLIST_VIEWER_MAINMENU;
|
|
|
|
|
goto exit;
|
2021-04-04 02:37:21 +00:00
|
|
|
|
#ifdef HAVE_QUICKSCREEN
|
|
|
|
|
case ACTION_STD_QUICKSCREEN:
|
|
|
|
|
if (!global_settings.shortcuts_replaces_qs)
|
|
|
|
|
{
|
2022-11-27 00:15:14 +00:00
|
|
|
|
if (quick_screen_quick(button) ==
|
|
|
|
|
QUICKSCREEN_GOTO_SHORTCUTS_MENU) /* currently disabled */
|
|
|
|
|
{
|
|
|
|
|
/* QuickScreen defers skin updates when popping its activity
|
|
|
|
|
to switch to Shortcuts Menu, so make up for that here: */
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
|
skin_update(CUSTOM_STATUSBAR, i, SKIN_REFRESH_ALL);
|
|
|
|
|
}
|
2021-04-04 02:37:21 +00:00
|
|
|
|
update_playlist(true);
|
2022-12-05 19:05:15 +00:00
|
|
|
|
prepare_lists(&playlist_lists);
|
2021-04-04 02:37:21 +00:00
|
|
|
|
}
|
2022-08-11 04:25:01 +00:00
|
|
|
|
break;
|
2021-04-04 02:37:21 +00:00
|
|
|
|
#endif
|
2022-04-18 09:35:20 +00:00
|
|
|
|
#ifdef HAVE_HOTKEY
|
|
|
|
|
case ACTION_TREE_HOTKEY:
|
|
|
|
|
{
|
|
|
|
|
struct playlist_entry *current_track = playlist_buffer_get_track(
|
|
|
|
|
&viewer.buffer,
|
|
|
|
|
viewer.selected_track);
|
|
|
|
|
enum pv_onplay_result (*do_plugin)(const struct playlist_entry *) = NULL;
|
|
|
|
|
#ifdef HAVE_TAGCACHE
|
|
|
|
|
if (global_settings.hotkey_tree == HOTKEY_PICTUREFLOW)
|
|
|
|
|
do_plugin = &open_pictureflow;
|
|
|
|
|
#endif
|
|
|
|
|
if (global_settings.hotkey_tree == HOTKEY_OPEN_WITH)
|
|
|
|
|
do_plugin = &open_with;
|
|
|
|
|
|
|
|
|
|
if (do_plugin != NULL)
|
|
|
|
|
{
|
2022-11-19 15:15:22 +00:00
|
|
|
|
int plugin_result = do_plugin(current_track);
|
|
|
|
|
|
|
|
|
|
if (plugin_result == PV_ONPLAY_USB_CLOSED)
|
2022-04-18 09:35:20 +00:00
|
|
|
|
return PLAYLIST_VIEWER_USB;
|
2022-11-19 15:15:22 +00:00
|
|
|
|
else if (plugin_result == PV_ONPLAY_WPS_CLOSED)
|
|
|
|
|
return PLAYLIST_VIEWER_OK;
|
2022-11-22 19:37:47 +00:00
|
|
|
|
else if (!open_playlist_viewer(filename, &playlist_lists, true, NULL))
|
2021-04-10 23:32:53 +00:00
|
|
|
|
{
|
|
|
|
|
ret = PLAYLIST_VIEWER_CANCEL;
|
2022-04-18 09:35:20 +00:00
|
|
|
|
goto exit;
|
2021-04-10 23:32:53 +00:00
|
|
|
|
}
|
2022-04-18 09:35:20 +00:00
|
|
|
|
}
|
|
|
|
|
else if (global_settings.hotkey_tree == HOTKEY_PROPERTIES)
|
|
|
|
|
{
|
|
|
|
|
if (show_track_info(current_track) == PV_ONPLAY_USB)
|
|
|
|
|
{
|
|
|
|
|
ret = PLAYLIST_VIEWER_USB;
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
update_lists(&playlist_lists);
|
|
|
|
|
}
|
|
|
|
|
else if (global_settings.hotkey_tree == HOTKEY_DELETE)
|
2021-04-10 23:32:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (update_viewer_with_changes(&playlist_lists,
|
2022-04-18 09:35:20 +00:00
|
|
|
|
delete_track(current_track->index,
|
|
|
|
|
viewer.selected_track,
|
2021-04-10 23:32:53 +00:00
|
|
|
|
(current_track->index == viewer.current_playing_track))))
|
|
|
|
|
{
|
|
|
|
|
ret = PLAYLIST_VIEWER_CANCEL;
|
|
|
|
|
exit = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:35:20 +00:00
|
|
|
|
else
|
|
|
|
|
onplay(current_track->name, FILE_ATTR_AUDIO, CONTEXT_STD, true);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
#endif /* HAVE_HOTKEY */
|
2004-07-26 16:06:59 +00:00
|
|
|
|
default:
|
|
|
|
|
if(default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
|
{
|
2010-02-20 19:06:39 +00:00
|
|
|
|
ret = PLAYLIST_VIEWER_USB;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-01-26 17:05:21 +00:00
|
|
|
|
exit:
|
2022-12-14 08:06:04 +00:00
|
|
|
|
pop_current_activity_without_refresh();
|
|
|
|
|
close_playlist_viewer();
|
2022-04-16 03:40:42 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-14 08:06:04 +00:00
|
|
|
|
static void close_playlist_viewer(void)
|
2022-04-16 03:40:42 +00:00
|
|
|
|
{
|
2018-10-30 13:45:26 +00:00
|
|
|
|
talk_shutup();
|
2004-01-26 17:05:21 +00:00
|
|
|
|
if (viewer.playlist)
|
2011-07-21 06:40:21 +00:00
|
|
|
|
{
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (viewer.initial_selection)
|
|
|
|
|
*(viewer.initial_selection) = viewer.selected_track;
|
|
|
|
|
|
2011-07-21 06:40:21 +00:00
|
|
|
|
if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES)))
|
|
|
|
|
save_playlist_screen(viewer.playlist);
|
2004-01-26 17:05:21 +00:00
|
|
|
|
playlist_close(viewer.playlist);
|
2011-07-21 06:40:21 +00:00
|
|
|
|
}
|
2022-04-16 03:40:42 +00:00
|
|
|
|
dirty = false;
|
2003-12-10 00:11:25 +00:00
|
|
|
|
}
|
2006-12-25 14:01:47 +00:00
|
|
|
|
|
2009-08-20 16:47:44 +00:00
|
|
|
|
static const char* playlist_search_callback_name(int selected_item, void * data,
|
|
|
|
|
char *buffer, size_t buffer_len)
|
2006-03-04 23:53:09 +00:00
|
|
|
|
{
|
2008-04-09 15:25:17 +00:00
|
|
|
|
(void)buffer_len; /* this should probably be used */
|
2006-03-04 23:53:09 +00:00
|
|
|
|
int *found_indicies = (int*)data;
|
2006-04-03 04:13:26 +00:00
|
|
|
|
static struct playlist_track_info track;
|
2008-04-09 15:25:17 +00:00
|
|
|
|
playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track);
|
|
|
|
|
format_name(buffer, track.filename);
|
2009-08-20 16:47:44 +00:00
|
|
|
|
return buffer;
|
2006-03-04 23:53:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-30 13:45:26 +00:00
|
|
|
|
static int say_search_item(int selected_item, void *data)
|
|
|
|
|
{
|
|
|
|
|
int *found_indicies = (int*)data;
|
|
|
|
|
static struct playlist_track_info track;
|
|
|
|
|
playlist_get_track_info(viewer.playlist,found_indicies[selected_item],&track);
|
|
|
|
|
if(global_settings.playlist_viewer_track_display)
|
|
|
|
|
talk_fullpath(track.filename, false);
|
|
|
|
|
else talk_file_or_spell(NULL, track.filename, NULL, false);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-03-04 23:53:09 +00:00
|
|
|
|
bool search_playlist(void)
|
|
|
|
|
{
|
|
|
|
|
char search_str[32] = "";
|
|
|
|
|
bool ret = false, exit = false;
|
|
|
|
|
int i, playlist_count;
|
2008-10-10 21:19:56 +00:00
|
|
|
|
int found_indicies[MAX_PLAYLIST_ENTRIES];
|
|
|
|
|
int found_indicies_count = 0, last_found_count = -1;
|
2006-03-04 23:53:09 +00:00
|
|
|
|
int button;
|
|
|
|
|
struct gui_synclist playlist_lists;
|
|
|
|
|
struct playlist_track_info track;
|
2006-04-03 04:13:26 +00:00
|
|
|
|
|
2022-11-22 19:37:47 +00:00
|
|
|
|
if (!playlist_viewer_init(&viewer, 0, false, NULL))
|
2006-03-04 23:53:09 +00:00
|
|
|
|
return ret;
|
2020-07-21 06:33:53 +00:00
|
|
|
|
if (kbd_input(search_str, sizeof(search_str), NULL) < 0)
|
2006-04-03 04:13:26 +00:00
|
|
|
|
return ret;
|
|
|
|
|
lcd_clear_display();
|
2006-03-04 23:53:09 +00:00
|
|
|
|
playlist_count = playlist_amount_ex(viewer.playlist);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
cond_talk_ids_fq(LANG_WAIT);
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
|
|
|
|
cpu_boost(true);
|
|
|
|
|
|
2011-04-08 13:39:56 +00:00
|
|
|
|
for (i = 0; i < playlist_count &&
|
|
|
|
|
found_indicies_count < MAX_PLAYLIST_ENTRIES; i++)
|
2006-03-04 23:53:09 +00:00
|
|
|
|
{
|
2008-10-10 21:19:56 +00:00
|
|
|
|
if (found_indicies_count != last_found_count)
|
2007-08-04 09:36:47 +00:00
|
|
|
|
{
|
2008-10-10 21:19:56 +00:00
|
|
|
|
splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), found_indicies_count,
|
|
|
|
|
str(LANG_OFF_ABORT));
|
|
|
|
|
last_found_count = found_indicies_count;
|
2007-08-04 09:36:47 +00:00
|
|
|
|
}
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
|
|
|
|
if (action_userabort(TIMEOUT_NOBLOCK))
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
playlist_get_track_info(viewer.playlist, i, &track);
|
|
|
|
|
|
2006-03-04 23:53:09 +00:00
|
|
|
|
if (strcasestr(track.filename,search_str))
|
|
|
|
|
found_indicies[found_indicies_count++] = track.index;
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
2008-09-29 19:29:42 +00:00
|
|
|
|
yield();
|
2006-03-04 23:53:09 +00:00
|
|
|
|
}
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
|
|
|
|
cpu_boost(false);
|
|
|
|
|
|
2018-10-30 13:45:26 +00:00
|
|
|
|
cond_talk_ids_fq(TALK_ID(found_indicies_count, UNIT_INT),
|
|
|
|
|
LANG_PLAYLIST_SEARCH_MSG);
|
2006-03-04 23:53:09 +00:00
|
|
|
|
if (!found_indicies_count)
|
|
|
|
|
{
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
backlight_on();
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
2006-03-04 23:53:09 +00:00
|
|
|
|
gui_synclist_init(&playlist_lists, playlist_search_callback_name,
|
2008-03-26 03:35:24 +00:00
|
|
|
|
found_indicies, false, 1, NULL);
|
2008-10-10 21:19:56 +00:00
|
|
|
|
gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON);
|
2007-04-16 09:14:36 +00:00
|
|
|
|
gui_synclist_set_icon_callback(&playlist_lists, NULL);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
if(global_settings.talk_file)
|
|
|
|
|
gui_synclist_set_voice_callback(&playlist_lists,
|
|
|
|
|
global_settings.talk_file?
|
|
|
|
|
&say_search_item:NULL);
|
2006-03-04 23:53:09 +00:00
|
|
|
|
gui_synclist_set_nb_items(&playlist_lists, found_indicies_count);
|
|
|
|
|
gui_synclist_select_item(&playlist_lists, 0);
|
|
|
|
|
gui_synclist_draw(&playlist_lists);
|
2018-10-30 13:45:26 +00:00
|
|
|
|
gui_synclist_speak_item(&playlist_lists);
|
2006-03-04 23:53:09 +00:00
|
|
|
|
while (!exit)
|
|
|
|
|
{
|
2022-09-19 11:48:15 +00:00
|
|
|
|
if (list_do_action(CONTEXT_LIST, HZ/4, &playlist_lists, &button))
|
2006-03-04 23:53:09 +00:00
|
|
|
|
continue;
|
|
|
|
|
switch (button)
|
|
|
|
|
{
|
2006-08-15 12:27:07 +00:00
|
|
|
|
case ACTION_STD_CANCEL:
|
2006-03-04 23:53:09 +00:00
|
|
|
|
exit = true;
|
|
|
|
|
break;
|
|
|
|
|
|
2006-08-15 12:27:07 +00:00
|
|
|
|
case ACTION_STD_OK:
|
2010-09-20 23:10:19 +00:00
|
|
|
|
{
|
|
|
|
|
int sel = gui_synclist_get_sel_pos(&playlist_lists);
|
2013-07-14 11:59:39 +00:00
|
|
|
|
playlist_start(found_indicies[sel], 0, 0);
|
2006-03-04 23:53:09 +00:00
|
|
|
|
exit = 1;
|
2010-09-20 23:10:19 +00:00
|
|
|
|
}
|
2011-04-08 13:39:56 +00:00
|
|
|
|
break;
|
2008-10-10 21:19:56 +00:00
|
|
|
|
|
2006-03-04 23:53:09 +00:00
|
|
|
|
default:
|
2011-04-08 13:39:56 +00:00
|
|
|
|
if (default_event_handler(button) == SYS_USB_CONNECTED)
|
2006-03-04 23:53:09 +00:00
|
|
|
|
{
|
|
|
|
|
ret = true;
|
|
|
|
|
exit = true;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-10-30 13:45:26 +00:00
|
|
|
|
talk_shutup();
|
2006-03-04 23:53:09 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|