Hans Schou
2003-Feb-28 03:02 UTC
[vorbis-dev] ogg123 -k 1:59 patch.ogg # minutes and seconds
Hi I have helped a user with a little patch for ogg123. He uses ogg123 for very big files, often more than an hour (blind books). When he breaks the book and later on want to go back to the same chapter, it is a little troublesome to calculate the seconds. Minutes is much more convenient as it is what is written on the screen. I guess my patch is a little buggy and would like to improve it upon request (guidelines are welcome). Anyway, here it is: diff -Naur vorbis-tools-1.0.orig/ogg123/cmdline_options.c vorbis-tools-1.0/ogg123/cmdline_options.c --- vorbis-tools-1.0.orig/ogg123/cmdline_options.c Thu Jul 11 04:44:39 2002 +++ vorbis-tools-1.0/ogg123/cmdline_options.c Thu Feb 27 13:37:46 2003 @@ -50,6 +50,24 @@ {0, 0, 0, 0} }; +double minsec_atof(const char *nptr) +{ + const char *p = nptr; + double min = 0.0; + double sec = 0.0; + + while (*p && *p != '.') { + if (*p >= '0' && *p <='9') + sec = sec * 10 + (*p-'0'); + else + if (*p == ':') { + min = sec; + sec = 0.0; + } + p++; + } + return (min*60+sec+atof(p)); +} int parse_cmdline_options (int argc, char **argv, ogg123_options_t *ogg123_opts, @@ -137,7 +155,7 @@ break; case 'k': - ogg123_opts->seekpos = atof(optarg); + ogg123_opts->seekpos = minsec_atof(optarg); break; case 'l': PS: Is there a library function for this kind of stuff? best regards/hans -- Hamletsgade 4 - 201, DK-2200 København N, Phone: +45 3582 9079 Schou Industries ApS http://schou.dk/ CVR: 26 13 44 39 -------------------------------------------------------------- You didn't answer my question. -- John McClane, Die Hard --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Stefan Bender
2003-Mar-01 14:39 UTC
[vorbis-dev] Re: ogg123 -k 1:59 patch.ogg # minutes and seconds
Hello, Hans Schou wrote on 2003-02-28 12:02:19:> I have helped a user with a little patch for ogg123. He uses ogg123 > for very big files, often more than an hour (blind books). When he > breaks the book and later on want to go back to the same chapter, it > is a little troublesome to calculate the seconds. Minutes is much more > convenient as it is what is written on the screen.[snip patch] I personally think that you can make such things easier, i.e. without patching ogg123. I see at least three obvious ways to do this, the first and most simple is to use your brain. (if you practice often, you will increase your neuron pool ;) More seriously, you can use bash's $(()) like ogg123 -k $((<min>*60+<sec>)) ... or you can feed an appropriate sequence to bc ogg123 -k `echo '<min>*60+<sec>' | bc` ... But, if you (and maybe more people) think, that support for this is useful to have in ogg123, I would suggest to do it in a more flexible way by appending a single letter to indicate minutes, seconds, hours, or even samples like ogg123 -k 1:23m ... for minutes ogg123 -k 2:34h ... for hours and ogg123 -k 23456s ... for samples (or maybe make that a capital S and use s for seconds?) /Stefan. --- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.
Segher Boessenkool
2003-Mar-02 07:44 UTC
[vorbis-dev] ogg123 -k 1:59 patch.ogg # minutes and seconds
Hans Schou wrote:> I guess my patch is a little buggy and would like to improve it upon > request (guidelines are welcome). Anyway, here it is:In pseudo-code, I'd do: time := get number while next character is ':' skip that ':' time := 60*time + get number That way, things like 2:14:01 parse, too. You can also accept fractional seconds with this, like in 5:49.216 for example, by having "get number" get floating point numbers, not integer. (You'll have to temporarily set the locale to "C" for this to work perfectly; otherwise, the locale-specific decimal point is used instead of '.', and that is not appropriate). Ah well, I'll write it in C for you [completely untested!] (leaving out the locale stuff). double strtotime(const char *s) { double time; time = strtod(s, &s); while (*s == ':') time = 60 * time + strtod(s + 1, &s); return time; } <p>Good luck, Segher <p>--- >8 ---- List archives: http://www.xiph.org/archives/ Ogg project homepage: http://www.xiph.org/ogg/ To unsubscribe from this list, send a message to 'vorbis-dev-request@xiph.org' containing only the word 'unsubscribe' in the body. No subject is needed. Unsubscribe messages sent to the list will be ignored/filtered.