Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: Add two durations (Read 926 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Add two durations

Hi everybody,

I'm using foo_skip to skip the beginning of some of my tracks.
I'd like to use a special column to display the accurate played length of such tracks.
For example a 4 minutes track where I will skip the first 15 seconds will have these fields :
%length% = 4:00
%skip% = -00:15

How could I add these two durations, to ultimately display the accurate played length which is 3:45 ?
$add(%length%;%skip%) doesn't seem to work here.

Thank you. :)

Re: Add two durations

Reply #1
It's quite complex. Here's a script that handles calculating final length only with -[hh:][mm:]ss skip string syntax:
Code: [Select]
$if(%skip%,
$if($strcmp($left(%skip%,1),-),

$puts(st,$pad_right($replace(%skip%,-,,:,),6,0))
$puts(ssecs,$right($get(st),2))
$puts(smins,$substr($get(st),3,4))
$puts(shrs,$substr($get(st),1,2))
$puts(slen,$add($mul($add($mul($get(shrs),60),$get(smins)),60),$get(ssecs)))

$ifgreater($get(slen),%_length_seconds%,%length%,

$puts(plen,$sub(%_length_seconds%,$get(slen)))

$puts(psecs,$mod($get(plen),60))
$puts(pmins,$mod($div($get(plen),60),60))
$puts(phrs,$div($get(plen),3600))

$ifgreater($get(phrs),0,$get(phrs):$num($get(pmins),2),$get(pmins)):$ifgreater($get(psecs),0,$num($get(psecs),2),)))

,%length%)

Re: Add two durations

Reply #2
Thanks Case. It is quite complex indeed. :)
It doesn't work in my case, probably because I'm using %skip% down to the 10th or 100th of second, so my skip string syntax is either -mm:ss, or -mm:ss.0, or -mm:ss.00 (no hours, never)
I know, that's complicated. Too bad foobar doesn't have an integrated calculator for this kind of thing. ;)

Re: Add two durations

Reply #3
I've created something that works. It's not a pretty code, but it works with my 3 syntaxes :

Code: [Select]
$if(%skip%,$puts(a,$sub(%length_seconds%,$add($mul($substr(%skip%,2,3),60),$substr(%skip%,5,6))))$div($get(a),60)':'$pad($sub($sub($get(a),$mul($div($get(a),60),60)),$if($or($strstr(%skip%,'.6'),$strstr(%skip%,'.7'),$strstr(%skip%,'.8'),$strstr(%skip%,'.9')),1,0)),2,0),%length%)