1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C)2003 by Benjamin Metzler
11 * All files in this archive are subject to the GNU General Public License.
12 * See the file COPYING in the source tree root for full license agreement.
14 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
15 * KIND, either express or implied.
17 ****************************************************************************/
25 #include "applimits.h"
54 #define MAX_BOOKMARKS 10
55 #define MAX_BOOKMARK_SIZE 350
56 #define RECENT_BOOKMARK_FILE ROCKBOX_DIR "/most-recent.bmark"
58 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
);
59 static bool check_bookmark(const char* bookmark
);
60 static char* create_bookmark(void);
61 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
);
62 static void display_bookmark(const char* bookmark
,
65 static void say_bookmark(const char* bookmark
,
67 static bool generate_bookmark_file_name(const char *in
);
68 static char* get_bookmark(const char* bookmark_file
, int bookmark_count
);
69 static bool parse_bookmark(const char *bookmark
,
73 int *resume_first_index
,
75 unsigned int resume_file_size
,
80 static char* select_bookmark(const char* bookmark_file_name
);
81 static bool system_check(void);
82 static bool write_bookmark(bool create_bookmark_file
);
83 static int get_bookmark_count(const char* bookmark_file_name
);
85 static char global_temp_buffer
[MAX_PATH
+1];
86 static char global_bookmark_file_name
[MAX_PATH
];
87 static char global_read_buffer
[MAX_BOOKMARK_SIZE
];
88 static char global_bookmark
[MAX_BOOKMARK_SIZE
];
89 static char global_filename
[MAX_PATH
];
91 /* ----------------------------------------------------------------------- */
92 /* This is the interface function from the main menu. */
93 /* ----------------------------------------------------------------------- */
94 bool bookmark_create_menu(void)
100 /* ----------------------------------------------------------------------- */
101 /* This function acts as the load interface from the main menu */
102 /* This function determines the bookmark file name and then loads that file*/
103 /* for the user. The user can then select a bookmark to load. */
104 /* If no file/directory is currently playing, the menu item does not work. */
105 /* ----------------------------------------------------------------------- */
106 bool bookmark_load_menu(void)
118 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
119 sizeof(global_temp_buffer
));
120 if (generate_bookmark_file_name(name
))
122 bookmark
= select_bookmark(global_bookmark_file_name
);
124 return false; /* User exited without selecting a bookmark */
126 success
= parse_bookmark(bookmark
,
132 sizeof(global_temp_buffer
),
134 &global_settings
.repeat_mode
,
135 &global_settings
.playlist_shuffle
,
140 /* something bad happened while creating bookmark name*/
145 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
152 /* ----------------------------------------------------------------------- */
153 /* Gives the user a list of the Most Recent Bookmarks. This is an */
154 /* interface function */
155 /* ----------------------------------------------------------------------- */
156 bool bookmark_mrb_load()
164 bookmark
= select_bookmark(RECENT_BOOKMARK_FILE
);
166 return false; /* User exited without selecting a bookmark */
168 success
= parse_bookmark(bookmark
,
174 sizeof(global_temp_buffer
),
176 &global_settings
.repeat_mode
,
177 &global_settings
.playlist_shuffle
,
181 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
188 /* ----------------------------------------------------------------------- */
189 /* This function handles an autobookmark creation. This is an interface */
191 /* ----------------------------------------------------------------------- */
192 bool bookmark_autobookmark(void)
197 audio_pause(); /* first pause playback */
198 switch (global_settings
.autocreatebookmark
)
201 return write_bookmark(true);
206 case BOOKMARK_RECENT_ONLY_YES
:
207 return write_bookmark(false);
209 #ifdef HAVE_LCD_BITMAP
210 unsigned char *lines
[]={str(LANG_AUTO_BOOKMARK_QUERY
)};
211 struct text_message message
={(char **)lines
, 1};
213 unsigned char *lines
[]={str(LANG_AUTO_BOOKMARK_QUERY
),
214 str(LANG_RESUME_CONFIRM_PLAYER
)};
215 struct text_message message
={(char **)lines
, 2};
217 gui_syncstatusbar_draw(&statusbars
, false);
218 if(gui_syncyesno_run(&message
, NULL
, NULL
)==YESNO_YES
)
220 if (global_settings
.autocreatebookmark
== BOOKMARK_RECENT_ONLY_ASK
)
221 return write_bookmark(false);
223 return write_bookmark(true);
228 /* ----------------------------------------------------------------------- */
229 /* This function takes the current current resume information and writes */
230 /* that to the beginning of the bookmark file. */
231 /* This file will contain N number of bookmarks in the following format: */
232 /* resume_index*resume_offset*resume_seed*resume_first_index* */
233 /* resume_file*milliseconds*MP3 Title* */
234 /* ------------------------------------------------------------------------*/
235 static bool write_bookmark(bool create_bookmark_file
)
241 return false; /* something didn't happen correctly, do nothing */
243 bookmark
= create_bookmark();
245 return false; /* something didn't happen correctly, do nothing */
247 if (global_settings
.usemrb
)
248 success
= add_bookmark(RECENT_BOOKMARK_FILE
, bookmark
);
251 /* writing the bookmark */
252 if (create_bookmark_file
)
254 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
255 sizeof(global_temp_buffer
));
256 if (generate_bookmark_file_name(name
))
258 success
= add_bookmark(global_bookmark_file_name
, bookmark
);
263 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_CREATE_SUCCESS
));
265 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_CREATE_FAILURE
));
270 /* ----------------------------------------------------------------------- */
271 /* This function adds a bookmark to a file. */
272 /* ------------------------------------------------------------------------*/
273 static bool add_bookmark(const char* bookmark_file_name
, const char* bookmark
)
275 int temp_bookmark_file
= 0;
276 int bookmark_file
= 0;
277 int bookmark_count
= 0;
278 char* playlist
= NULL
;
284 /* Opening up a temp bookmark file */
285 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
286 "%s.tmp", bookmark_file_name
);
287 temp_bookmark_file
= open(global_temp_buffer
,
288 O_WRONLY
| O_CREAT
| O_TRUNC
);
289 if (temp_bookmark_file
< 0)
290 return false; /* can't open the temp file */
292 if (!strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
) &&
293 (global_settings
.usemrb
== BOOKMARK_UNIQUE_ONLY
))
295 playlist
= strchr(bookmark
,'/');
296 cp
= strrchr(bookmark
,';');
301 /* Writing the new bookmark to the begining of the temp file */
302 write(temp_bookmark_file
, bookmark
, strlen(bookmark
));
303 write(temp_bookmark_file
, "\n", 1);
306 /* Reading in the previous bookmarks and writing them to the temp file */
307 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
308 if (bookmark_file
>= 0)
310 while (read_line(bookmark_file
, global_read_buffer
,
311 sizeof(global_read_buffer
)))
313 /* The MRB has a max of MAX_BOOKMARKS in it */
314 /* This keeps it from getting too large */
315 if ((strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
)==0))
317 if(bookmark_count
>= MAX_BOOKMARKS
)
321 cp
= strchr(global_read_buffer
,'/');
322 tmp
= strrchr(global_read_buffer
,';');
323 if (check_bookmark(global_read_buffer
) &&
324 (!unique
|| len
!= tmp
-cp
|| strncmp(playlist
,cp
,len
)))
327 write(temp_bookmark_file
, global_read_buffer
,
328 strlen(global_read_buffer
));
329 write(temp_bookmark_file
, "\n", 1);
332 close(bookmark_file
);
334 close(temp_bookmark_file
);
336 remove(bookmark_file_name
);
337 rename(global_temp_buffer
, bookmark_file_name
);
343 /* ----------------------------------------------------------------------- */
344 /* This function takes the system resume data and formats it into a valid */
346 /* ----------------------------------------------------------------------- */
347 static char* create_bookmark()
349 int resume_index
= 0;
352 /* grab the currently playing track */
353 struct mp3entry
*id3
= audio_current_track();
357 /* Get some basic resume information */
358 /* queue_resume and queue_resume_index are not used and can be ignored.*/
359 playlist_get_resume_info(&resume_index
);
361 /* Get the currently playing file minus the path */
362 /* This is used when displaying the available bookmarks */
363 file
= strrchr(id3
->path
,'/');
367 /* create the bookmark */
368 snprintf(global_bookmark
, sizeof(global_bookmark
),
369 "%d;%ld;%d;%d;%ld;%d;%d;%s;%s",
372 playlist_get_seed(NULL
),
375 global_settings
.repeat_mode
,
376 global_settings
.playlist_shuffle
,
377 playlist_get_name(NULL
, global_temp_buffer
,
378 sizeof(global_temp_buffer
)),
381 /* checking to see if the bookmark is valid */
382 if (check_bookmark(global_bookmark
))
383 return global_bookmark
;
388 static bool check_bookmark(const char* bookmark
)
390 return parse_bookmark(bookmark
,
391 NULL
,NULL
,NULL
, NULL
,
396 /* ----------------------------------------------------------------------- */
397 /* This function will determine if an autoload is necessary. This is an */
398 /* interface function. */
399 /* ------------------------------------------------------------------------*/
400 bool bookmark_autoload(const char* file
)
406 if(global_settings
.autoloadbookmark
== BOOKMARK_NO
)
409 /*Checking to see if a bookmark file exists.*/
410 if(!generate_bookmark_file_name(file
))
414 fd
= open(global_bookmark_file_name
, O_RDONLY
);
417 if(-1 == lseek(fd
, 0, SEEK_END
))
423 if(global_settings
.autoloadbookmark
== BOOKMARK_YES
)
425 return bookmark_load(global_bookmark_file_name
, true);
429 /* Prompting user to confirm bookmark load */
431 gui_syncstatusbar_draw(&statusbars
, false);
432 #ifdef HAVE_LCD_BITMAP
433 lcd_setmargins(0, STATUSBAR_HEIGHT
);
434 lcd_puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY
));
435 lcd_puts(0,1, str(LANG_CONFIRM_WITH_PLAY_RECORDER
));
436 lcd_puts(0,2, str(LANG_BOOKMARK_SELECT_LIST_BOOKMARKS
));
437 lcd_puts(0,3, str(LANG_CANCEL_WITH_ANY_RECORDER
));
439 lcd_puts_scroll(0,0, str(LANG_BOOKMARK_AUTOLOAD_QUERY
));
440 lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER
));
446 /* Wait for a key to be pushed */
447 key
= button_get(true);
450 #ifdef HAVE_LCD_BITMAP
452 return bookmark_load(global_bookmark_file_name
, false);
455 return bookmark_load(global_bookmark_file_name
, true);
458 /* Handle sys events, ignore button releases & repeats */
459 if (default_event_handler(key
) ||
460 !(key
& (BUTTON_REPEAT
|BUTTON_REL
)))
469 /* ----------------------------------------------------------------------- */
470 /* This function loads the bookmark information into the resume memory. */
471 /* This is an interface function. */
472 /* ------------------------------------------------------------------------*/
473 bool bookmark_load(const char* file
, bool autoload
)
480 char* bookmark
= NULL
;;
484 fd
= open(file
, O_RDONLY
);
487 if(read_line(fd
, global_read_buffer
, sizeof(global_read_buffer
)))
488 bookmark
=global_read_buffer
;
494 /* This is not an auto-load, so list the bookmarks */
495 bookmark
=select_bookmark(file
);
497 return true; /* User exited without selecting a bookmark */
502 success
= parse_bookmark(bookmark
,
508 sizeof(global_temp_buffer
),
510 &global_settings
.repeat_mode
,
511 &global_settings
.playlist_shuffle
,
517 bookmark_play(global_temp_buffer
, index
, offset
, seed
,
524 static int get_bookmark_count(const char* bookmark_file_name
)
527 int file
= open(bookmark_file_name
, O_RDONLY
);
532 /* Get the requested bookmark */
533 while(read_line(file
, global_read_buffer
, sizeof(global_read_buffer
)))
535 if(check_bookmark(global_read_buffer
))
545 /* ----------------------------------------------------------------------- */
546 /* This displays a the bookmarks in a file and allows the user to */
547 /* select one to play. */
548 /* ------------------------------------------------------------------------*/
549 static char* select_bookmark(const char* bookmark_file_name
)
552 int bookmark_id_prev
= -1;
554 int lastkey
= BUTTON_NONE
;
555 char* bookmark
= NULL
;
556 int bookmark_count
= 0;
558 #ifdef HAVE_LCD_BITMAP
559 int x
= lcd_getxmargin();
560 int y
= lcd_getymargin();
561 lcd_setmargins(0, 0);
564 bookmark_count
= get_bookmark_count(bookmark_file_name
);
569 bookmark_id
= bookmark_count
-1;
570 if(bookmark_id
>= bookmark_count
)
573 if (bookmark_id
!= bookmark_id_prev
)
575 bookmark
= get_bookmark(bookmark_file_name
, bookmark_id
);
576 bookmark_id_prev
= bookmark_id
;
581 /* if there were no bookmarks in the file, delete the file and exit. */
584 gui_syncsplash(HZ
, true, str(LANG_BOOKMARK_LOAD_EMPTY
));
585 remove(bookmark_file_name
);
590 bookmark_id_prev
= bookmark_id
;
596 display_bookmark(bookmark
, bookmark_id
, bookmark_count
);
597 if (global_settings
.talk_menu
) /* for voice UI */
598 say_bookmark(bookmark
, bookmark_id
);
601 /* waiting for the user to click a button */
602 key
= button_get(true);
605 case BOOKMARK_SELECT
:
606 #ifdef BOOKMARK_SELECT_PRE
607 if (lastkey
!= BOOKMARK_SELECT_PRE
)
610 /* User wants to use this bookmark */
611 #ifdef HAVE_LCD_BITMAP
612 if (global_settings
.statusbar
)
613 lcd_setmargins(0, STATUSBAR_HEIGHT
);
615 lcd_setmargins(0, 0);
619 case BOOKMARK_DELETE
:
620 /* User wants to delete this bookmark */
621 delete_bookmark(bookmark_file_name
, bookmark_id
);
624 if(bookmark_id
>= bookmark_count
)
625 bookmark_id
= bookmark_count
-1;
629 case SETTINGS_DEC
| BUTTON_REPEAT
:
634 case SETTINGS_INC
| BUTTON_REPEAT
:
638 case SETTINGS_CANCEL
:
639 #ifdef SETTINGS_CANCEL2
640 case SETTINGS_CANCEL2
:
645 #ifdef HAVE_LCD_BITMAP
646 lcd_setmargins(x
, y
);
651 if(default_event_handler(key
) == SYS_USB_CONNECTED
)
662 /* ----------------------------------------------------------------------- */
663 /* This function takes a location in a bookmark file and deletes that */
665 /* ------------------------------------------------------------------------*/
666 static bool delete_bookmark(const char* bookmark_file_name
, int bookmark_id
)
668 int temp_bookmark_file
= 0;
669 int bookmark_file
= 0;
670 int bookmark_count
= 0;
672 /* Opening up a temp bookmark file */
673 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
674 "%s.tmp", bookmark_file_name
);
675 temp_bookmark_file
= open(global_temp_buffer
,
676 O_WRONLY
| O_CREAT
| O_TRUNC
);
677 bookmark_file
= open(bookmark_file_name
, O_RDONLY
);
679 if (temp_bookmark_file
< 0 || bookmark_file
< 0)
680 return false; /* can't open one of the files */
682 /* Reading in the previous bookmarks and writing them to the temp file */
683 while (read_line(bookmark_file
, global_read_buffer
,
684 sizeof(global_read_buffer
)))
686 /* The MRB has a max of MAX_BOOKMARKS in it */
687 /* This keeps it from getting too large */
688 if ((strcmp(bookmark_file_name
,RECENT_BOOKMARK_FILE
)==0))
690 if(bookmark_count
>= MAX_BOOKMARKS
)
694 if (check_bookmark(global_read_buffer
))
696 if (bookmark_id
!= bookmark_count
)
698 write(temp_bookmark_file
, global_read_buffer
,
699 strlen(global_read_buffer
));
700 write(temp_bookmark_file
, "\n", 1);
706 close(bookmark_file
);
707 close(temp_bookmark_file
);
709 remove(bookmark_file_name
);
710 rename(global_temp_buffer
, bookmark_file_name
);
715 /* ----------------------------------------------------------------------- */
716 /* This function parses a bookmark and displays it for the user. */
717 /* ------------------------------------------------------------------------*/
718 static void display_bookmark(const char* bookmark
,
722 int resume_index
= 0;
725 bool playlist_shuffle
= false;
729 /* getting the index and the time into the file */
730 parse_bookmark(bookmark
,
731 &resume_index
, NULL
, NULL
, NULL
, NULL
, 0,
732 &ms
, &repeat_mode
, &playlist_shuffle
,
738 #ifdef HAVE_LCD_BITMAP
739 /* bookmark shuffle and repeat states*/
742 #if (AB_REPEAT_ENABLE == 1)
744 statusbar_icon_play_mode(Icon_RepeatAB
);
749 statusbar_icon_play_mode(Icon_RepeatOne
);
753 statusbar_icon_play_mode(Icon_Repeat
);
757 statusbar_icon_shuffle();
760 len
=strlen(global_filename
);
762 dot
=strrchr(global_filename
+ len
- 4, '.');
767 lcd_puts_scroll(0, 0, (unsigned char *)global_filename
);
771 /* bookmark number */
772 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %2d/%2d",
773 str(LANG_BOOKMARK_SELECT_BOOKMARK_TEXT
),
774 bookmark_id
+ 1, bookmark_count
);
775 lcd_puts_scroll(0, 1, (unsigned char *)global_temp_buffer
);
777 /* bookmark resume index */
778 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %2d",
779 str(LANG_BOOKMARK_SELECT_INDEX_TEXT
), resume_index
+1);
780 lcd_puts_scroll(0, 2, (unsigned char *)global_temp_buffer
);
785 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
), "%s: %ld:%02d",
786 str(LANG_BOOKMARK_SELECT_TIME_TEXT
),
788 (unsigned int)(ms
% 60000) / 1000);
789 /* unsigned int: hinting for 16bits archs */
793 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
794 "%s: %ld:%02ld:%02d",
795 str(LANG_BOOKMARK_SELECT_TIME_TEXT
),
797 ms
% 3600000 / 60000,
798 (unsigned int)(ms
% 60000) / 1000);
800 lcd_puts_scroll(0, 3, (unsigned char *)global_temp_buffer
);
803 lcd_puts_scroll(0, 4, str(LANG_BOOKMARK_SELECT_PLAY
));
804 lcd_puts_scroll(0, 5, str(LANG_BOOKMARK_SELECT_EXIT
));
805 lcd_puts_scroll(0, 6, str(LANG_BOOKMARK_SELECT_DELETE
));
808 len
=strlen(global_filename
);
810 dot
=strrchr(global_filename
+len
-4,'.');
817 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
818 "%2d, %ld:%02ld, %s,",
826 snprintf(global_temp_buffer
, sizeof(global_temp_buffer
),
827 "%2d, %ld:%02ld:%02ld, %s,",
830 ms
% 3600000 / 60000,
835 gui_syncstatusbar_draw(&statusbars
, false);
836 lcd_puts_scroll(0,0,global_temp_buffer
);
837 lcd_puts(0,1,str(LANG_RESUME_CONFIRM_PLAYER
));
845 /* ----------------------------------------------------------------------- */
846 /* This function parses a bookmark, says the voice UI part of it. */
847 /* ------------------------------------------------------------------------*/
848 static void say_bookmark(const char* bookmark
,
854 bool enqueue
= false; /* only the first voice is not queued */
856 parse_bookmark(bookmark
,
862 /* disabled, because transition between talkbox and voice UI clip is not nice */
864 if (global_settings
.talk_dir
>= 3)
865 { /* "talkbox" enabled */
866 char* last
= strrchr(dir
, '/');
868 { /* compose filename for talkbox */
869 strncpy(last
+ 1, dir_thumbnail_name
, sizeof(dir
)-(last
-dir
)-1);
870 talk_file(dir
, enqueue
);
875 talk_id(VOICE_EXT_BMARK
, enqueue
);
876 talk_number(bookmark_id
+ 1, true);
877 talk_id(LANG_BOOKMARK_SELECT_INDEX_TEXT
, true);
878 talk_number(resume_index
+ 1, true);
879 talk_id(LANG_BOOKMARK_SELECT_TIME_TEXT
, true);
881 talk_value(ms
/ 60000, UNIT_MIN
, true);
882 talk_value((ms
% 60000) / 1000, UNIT_SEC
, true);
886 /* ----------------------------------------------------------------------- */
887 /* This function retrieves a given bookmark from a file. */
888 /* If the bookmark requested is beyond the number of bookmarks available */
889 /* in the file, it will return the last one. */
890 /* It also returns the index number of the bookmark in the file */
891 /* ------------------------------------------------------------------------*/
892 static char* get_bookmark(const char* bookmark_file
, int bookmark_count
)
896 int file
= open(bookmark_file
, O_RDONLY
);
901 if (bookmark_count
< 0)
904 /* Get the requested bookmark */
905 while (read_count
< bookmark_count
)
907 /*Reading in a single bookmark */
908 result
= read_line(file
,
910 sizeof(global_read_buffer
));
912 /* Reading past the last bookmark in the file
913 causes the loop to stop */
921 if (read_count
== bookmark_count
)
922 return global_read_buffer
;
927 /* ----------------------------------------------------------------------- */
928 /* This function takes a bookmark and parses it. This function also */
929 /* validates the bookmark. Passing in NULL for an output variable */
930 /* indicates that value is not requested. */
931 /* ----------------------------------------------------------------------- */
932 static bool parse_bookmark(const char *bookmark
,
936 int *resume_first_index
,
938 unsigned int resume_file_size
,
940 int * repeat_mode
, bool *shuffle
,
943 /* First check to see if a valid line was passed in. */
944 int bookmark_len
= strlen(bookmark
);
945 int local_resume_index
= 0;
946 int local_resume_offset
= 0;
947 int local_resume_seed
= 0;
948 int local_resume_first_index
= 0;
950 int local_shuffle
= 0;
951 int local_repeat_mode
= 0;
952 char* local_resume_file
= NULL
;
953 char* local_file_name
= NULL
;
956 static char bookmarkcopy
[MAX_BOOKMARK_SIZE
];
958 /* Don't do anything if the bookmark length is 0 */
959 if (bookmark_len
<= 0)
962 /* Making a dup of the bookmark to use with strtok_r */
963 strncpy(bookmarkcopy
, bookmark
, sizeof(bookmarkcopy
));
964 bookmarkcopy
[sizeof(bookmarkcopy
) - 1] = 0;
967 if ((field
= strtok_r(bookmarkcopy
, ";", &end
)))
968 local_resume_index
= atoi(field
);
973 if ((field
= strtok_r(NULL
, ";", &end
)))
974 local_resume_offset
= atoi(field
);
979 if ((field
= strtok_r(NULL
, ";", &end
)))
980 local_resume_seed
= atoi(field
);
984 /* resume_first_index */
985 if ((field
= strtok_r(NULL
, ";", &end
)))
986 local_resume_first_index
= atoi(field
);
990 /* Milliseconds into MP3. Used for the bookmark select menu */
991 if ((field
= strtok_r(NULL
, ";", &end
)))
992 local_mS
= atoi(field
);
997 if ((field
= strtok_r(NULL
, ";", &end
)))
998 local_repeat_mode
= atoi(field
);
1003 if ((field
= strtok_r(NULL
, ";", &end
)))
1004 local_shuffle
= atoi(field
);
1008 /* resume_file & file_name (for the bookmark select menu)*/
1011 local_resume_file
= strtok_r(NULL
, ";", &end
);
1014 local_file_name
= strtok_r(NULL
, ";", &end
);
1019 /* Only return the values the calling function wants */
1021 *resume_index
= local_resume_index
;
1024 *resume_offset
= local_resume_offset
;
1027 *resume_seed
= local_resume_seed
;
1029 if (resume_first_index
)
1030 *resume_first_index
= local_resume_first_index
;
1032 if (resume_file
&& local_resume_file
)
1034 strncpy(resume_file
, local_resume_file
,
1035 MIN(strlen(local_resume_file
), resume_file_size
-1));
1036 resume_file
[MIN(strlen(local_resume_file
), resume_file_size
-1)]=0;
1043 *shuffle
= local_shuffle
;
1046 *repeat_mode
= local_repeat_mode
;
1048 if (file_name
&& local_file_name
)
1050 strncpy(file_name
, local_file_name
,MAX_PATH
-1);
1051 file_name
[MAX_PATH
-1] = 0;
1057 /* ----------------------------------------------------------------------- */
1058 /* This function is used by multiple functions and is used to generate a */
1059 /* bookmark named based off of the input. */
1060 /* Changing this function could result in how the bookmarks are stored. */
1061 /* it would be here that the centralized/decentralized bookmark code */
1062 /* could be placed. */
1063 /* ----------------------------------------------------------------------- */
1064 static bool generate_bookmark_file_name(const char *in
)
1066 int len
= strlen(in
);
1068 /* if this is a root dir MP3, rename the bookmark file root_dir.bmark */
1069 /* otherwise, name it based on the in variable */
1070 if (!strcmp("/", in
))
1071 strcpy(global_bookmark_file_name
, "/root_dir.bmark");
1074 strcpy(global_bookmark_file_name
, in
);
1075 if(global_bookmark_file_name
[len
-1] == '/')
1077 strcpy(&global_bookmark_file_name
[len
], ".bmark");
1083 /* ----------------------------------------------------------------------- */
1084 /* Returns the bookmark name for the current playlist */
1085 /* ----------------------------------------------------------------------- */
1086 bool bookmark_exist(void)
1092 char* name
= playlist_get_name(NULL
, global_temp_buffer
,
1093 sizeof(global_temp_buffer
));
1094 if (generate_bookmark_file_name(name
))
1096 int fd
=open(global_bookmark_file_name
, O_RDONLY
);
1108 /* ----------------------------------------------------------------------- */
1109 /* Checks the current state of the system and returns if it is in a */
1110 /* bookmarkable state. */
1111 /* ----------------------------------------------------------------------- */
1113 /* ----------------------------------------------------------------------- */
1115 /* return bool: Indicates if the system was in a bookmarkable state */
1116 /* ----------------------------------------------------------------------- */
1117 static bool system_check(void)
1119 int resume_index
= 0;
1120 struct mp3entry
*id3
= audio_current_track();
1124 /* no track playing */
1128 /* Checking to see if playing a queued track */
1129 if (playlist_get_resume_info(&resume_index
) == -1)
1131 /* something bad happened while getting the queue information */
1134 else if (playlist_modified(NULL
))
1136 /* can't bookmark while in the queue */