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> |
| 27 | #include <sprintf.h> |
| 28 | #include "playlist.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 29 | #include "audio.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 30 | #include "screens.h" |
| 31 | #include "status.h" |
| 32 | #include "settings.h" |
| 33 | #include "icons.h" |
| 34 | #include "menu.h" |
| 35 | #include "plugin.h" |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 36 | #include "keyboard.h" |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 37 | #include "filetypes.h" |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 38 | #include "onplay.h" |
Jörg Hohensohn | fa97f16 | 2004-03-19 22:15:53 +0000 | [diff] [blame] | 39 | #include "talk.h" |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 40 | #include "misc.h" |
Linus Nielsen Feltzing | 6e0436f | 2005-06-23 01:31:26 +0000 | [diff] [blame] | 41 | #include "action.h" |
Linus Nielsen Feltzing | 2f56ee9 | 2006-01-17 14:15:47 +0000 | [diff] [blame] | 42 | #include "debug.h" |
Tomas Salfischberger | 4ec9dbd | 2006-03-05 00:16:34 +0000 | [diff] [blame] | 43 | #include "backlight.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 44 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 45 | #include "lang.h" |
| 46 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 47 | #include "playlist_viewer.h" |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 48 | #include "playlist_catalog.h" |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 49 | #include "icon.h" |
| 50 | #include "list.h" |
| 51 | #include "statusbar.h" |
| 52 | #include "splash.h" |
Hardeep Sidhu | 0cca6ca | 2006-02-09 09:09:32 +0000 | [diff] [blame] | 53 | #include "playlist_menu.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 54 | #include "action.h" |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 55 | |
| 56 | /* Maximum number of tracks we can have loaded at one time */ |
Kevin Ferrare | 6a53c33 | 2005-11-16 02:55:26 +0000 | [diff] [blame] | 57 | #define MAX_PLAYLIST_ENTRIES 200 |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 58 | |
| 59 | /* The number of items between the selected one and the end/start of |
| 60 | * the buffer under which the buffer must reload */ |
Hardeep Sidhu | 06605a9 | 2006-05-17 07:57:54 +0000 | [diff] [blame] | 61 | #define MIN_BUFFER_MARGIN (screens[0].nb_lines+1) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 62 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 63 | /* Information about a specific track */ |
| 64 | struct playlist_entry { |
| 65 | char *name; /* Formatted track name */ |
| 66 | int index; /* Playlist index */ |
| 67 | int display_index; /* Display index */ |
| 68 | bool queued; /* Is track queued? */ |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 69 | bool skipped; /* Is track marked as bad? */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 72 | enum direction |
| 73 | { |
| 74 | FORWARD, |
| 75 | BACKWARD |
| 76 | }; |
| 77 | |
| 78 | struct playlist_buffer |
| 79 | { |
| 80 | char *name_buffer; /* Buffer used to store track names */ |
| 81 | int buffer_size; /* Size of name buffer */ |
| 82 | |
| 83 | int first_index; /* Real index of first track loaded inside |
| 84 | the buffer */ |
| 85 | |
| 86 | enum direction direction; /* Direction of the buffer (if the buffer |
| 87 | was loaded BACKWARD, the last track in |
| 88 | the buffer has a real index < to the |
| 89 | real index of the the first track)*/ |
| 90 | |
| 91 | struct playlist_entry tracks[MAX_PLAYLIST_ENTRIES]; |
| 92 | int num_loaded; /* Number of track entries loaded in buffer */ |
| 93 | }; |
| 94 | |
| 95 | /* Global playlist viewer settings */ |
| 96 | struct playlist_viewer { |
| 97 | struct playlist_info* playlist; /* playlist being viewed */ |
| 98 | int num_tracks; /* Number of tracks in playlist */ |
| 99 | int current_playing_track; /* Index of current playing track */ |
| 100 | int selected_track; /* The selected track, relative (first is 0)*/ |
| 101 | int move_track; /* Playlist index of track to move or -1 */ |
| 102 | struct playlist_buffer buffer; |
| 103 | }; |
| 104 | |
| 105 | static struct playlist_viewer viewer; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 106 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 107 | /* Used when viewing playlists on disk */ |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 108 | static struct playlist_info temp_playlist; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 109 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 110 | static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, |
| 111 | int names_buffer_size); |
| 112 | static void playlist_buffer_load_entries(struct playlist_buffer * pb, int index, |
| 113 | enum direction direction); |
| 114 | static int playlist_entry_load(struct playlist_entry *entry, int index, |
| 115 | char* name_buffer, int remaining_size); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 116 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 117 | static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb, |
| 118 | int index); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 119 | |
| 120 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 121 | const char* filename, bool reload); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 122 | |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 123 | static void format_name(char* dest, const char* src); |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 124 | static void format_line(const struct playlist_entry* track, char* str, |
| 125 | int len); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 126 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 127 | static bool update_playlist(bool force); |
| 128 | static int onplay_menu(int index); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 129 | static bool viewer_menu(void); |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 130 | static int save_playlist_func(void); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 131 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 132 | static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, |
| 133 | int names_buffer_size) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 134 | { |
| 135 | pb->name_buffer=names_buffer; |
| 136 | pb->buffer_size=names_buffer_size; |
| 137 | pb->first_index=0; |
| 138 | pb->num_loaded=0; |
| 139 | } |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 140 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 141 | /* |
| 142 | * Loads the entries following 'index' in the playlist buffer |
| 143 | */ |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 144 | static void playlist_buffer_load_entries(struct playlist_buffer *pb, int index, |
| 145 | enum direction direction) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 146 | { |
| 147 | int num_entries = viewer.num_tracks; |
| 148 | char* p = pb->name_buffer; |
| 149 | int remaining = pb->buffer_size; |
| 150 | int i; |
| 151 | |
| 152 | pb->first_index = index; |
| 153 | if (num_entries > MAX_PLAYLIST_ENTRIES) |
| 154 | num_entries = MAX_PLAYLIST_ENTRIES; |
| 155 | |
| 156 | for(i=0; i<num_entries; i++) |
| 157 | { |
| 158 | int len = playlist_entry_load(&(pb->tracks[i]), index, p, remaining); |
| 159 | if (len < 0) |
| 160 | { |
| 161 | /* Out of name buffer space */ |
| 162 | num_entries = i; |
| 163 | break; |
| 164 | } |
| 165 | |
| 166 | p += len; |
| 167 | remaining -= len; |
| 168 | |
| 169 | if(direction==FORWARD) |
| 170 | index++; |
| 171 | else |
| 172 | index--; |
| 173 | index+=viewer.num_tracks; |
| 174 | index%=viewer.num_tracks; |
| 175 | } |
| 176 | pb->direction=direction; |
| 177 | pb->num_loaded = i; |
| 178 | } |
| 179 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 180 | static void playlist_buffer_load_entries_screen(struct playlist_buffer * pb, |
| 181 | enum direction direction) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 182 | { |
| 183 | if(direction==FORWARD) |
| 184 | { |
| 185 | int min_start=viewer.selected_track-2*screens[0].nb_lines; |
Linus Nielsen Feltzing | 2f56ee9 | 2006-01-17 14:15:47 +0000 | [diff] [blame] | 186 | while(min_start<0) |
| 187 | min_start+=viewer.num_tracks; |
| 188 | min_start %= viewer.num_tracks; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 189 | playlist_buffer_load_entries(pb, min_start, FORWARD); |
| 190 | } |
| 191 | else |
| 192 | { |
| 193 | int max_start=viewer.selected_track+2*screens[0].nb_lines; |
| 194 | max_start%=viewer.num_tracks; |
| 195 | playlist_buffer_load_entries(pb, max_start, BACKWARD); |
| 196 | } |
| 197 | } |
| 198 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 199 | static int playlist_entry_load(struct playlist_entry *entry, int index, |
| 200 | char* name_buffer, int remaining_size) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 201 | { |
| 202 | struct playlist_track_info info; |
| 203 | int len; |
| 204 | |
| 205 | /* Playlist viewer orders songs based on display index. We need to |
| 206 | convert to real playlist index to access track */ |
| 207 | index = (index + playlist_get_first_index(viewer.playlist)) % |
| 208 | viewer.num_tracks; |
| 209 | if (playlist_get_track_info(viewer.playlist, index, &info) < 0) |
| 210 | return -1; |
| 211 | |
| 212 | len = strlen(info.filename) + 1; |
| 213 | |
| 214 | if (len <= remaining_size) |
| 215 | { |
| 216 | strcpy(name_buffer, info.filename); |
| 217 | |
| 218 | entry->name = name_buffer; |
| 219 | entry->index = info.index; |
| 220 | entry->display_index = info.display_index; |
| 221 | entry->queued = info.attr & PLAYLIST_ATTR_QUEUED; |
| 222 | entry->skipped = info.attr & PLAYLIST_ATTR_SKIPPED; |
| 223 | return len; |
| 224 | } |
| 225 | return -1; |
| 226 | } |
| 227 | |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 228 | static int playlist_buffer_get_index(struct playlist_buffer *pb, int index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 229 | { |
| 230 | int buffer_index; |
| 231 | if(pb->direction==FORWARD) |
| 232 | { |
| 233 | if(index>=pb->first_index) |
| 234 | buffer_index=index-pb->first_index; |
| 235 | else /* rotation : track0 in buffer + requested track */ |
| 236 | buffer_index=(viewer.num_tracks-pb->first_index)+(index); |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | if(index<=pb->first_index) |
| 241 | buffer_index=pb->first_index-index; |
| 242 | else /* rotation : track0 in buffer + dist from the last track |
| 243 | to the requested track (num_tracks-requested track) */ |
| 244 | buffer_index=(pb->first_index)+(viewer.num_tracks-index); |
| 245 | } |
| 246 | return(buffer_index); |
| 247 | } |
| 248 | |
| 249 | #define distance(a, b) \ |
| 250 | a>b? (a) - (b) : (b) - (a) |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 251 | static bool playlist_buffer_needs_reload(struct playlist_buffer* pb, |
| 252 | int track_index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 253 | { |
| 254 | if(pb->num_loaded==viewer.num_tracks) |
| 255 | return(false); |
| 256 | int selected_index=playlist_buffer_get_index(pb, track_index); |
| 257 | int first_buffer_index=playlist_buffer_get_index(pb, pb->first_index); |
| 258 | int distance_beginning=distance(selected_index, first_buffer_index); |
| 259 | if(distance_beginning<MIN_BUFFER_MARGIN) |
| 260 | return(true); |
| 261 | |
| 262 | if(pb->num_loaded - distance_beginning < MIN_BUFFER_MARGIN) |
| 263 | return(true); |
| 264 | return(false); |
| 265 | } |
| 266 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 267 | static struct playlist_entry * playlist_buffer_get_track(struct playlist_buffer *pb, |
| 268 | int index) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 269 | { |
| 270 | int buffer_index=playlist_buffer_get_index(pb, index); |
| 271 | return(&(pb->tracks[buffer_index])); |
| 272 | } |
| 273 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 274 | /* Initialize the playlist viewer. */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 275 | static bool playlist_viewer_init(struct playlist_viewer * viewer, |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 276 | const char* filename, bool reload) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 277 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 278 | char* buffer; |
Michael Sevakis | eb85f14 | 2007-04-21 19:20:20 +0000 | [diff] [blame] | 279 | size_t buffer_size; |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 280 | bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE); |
| 281 | bool have_list = filename || is_playing; |
| 282 | if (!have_list && (global_status.resume_index != -1)) |
| 283 | { |
| 284 | /* Try to restore the list from control file */ |
| 285 | have_list = (playlist_resume() != -1); |
| 286 | } |
Peter D'Hoye | b8ded7d | 2007-08-25 16:05:58 +0000 | [diff] [blame] | 287 | if (!have_list && (playlist_amount() > 0)) |
| 288 | { |
| 289 | /*If dynamic playlist still exists, view it anyway even |
| 290 | if playback has reached the end of the playlist */ |
| 291 | have_list = true; |
| 292 | } |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 293 | if (!have_list) |
| 294 | { |
| 295 | /* Nothing to view, exit */ |
| 296 | gui_syncsplash(HZ, str(LANG_CATALOG_NO_PLAYLISTS)); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 297 | return false; |
Jonathan Gordon | 3d44a20 | 2007-04-26 08:21:29 +0000 | [diff] [blame] | 298 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 299 | |
Michael Sevakis | eb85f14 | 2007-04-21 19:20:20 +0000 | [diff] [blame] | 300 | buffer = plugin_get_buffer(&buffer_size); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 301 | if (!buffer) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 302 | return false; |
| 303 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 304 | if (!filename) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 305 | viewer->playlist = NULL; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 306 | else |
| 307 | { |
| 308 | /* Viewing playlist on disk */ |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 309 | const char *dir, *file; |
| 310 | char *temp_ptr; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 311 | char *index_buffer = NULL; |
Michael Sevakis | 26d242a | 2007-04-21 18:38:25 +0000 | [diff] [blame] | 312 | ssize_t index_buffer_size = 0; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 313 | |
| 314 | viewer->playlist = &temp_playlist; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 315 | |
| 316 | /* Separate directory from filename */ |
| 317 | temp_ptr = strrchr(filename+1,'/'); |
| 318 | if (temp_ptr) |
| 319 | { |
| 320 | *temp_ptr = 0; |
| 321 | dir = filename; |
| 322 | file = temp_ptr + 1; |
| 323 | } |
| 324 | else |
| 325 | { |
| 326 | dir = "/"; |
| 327 | file = filename+1; |
| 328 | } |
| 329 | |
| 330 | if (is_playing) |
| 331 | { |
| 332 | /* Something is playing, use half the plugin buffer for playlist |
| 333 | indices */ |
| 334 | index_buffer_size = buffer_size / 2; |
| 335 | index_buffer = buffer; |
| 336 | } |
| 337 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 338 | playlist_create_ex(viewer->playlist, dir, file, index_buffer, |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 339 | index_buffer_size, buffer+index_buffer_size, |
| 340 | buffer_size-index_buffer_size); |
| 341 | |
| 342 | if (temp_ptr) |
| 343 | *temp_ptr = '/'; |
| 344 | |
| 345 | buffer += index_buffer_size; |
| 346 | buffer_size -= index_buffer_size; |
| 347 | } |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 348 | playlist_buffer_init(&viewer->buffer, buffer, buffer_size ); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 349 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 350 | viewer->move_track = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 351 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 352 | if (!reload) |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 353 | { |
Linus Nielsen Feltzing | 0b8149f | 2006-01-17 12:30:03 +0000 | [diff] [blame] | 354 | if (viewer->playlist) |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 355 | viewer->selected_track = 0; |
Linus Nielsen Feltzing | 0b8149f | 2006-01-17 12:30:03 +0000 | [diff] [blame] | 356 | else |
| 357 | viewer->selected_track = playlist_get_display_index() - 1; |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 358 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 359 | |
| 360 | if (!update_playlist(true)) |
| 361 | return false; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 362 | return true; |
| 363 | } |
| 364 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 365 | /* Format trackname for display purposes */ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 366 | static void format_name(char* dest, const char* src) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 367 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 368 | switch (global_settings.playlist_viewer_track_display) |
| 369 | { |
| 370 | case 0: |
| 371 | default: |
| 372 | { |
Antoine Cellerier | 59dc18d | 2006-08-10 21:08:44 +0000 | [diff] [blame] | 373 | /* Only display the filename */ |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 374 | char* p = strrchr(src, '/'); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 375 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 376 | strcpy(dest, p+1); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 377 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 378 | /* Remove the extension */ |
Nils Wallménius | 4acae4d | 2007-11-18 14:12:01 +0000 | [diff] [blame] | 379 | strrsplt(dest, '.'); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 380 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 381 | break; |
| 382 | } |
| 383 | case 1: |
| 384 | /* Full path */ |
| 385 | strcpy(dest, src); |
| 386 | break; |
| 387 | } |
| 388 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 389 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 390 | /* Format display line */ |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 391 | static void format_line(const struct playlist_entry* track, char* str, |
| 392 | int len) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 393 | { |
| 394 | char name[MAX_PATH]; |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 395 | char *skipped = ""; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 396 | |
| 397 | format_name(name, track->name); |
| 398 | |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 399 | if (track->skipped) |
| 400 | skipped = "(ERR) "; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 401 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 402 | if (global_settings.playlist_viewer_indices) |
| 403 | /* Display playlist index */ |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 404 | snprintf(str, len, "%d. %s%s", track->display_index, skipped, name); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 405 | else |
Miika Pekkarinen | c52f7f1 | 2005-10-21 06:40:45 +0000 | [diff] [blame] | 406 | snprintf(str, len, "%s%s", skipped, name); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 407 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 410 | /* Update playlist in case something has changed or forced */ |
| 411 | static bool update_playlist(bool force) |
| 412 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 413 | if (!viewer.playlist) |
| 414 | playlist_get_resume_info(&viewer.current_playing_track); |
| 415 | else |
| 416 | viewer.current_playing_track = -1; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 417 | int nb_tracks=playlist_amount_ex(viewer.playlist); |
| 418 | force=force || nb_tracks != viewer.num_tracks; |
| 419 | if (force) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 420 | { |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 421 | /* Reload tracks */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 422 | viewer.num_tracks = nb_tracks; |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 423 | if (viewer.num_tracks <= 0) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 424 | return false; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 425 | playlist_buffer_load_entries_screen(&viewer.buffer, FORWARD); |
| 426 | if (viewer.buffer.num_loaded <= 0) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 427 | return false; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 428 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 429 | return true; |
| 430 | } |
| 431 | |
| 432 | /* Menu of playlist commands. Invoked via ON+PLAY on main viewer screen. |
| 433 | Returns -1 if USB attached, 0 if no playlist change, and 1 if playlist |
| 434 | changed. */ |
| 435 | static int onplay_menu(int index) |
| 436 | { |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 437 | int result, ret = 0; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 438 | struct playlist_entry * current_track= |
| 439 | playlist_buffer_get_track(&viewer.buffer, index); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 440 | MENUITEM_STRINGLIST(menu_items, ID2P(LANG_PLAYLIST), NULL, |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 441 | ID2P(LANG_REMOVE), ID2P(LANG_MOVE), |
| 442 | ID2P(LANG_CATALOG_ADD_TO), ID2P(LANG_CATALOG_ADD_TO_NEW)); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 443 | bool current = (current_track->index == viewer.current_playing_track); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 444 | |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 445 | result = do_menu(&menu_items, NULL, NULL, false); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 446 | if (result == MENU_ATTACHED_USB) |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 447 | { |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 448 | ret = -1; |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 449 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 450 | else if (result >= 0) |
| 451 | { |
| 452 | /* Abort current move */ |
| 453 | viewer.move_track = -1; |
| 454 | |
| 455 | switch (result) |
| 456 | { |
| 457 | case 0: |
| 458 | /* delete track */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 459 | playlist_delete(viewer.playlist, current_track->index); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 460 | if (current) |
| 461 | { |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 462 | if (playlist_amount_ex(viewer.playlist) <= 0) |
| 463 | audio_stop(); |
| 464 | else |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 465 | { |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 466 | /* Start playing new track except if it's the lasttrack |
| 467 | track in the playlist and repeat mode is disabled */ |
| 468 | current_track = |
| 469 | playlist_buffer_get_track(&viewer.buffer, index); |
| 470 | if (current_track->display_index!=viewer.num_tracks || |
| 471 | global_settings.repeat_mode == REPEAT_ALL) |
| 472 | { |
Michael Sevakis | acc29d9 | 2006-11-18 02:18:29 +0000 | [diff] [blame] | 473 | #if CONFIG_CODEC != SWCODEC |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 474 | talk_buffer_steal(); /* will use the mp3 buffer */ |
Michael Sevakis | acc29d9 | 2006-11-18 02:18:29 +0000 | [diff] [blame] | 475 | #endif |
Hardeep Sidhu | c7f304e | 2006-04-20 07:30:28 +0000 | [diff] [blame] | 476 | audio_play(0); |
| 477 | viewer.current_playing_track = -1; |
| 478 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 481 | ret = 1; |
| 482 | break; |
| 483 | case 1: |
| 484 | /* move track */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 485 | viewer.move_track = current_track->index; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 486 | ret = 0; |
| 487 | break; |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 488 | case 2: /* add to catalog */ |
| 489 | case 3: /* add to a new one */ |
| 490 | catalog_add_to_a_playlist(current_track->name, |
Jonathan Gordon | 36a2e30 | 2007-04-18 13:03:01 +0000 | [diff] [blame] | 491 | FILE_ATTR_AUDIO, |
Jonathan Gordon | 517aca8 | 2008-05-04 13:01:16 +0000 | [diff] [blame] | 492 | result==3, NULL); |
Jonathan Gordon | ce58428 | 2007-02-12 05:02:42 +0000 | [diff] [blame] | 493 | ret = 0; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 494 | break; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 495 | } |
| 496 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 497 | return ret; |
| 498 | } |
| 499 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 500 | /* Menu of viewer options. Invoked via F1(r) or Menu(p). */ |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 501 | MENUITEM_SETTING(show_icons, &global_settings.playlist_viewer_icons, NULL); |
| 502 | MENUITEM_SETTING(show_indices, &global_settings.playlist_viewer_indices, NULL); |
| 503 | MENUITEM_SETTING(track_display, |
| 504 | &global_settings.playlist_viewer_track_display, NULL); |
| 505 | MENUITEM_FUNCTION(save_playlist_item, 0, ID2P(LANG_SAVE_DYNAMIC_PLAYLIST), |
| 506 | save_playlist_func, 0, NULL, Icon_NOICON); |
| 507 | MAKE_MENU(viewer_settings_menu, ID2P(LANG_PLAYLISTVIEWER_SETTINGS), |
| 508 | NULL, Icon_Playlist, |
| 509 | &show_icons, &show_indices, &track_display, &save_playlist_item); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 510 | static bool viewer_menu(void) |
| 511 | { |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 512 | return do_menu(&viewer_settings_menu, NULL, NULL, false) == MENU_ATTACHED_USB; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | /* Save playlist to disk */ |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 516 | static int save_playlist_func(void) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 517 | { |
Hardeep Sidhu | 0cca6ca | 2006-02-09 09:09:32 +0000 | [diff] [blame] | 518 | save_playlist_screen(viewer.playlist); |
Jonathan Gordon | a2740d9 | 2007-04-25 11:20:19 +0000 | [diff] [blame] | 519 | return 0; |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | /* View current playlist */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 523 | bool playlist_viewer(void) |
| 524 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 525 | return playlist_viewer_ex(NULL); |
| 526 | } |
| 527 | |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 528 | static int get_track_num( struct playlist_viewer * local_viewer, |
| 529 | int selected_item ) |
| 530 | { |
| 531 | if( local_viewer->move_track >= 0 ) |
| 532 | { |
| 533 | if( local_viewer->selected_track == selected_item ) |
| 534 | { |
| 535 | return local_viewer->move_track; |
| 536 | } |
| 537 | else if( local_viewer->selected_track > selected_item |
| 538 | && selected_item >= local_viewer->move_track ) |
| 539 | { |
| 540 | return selected_item+1; |
| 541 | } |
| 542 | else if( local_viewer->selected_track < selected_item |
| 543 | && selected_item <= local_viewer->move_track ) |
| 544 | { |
| 545 | return selected_item-1; |
| 546 | } |
| 547 | } |
| 548 | return selected_item; |
| 549 | } |
| 550 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 551 | static char *playlist_callback_name(int selected_item, |
| 552 | void *data, |
| 553 | char *buffer, |
| 554 | size_t buffer_len) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 555 | { |
| 556 | struct playlist_viewer * local_viewer = (struct playlist_viewer *)data; |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 557 | |
| 558 | int track_num = get_track_num(local_viewer, selected_item); |
| 559 | struct playlist_entry *track = |
| 560 | playlist_buffer_get_track(&(local_viewer->buffer), track_num); |
| 561 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 562 | format_line(track, buffer, buffer_len); |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 563 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 564 | return(buffer); |
| 565 | } |
| 566 | |
| 567 | |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 568 | static int playlist_callback_icons(int selected_item, void *data) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 569 | { |
| 570 | struct playlist_viewer * local_viewer=(struct playlist_viewer *)data; |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 571 | |
| 572 | int track_num = get_track_num(local_viewer, selected_item); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 573 | struct playlist_entry *track= |
Nils Wallménius | 791e092 | 2008-04-09 21:47:43 +0000 | [diff] [blame] | 574 | playlist_buffer_get_track(&(local_viewer->buffer), track_num); |
| 575 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 576 | if (track->index == local_viewer->current_playing_track) |
| 577 | { |
| 578 | /* Current playing track */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 579 | return Icon_Audio; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 580 | } |
| 581 | else if (track->index == local_viewer->move_track) |
| 582 | { |
| 583 | /* Track we are moving */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 584 | return Icon_Moving; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 585 | } |
| 586 | else if (track->queued) |
| 587 | { |
| 588 | /* Queued track */ |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 589 | return Icon_Queued; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 590 | } |
| 591 | else |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 592 | return Icon_NOICON; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 595 | /* Main viewer function. Filename identifies playlist to be viewed. If NULL, |
| 596 | view current playlist. */ |
Steve Bavin | ad95df2 | 2008-05-12 17:52:50 +0000 | [diff] [blame] | 597 | bool playlist_viewer_ex(const char* filename) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 598 | { |
| 599 | bool ret = false; /* return value */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 600 | bool exit=false; /* exit viewer */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 601 | int button; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 602 | struct gui_synclist playlist_lists; |
| 603 | if (!playlist_viewer_init(&viewer, filename, false)) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 604 | goto exit; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 605 | |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 606 | gui_synclist_init(&playlist_lists, playlist_callback_name, |
| 607 | &viewer, false, 1, NULL); |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 608 | gui_synclist_set_icon_callback(&playlist_lists, |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 609 | global_settings.playlist_viewer_icons? |
| 610 | &playlist_callback_icons:NULL); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 611 | gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); |
| 612 | gui_synclist_select_item(&playlist_lists, viewer.selected_track); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 613 | gui_synclist_set_title(&playlist_lists, str(LANG_PLAYLIST), Icon_Playlist); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 614 | gui_synclist_draw(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 615 | while (!exit) |
| 616 | { |
Björn Stenberg | a108ec2 | 2004-01-14 00:13:04 +0000 | [diff] [blame] | 617 | int track; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 618 | |
Peter D'Hoye | df32813 | 2007-08-21 23:50:26 +0000 | [diff] [blame] | 619 | if (global_status.resume_index != -1 && !viewer.playlist) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 620 | playlist_get_resume_info(&track); |
| 621 | else |
| 622 | track = -1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 623 | |
| 624 | if (track != viewer.current_playing_track || |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 625 | playlist_amount_ex(viewer.playlist) != viewer.num_tracks) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 626 | { |
| 627 | /* Playlist has changed (new track started?) */ |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 628 | if (!update_playlist(false)) |
Hardeep Sidhu | 1b44632 | 2004-04-15 06:12:02 +0000 | [diff] [blame] | 629 | goto exit; |
Peter D'Hoye | df32813 | 2007-08-21 23:50:26 +0000 | [diff] [blame] | 630 | /*Needed because update_playlist gives wrong value when |
| 631 | playing is stopped*/ |
| 632 | viewer.current_playing_track = track; |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 633 | gui_synclist_set_nb_items(&playlist_lists, viewer.num_tracks); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 634 | /* Abort move on playlist change */ |
| 635 | viewer.move_track = -1; |
Hardeep Sidhu | 9a681dd | 2006-06-12 23:25:12 +0000 | [diff] [blame] | 636 | gui_synclist_draw(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 637 | } |
| 638 | |
Hardeep Sidhu | 1b44632 | 2004-04-15 06:12:02 +0000 | [diff] [blame] | 639 | /* Timeout so we can determine if play status has changed */ |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 640 | button = get_action(CONTEXT_TREE,HZ/2); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 641 | if( (gui_synclist_do_button(&playlist_lists, &button,LIST_WRAP_UNLESS_HELD)) ) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 642 | { |
| 643 | viewer.selected_track=gui_synclist_get_sel_pos(&playlist_lists); |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 644 | if(playlist_buffer_needs_reload(&viewer.buffer, |
| 645 | viewer.selected_track)) |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 646 | playlist_buffer_load_entries_screen(&viewer.buffer, |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 647 | button==ACTION_STD_NEXT? |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 648 | FORWARD |
| 649 | : |
| 650 | BACKWARD |
| 651 | ); |
Antoine Cellerier | 2490700 | 2007-10-15 20:34:02 +0000 | [diff] [blame] | 652 | gui_synclist_draw(&playlist_lists); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 653 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 654 | switch (button) |
| 655 | { |
Peter D'Hoye | 734278b | 2007-04-12 21:28:58 +0000 | [diff] [blame] | 656 | case ACTION_TREE_WPS: |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 657 | case ACTION_STD_CANCEL: |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 658 | { |
| 659 | if (viewer.move_track >= 0) |
| 660 | { |
| 661 | viewer.selected_track = viewer.move_track; |
| 662 | gui_synclist_select_item(&playlist_lists, viewer.move_track); |
| 663 | viewer.move_track = -1; |
| 664 | gui_synclist_draw(&playlist_lists); |
| 665 | } |
| 666 | else |
| 667 | exit = true; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 668 | break; |
Antoine Cellerier | a6d4e53 | 2007-12-15 17:14:04 +0000 | [diff] [blame] | 669 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 670 | case ACTION_STD_OK: |
| 671 | { |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 672 | struct playlist_entry * current_track = |
| 673 | playlist_buffer_get_track(&viewer.buffer, |
| 674 | viewer.selected_track); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 675 | if (viewer.move_track >= 0) |
| 676 | { |
| 677 | /* Move track */ |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 678 | int ret_val; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 679 | |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 680 | ret_val = playlist_move(viewer.playlist, viewer.move_track, |
Hardeep Sidhu | 3074394 | 2005-11-19 18:19:46 +0000 | [diff] [blame] | 681 | current_track->index); |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 682 | if (ret_val < 0) |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 683 | gui_syncsplash(HZ, (unsigned char *)"%s %s", |
| 684 | str(LANG_MOVE), str(LANG_FAILED)); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 685 | update_playlist(true); |
| 686 | viewer.move_track = -1; |
| 687 | } |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 688 | else if (!viewer.playlist) |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 689 | { |
Hardeep Sidhu | 0574151 | 2005-06-23 17:31:44 +0000 | [diff] [blame] | 690 | /* play new track */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 691 | playlist_start(current_track->index, 0); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 692 | update_playlist(false); |
| 693 | } |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 694 | else |
| 695 | { |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 696 | /* New playlist */ |
| 697 | if (playlist_set_current(viewer.playlist) < 0) |
| 698 | goto exit; |
| 699 | |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 700 | playlist_start(current_track->index, 0); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 701 | |
| 702 | /* Our playlist is now the current list */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 703 | if (!playlist_viewer_init(&viewer, NULL, true)) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 704 | goto exit; |
| 705 | } |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 706 | gui_synclist_draw(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 707 | |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 708 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 709 | } |
| 710 | case ACTION_STD_CONTEXT: |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 711 | { |
| 712 | /* ON+PLAY menu */ |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 713 | int ret_val; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 714 | |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 715 | ret_val = onplay_menu(viewer.selected_track); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 716 | |
Jonathan Gordon | 52ba1c6 | 2007-04-26 10:28:32 +0000 | [diff] [blame] | 717 | if (ret_val < 0) |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 718 | { |
| 719 | ret = true; |
| 720 | goto exit; |
| 721 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 722 | else if (ret > 0) |
| 723 | { |
| 724 | /* Playlist changed */ |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 725 | gui_synclist_del_item(&playlist_lists); |
| 726 | update_playlist(true); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 727 | if (viewer.num_tracks <= 0) |
| 728 | exit = true; |
Peter D'Hoye | b16137e | 2007-04-11 22:39:12 +0000 | [diff] [blame] | 729 | if(viewer.selected_track >= viewer.num_tracks) |
| 730 | viewer.selected_track = viewer.num_tracks-1; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 731 | } |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 732 | gui_synclist_draw(&playlist_lists); |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 733 | break; |
| 734 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 735 | case ACTION_STD_MENU: |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 736 | if (viewer_menu()) |
| 737 | { |
| 738 | ret = true; |
| 739 | goto exit; |
| 740 | } |
Kevin Ferrare | 15046f9 | 2005-11-16 17:23:49 +0000 | [diff] [blame] | 741 | gui_synclist_set_icon_callback( |
| 742 | &playlist_lists, |
| 743 | global_settings.playlist_viewer_icons? |
| 744 | &playlist_callback_icons:NULL |
| 745 | ); |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 746 | gui_synclist_draw(&playlist_lists); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 747 | break; |
| 748 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 749 | case ACTION_NONE: |
Kevin Ferrare | 8517ed8 | 2005-11-16 02:12:25 +0000 | [diff] [blame] | 750 | gui_syncstatusbar_draw(&statusbars, false); |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 751 | break; |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 752 | |
| 753 | default: |
| 754 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 755 | { |
| 756 | ret = true; |
| 757 | goto exit; |
| 758 | } |
| 759 | break; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 760 | } |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Hardeep Sidhu | 107ebc5 | 2004-01-26 17:05:21 +0000 | [diff] [blame] | 763 | exit: |
| 764 | if (viewer.playlist) |
| 765 | playlist_close(viewer.playlist); |
| 766 | return ret; |
Hardeep Sidhu | 00acdfa | 2003-12-10 00:11:25 +0000 | [diff] [blame] | 767 | } |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 768 | |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 769 | static char *playlist_search_callback_name(int selected_item, void * data, |
| 770 | char *buffer, size_t buffer_len) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 771 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 772 | (void)buffer_len; /* this should probably be used */ |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 773 | int *found_indicies = (int*)data; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 774 | static struct playlist_track_info track; |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 775 | playlist_get_track_info(viewer.playlist, found_indicies[selected_item], &track); |
| 776 | format_name(buffer, track.filename); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 777 | return(buffer); |
| 778 | } |
| 779 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 780 | bool search_playlist(void) |
| 781 | { |
| 782 | char search_str[32] = ""; |
| 783 | bool ret = false, exit = false; |
| 784 | int i, playlist_count; |
| 785 | int found_indicies[MAX_PLAYLIST_ENTRIES],found_indicies_count = 0; |
| 786 | int button; |
| 787 | struct gui_synclist playlist_lists; |
| 788 | struct playlist_track_info track; |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 789 | |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 790 | if (!playlist_viewer_init(&viewer, 0, false)) |
| 791 | return ret; |
| 792 | if (kbd_input(search_str,sizeof(search_str)) == -1) |
Zakk Roberts | 34ad56d | 2006-04-03 04:13:26 +0000 | [diff] [blame] | 793 | return ret; |
| 794 | lcd_clear_display(); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 795 | playlist_count = playlist_amount_ex(viewer.playlist); |
| 796 | for (i=0;(i<playlist_count)&&(found_indicies_count<MAX_PLAYLIST_ENTRIES);i++) |
| 797 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 798 | gui_syncsplash(0, str(LANG_PLAYLIST_SEARCH_MSG),found_indicies_count, |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 799 | str(LANG_OFF_ABORT)); |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 800 | if (action_userabort(TIMEOUT_NOBLOCK)) |
Jonathan Gordon | 88882a8 | 2007-08-04 09:36:47 +0000 | [diff] [blame] | 801 | { |
| 802 | if (!found_indicies_count) |
| 803 | return ret; |
| 804 | break; |
| 805 | } |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 806 | playlist_get_track_info(viewer.playlist,i,&track); |
| 807 | if (strcasestr(track.filename,search_str)) |
| 808 | { |
| 809 | found_indicies[found_indicies_count++] = track.index; |
| 810 | } |
| 811 | } |
| 812 | if (!found_indicies_count) |
| 813 | { |
| 814 | return ret; |
| 815 | } |
| 816 | backlight_on(); |
| 817 | gui_synclist_init(&playlist_lists, playlist_search_callback_name, |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 818 | found_indicies, false, 1, NULL); |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 819 | gui_synclist_set_icon_callback(&playlist_lists, NULL); |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 820 | gui_synclist_set_nb_items(&playlist_lists, found_indicies_count); |
| 821 | gui_synclist_select_item(&playlist_lists, 0); |
| 822 | gui_synclist_draw(&playlist_lists); |
| 823 | while (!exit) |
| 824 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 825 | button = get_action(CONTEXT_LIST,TIMEOUT_BLOCK); |
Jonathan Gordon | cf1cef5 | 2007-09-17 10:08:50 +0000 | [diff] [blame] | 826 | if (gui_synclist_do_button(&playlist_lists, &button, LIST_WRAP_UNLESS_HELD)) |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 827 | continue; |
| 828 | switch (button) |
| 829 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 830 | case ACTION_STD_CANCEL: |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 831 | exit = true; |
| 832 | break; |
| 833 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 834 | case ACTION_STD_OK: |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 835 | playlist_start( |
| 836 | found_indicies[gui_synclist_get_sel_pos(&playlist_lists)] |
| 837 | ,0); |
| 838 | exit = 1; |
| 839 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 840 | case ACTION_NONE: |
Tomas Salfischberger | c2e86cd | 2006-03-04 23:53:09 +0000 | [diff] [blame] | 841 | break; |
| 842 | default: |
| 843 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 844 | { |
| 845 | ret = true; |
| 846 | exit = true; |
| 847 | } |
| 848 | break; |
| 849 | } |
| 850 | } |
| 851 | return ret; |
| 852 | } |
| 853 | |