diff options
| author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-05-28 23:18:31 +0000 |
|---|---|---|
| committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2007-05-28 23:18:31 +0000 |
| commit | 6579818b4346a9b455734fb5a067e8d3ab2f09b4 (patch) | |
| tree | dc234157ee00e026a7110502c5c8379c88721166 | |
| parent | 1bae792e5c2ef6f624c7038ce83cd48aeabf636f (diff) | |
| download | rockbox-6579818b4346a9b455734fb5a067e8d3ab2f09b4.zip rockbox-6579818b4346a9b455734fb5a067e8d3ab2f09b4.tar.gz rockbox-6579818b4346a9b455734fb5a067e8d3ab2f09b4.tar.bz2 rockbox-6579818b4346a9b455734fb5a067e8d3ab2f09b4.tar.xz | |
Add the possibility to store cuesheets in /.rockbox/cue. The code will look for a cuesheet there in case there wasn't one in the same folder as the audio file. This is to reduce the clutter created by one cuesheet per audio file in some places.
Also some duplicate code was replaced by a function call.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13508 a1c6a512-1295-4272-9138-f99709370657
| -rw-r--r-- | apps/cuesheet.c | 37 | ||||
| -rw-r--r-- | apps/cuesheet.h | 2 | ||||
| -rw-r--r-- | apps/gui/gwps-common.c | 6 | ||||
| -rw-r--r-- | apps/metadata.c | 2 | ||||
| -rw-r--r-- | apps/playback.c | 6 |
5 files changed, 29 insertions, 24 deletions
diff --git a/apps/cuesheet.c b/apps/cuesheet.c index 9bac368..ce7714f 100644 --- a/apps/cuesheet.c +++ b/apps/cuesheet.c @@ -41,11 +41,13 @@ #include "playback.h" #include "cuesheet.h" +#define CUE_DIR ROCKBOX_DIR "/cue" + #if CONFIG_CODEC != SWCODEC /* special trickery because the hwcodec playback engine is in firmware/ */ static bool cuesheet_handler(const char *filename) { - return cuesheet_is_enabled() && look_for_cuesheet_file(filename); + return cuesheet_is_enabled() && look_for_cuesheet_file(filename, NULL); } #endif @@ -68,8 +70,9 @@ bool cuesheet_is_enabled(void) return (curr_cue != NULL); } -bool look_for_cuesheet_file(const char *trackpath) +bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path) { + DEBUGF("look for cue file\n"); char cuepath[MAX_PATH]; strncpy(cuepath, trackpath, MAX_PATH); char *dot = strrchr(cuepath, '.'); @@ -78,13 +81,22 @@ bool look_for_cuesheet_file(const char *trackpath) int fd = open(cuepath,O_RDONLY); if (fd < 0) { - return false; - } - else - { - close(fd); - return true; + strcpy(cuepath, CUE_DIR); + strcat(cuepath, strrchr(trackpath, '/')); + char *dot = strrchr(cuepath, '.'); + strcpy(dot, ".cue"); + fd = open(cuepath,O_RDONLY); + if (fd < 0) + { + if (found_cue_path) + found_cue_path = NULL; + return false; + } } + close(fd); + if (found_cue_path) + strncpy(found_cue_path, cuepath, MAX_PATH); + return true; } static char *skip_whitespace(char* buf) @@ -122,6 +134,7 @@ bool parse_cuesheet(char *file, struct cuesheet *cue) char line[MAX_PATH]; char *s; + DEBUGF("cue parse\n"); int fd = open(file,O_RDONLY); if (fd < 0) { @@ -271,9 +284,7 @@ void browse_cuesheet(struct cuesheet *cue) if (id3 && *id3->path && strcmp(id3->path, "No file!")) { - strncpy(cuepath, id3->path, MAX_PATH); - dot = strrchr(cuepath, '.'); - strcpy(dot, ".cue"); + look_for_cuesheet_file(id3->path, cuepath); } if (id3 && id3->cuesheet_type && !strcmp(cue->path, cuepath)) @@ -294,9 +305,7 @@ void browse_cuesheet(struct cuesheet *cue) id3 = audio_current_track(); if (id3 && *id3->path && strcmp(id3->path, "No file!")) { - strncpy(cuepath, id3->path, MAX_PATH); - dot = strrchr(cuepath, '.'); - strcpy(dot, ".cue"); + look_for_cuesheet_file(id3->path, cuepath); if (id3->cuesheet_type && !strcmp(cue->path, cuepath)) { sel = gui_synclist_get_sel_pos(&lists); diff --git a/apps/cuesheet.h b/apps/cuesheet.h index 51e3860..3fe9c1f 100644 --- a/apps/cuesheet.h +++ b/apps/cuesheet.h @@ -58,7 +58,7 @@ bool cuesheet_is_enabled(void); void cuesheet_init(void); /* looks if there is a cuesheet file that has a name matching "trackpath" */ -bool look_for_cuesheet_file(const char *trackpath); +bool look_for_cuesheet_file(const char *trackpath, char *found_cue_path); /* parse cuesheet "file" and store the information in "cue" */ bool parse_cuesheet(char *file, struct cuesheet *cue); diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 5524c14..b25168f 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -389,11 +389,9 @@ bool update(struct gui_wps *gwps) /* We need to parse the new cuesheet */ char cuepath[MAX_PATH]; - strncpy(cuepath, gwps->state->id3->path, MAX_PATH); - char *dot = strrchr(cuepath, '.'); - strcpy(dot, ".cue"); - if (parse_cuesheet(cuepath, curr_cue)) + if (look_for_cuesheet_file(gwps->state->id3->path, cuepath) && + parse_cuesheet(cuepath, curr_cue)) { gwps->state->id3->cuesheet_type = 1; strcpy(curr_cue->audio_filename, gwps->state->id3->path); diff --git a/apps/metadata.c b/apps/metadata.c index 54bb404..430bd3c 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -2369,7 +2369,7 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, /* We have successfully read the metadata from the file */ #ifndef __PCTOOL__ - if (cuesheet_is_enabled() && look_for_cuesheet_file(trackname)) + if (cuesheet_is_enabled() && look_for_cuesheet_file(trackname, NULL)) { track->id3.cuesheet_type = 1; } diff --git a/apps/playback.c b/apps/playback.c index abc2e9e..25dec7a 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -2762,13 +2762,11 @@ static bool audio_load_track(int offset, bool start_play, bool rebuffer) if (cuesheet_is_enabled() && tracks[track_widx].id3.cuesheet_type == 1) { char cuepath[MAX_PATH]; - strncpy(cuepath, trackname, MAX_PATH); - char *dot = strrchr(cuepath, '.'); - strcpy(dot, ".cue"); struct cuesheet *cue = start_play ? curr_cue : temp_cue; - if (parse_cuesheet(cuepath, cue)) + if (look_for_cuesheet_file(trackname, cuepath) && + parse_cuesheet(cuepath, cue)) { strcpy((cue)->audio_filename, trackname); if (start_play) |