Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * |
| 3 | * __________ __ ___. |
| 4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 8 | * \/ \/ \/ \/ \/ |
| 9 | * $Id$ |
| 10 | * |
| 11 | * Copyright (C) 2003 Hardeep Sidhu |
| 12 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU General Public License |
| 15 | * as published by the Free Software Foundation; either version 2 |
| 16 | * of the License, or (at your option) any later version. |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 17 | * |
| 18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 19 | * KIND, either express or implied. |
| 20 | * |
| 21 | ****************************************************************************/ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 22 | /* |
| 23 | * Kevin Ferrare 2005/10/16 |
| 24 | * multi-screen support, rewrote a lot of code |
| 25 | */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 26 | #include <string.h> |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 27 | #include "playlist.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 28 | #include "audio.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 29 | #include "screens.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 30 | #include "settings.h" |
| 31 | #include "icons.h" |
| 32 | #include "menu.h" |
| 33 | #include "plugin.h" |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 34 | #include "keyboard.h" |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 35 | #include "filetypes.h" |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 36 | #include "onplay.h" |
Jörg Hohensohn | fa97f16 | 2004-03-19 22:15:53 +0000 | [diff] [blame] | 37 | #include "talk.h" |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 38 | #include "misc.h" |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 39 | #include "action.h" |
Linus Nielsen Feltzing | 2f56ee9 | 2006-01-17 14:15:47 +0000 | [diff] [blame] | 40 | #include "debug.h" |
Tomas Salfischberger | 4ec9dbd | 2006-03-05 00:16:34 +0000 | [diff] [blame] | 41 | #include "backlight.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 42 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 43 | #include "lang.h" |
| 44 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 45 | #include "playlist_viewer.h" |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 46 | #include "playlist_catalog.h" |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 47 | #include "icon.h" |
| 48 | #include "list.h" |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 49 | #include "splash.h" |
Hardeep Sidhu | 0cca6ca | 2006-02-09 09:09:32 +0000 | [diff] [blame] | 50 | #include "playlist_menu.h" |
Thomas Martitz | 2d4bf62 | 2014-01-11 10:46:37 +0100 | [diff] [blame] | 51 | #include "menus/exported_menus.h" |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 52 | #include "yesno.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 53 | |
| 54 | /* Maximum number of tracks we can have loaded at one time */ |
Kevin Ferrare | 6a53c33 | 2005-11-16 02:55:26 +0000 | [diff] [blame] | 55 | #define MAX_PLAYLIST_ENTRIES 200 |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 56 | |
| 57 | /* The number of items between the selected one and the end/start of |
| 58 | * the buffer under which the buffer must reload */ |
Peter D'Hoye | 3c1e9ca | 2008-09-07 20:09:11 +0000 | [diff] [blame] | 59 | #define MIN_BUFFER_MARGIN (screens[0].getnblines()+1) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 60 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 61 | /* Information about a specific track */ |
| 62 | struct playlist_entry { |
| 63 | char *name; /* Formatted track name */ |
| 64 | int index; /* Playlist index */ |
| 65 | int display_index; /* Display index */ |
| 66 | bool queued; /* Is track queued? */ |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 67 | bool skipped; /* Is track marked as bad? */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 70 | enum direction |
| 71 | { |
| 72 | FORWARD, |
| 73 | BACKWARD |
| 74 | }; |
| 75 | |
| 76 | struct playlist_buffer |
| 77 | { |
| 78 | char *name_buffer; /* Buffer used to store track names */ |
| 79 | int buffer_size; /* Size of name buffer */ |
| 80 | |
| 81 | int first_index; /* Real index of first track loaded inside |
| 82 | the buffer */ |
| 83 | |
| 84 | enum direction direction; /* Direction of the buffer (if the buffer |
| 85 | was loaded BACKWARD, the last track in |
| 86 | the buffer has a real index < to the |
| 87 | real index of the the first track)*/ |
| 88 | |
| 89 | struct playlist_entry tracks[MAX_PLAYLIST_ENTRIES]; |
| 90 | int num_loaded; /* Number of track entries loaded in buffer */ |
| 91 | }; |
| 92 | |
| 93 | /* Global playlist viewer settings */ |
| 94 | struct playlist_viewer { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 95 | struct playlist_info* playlist; /* playlist being viewed */ |
| 96 | int num_tracks; /* Number of tracks in playlist */ |
| 97 | int current_playing_track; /* Index of current playing track */ |
| 98 | int selected_track; /* The selected track, relative (first is 0) */ |
| 99 | int moving_track; /* The track to move, relative (first is 0) |
| 100 | or -1 if nothing is currently being moved */ |
| 101 | int moving_playlist_index; /* Playlist-relative index (as opposed to |
| 102 | viewer-relative index) of moving track */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 103 | struct playlist_buffer buffer; |
| 104 | }; |
| 105 | |
| 106 | static struct playlist_viewer viewer; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 107 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 108 | /* Used when viewing playlists on disk */ |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 109 | static struct playlist_info temp_playlist; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 110 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 111 | static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, |
| 112 | int names_buffer_size); |
| 113 | static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index, |
| 114 | enum direction direction); |
| 115 | static int playlist_entry_load(struct playlist_entry *entry, int index, |
| 116 | char* name_buffer, int remaining_size); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 117 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 118 | static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb, |
| 119 | int index); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 120 | |
| 121 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 122 | const char* filename, bool reload); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 123 | |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 124 | static void format_name(char* dest, const char* src); |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 125 | static void format_line(const struct playlist_entry* track, char* str, |
| 126 | int len); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 127 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 128 | static bool update_playlist(bool force); |
| 129 | static int onplay_menu(int index); |
| 130 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 131 | static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, |
| 132 | int names_buffer_size) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 133 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 134 | pb->name_buffer = names_buffer; |
| 135 | pb->buffer_size = names_buffer_size; |
| 136 | pb->first_index = 0; |
| 137 | pb->num_loaded = 0; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 138 | } |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 139 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 140 | /* |
| 141 | * Loads the entries following 'index' in the playlist buffer |
| 142 | */ |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 143 | static void playlist_buffer_load_entries(struct playlist_buffer *pb, int index, |
| 144 | enum direction direction) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 145 | { |
| 146 | int num_entries = viewer.num_tracks; |
| 147 | char* p = pb->name_buffer; |
| 148 | int remaining = pb->buffer_size; |
| 149 | int i; |
| 150 | |
| 151 | pb->first_index = index; |
| 152 | if (num_entries > MAX_PLAYLIST_ENTRIES) |
| 153 | num_entries = MAX_PLAYLIST_ENTRIES; |
| 154 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 155 | for (i = 0; i < num_entries; i++) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 156 | { |
| 157 | int len = playlist_entry_load(&(pb->tracks[i]), index, p, remaining); |
| 158 | if (len < 0) |
| 159 | { |
| 160 | /* Out of name buffer space */ |
| 161 | num_entries = i; |
| 162 | break; |
| 163 | } |
| 164 | |
| 165 | p += len; |
| 166 | remaining -= len; |
| 167 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 168 | if(direction == FORWARD) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 169 | index++; |
| 170 | else |
| 171 | index--; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 172 | index += viewer.num_tracks; |
| 173 | index %= viewer.num_tracks; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 174 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 175 | pb->direction = direction; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 176 | pb->num_loaded = i; |
| 177 | } |
| 178 | |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 179 | /* playlist_buffer_load_entries_screen() |
| 180 | * This function is called when the currently selected item gets too close |
| 181 | * to the start or the end of the loaded part of the playlis, or when |
| 182 | * the list callback requests a playlist item that has not been loaded yet |
| 183 | * |
| 184 | * reference_track is either the currently selected track, or the track that |
| 185 | * has been requested by the callback, and has not been loaded yet. |
| 186 | */ |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 187 | static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb, |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 188 | enum direction direction, |
| 189 | int reference_track) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 190 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 191 | if (direction == FORWARD) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 192 | { |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 193 | int min_start = reference_track-2*screens[0].getnblines(); |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 194 | while (min_start < 0) |
| 195 | min_start += viewer.num_tracks; |
Linus Nielsen Feltzing | 2f56ee9 | 2006-01-17 14:15:47 +0000 | [diff] [blame] | 196 | min_start %= viewer.num_tracks; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 197 | playlist_buffer_load_entries(pb, min_start, FORWARD); |
| 198 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 199 | else |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 200 | { |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 201 | int max_start = reference_track+2*screens[0].getnblines(); |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 202 | max_start %= viewer.num_tracks; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 203 | playlist_buffer_load_entries(pb, max_start, BACKWARD); |
| 204 | } |
| 205 | } |
| 206 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 207 | static int playlist_entry_load(struct playlist_entry *entry, int index, |
| 208 | char* name_buffer, int remaining_size) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 209 | { |
| 210 | struct playlist_track_info info; |
| 211 | int len; |
| 212 | |
| 213 | /* Playlist viewer orders songs based on display index. We need to |
| 214 | convert to real playlist index to access track */ |
| 215 | index = (index + playlist_get_first_index(viewer.playlist)) % |
| 216 | viewer.num_tracks; |
| 217 | if (playlist_get_track_info(viewer.playlist, index, &info) < 0) |
| 218 | return -1; |
| 219 | |
| 220 | len = strlen(info.filename) + 1; |
| 221 | |
| 222 | if (len <= remaining_size) |
| 223 | { |
| 224 | strcpy(name_buffer, info.filename); |
| 225 | |
| 226 | entry->name = name_buffer; |
| 227 | entry->index = info.index; |
| 228 | entry->display_index = info.display_index; |
| 229 | entry->queued = info.attr & PLAYLIST_ATTR_QUEUED; |
| 230 | entry->skipped = info.attr & PLAYLIST_ATTR_SKIPPED; |
| 231 | return len; |
| 232 | } |
| 233 | return -1; |
| 234 | } |
| 235 | |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 236 | static int playlist_buffer_get_index(struct playlist_buffer *pb, int index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 237 | { |
| 238 | int buffer_index; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 239 | if (pb->direction == FORWARD) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 240 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 241 | if (index >= pb->first_index) |
| 242 | buffer_index = index-pb->first_index; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 243 | else /* rotation : track0 in buffer + requested track */ |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 244 | buffer_index = viewer.num_tracks-pb->first_index+index; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 245 | } |
| 246 | else |
| 247 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 248 | if (index <= pb->first_index) |
| 249 | buffer_index = pb->first_index-index; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 250 | else /* rotation : track0 in buffer + dist from the last track |
| 251 | to the requested track (num_tracks-requested track) */ |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 252 | buffer_index = pb->first_index+viewer.num_tracks-index; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 253 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 254 | return buffer_index; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | #define distance(a, b) \ |
| 258 | a>b? (a) - (b) : (b) - (a) |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 259 | static bool playlist_buffer_needs_reload(struct playlist_buffer* pb, |
| 260 | int track_index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 261 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 262 | if (pb->num_loaded == viewer.num_tracks) |
| 263 | return false; |
| 264 | int selected_index = playlist_buffer_get_index(pb, track_index); |
| 265 | int first_buffer_index = playlist_buffer_get_index(pb, pb->first_index); |
| 266 | int distance_beginning = distance(selected_index, first_buffer_index); |
| 267 | if (distance_beginning < MIN_BUFFER_MARGIN) |
| 268 | return true; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 269 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 270 | if (pb->num_loaded - distance_beginning < MIN_BUFFER_MARGIN) |
| 271 | return true; |
| 272 | return false; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 275 | static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb, |
| 276 | int index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 277 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 278 | int buffer_index = playlist_buffer_get_index(pb, index); |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 279 | /* Make sure that we are not returning an invalid pointer. |
| 280 | In some cases, when scrolling really fast, it could happen that a reqested track |
| 281 | has not been pre-loaded */ |
| 282 | if (buffer_index < 0) { |
| 283 | playlist_buffer_load_entries_screen(&viewer.buffer, |
| 284 | pb->direction == FORWARD ? BACKWARD : FORWARD, |
| 285 | index); |
| 286 | |
| 287 | } else if (buffer_index >= pb->num_loaded) { |
| 288 | playlist_buffer_load_entries_screen(&viewer.buffer, |
| 289 | pb->direction, |
| 290 | index); |
| 291 | } |
| 292 | buffer_index = playlist_buffer_get_index(pb, index); |
| 293 | if (buffer_index < 0 || buffer_index >= pb->num_loaded) { |
| 294 | /* This really shouldn't happen. If this happens, then |
| 295 | the name_buffer is probably too small to store enough |
| 296 | titles to fill the screen, and preload data in the short |
| 297 | direction. |
| 298 | |
| 299 | If this happens then scrolling performance will probably |
| 300 | be quite low, but it's better then having Data Abort errors */ |
| 301 | playlist_buffer_load_entries(pb, index, FORWARD); |
| 302 | buffer_index = playlist_buffer_get_index(pb, index); |
| 303 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 304 | return &(pb->tracks[buffer_index]); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 307 | /* Initialize the playlist viewer. */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 308 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 309 | const char* filename, bool reload) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 310 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 311 | char* buffer; |
Michael Sevakis | eb85f14 | 2007-04-21 19:20:20 +0000 | [diff] [blame] | 312 | size_t buffer_size; |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 313 | bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE); |
| 314 | bool have_list = filename || is_playing; |
Frank Gevaerts | 94b4a8b | 2011-08-01 08:38:32 +0000 | [diff] [blame] | 315 | if (!have_list && (global_status.resume_index != -1)) |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 316 | { |
| 317 | /* Try to restore the list from control file */ |
| 318 | have_list = (playlist_resume() != -1); |
| 319 | } |
Peter D'Hoye | b8ded7d | 2007-08-25 16:05:58 +0000 | [diff] [blame] | 320 | if (!have_list && (playlist_amount() > 0)) |
| 321 | { |
| 322 | /*If dynamic playlist still exists, view it anyway even |
| 323 | if playback has reached the end of the playlist */ |
| 324 | have_list = true; |
| 325 | } |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 326 | if (!have_list) |
| 327 | { |
| 328 | /* Nothing to view, exit */ |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 329 | splash(HZ, ID2P(LANG_CATALOG_NO_PLAYLISTS)); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 330 | return false; |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 331 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 332 | |
Michael Sevakis | eb85f14 | 2007-04-21 19:20:20 +0000 | [diff] [blame] | 333 | buffer = plugin_get_buffer(&buffer_size); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 334 | if (!buffer) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 335 | return false; |
| 336 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 337 | if (!filename) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 338 | viewer->playlist = NULL; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 339 | else |
| 340 | { |
| 341 | /* Viewing playlist on disk */ |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 342 | const char *dir, *file; |
| 343 | char *temp_ptr; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 344 | char *index_buffer = NULL; |
Michael Sevakis | 26d242a | 2007-04-21 18:38:25 +0000 | [diff] [blame] | 345 | ssize_t index_buffer_size = 0; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 346 | |
| 347 | viewer->playlist = &temp_playlist; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 348 | |
| 349 | /* Separate directory from filename */ |
| 350 | temp_ptr = strrchr(filename+1,'/'); |
| 351 | if (temp_ptr) |
| 352 | { |
| 353 | *temp_ptr = 0; |
| 354 | dir = filename; |
| 355 | file = temp_ptr + 1; |
| 356 | } |
| 357 | else |
| 358 | { |
| 359 | dir = "/"; |
| 360 | file = filename+1; |
| 361 | } |
| 362 | |
| 363 | if (is_playing) |
| 364 | { |
| 365 | /* Something is playing, use half the plugin buffer for playlist |
| 366 | indices */ |
| 367 | index_buffer_size = buffer_size / 2; |
| 368 | index_buffer = buffer; |
| 369 | } |
| 370 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 371 | playlist_create_ex(viewer->playlist, dir, file, index_buffer, |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 372 | index_buffer_size, buffer+index_buffer_size, |
| 373 | buffer_size-index_buffer_size); |
| 374 | |
| 375 | if (temp_ptr) |
| 376 | *temp_ptr = '/'; |
| 377 | |
| 378 | buffer += index_buffer_size; |
| 379 | buffer_size -= index_buffer_size; |
| 380 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 381 | playlist_buffer_init(&viewer->buffer, buffer, buffer_size); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 382 | |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 383 | viewer->moving_track = -1; |
Dave Hooper | be0cd73 | 2009-07-07 22:40:47 +0000 | [diff] [blame] | 384 | viewer->moving_playlist_index = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 385 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 386 | if (!reload) |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 387 | { |
Linus Nielsen Feltzing | 0b8149f | 2006-01-17 12:30:03 +0000 | [diff] [blame] | 388 | if (viewer->playlist) |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 389 | viewer->selected_track = 0; |
Linus Nielsen Feltzing | 0b8149f | 2006-01-17 12:30:03 +0000 | [diff] [blame] | 390 | else |
| 391 | viewer->selected_track = playlist_get_display_index() - 1; |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 392 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 393 | |
| 394 | if (!update_playlist(true)) |
| 395 | return false; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 396 | return true; |
| 397 | } |
| 398 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 399 | /* Format trackname for display purposes */ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 400 | static void format_name(char* dest, const char* src) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 401 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 402 | switch (global_settings.playlist_viewer_track_display) |
| 403 | { |
| 404 | case 0: |
| 405 | default: |
| 406 | { |
Antoine Cellerier | 59dc18d | 2006-08-10 21:08:44 +0000 | [diff] [blame] | 407 | /* Only display the filename */ |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 408 | char* p = strrchr(src, '/'); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 409 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 410 | strcpy(dest, p+1); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 411 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 412 | /* Remove the extension */ |
Nils Wallménius | 4acae4d | 2007-11-18 14:12:01 +0000 | [diff] [blame] | 413 | strrsplt(dest, '.'); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 414 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 415 | break; |
| 416 | } |
| 417 | case 1: |
| 418 | /* Full path */ |
| 419 | strcpy(dest, src); |
| 420 | break; |
| 421 | } |
| 422 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 423 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 424 | /* Format display line */ |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 425 | static void format_line(const struct playlist_entry* track, char* str, |
| 426 | int len) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 427 | { |
| 428 | char name[MAX_PATH]; |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 429 | char *skipped = ""; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 430 | |
| 431 | format_name(name, track->name); |
| 432 | |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 433 | if (track->skipped) |
| 434 | skipped = "(ERR) "; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 435 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 436 | if (global_settings.playlist_viewer_indices) |
| 437 | /* Display playlist index */ |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 438 | snprintf(str, len, "%d. %s%s", track->display_index, skipped, name); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 439 | else |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 440 | snprintf(str, len, "%s%s", skipped, name); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 441 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 442 | } |
| 443 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 444 | /* Update playlist in case something has changed or forced */ |
| 445 | static bool update_playlist(bool force) |
| 446 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 447 | if (!viewer.playlist) |
| 448 | playlist_get_resume_info(&viewer.current_playing_track); |
| 449 | else |
| 450 | viewer.current_playing_track = -1; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 451 | int nb_tracks = playlist_amount_ex(viewer.playlist); |
| 452 | force = force || nb_tracks != viewer.num_tracks; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 453 | if (force) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 454 | { |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 455 | /* Reload tracks */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 456 | viewer.num_tracks = nb_tracks; |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 457 | if (viewer.num_tracks <= 0) |
Dave Hooper | 4044499 | 2009-07-02 22:45:00 +0000 | [diff] [blame] | 458 | { |
| 459 | global_status.resume_index = -1; |
| 460 | global_status.resume_offset = -1; |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 461 | global_status.resume_elapsed = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 462 | return false; |
Dave Hooper | 4044499 | 2009-07-02 22:45:00 +0000 | [diff] [blame] | 463 | } |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 464 | playlist_buffer_load_entries_screen(&viewer.buffer, FORWARD, |
| 465 | viewer.selected_track); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 466 | if (viewer.buffer.num_loaded <= 0) |
Dave Hooper | 4044499 | 2009-07-02 22:45:00 +0000 | [diff] [blame] | 467 | { |
| 468 | global_status.resume_index = -1; |
| 469 | global_status.resume_offset = -1; |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 470 | global_status.resume_elapsed = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 471 | return false; |
Dave Hooper | 4044499 | 2009-07-02 22:45:00 +0000 | [diff] [blame] | 472 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 473 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 474 | return true; |
| 475 | } |
| 476 | |
| 477 | /* Menu of playlist commands. Invoked via ON+PLAY on main viewer screen. |
Thomas White | d5ead5c | 2015-03-11 22:43:42 +0100 | [diff] [blame] | 478 | Returns -1 if USB attached, 0 if no playlist change, 1 if playlist |
| 479 | changed, 2 if a track was removed from the playlist */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 480 | static int onplay_menu(int index) |
| 481 | { |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 482 | int result, ret = 0; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 483 | struct playlist_entry * current_track = |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 484 | playlist_buffer_get_track(&viewer.buffer, index); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 485 | MENUITEM_STRINGLIST(menu_items, ID2P(LANG_PLAYLIST), NULL, |
Jonathan Gordon | 061ff42 | 2011-07-20 14:54:10 +0000 | [diff] [blame] | 486 | ID2P(LANG_CURRENT_PLAYLIST), ID2P(LANG_CATALOG), |
Jonathan Gordon | e03faf8 | 2011-09-17 09:29:19 +0000 | [diff] [blame] | 487 | ID2P(LANG_REMOVE), ID2P(LANG_MOVE), ID2P(LANG_SHUFFLE), |
Thomas Martitz | 2d4bf62 | 2014-01-11 10:46:37 +0100 | [diff] [blame] | 488 | ID2P(LANG_SAVE_DYNAMIC_PLAYLIST), |
| 489 | ID2P(LANG_PLAYLISTVIEWER_SETTINGS)); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 490 | bool current = (current_track->index == viewer.current_playing_track); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 491 | |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 492 | result = do_menu(&menu_items, NULL, NULL, false); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 493 | if (result == MENU_ATTACHED_USB) |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 494 | { |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 495 | ret = -1; |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 496 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 497 | else if (result >= 0) |
| 498 | { |
| 499 | /* Abort current move */ |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 500 | viewer.moving_track = -1; |
Dave Hooper | be0cd73 | 2009-07-07 22:40:47 +0000 | [diff] [blame] | 501 | viewer.moving_playlist_index = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 502 | |
| 503 | switch (result) |
| 504 | { |
| 505 | case 0: |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 506 | /* playlist */ |
| 507 | onplay_show_playlist_menu(current_track->name); |
| 508 | ret = 0; |
| 509 | break; |
| 510 | case 1: |
| 511 | /* add to catalog */ |
| 512 | onplay_show_playlist_cat_menu(current_track->name); |
| 513 | ret = 0; |
| 514 | break; |
| 515 | case 2: |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 516 | /* delete track */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 517 | playlist_delete(viewer.playlist, current_track->index); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 518 | if (current) |
| 519 | { |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 520 | if (playlist_amount_ex(viewer.playlist) <= 0) |
| 521 | audio_stop(); |
| 522 | else |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 523 | { |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 524 | /* Start playing new track except if it's the lasttrack |
| 525 | track in the playlist and repeat mode is disabled */ |
| 526 | current_track = |
| 527 | playlist_buffer_get_track(&viewer.buffer, index); |
| 528 | if (current_track->display_index!=viewer.num_tracks || |
| 529 | global_settings.repeat_mode == REPEAT_ALL) |
| 530 | { |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 531 | audio_play(0, 0); |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 532 | viewer.current_playing_track = -1; |
| 533 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 534 | } |
| 535 | } |
Thomas White | d5ead5c | 2015-03-11 22:43:42 +0100 | [diff] [blame] | 536 | ret = 2; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 537 | break; |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 538 | case 3: |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 539 | /* move track */ |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 540 | viewer.moving_track = index; |
| 541 | viewer.moving_playlist_index = current_track->index; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 542 | ret = 0; |
| 543 | break; |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 544 | case 4: |
Jonathan Gordon | e03faf8 | 2011-09-17 09:29:19 +0000 | [diff] [blame] | 545 | /* shuffle */ |
| 546 | playlist_randomise(viewer.playlist, current_tick, false); |
| 547 | ret = 1; |
| 548 | break; |
| 549 | case 5: |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 550 | /* save playlist */ |
| 551 | save_playlist_screen(viewer.playlist); |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 552 | ret = 0; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 553 | break; |
Thomas Martitz | 2d4bf62 | 2014-01-11 10:46:37 +0100 | [diff] [blame] | 554 | case 6: |
| 555 | /* playlist viewer settings */ |
| 556 | result = do_menu(&viewer_settings_menu, NULL, NULL, false); |
| 557 | ret = (result == MENU_ATTACHED_USB) ? -1 : 0; |
| 558 | break; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 559 | } |
| 560 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 561 | return ret; |
| 562 | } |
| 563 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 564 | /* View current playlist */ |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 565 | enum playlist_viewer_result playlist_viewer(void) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 566 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 567 | return playlist_viewer_ex(NULL); |
| 568 | } |
| 569 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 570 | static int get_track_num(struct playlist_viewer *local_viewer, |
| 571 | int selected_item) |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 572 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 573 | if (local_viewer->moving_track >= 0) |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 574 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 575 | if (local_viewer->selected_track == selected_item) |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 576 | { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 577 | return local_viewer->moving_track; |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 578 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 579 | else if (local_viewer->selected_track > selected_item |
| 580 | && selected_item >= local_viewer->moving_track) |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 581 | { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 582 | return selected_item+1; /* move down */ |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 583 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 584 | else if (local_viewer->selected_track < selected_item |
| 585 | && selected_item <= local_viewer->moving_track) |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 586 | { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 587 | return selected_item-1; /* move up */ |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 588 | } |
| 589 | } |
| 590 | return selected_item; |
| 591 | } |
| 592 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 593 | static const char* playlist_callback_name(int selected_item, |
| 594 | void *data, |
| 595 | char *buffer, |
| 596 | size_t buffer_len) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 597 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 598 | struct playlist_viewer *local_viewer = (struct playlist_viewer *)data; |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 599 | |
| 600 | int track_num = get_track_num(local_viewer, selected_item); |
| 601 | struct playlist_entry *track = |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 602 | playlist_buffer_get_track(&(local_viewer->buffer), track_num); |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 603 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 604 | format_line(track, buffer, buffer_len); |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 605 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 606 | return(buffer); |
| 607 | } |
| 608 | |
| 609 | |
Andrew Mahone | 1bc67c8 | 2009-07-11 00:22:26 +0000 | [diff] [blame] | 610 | static enum themable_icons playlist_callback_icons(int selected_item, |
| 611 | void *data) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 612 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 613 | struct playlist_viewer *local_viewer = (struct playlist_viewer *)data; |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 614 | |
| 615 | int track_num = get_track_num(local_viewer, selected_item); |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 616 | struct playlist_entry *track = |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 617 | playlist_buffer_get_track(&(local_viewer->buffer), track_num); |
| 618 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 619 | if (track->index == local_viewer->current_playing_track) |
| 620 | { |
| 621 | /* Current playing track */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 622 | return Icon_Audio; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 623 | } |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 624 | else if (track->index == local_viewer->moving_playlist_index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 625 | { |
| 626 | /* Track we are moving */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 627 | return Icon_Moving; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 628 | } |
| 629 | else if (track->queued) |
| 630 | { |
| 631 | /* Queued track */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 632 | return Icon_Queued; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 633 | } |
| 634 | else |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 635 | return Icon_NOICON; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 636 | } |
| 637 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 638 | static int playlist_callback_voice(int selected_item, void *data) |
Nils Wallménius | a079117 | 2011-04-08 13:10:32 +0000 | [diff] [blame] | 639 | { |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 640 | struct playlist_viewer *local_viewer = (struct playlist_viewer *)data; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 641 | struct playlist_entry *track= |
| 642 | playlist_buffer_get_track(&(local_viewer->buffer), |
| 643 | selected_item); |
| 644 | (void)selected_item; |
| 645 | if(global_settings.playlist_viewer_icons) { |
| 646 | if (track->index == local_viewer->current_playing_track) |
| 647 | talk_id(LANG_NOW_PLAYING, true); |
| 648 | if (track->index == local_viewer->moving_track) |
| 649 | talk_id(VOICE_TRACK_TO_MOVE, true); |
| 650 | if (track->queued) |
| 651 | talk_id(VOICE_QUEUED, true); |
Nils Wallménius | a079117 | 2011-04-08 13:10:32 +0000 | [diff] [blame] | 652 | } |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 653 | if (track->skipped) |
| 654 | talk_id(VOICE_BAD_TRACK, true); |
| 655 | if (global_settings.playlist_viewer_indices) |
Nils Wallménius | a079117 | 2011-04-08 13:10:32 +0000 | [diff] [blame] | 656 | talk_number(track->display_index, true); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 657 | |
| 658 | if(global_settings.playlist_viewer_track_display) |
| 659 | talk_fullpath(track->name, true); |
| 660 | else talk_file_or_spell(NULL, track->name, NULL, true); |
| 661 | if (viewer.moving_track != -1) |
| 662 | talk_ids(true,VOICE_PAUSE, VOICE_MOVING_TRACK); |
Nils Wallménius | a079117 | 2011-04-08 13:10:32 +0000 | [diff] [blame] | 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 667 | /* Main viewer function. Filename identifies playlist to be viewed. If NULL, |
| 668 | view current playlist. */ |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 669 | enum playlist_viewer_result playlist_viewer_ex(const char* filename) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 670 | { |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 671 | enum playlist_viewer_result ret = PLAYLIST_VIEWER_OK; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 672 | bool exit = false; /* exit viewer */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 673 | int button; |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 674 | bool dirty = false; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 675 | struct gui_synclist playlist_lists; |
| 676 | if (!playlist_viewer_init(&viewer, filename, false)) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 677 | goto exit; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 678 | |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 679 | push_current_activity(ACTIVITY_PLAYLISTVIEWER); |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 680 | gui_synclist_init(&playlist_lists, playlist_callback_name, |
| 681 | &viewer, false, 1, NULL); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 682 | gui_synclist_set_voice_callback(&playlist_lists, |
| 683 | global_settings.talk_file? |
| 684 | &playlist_callback_voice:NULL); |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 685 | gui_synclist_set_icon_callback(&playlist_lists, |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 686 | global_settings.playlist_viewer_icons? |
| 687 | &playlist_callback_icons:NULL); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 688 | gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 689 | gui_synclist_set_title(&playlist_lists, str(LANG_PLAYLIST), Icon_Playlist); |
Jonathan Gordon | eeb1f3e | 2009-12-24 07:13:04 +0000 | [diff] [blame] | 690 | gui_synclist_select_item(&playlist_lists, viewer.selected_track); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 691 | gui_synclist_draw(&playlist_lists); |
Nils Wallménius | a079117 | 2011-04-08 13:10:32 +0000 | [diff] [blame] | 692 | gui_synclist_speak_item(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 693 | while (!exit) |
| 694 | { |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 695 | int track; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 696 | |
Peter D'Hoye | df32813 | 2007-08-21 23:50:26 +0000 | [diff] [blame] | 697 | if (global_status.resume_index != -1 && !viewer.playlist) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 698 | playlist_get_resume_info(&track); |
| 699 | else |
| 700 | track = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 701 | |
| 702 | if (track != viewer.current_playing_track || |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 703 | playlist_amount_ex(viewer.playlist) != viewer.num_tracks) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 704 | { |
| 705 | /* Playlist has changed (new track started?) */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 706 | if (!update_playlist(false)) |
Hardeep Sidhu | 1b44632 | 2004-04-15 06:12:02 +0000 | [diff] [blame] | 707 | goto exit; |
Peter D'Hoye | df32813 | 2007-08-21 23:50:26 +0000 | [diff] [blame] | 708 | /*Needed because update_playlist gives wrong value when |
| 709 | playing is stopped*/ |
| 710 | viewer.current_playing_track = track; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 711 | gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); |
Dave Hooper | 6c62b1b | 2009-11-25 22:48:15 +0000 | [diff] [blame] | 712 | |
Hardeep Sidhu | 9a681dd | 2006-06-12 23:25:12 +0000 | [diff] [blame] | 713 | gui_synclist_draw(&playlist_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 714 | gui_synclist_speak_item(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Hardeep Sidhu | 1b44632 | 2004-04-15 06:12:02 +0000 | [diff] [blame] | 717 | /* Timeout so we can determine if play status has changed */ |
Thomas Martitz | 16d44e9 | 2010-11-23 07:39:16 +0000 | [diff] [blame] | 718 | bool res = list_do_action(CONTEXT_TREE, HZ/2, |
Thomas Martitz | 3013103 | 2010-09-21 22:56:12 +0000 | [diff] [blame] | 719 | &playlist_lists, &button, LIST_WRAP_UNLESS_HELD); |
Thomas Martitz | c4925f1 | 2010-10-02 20:15:35 +0000 | [diff] [blame] | 720 | /* during moving, another redraw is going to be needed, |
| 721 | * since viewer.selected_track is updated too late (after the first draw) |
| 722 | * drawing the moving item needs it */ |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 723 | viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists); |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 724 | if (res) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 725 | { |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 726 | bool reload = playlist_buffer_needs_reload(&viewer.buffer, |
| 727 | viewer.selected_track); |
Thomas Martitz | c4925f1 | 2010-10-02 20:15:35 +0000 | [diff] [blame] | 728 | if (reload) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 729 | playlist_buffer_load_entries_screen(&viewer.buffer, |
Purdea Andrei | 323282f | 2012-06-18 12:37:22 +0300 | [diff] [blame] | 730 | button == ACTION_STD_NEXT ? FORWARD : BACKWARD, |
| 731 | viewer.selected_track); |
Thomas Martitz | c4925f1 | 2010-10-02 20:15:35 +0000 | [diff] [blame] | 732 | if (reload || viewer.moving_track >= 0) |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 733 | gui_synclist_draw(&playlist_lists); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 734 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 735 | switch (button) |
| 736 | { |
Peter D'Hoye | 734278b | 2007-04-12 21:28:58 +0000 | [diff] [blame] | 737 | case ACTION_TREE_WPS: |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 738 | case ACTION_STD_CANCEL: |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 739 | { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 740 | if (viewer.moving_track >= 0) |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 741 | { |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 742 | viewer.selected_track = viewer.moving_track; |
| 743 | gui_synclist_select_item(&playlist_lists, viewer.moving_track); |
| 744 | viewer.moving_track = -1; |
Dave Hooper | be0cd73 | 2009-07-07 22:40:47 +0000 | [diff] [blame] | 745 | viewer.moving_playlist_index = -1; |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 746 | gui_synclist_draw(&playlist_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 747 | gui_synclist_speak_item(&playlist_lists); |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 748 | } |
| 749 | else |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 750 | { |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 751 | exit = true; |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 752 | ret = PLAYLIST_VIEWER_CANCEL; |
| 753 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 754 | break; |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 755 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 756 | case ACTION_STD_OK: |
| 757 | { |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 758 | struct playlist_entry * current_track = |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 759 | playlist_buffer_get_track(&viewer.buffer, |
| 760 | viewer.selected_track); |
| 761 | |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 762 | if (viewer.moving_track >= 0) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 763 | { |
| 764 | /* Move track */ |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 765 | int ret_val; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 766 | |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 767 | ret_val = playlist_move(viewer.playlist, |
| 768 | viewer.moving_playlist_index, |
| 769 | current_track->index); |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 770 | if (ret_val < 0) |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 771 | { |
| 772 | cond_talk_ids_fq(LANG_MOVE, LANG_FAILED); |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 773 | splashf(HZ, (unsigned char *)"%s %s", str(LANG_MOVE), |
| 774 | str(LANG_FAILED)); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 775 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 776 | update_playlist(true); |
Dave Hooper | 1192521 | 2009-07-02 23:03:46 +0000 | [diff] [blame] | 777 | viewer.moving_track = -1; |
Dave Hooper | be0cd73 | 2009-07-07 22:40:47 +0000 | [diff] [blame] | 778 | viewer.moving_playlist_index = -1; |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 779 | dirty = true; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 780 | } |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 781 | else if (!viewer.playlist) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 782 | { |
Hardeep Sidhu | 0574151 | 2005-06-23 17:31:44 +0000 | [diff] [blame] | 783 | /* play new track */ |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 784 | if (!global_settings.party_mode) |
| 785 | { |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 786 | playlist_start(current_track->index, 0, 0); |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 787 | update_playlist(false); |
| 788 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 789 | } |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 790 | else if (!global_settings.party_mode) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 791 | { |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 792 | int start_index = current_track->index; |
| 793 | if (!warn_on_pl_erase()) |
| 794 | { |
| 795 | gui_synclist_draw(&playlist_lists); |
| 796 | break; |
| 797 | } |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 798 | /* New playlist */ |
| 799 | if (playlist_set_current(viewer.playlist) < 0) |
| 800 | goto exit; |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 801 | if (global_settings.playlist_shuffle) |
| 802 | start_index = playlist_shuffle(current_tick, start_index); |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 803 | playlist_start(start_index, 0, 0); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 804 | |
| 805 | /* Our playlist is now the current list */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 806 | if (!playlist_viewer_init(&viewer, NULL, true)) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 807 | goto exit; |
Jonathan Gordon | 97a4c1e | 2011-07-20 14:11:15 +0000 | [diff] [blame] | 808 | exit = true; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 809 | } |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 810 | gui_synclist_draw(&playlist_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 811 | gui_synclist_speak_item(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 812 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 813 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 814 | } |
| 815 | case ACTION_STD_CONTEXT: |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 816 | { |
| 817 | /* ON+PLAY menu */ |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 818 | int ret_val; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 819 | |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 820 | ret_val = onplay_menu(viewer.selected_track); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 821 | |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 822 | if (ret_val < 0) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 823 | { |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 824 | ret = PLAYLIST_VIEWER_USB; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 825 | goto exit; |
| 826 | } |
Dave Hooper | 4044499 | 2009-07-02 22:45:00 +0000 | [diff] [blame] | 827 | else if (ret_val > 0) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 828 | { |
| 829 | /* Playlist changed */ |
Thomas White | d5ead5c | 2015-03-11 22:43:42 +0100 | [diff] [blame] | 830 | if (ret_val == 2) |
| 831 | gui_synclist_del_item(&playlist_lists); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 832 | update_playlist(true); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 833 | if (viewer.num_tracks <= 0) |
| 834 | exit = true; |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 835 | if (viewer.selected_track >= viewer.num_tracks) |
Peter D'Hoye | b16137e | 2007-04-11 22:39:12 +0000 | [diff] [blame] | 836 | viewer.selected_track = viewer.num_tracks-1; |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 837 | dirty = true; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 838 | } |
Thomas Martitz | fe73d75 | 2014-01-11 10:49:45 +0100 | [diff] [blame] | 839 | /* the show_icons option in the playlist viewer settings |
| 840 | * menu might have changed */ |
| 841 | gui_synclist_set_icon_callback(&playlist_lists, |
| 842 | global_settings.playlist_viewer_icons? |
| 843 | &playlist_callback_icons:NULL); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 844 | gui_synclist_draw(&playlist_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 845 | gui_synclist_speak_item(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 846 | break; |
| 847 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 848 | case ACTION_STD_MENU: |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 849 | ret = PLAYLIST_VIEWER_MAINMENU; |
| 850 | goto exit; |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 851 | default: |
| 852 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 853 | { |
Thomas Martitz | c19e536 | 2010-02-20 19:06:39 +0000 | [diff] [blame] | 854 | ret = PLAYLIST_VIEWER_USB; |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 855 | goto exit; |
| 856 | } |
| 857 | break; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 858 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 861 | exit: |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 862 | talk_shutup(); |
Jonathan Gordon | 835683b | 2011-08-07 08:39:56 +0000 | [diff] [blame] | 863 | pop_current_activity(); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 864 | if (viewer.playlist) |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 865 | { |
| 866 | if(dirty && yesno_pop(ID2P(LANG_SAVE_CHANGES))) |
| 867 | save_playlist_screen(viewer.playlist); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 868 | playlist_close(viewer.playlist); |
Jonathan Gordon | d1fd4f0 | 2011-07-21 06:40:21 +0000 | [diff] [blame] | 869 | } |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 870 | return ret; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 871 | } |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 872 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 873 | static const char* playlist_search_callback_name(int selected_item, void * data, |
| 874 | char *buffer, size_t buffer_len) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 875 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 876 | (void)buffer_len; /* this should probably be used */ |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 877 | int *found_indicies = (int*)data; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 878 | static struct playlist_track_info track; |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 879 | playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track); |
| 880 | format_name(buffer, track.filename); |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 881 | return buffer; |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 882 | } |
| 883 | |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 884 | static int say_search_item(int selected_item, void *data) |
| 885 | { |
| 886 | int *found_indicies = (int*)data; |
| 887 | static struct playlist_track_info track; |
| 888 | playlist_get_track_info(viewer.playlist,found_indicies[selected_item],&track); |
| 889 | if(global_settings.playlist_viewer_track_display) |
| 890 | talk_fullpath(track.filename, false); |
| 891 | else talk_file_or_spell(NULL, track.filename, NULL, false); |
| 892 | return 0; |
| 893 | } |
| 894 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 895 | bool search_playlist(void) |
| 896 | { |
| 897 | char search_str[32] = ""; |
| 898 | bool ret = false, exit = false; |
| 899 | int i, playlist_count; |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 900 | int found_indicies[MAX_PLAYLIST_ENTRIES]; |
| 901 | int found_indicies_count = 0, last_found_count = -1; |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 902 | int button; |
| 903 | struct gui_synclist playlist_lists; |
| 904 | struct playlist_track_info track; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 905 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 906 | if (!playlist_viewer_init(&viewer, 0, false)) |
| 907 | return ret; |
Thomas Martitz | 18e40e0 | 2009-08-12 14:38:25 +0000 | [diff] [blame] | 908 | if (kbd_input(search_str, sizeof(search_str)) < 0) |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 909 | return ret; |
| 910 | lcd_clear_display(); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 911 | playlist_count = playlist_amount_ex(viewer.playlist); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 912 | cond_talk_ids_fq(LANG_WAIT); |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 913 | |
| 914 | cpu_boost(true); |
| 915 | |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 916 | for (i = 0; i < playlist_count && |
| 917 | found_indicies_count < MAX_PLAYLIST_ENTRIES; i++) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 918 | { |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 919 | if (found_indicies_count != last_found_count) |
| 920 | { |
| 921 | splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), found_indicies_count, |
| 922 | str(LANG_OFF_ABORT)); |
| 923 | last_found_count = found_indicies_count; |
| 924 | } |
| 925 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 926 | if (action_userabort(TIMEOUT_NOBLOCK)) |
Jonathan Gordon | 88882a8 | 2007-08-04 09:36:47 +0000 | [diff] [blame] | 927 | break; |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 928 | |
| 929 | playlist_get_track_info(viewer.playlist, i, &track); |
| 930 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 931 | if (strcasestr(track.filename,search_str)) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 932 | found_indicies[found_indicies_count++] = track.index; |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 933 | |
Nils Wallménius | 173b411 | 2008-09-29 19:29:42 +0000 | [diff] [blame] | 934 | yield(); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 935 | } |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 936 | |
| 937 | cpu_boost(false); |
| 938 | |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 939 | cond_talk_ids_fq(TALK_ID(found_indicies_count, UNIT_INT), |
| 940 | LANG_PLAYLIST_SEARCH_MSG); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 941 | if (!found_indicies_count) |
| 942 | { |
| 943 | return ret; |
| 944 | } |
| 945 | backlight_on(); |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 946 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 947 | gui_synclist_init(&playlist_lists, playlist_search_callback_name, |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 948 | found_indicies, false, 1, NULL); |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 949 | gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON); |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 950 | gui_synclist_set_icon_callback(&playlist_lists, NULL); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 951 | if(global_settings.talk_file) |
| 952 | gui_synclist_set_voice_callback(&playlist_lists, |
| 953 | global_settings.talk_file? |
| 954 | &say_search_item:NULL); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 955 | gui_synclist_set_nb_items(&playlist_lists, found_indicies_count); |
| 956 | gui_synclist_select_item(&playlist_lists, 0); |
| 957 | gui_synclist_draw(&playlist_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 958 | gui_synclist_speak_item(&playlist_lists); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 959 | while (!exit) |
| 960 | { |
Thomas Martitz | 138ee63 | 2010-09-21 22:55:24 +0000 | [diff] [blame] | 961 | if (list_do_action(CONTEXT_LIST, HZ/4, |
| 962 | &playlist_lists, &button, LIST_WRAP_UNLESS_HELD)) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 963 | continue; |
| 964 | switch (button) |
| 965 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 966 | case ACTION_STD_CANCEL: |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 967 | exit = true; |
| 968 | break; |
| 969 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 970 | case ACTION_STD_OK: |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 971 | { |
| 972 | int sel = gui_synclist_get_sel_pos(&playlist_lists); |
Michael Sevakis | 31b7122 | 2013-07-14 07:59:39 -0400 | [diff] [blame] | 973 | playlist_start(found_indicies[sel], 0, 0); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 974 | exit = 1; |
Thomas Martitz | aa01ee3 | 2010-09-20 23:10:19 +0000 | [diff] [blame] | 975 | } |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 976 | break; |
Nils Wallménius | da01219 | 2008-10-10 21:19:56 +0000 | [diff] [blame] | 977 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 978 | default: |
Nils Wallménius | e7c6ba6 | 2011-04-08 13:39:56 +0000 | [diff] [blame] | 979 | if (default_event_handler(button) == SYS_USB_CONNECTED) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 980 | { |
| 981 | ret = true; |
| 982 | exit = true; |
| 983 | } |
| 984 | break; |
| 985 | } |
| 986 | } |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 987 | talk_shutup(); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 988 | return ret; |
| 989 | } |