From 995493a43d6f840486df9c144549a0af496e5226 Mon Sep 17 00:00:00 2001 From: Nicolas Pennequin Date: Sat, 4 Aug 2007 17:09:06 +0200 Subject: [PATCH] Introducing metadata in the test ! Before opening the audio files, the bufopen thread will open corresponding metadata files from /meta/X.txt, where X is the name of the audio file. The first two lines of the file will be displayed on the screen while the audio file is read. --- testplugin.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/testplugin.c b/testplugin.c index 132a133..f688aa2 100644 --- a/testplugin.c +++ b/testplugin.c @@ -725,12 +725,36 @@ static void graph_view(int width) void print_progress(size_t amount, int file, int numfiles) { char buf[32]; - rb->lcd_clear_display(); rb->snprintf(buf, sizeof(buf), "file %d of %d", file, numfiles); rb->lcd_puts(0, 0, buf); rb->snprintf(buf, sizeof(buf), "read: %ld", amount); rb->lcd_puts(0, 1, buf); - rb->lcd_update(); +} + +void print_metadata(int handle_id) +{ + ssize_t ret; + char *artist, *title, *newline; + char art[50], ttl[50]; + int artist_len, title_len; + unsigned char *buf; + + ret = bufgetdata(handle_id, 0, &buf); + + artist = buf; + newline = rb->strchr(artist, '\n'); + artist_len = newline - artist; + rb->strncpy(art, artist, artist_len); + art[artist_len] = 0; + + title = newline + 1; + newline = rb->strchr(title, '\n'); + title_len = newline - title; + rb->strncpy(ttl, title, title_len); + ttl[title_len] = 0; + + rb->lcd_puts(0, 3, art); + rb->lcd_puts(0, 4, ttl); } bool buffer_init(void) @@ -773,6 +797,7 @@ bool done_playing = false; #define MAX_HANDLES 16 int handles[MAX_HANDLES]; +int meta_handles[MAX_HANDLES]; void codec_thread(void) { @@ -804,7 +829,10 @@ void codec_thread(void) rb->write(fd, data, read); total += read; bufadvance(handles[idx], read); + rb->lcd_clear_display(); print_progress(total, idx+1, num_files); + print_metadata(meta_handles[idx]); + rb->lcd_update(); } rb->sleep(HZ/100); } while (read > 0); @@ -821,6 +849,7 @@ void codec_thread(void) } else if (read == 0) { DEBUGF("finished reading handle %d\n", handles[idx]); bufclose(handles[idx]); + bufclose(meta_handles[idx]); rb->close(fd); fd = -1; total = 0; @@ -844,11 +873,19 @@ void codec_thread(void) void bufopen_thread(void) { int idx = 0, ret; + char buf[MAX_PATH]; while (idx < num_files) { - ret = bufopen(files[idx], 0); - if (ret > 0) { - handles[idx++] = ret; + snprintf(buf, MAX_PATH, "/meta%s.txt", files[idx]); + meta_handles[idx] = bufopen(buf, 0, TYPE_ID3); + if (meta_handles[idx] > 0) + { + ret = bufopen(files[idx], 0, TYPE_AUDIO); + if (ret > 0) { + handles[idx++] = ret; + } else { + bufclose(meta_handles[idx]); + } } rb->sleep(HZ*2); } -- 2.11.4.GIT