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: Is there a $log()? (Read 1055 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Is there a $log()?

I checked the "Foobar2000:Title Formatting Reference" for the logarithm function, but it is not supported.  Does anyone know of a simple workaround?  I want to use it for a "View" in the "Album List" to view by duration.  For example, it could group files by durations of [n to 2*n) seconds -- 0 to 1 minute, 1 to 2 minutes, 2 to 4 minutes, 4 to 8 minutes, and so on.  (I realize that one could implement division with several $if statements, but that is complicated and does not scale).

Thanks!

Is there a $log()?

Reply #1
No, there are no exponential or logarithm functions. Note that all title formatting functions operate on integers only.

However, you can compute $floor($log10(x)) for a natural number x, even though neither a $floor nor a $log10 function actually exists. For this you have to compute the number of digits of the number which can be done with the $len function. Here is an example that applies this to the track length in minutes:
Code: [Select]
$puts(L,$len($div(%length_seconds%,60)))
1$repeat(0,$sub($get(L),1)) to $add(1$repeat(9,$sub($get(L),1)),1) minutes

This displays things like "10 to 20 minutes" or "1 to 2 minutes". Note that it will display the latter even for tracks shorter than 1 minute.

For maximum flexibility you have to resort to an $if cascade. Like you said this does not scale, but on the other hand you can choose the intervals freely. For example:
Code: [Select]
$ifgreater(%length_seconds%,599,
10 minutes or longer,
$ifgreater(%length_seconds%,179,
3 to 10 minutes,
$ifgreater(%length_seconds%,59,
1 to 3 minutes,
0 to 1 minute
)))

 

Is there a $log()?

Reply #2
Thanks for the reply, foosion.  I ended up going with your latter suggestion.  In case anyone else would benefit,

Code: [Select]
$ifgreater(%length%,3,$ifgreater(%length%,5,$ifgreater(%length%,10,$ifgreater(%length%,15,$ifgreater(%length%,30,$ifgreater(%length%,60,60:00 +,30:00 - 60:00),15:00 - 30:00),10:00 - 15:00),5:00 - 10:00),3:00 - 5:00),0:00 - 3:00)|$filename(%path%)