From 24b136f62de82d7419751b6aaeae0ad3d8497bea Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 20 Jul 2009 05:18:18 +0000 Subject: rework cuesheet support: swcodec: search for a .cue during buffering (with the possibility of adding embedded cuesheets later) hwcodec: search for a .cue when the id3 info for the current track is requested for the first time (disk should be spining so non issue) major beenfit from this is simplofy cuesheet handling code a bit... if mp3entry.cuesheet != NULL then there is a valid cuesheet.. no need to worry about if its enabled and preloaded. There is the possibility of putting the next/prev subtrack handling inside the playback code (as well as the id3 updating stuff (see FS#9789 for more info), but thats probably not a good idea. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21978 a1c6a512-1295-4272-9138-f99709370657 --- apps/playback.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'apps/playback.c') diff --git a/apps/playback.c b/apps/playback.c index cee89d3bbb..7bd3f252ae 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -210,6 +210,9 @@ static struct mp3entry *thistrack_id3, /* the currently playing track */ * next track otherwise */ static struct mp3entry unbuffered_id3; /* the id3 for the first unbuffered track */ +/* for cuesheet support */ +static struct cuesheet *curr_cue = NULL; + /* Track info structure about songs in the file buffer (A/C-) */ struct track_info { int audio_hid; /* The ID for the track's buffer handle */ @@ -218,6 +221,7 @@ struct track_info { #ifdef HAVE_ALBUMART int aa_hid; /* The ID for the track's album art handle */ #endif + int cuesheet_hid; /* The ID for the track's parsed cueesheet handle */ size_t filesize; /* File total length */ @@ -384,6 +388,13 @@ static bool clear_track_info(struct track_info *track) } #endif + if (track->cuesheet_hid >= 0) { + if (bufclose(track->cuesheet_hid)) + track->cuesheet_hid = -1; + else + return false; + } + track->filesize = 0; track->taginfo_ready = false; @@ -566,6 +577,12 @@ struct mp3entry* audio_current_track(void) if (cur_idx == track_ridx && *thistrack_id3->path) { /* The usual case */ + if (tracks[cur_idx].cuesheet_hid >= 0) + { + bufread(tracks[cur_idx].cuesheet_hid, sizeof(struct cuesheet), curr_cue); + thistrack_id3->cuesheet = curr_cue; + cue_spoof_id3(thistrack_id3->cuesheet, thistrack_id3); + } return thistrack_id3; } else if (automatic_skip && offset == -1 && *othertrack_id3->path) @@ -574,6 +591,12 @@ struct mp3entry* audio_current_track(void) but the audio being played is still the same (now previous) track. othertrack_id3.elapsed is being updated in an ISR by codec_pcmbuf_position_callback */ + if (tracks[cur_idx].cuesheet_hid >= 0) + { + bufread(tracks[cur_idx].cuesheet_hid, sizeof(struct cuesheet), curr_cue); + othertrack_id3->cuesheet = curr_cue; + cue_spoof_id3(othertrack_id3->cuesheet, othertrack_id3); + } return othertrack_id3; } @@ -1826,7 +1849,21 @@ static void audio_finish_load_track(void) return; } + /* Try to load a cuesheet for the track */ + if (curr_cue) + { + char cuepath[MAX_PATH]; + struct cuesheet temp_cue; + + if (look_for_cuesheet_file(track_id3->path, cuepath) && + parse_cuesheet(cuepath, &temp_cue)) + { + strcpy(temp_cue.audio_filename, track_id3->path); + tracks[track_widx].cuesheet_hid = + bufalloc(&temp_cue, sizeof(struct cuesheet), TYPE_CUESHEET); + } + } #ifdef HAVE_ALBUMART if (tracks[track_widx].aa_hid < 0 && gui_sync_wps_uses_albumart()) { @@ -2602,6 +2639,10 @@ void audio_init(void) thistrack_id3 = &mp3entry_buf[0]; othertrack_id3 = &mp3entry_buf[1]; + /* cuesheet support */ + if (global_settings.cuesheet) + curr_cue = (struct cuesheet*)buffer_alloc(sizeof(struct cuesheet)); + /* initialize the buffer */ filebuf = audiobuf; @@ -2648,6 +2689,7 @@ void audio_init(void) #ifdef HAVE_ALBUMART tracks[i].aa_hid = -1; #endif + tracks[i].cuesheet_hid = -1; } add_event(BUFFER_EVENT_REBUFFER, false, buffering_handle_rebuffer_callback); -- cgit v1.2.3