@@ -35,8 +35,8 @@ typedef struct {
3535 int current_count ; // number of processed files
3636 int total_count ; // number of items in the playlist
3737
38- int single_repetitions ; // number of times to repeat items in the playlist
39- int current_single_repetition ; // current single repetition
38+ int playlist_repetitions ; // number of times to repeat the whole playlist
39+ int current_playlist_repetition ; // current playlist repetition
4040
4141 // last 3 files
4242 string_t prev_0_path ; // current file
@@ -215,27 +215,19 @@ static bool playlist_worker_wait_pause(PlaylistWorker* worker) {
215215 return true;
216216}
217217
218- static int32_t playlist_worker_thread ( void * ctx ) {
219- Storage * storage = furi_record_open ( RECORD_STORAGE );
220- FlipperFormat * fff_head = flipper_format_file_alloc ( storage );
221-
222- PlaylistWorker * worker = ctx ;
223- if (! flipper_format_file_open_existing ( fff_head , string_get_cstr ( worker -> file_path ))) {
224- FURI_LOG_E ( TAG , "Failed to open %s" , string_get_cstr ( worker -> file_path ));
225- worker -> is_running = false;
226-
227- furi_record_close ( RECORD_STORAGE );
228- flipper_format_free ( fff_head );
229- return 0 ;
218+ static bool playlist_worker_play_playlist_once (
219+ PlaylistWorker * worker ,
220+ Storage * storage ,
221+ FlipperFormat * fff_head ,
222+ FlipperFormat * fff_data ,
223+ string_t data ,
224+ string_t preset ,
225+ string_t protocol ) {
226+ //
227+ if (! flipper_format_rewind ( fff_head )) {
228+ FURI_LOG_E ( TAG , "Failed to rewind file" );
229+ return false ;
230230 }
231-
232- FlipperFormat * fff_data = flipper_format_string_alloc ();
233-
234- string_t data , preset , protocol ;
235- string_init (data );
236- string_init (preset );
237- string_init (protocol );
238-
239231 while (flipper_format_read_string (fff_head , "sub" , data )) {
240232 if (!playlist_worker_wait_pause (worker )) {
241233 break ;
@@ -244,9 +236,7 @@ static int32_t playlist_worker_thread(void* ctx) {
244236 // update state to sending
245237 meta_set_state (worker -> meta , STATE_SENDING );
246238
247- worker -> meta -> current_single_repetition = 0 ;
248239 ++ worker -> meta -> current_count ;
249-
250240 const char * str = string_get_cstr (data );
251241
252242 // it's not fancy, but it works for now :)
@@ -260,20 +250,14 @@ static int32_t playlist_worker_thread(void* ctx) {
260250 string_set_str (worker -> meta -> prev_0_path , str );
261251 view_port_update (worker -> meta -> view_port );
262252
263- for (int i = 0 ; i < MAX ( 1 , worker -> meta -> single_repetitions ) ; i ++ ) {
253+ for (int i = 0 ; i < 1 ; i ++ ) {
264254 if (!playlist_worker_wait_pause (worker )) {
265255 break ;
266256 }
267257
268- ++ worker -> meta -> current_single_repetition ;
269258 view_port_update (worker -> meta -> view_port );
270259
271- FURI_LOG_I (
272- TAG ,
273- "(worker) Sending %s (%d/%d)" ,
274- str ,
275- worker -> meta -> current_single_repetition ,
276- worker -> meta -> single_repetitions );
260+ FURI_LOG_I (TAG , "(worker) Sending %s" , str );
277261
278262 FlipperFormat * fff_file = flipper_format_file_alloc (storage );
279263
@@ -293,10 +277,56 @@ static int32_t playlist_worker_thread(void* ctx) {
293277 break ;
294278 // exited, exit loop
295279 } else if (status == 2 ) {
296- break ;
280+ return false ;
297281 }
298282 }
299283 } // end of loop
284+ return true;
285+ }
286+
287+ static int32_t playlist_worker_thread (void * ctx ) {
288+ Storage * storage = furi_record_open (RECORD_STORAGE );
289+ FlipperFormat * fff_head = flipper_format_file_alloc (storage );
290+
291+ PlaylistWorker * worker = ctx ;
292+ if (!flipper_format_file_open_existing (fff_head , string_get_cstr (worker -> file_path ))) {
293+ FURI_LOG_E (TAG , "Failed to open %s" , string_get_cstr (worker -> file_path ));
294+ worker -> is_running = false;
295+
296+ furi_record_close (RECORD_STORAGE );
297+ flipper_format_free (fff_head );
298+ return 0 ;
299+ }
300+
301+ playlist_worker_wait_pause (worker );
302+ FlipperFormat * fff_data = flipper_format_string_alloc ();
303+
304+ string_t data , preset , protocol ;
305+ string_init (data );
306+ string_init (preset );
307+ string_init (protocol );
308+
309+ for (int i = 0 ; i < MAX (1 , worker -> meta -> playlist_repetitions ); i ++ ) {
310+ // infinite repetitions if playlist_repetitions is 0
311+ if (worker -> meta -> playlist_repetitions <= 0 ) {
312+ -- i ;
313+ }
314+ ++ worker -> meta -> current_playlist_repetition ;
315+ // send playlist
316+ worker -> meta -> current_count = 0 ;
317+
318+ FURI_LOG_I (
319+ TAG ,
320+ "Sending playlist (i %d rep %d b %d)" ,
321+ i ,
322+ worker -> meta -> current_playlist_repetition ,
323+ worker -> meta -> playlist_repetitions );
324+
325+ if (!playlist_worker_play_playlist_once (
326+ worker , storage , fff_head , fff_data , data , preset , protocol )) {
327+ break ;
328+ }
329+ }
300330
301331 furi_record_close (RECORD_STORAGE );
302332 flipper_format_free (fff_head );
@@ -320,7 +350,6 @@ static int32_t playlist_worker_thread(void* ctx) {
320350
321351void playlist_meta_reset (DisplayMeta * instance ) {
322352 instance -> current_count = 0 ;
323- instance -> current_single_repetition = 0 ;
324353
325354 string_reset (instance -> prev_0_path );
326355 string_reset (instance -> prev_1_path );
@@ -335,7 +364,6 @@ DisplayMeta* playlist_meta_alloc() {
335364 string_init (instance -> prev_2_path );
336365 string_init (instance -> prev_3_path );
337366 playlist_meta_reset (instance );
338- instance -> single_repetitions = 1 ;
339367 instance -> state = STATE_NONE ;
340368 return instance ;
341369}
@@ -438,7 +466,14 @@ static void render_callback(Canvas* canvas, void* ctx) {
438466 string_t str ;
439467 string_init_printf (str , "%d Items in playlist" , app -> meta -> total_count );
440468 canvas_draw_str_aligned (canvas , 1 , 19 , AlignLeft , AlignTop , string_get_cstr (str ));
441- string_printf (str , "Repetitions: (single) %d" , app -> meta -> single_repetitions );
469+
470+ if (app -> meta -> playlist_repetitions <= 0 ) {
471+ string_printf (str , "Repeat: yes" , app -> meta -> playlist_repetitions );
472+ } else if (app -> meta -> playlist_repetitions == 1 ) {
473+ string_printf (str , "Repeat: no" , app -> meta -> playlist_repetitions );
474+ } else {
475+ string_printf (str , "Repeat: %dx" , app -> meta -> playlist_repetitions );
476+ }
442477 canvas_draw_str_aligned (canvas , 1 , 29 , AlignLeft , AlignTop , string_get_cstr (str ));
443478 string_clear (str );
444479 }
@@ -498,6 +533,19 @@ static void render_callback(Canvas* canvas, void* ctx) {
498533 AlignBottom ,
499534 string_get_cstr (progress_text ));
500535
536+ canvas_set_color (canvas , ColorBlack );
537+ if (app -> meta -> playlist_repetitions <= 0 ) {
538+ string_printf (progress_text , "[%d/Inf]" , app -> meta -> current_playlist_repetition );
539+ } else {
540+ string_printf (
541+ progress_text ,
542+ "[%d/%d]" ,
543+ app -> meta -> current_playlist_repetition ,
544+ app -> meta -> playlist_repetitions );
545+ }
546+ canvas_draw_str_aligned (
547+ canvas , WIDTH - 1 , 1 , AlignRight , AlignTop , string_get_cstr (progress_text ));
548+
501549 string_clear (progress_text );
502550 }
503551
@@ -513,17 +561,6 @@ static void render_callback(Canvas* canvas, void* ctx) {
513561 // current
514562 if (!string_empty_p (app -> meta -> prev_0_path )) {
515563 path_extract_filename (app -> meta -> prev_0_path , path , true);
516-
517- // add repetition to current file
518- if (app -> meta -> single_repetitions > 1 ) {
519- string_printf (
520- path ,
521- "%s [%d/%d]" ,
522- string_get_cstr (path ),
523- app -> meta -> current_single_repetition ,
524- app -> meta -> single_repetitions );
525- }
526-
527564 int w = canvas_string_width (canvas , string_get_cstr (path ));
528565 canvas_set_color (canvas , ColorBlack );
529566 canvas_draw_rbox (canvas , 1 , 1 , w + 4 , 12 , 2 );
@@ -694,14 +731,18 @@ int32_t playlist_app(void* p) {
694731
695732 switch (input .key ) {
696733 case InputKeyLeft :
697- if (input .type == InputTypeShort && app -> meta -> single_repetitions > 1 ) {
698- -- app -> meta -> single_repetitions ;
734+ if (app -> meta -> state == STATE_OVERVIEW ) {
735+ if (input .type == InputTypeShort && app -> meta -> playlist_repetitions > 0 ) {
736+ -- app -> meta -> playlist_repetitions ;
737+ }
699738 }
700739 break ;
701740
702741 case InputKeyRight :
703- if (input .type == InputTypeShort ) {
704- ++ app -> meta -> single_repetitions ;
742+ if (app -> meta -> state == STATE_OVERVIEW ) {
743+ if (input .type == InputTypeShort ) {
744+ ++ app -> meta -> playlist_repetitions ;
745+ }
705746 }
706747 break ;
707748
0 commit comments