summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeffrey Goode <jeffg7@gmail.com>2010-04-10 21:17:09 +0000
committerJeffrey Goode <jeffg7@gmail.com>2010-04-10 21:17:09 +0000
commit55064f7b7d09375c53582f1743bb52164aec8fd2 (patch)
tree65eeb886b79ec4704a597420b810043baa2ad4b4
parent470277093399fd34531a9c19bb0451a32d1320b7 (diff)
downloadrockbox-55064f7b7d09375c53582f1743bb52164aec8fd2.tar.gz
rockbox-55064f7b7d09375c53582f1743bb52164aec8fd2.zip
New bookmarks contain pitch and speed info. Old bookmarks still work, behavior unchanged.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25576 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/bookmark.c72
1 files changed, 50 insertions, 22 deletions
diff --git a/apps/bookmark.c b/apps/bookmark.c
index 1b82966be8..eed4219ae7 100644
--- a/apps/bookmark.c
+++ b/apps/bookmark.c
@@ -42,6 +42,7 @@
42#include "plugin.h" 42#include "plugin.h"
43#include "file.h" 43#include "file.h"
44#include "filefuncs.h" 44#include "filefuncs.h"
45#include "dsp.h"
45 46
46#define MAX_BOOKMARKS 10 47#define MAX_BOOKMARKS 10
47#define MAX_BOOKMARK_SIZE 350 48#define MAX_BOOKMARK_SIZE 350
@@ -61,8 +62,9 @@ struct bookmark_list
61 char* items[]; 62 char* items[];
62}; 63};
63 64
64/* bookmark flags */ 65/* flags for optional bookmark tokens */
65#define F_BMFILES 0x01 66#define BM_PITCH 0x01
67#define BM_SPEED 0x02
66 68
67/* bookmark values */ 69/* bookmark values */
68static struct { 70static struct {
@@ -72,6 +74,9 @@ static struct {
72 long resume_time; 74 long resume_time;
73 int repeat_mode; 75 int repeat_mode;
74 bool shuffle; 76 bool shuffle;
77 /* optional values */
78 int pitch;
79 int speed;
75} bm; 80} bm;
76 81
77static bool add_bookmark(const char* bookmark_file_name, const char* bookmark, 82static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
@@ -82,7 +87,7 @@ static void say_bookmark(const char* bookmark,
82 int bookmark_id, bool show_playlist_name); 87 int bookmark_id, bool show_playlist_name);
83static bool play_bookmark(const char* bookmark); 88static bool play_bookmark(const char* bookmark);
84static bool generate_bookmark_file_name(const char *in); 89static bool generate_bookmark_file_name(const char *in);
85static bool parse_bookmark(const char *bookmark, const int flags); 90static bool parse_bookmark(const char *bookmark, const bool get_filenames);
86static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line); 91static int buffer_bookmarks(struct bookmark_list* bookmarks, int first_line);
87static const char* get_bookmark_info(int list_index, 92static const char* get_bookmark_info(int list_index,
88 void* data, 93 void* data,
@@ -285,7 +290,7 @@ static bool add_bookmark(const char* bookmark_file_name, const char* bookmark,
285 290
286 cp = strchr(global_read_buffer,'/'); 291 cp = strchr(global_read_buffer,'/');
287 tmp = strrchr(global_read_buffer,';'); 292 tmp = strrchr(global_read_buffer,';');
288 if (parse_bookmark(global_read_buffer, 0) && 293 if (parse_bookmark(global_read_buffer, false) &&
289 (!unique || len != tmp -cp || strncmp(playlist,cp,len))) 294 (!unique || len != tmp -cp || strncmp(playlist,cp,len)))
290 { 295 {
291 bookmark_count++; 296 bookmark_count++;
@@ -334,20 +339,27 @@ static char* create_bookmark()
334 339
335 /* create the bookmark */ 340 /* create the bookmark */
336 snprintf(global_bookmark, sizeof(global_bookmark), 341 snprintf(global_bookmark, sizeof(global_bookmark),
337 "%d;%ld;%d;%d;%ld;%d;%d;%s;%s", 342 /* new optional bookmark token descriptors should be inserted
343 just before the "%s;%s" in this line... */
344 ">%d;%d;%ld;%d;%ld;%d;%d;%d;%d;%s;%s",
345 /* ... their flags should go here ... */
346 BM_PITCH | BM_SPEED,
338 resume_index, 347 resume_index,
339 id3->offset, 348 id3->offset,
340 playlist_get_seed(NULL), 349 playlist_get_seed(NULL),
341 0,
342 id3->elapsed, 350 id3->elapsed,
343 global_settings.repeat_mode, 351 global_settings.repeat_mode,
344 global_settings.playlist_shuffle, 352 global_settings.playlist_shuffle,
353 /* ...and their values should go here */
354 sound_get_pitch(),
355 dsp_get_timestretch(),
356 /* more mandatory tokens */
345 playlist_get_name(NULL, global_temp_buffer, 357 playlist_get_name(NULL, global_temp_buffer,
346 sizeof(global_temp_buffer)), 358 sizeof(global_temp_buffer)),
347 file+1); 359 file+1);
348 360
349 /* checking to see if the bookmark is valid */ 361 /* checking to see if the bookmark is valid */
350 if (parse_bookmark(global_bookmark, 0)) 362 if (parse_bookmark(global_bookmark, false))
351 return global_bookmark; 363 return global_bookmark;
352 else 364 else
353 return NULL; 365 return NULL;
@@ -563,9 +575,7 @@ static const char* get_bookmark_info(int list_index,
563 } 575 }
564 } 576 }
565 577
566 const int flags = F_BMFILES; 578 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], true))
567
568 if (!parse_bookmark(bookmarks->items[index - bookmarks->start], flags))
569 { 579 {
570 return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " "; 580 return list_index % 2 == 0 ? (char*) str(LANG_BOOKMARK_INVALID) : " ";
571 } 581 }
@@ -832,9 +842,7 @@ static void say_bookmark(const char* bookmark,
832{ 842{
833 bool is_dir; 843 bool is_dir;
834 844
835 const int flags = F_BMFILES; 845 if (!parse_bookmark(bookmark, true))
836
837 if (!parse_bookmark(bookmark, flags))
838 { 846 {
839 talk_id(LANG_BOOKMARK_INVALID, false); 847 talk_id(LANG_BOOKMARK_INVALID, false);
840 return; 848 return;
@@ -888,12 +896,16 @@ static void say_bookmark(const char* bookmark,
888/* ------------------------------------------------------------------------*/ 896/* ------------------------------------------------------------------------*/
889static bool play_bookmark(const char* bookmark) 897static bool play_bookmark(const char* bookmark)
890{ 898{
891 const int flags = F_BMFILES; 899 /* preset pitch and speed to 100% in case bookmark doesn't have info */
900 bm.pitch = sound_get_pitch();
901 bm.speed = dsp_get_timestretch();
892 902
893 if (parse_bookmark(bookmark, flags)) 903 if (parse_bookmark(bookmark, true))
894 { 904 {
895 global_settings.repeat_mode = bm.repeat_mode; 905 global_settings.repeat_mode = bm.repeat_mode;
896 global_settings.playlist_shuffle = bm.shuffle; 906 global_settings.playlist_shuffle = bm.shuffle;
907 sound_set_pitch(bm.pitch);
908 dsp_set_timestretch(bm.speed);
897 return bookmark_play(global_temp_buffer, bm.resume_index, 909 return bookmark_play(global_temp_buffer, bm.resume_index,
898 bm.resume_offset, bm.resume_seed, global_filename); 910 bm.resume_offset, bm.resume_seed, global_filename);
899 } 911 }
@@ -924,27 +936,43 @@ static const char* long_token(const char* s, long* dest)
924 936
925/* ----------------------------------------------------------------------- */ 937/* ----------------------------------------------------------------------- */
926/* This function takes a bookmark and parses it. This function also */ 938/* This function takes a bookmark and parses it. This function also */
927/* validates the bookmark. Flags are set to indicate which bookmark */ 939/* validates the bookmark. The parse_filenames flag indicates whether */
928/* tokens are to be processed. */ 940/* the filename tokens are to be extracted. */
929/* ----------------------------------------------------------------------- */ 941/* ----------------------------------------------------------------------- */
930static bool parse_bookmark(const char *bookmark, const int flags) 942static bool parse_bookmark(const char *bookmark, const bool parse_filenames)
931{ 943{
932 const char* s = bookmark; 944 const char* s = bookmark;
933 const char* end; 945 const char* end;
934 946
935#define FLAG(a) (flags & a)
936#define GET_INT_TOKEN(var) s = long_token(s, (long *)&var) 947#define GET_INT_TOKEN(var) s = long_token(s, (long *)&var)
937#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s) 948#define GET_BOOL_TOKEN(var) var = (atoi(s)!=0); s = skip_token(s)
938 949
950 /* if new format bookmark, extract the optional content flags,
951 otherwise treat as an original format bookmark */
952 int opt_flags = 0;
953 bool new_format = (strchr(s, '>') == s);
954 if (new_format)
955 {
956 s++;
957 GET_INT_TOKEN(opt_flags);
958 }
959
960 /* extract all original bookmark tokens */
939 GET_INT_TOKEN(bm.resume_index); 961 GET_INT_TOKEN(bm.resume_index);
940 GET_INT_TOKEN(bm.resume_offset); 962 GET_INT_TOKEN(bm.resume_offset);
941 GET_INT_TOKEN(bm.resume_seed); 963 GET_INT_TOKEN(bm.resume_seed);
942 /* skip deprecated token */ 964 if (!new_format) /* skip deprecated token */
943 s = skip_token(s); 965 s = skip_token(s);
944 GET_INT_TOKEN(bm.resume_time); 966 GET_INT_TOKEN(bm.resume_time);
945 GET_INT_TOKEN(bm.repeat_mode); 967 GET_INT_TOKEN(bm.repeat_mode);
946 GET_BOOL_TOKEN(bm.shuffle); 968 GET_BOOL_TOKEN(bm.shuffle);
947 969
970 /* extract all optional bookmark tokens */
971 if (opt_flags & BM_PITCH)
972 GET_INT_TOKEN(bm.pitch);
973 if (opt_flags & BM_SPEED)
974 GET_INT_TOKEN(bm.speed);
975
948 if (*s == 0) 976 if (*s == 0)
949 { 977 {
950 return false; 978 return false;
@@ -953,7 +981,7 @@ static bool parse_bookmark(const char *bookmark, const int flags)
953 end = strchr(s, ';'); 981 end = strchr(s, ';');
954 982
955 /* extract file names */ 983 /* extract file names */
956 if (FLAG(F_BMFILES)) 984 if (parse_filenames)
957 { 985 {
958 size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s); 986 size_t len = (end == NULL) ? strlen(s) : (size_t) (end - s);
959 len = MIN(TEMP_BUF_SIZE - 1, len); 987 len = MIN(TEMP_BUF_SIZE - 1, len);