summaryrefslogtreecommitdiff
path: root/apps/onplay.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/onplay.c')
-rw-r--r--apps/onplay.c116
1 files changed, 105 insertions, 11 deletions
diff --git a/apps/onplay.c b/apps/onplay.c
index 3e0f5a365e..6c538f8d8a 100644
--- a/apps/onplay.c
+++ b/apps/onplay.c
@@ -38,13 +38,103 @@
38#include "screens.h" 38#include "screens.h"
39#include "tree.h" 39#include "tree.h"
40#include "buffer.h" 40#include "buffer.h"
41#include "settings.h"
42#include "status.h"
43#include "onplay.h"
41 44
42static char* selected_file = NULL; 45static char* selected_file = NULL;
43static bool reload_dir = false; 46static int selected_file_attr = 0;
47static int onplay_result = ONPLAY_OK;
44 48
45static bool queue_file(void) 49/* For playlist options */
50struct playlist_args {
51 int position;
52 bool queue;
53};
54
55static bool add_to_playlist(int position, bool queue)
46{ 56{
47 queue_add(selected_file); 57 bool new_playlist = !(mpeg_status() & MPEG_STATUS_PLAY);
58
59 if (new_playlist)
60 playlist_create(NULL, NULL);
61
62 if (selected_file_attr & TREE_ATTR_MPA)
63 playlist_insert_track(selected_file, position, queue);
64 else if (selected_file_attr & ATTR_DIRECTORY)
65 playlist_insert_directory(selected_file, position, queue);
66 else if (selected_file_attr & TREE_ATTR_M3U)
67 playlist_insert_playlist(selected_file, position, queue);
68
69 if (new_playlist && (playlist_amount() > 0))
70 {
71 /* nothing is currently playing so begin playing what we just
72 inserted */
73 if (global_settings.playlist_shuffle)
74 playlist_shuffle(current_tick, -1);
75 playlist_start(0,0);
76 status_set_playmode(STATUS_PLAY);
77 status_draw(false);
78 onplay_result = ONPLAY_START_PLAY;
79 }
80
81 return false;
82}
83
84/* Sub-menu for playlist options */
85static bool playlist_options(void)
86{
87 struct menu_items menu[6];
88 struct playlist_args args[6]; /* increase these 2 if you add entries! */
89 int m, i=0, result;
90
91 if (mpeg_status() & MPEG_STATUS_PLAY)
92 {
93 menu[i].desc = str(LANG_INSERT);
94 args[i].position = PLAYLIST_INSERT;
95 args[i].queue = false;
96 i++;
97
98 menu[i].desc = str(LANG_INSERT_FIRST);
99 args[i].position = PLAYLIST_INSERT_FIRST;
100 args[i].queue = false;
101 i++;
102
103 menu[i].desc = str(LANG_INSERT_LAST);
104 args[i].position = PLAYLIST_INSERT_LAST;
105 args[i].queue = false;
106 i++;
107
108 menu[i].desc = str(LANG_QUEUE);
109 args[i].position = PLAYLIST_INSERT;
110 args[i].queue = true;
111 i++;
112
113 menu[i].desc = str(LANG_QUEUE_FIRST);
114 args[i].position = PLAYLIST_INSERT_FIRST;
115 args[i].queue = true;
116 i++;
117
118 menu[i].desc = str(LANG_QUEUE_LAST);
119 args[i].position = PLAYLIST_INSERT_LAST;
120 args[i].queue = true;
121 i++;
122 }
123 else if ((selected_file_attr & TREE_ATTR_MPA) ||
124 (selected_file_attr & ATTR_DIRECTORY))
125 {
126 menu[i].desc = str(LANG_INSERT);
127 args[i].position = PLAYLIST_INSERT;
128 args[i].queue = false;
129 i++;
130 }
131
132 m = menu_init( menu, i );
133 result = menu_show(m);
134 if (result >= 0)
135 add_to_playlist(args[result].position, args[result].queue);
136 menu_exit(m);
137
48 return false; 138 return false;
49} 139}
50 140
@@ -68,7 +158,7 @@ static bool delete_file(void)
68 switch (btn) { 158 switch (btn) {
69 case BUTTON_PLAY: 159 case BUTTON_PLAY:
70 if (!remove(selected_file)) { 160 if (!remove(selected_file)) {
71 reload_dir = true; 161 onplay_result = ONPLAY_RELOAD_DIR;
72 lcd_clear_display(); 162 lcd_clear_display();
73 lcd_puts(0,0,str(LANG_DELETED)); 163 lcd_puts(0,0,str(LANG_DELETED));
74 lcd_puts_scroll(0,1,selected_file); 164 lcd_puts_scroll(0,1,selected_file);
@@ -104,7 +194,7 @@ static bool rename_file(void)
104 sleep(HZ*2); 194 sleep(HZ*2);
105 } 195 }
106 else 196 else
107 reload_dir = true; 197 onplay_result = ONPLAY_RELOAD_DIR;
108 } 198 }
109 199
110 return false; 200 return false;
@@ -225,7 +315,7 @@ static bool vbr_fix(void)
225 315
226 if(mpeg_status()) { 316 if(mpeg_status()) {
227 splash(HZ*2, 0, true, str(LANG_VBRFIX_STOP_PLAY)); 317 splash(HZ*2, 0, true, str(LANG_VBRFIX_STOP_PLAY));
228 return reload_dir; 318 return onplay_result;
229 } 319 }
230 320
231 lcd_clear_display(); 321 lcd_clear_display();
@@ -356,12 +446,16 @@ int onplay(char* file, int attr)
356 struct menu_items menu[5]; /* increase this if you add entries! */ 446 struct menu_items menu[5]; /* increase this if you add entries! */
357 int m, i=0, result; 447 int m, i=0, result;
358 448
449 onplay_result = ONPLAY_OK;
450
359 selected_file = file; 451 selected_file = file;
360 452 selected_file_attr = attr;
361 if ((mpeg_status() & MPEG_STATUS_PLAY) && (attr & TREE_ATTR_MPA)) 453
454 if ((attr & TREE_ATTR_MPA) || (attr & ATTR_DIRECTORY) ||
455 (attr & TREE_ATTR_M3U))
362 { 456 {
363 menu[i].desc = str(LANG_QUEUE); 457 menu[i].desc = str(LANG_PLAYINDICES_PLAYLIST);
364 menu[i].function = queue_file; 458 menu[i].function = playlist_options;
365 i++; 459 i++;
366 } 460 }
367 461
@@ -390,5 +484,5 @@ int onplay(char* file, int attr)
390 menu[result].function(); 484 menu[result].function();
391 menu_exit(m); 485 menu_exit(m);
392 486
393 return reload_dir; 487 return onplay_result;
394} 488}