Help - Search - Members - Calendar
Full Version: FB2K Title Formatting Functions
Hydrogenaudio Forums > Hosted Forums > foobar2000 > General - (fb2k)
Canar
I figured that it may be time to create a separate thread for nifty things done with the title formatting library, rather than lumping them into the huge playlist title formatting thread. So, I'll start things with my HSL code, and hopefully the people who did other interesting things (like for example the album hashing) will contribute.

Notes:
Variables hue, sat and lum accept values from 0 to 239, like the standard color dialog.
Anything above/below the ranges shown will default to the highest/lowest value in the range, respectively.
Variable hsl returns the RGB colour code corresponding to your values of hue, sat, and lum, each meaning Hue, Saturation, and Luminosity respectively.

CODE
//Hue
$puts(hsl,
$ifgreater($get(hue),200,$blend(FF00FF,0000FF,$sub($get(hue),200),40),
$ifgreater($get(hue),160,$blend(FF0000,FF00FF,$sub($get(hue),160),40),
$ifgreater($get(hue),120,$blend(FFFF00,FF0000,$sub($get(hue),120),40),
$ifgreater($get(hue),80,$blend(00FF00,FFFF00,$sub($get(hue),80),40),
$ifgreater($get(hue),40,$blend(00FFFF,00FF00,$sub($get(hue),40),40),
$blend(0000FF,00FFFF,$get(hue),40)))))))

//Luminosity
$puts(hsl,$ifgreater($get(lum),119,$blend($get(hsl),FFFFFF,$sub($get(lum),120),120),
$blend(000000,$get(hsl),$get(lum),120)))

//Saturation
$puts(hsl,$blend($blend(000000,FFFFFF,$get(lum),240),$get(hsl),$get(sat),240))
superdumprob
CODE
000080'['$progress2(%_time_elapsed_seconds%,%_time_total_seconds%,30,'|',)
000080':B'
$progress2(%_time_elapsed_seconds%,%_time_total_seconds%,30,,808080'|')000080']'


I spotted this two colour progress bar method on Skibbi's status bar and felt like a 2 minute challenge so I figured out how to do it. By two colour I mean the symbols before the current position marker can be completely different to the ones after it. It also means the current position marker can be different from the other symbols used. I like to just change the colour. I use the large filled circles ( I think it's unicode symbol 25CF using Tahoma) in my own Status Bar and in keeping with foobar I use '|:B|' as my current position marker. Not that nifty really and the credit should go to others...

Thanks people

Edit: added a little more explanation
TurinsRevenge
Here are three from me (Rhymes) that I especially like wink.gif


QUOTE
// Status Bar Blinker - White and Blue with Pause in Red

$if(%_ispaused%,0000FFPaused,
$select($add($mod(%_time_elapsed_seconds%,2),1),'FF0000>FFFFFF>','FFFFFF>FF0000>'))


QUOTE
// Aproximate File Size with right justification- Playlist or Status Bar

$puts(fsize,$div($mul(%_length_seconds%,%__bitrate%,125),1024))
997C51
$repeat($char(95),$sub(6,$len($get(fsize))))

$if(%_isplaying%,97FE5F,FFFFFF)
$ifgreater($get(fsize),9999,$left($get(fsize),2)
$char(44)$right($get(fsize),3),
$ifgreater($get(fsize),999,$left($get(fsize),1)
$char(44)$right($get(fsize),3),
$char(32)
$right($get(fsize),3)))K


QUOTE
//Progress Bar with Percentage for Status Bar

// Store Past Color - Blue
$puts(past,FF0000)
// Store Future Color - Red
$puts(future,0000FF)
// Store Current Color - Black
$puts(present,000000)
// Store Separator - Dark gray for 3d effect
$puts(sep,838383 _| )
// Store Elapsed and Total Time
$puts(time_elap_tot, %_time_elapsed%[ / %_time_total%])
// Store Time Percentage
$puts(time_percent,[ $div($mul(100,%_time_elapsed_seconds%),%_time_total_seconds%)])
// Neat Characters to use • ÷ | — - =
// Store custom progress bar
$puts(plen,30)
$puts(leftchar,•)
$puts(rightchar,•)
// Store Past Time
$puts(past_time,$div($mul(%_time_elapsed_seconds%,$get(plen)),%_time_total_seconds%))

//Start Progress Bar
//Set Separator - Beginning of Progress Bar
$Get(sep)
// Set Past Color
$Get(Past)
// Set Past Characters
$repeat($get(leftchar),$get(past_time))
// Set Time Percentage
$get(present)<$get(time_percent)'%'$get(color_black)>
// Set Future Color
$get(future)
// Set Future Characters
$repeat($get(rightchar),$sub($get(plen),$get(past_time)))
// Set Separator - End of Progress Bar
$get(sep)
dbs
(first time poster)
i'm not sure if this belongs in this thread or in the other title formatting one...

i didn't want to use the footbar plugin for whatever reason (a little flickery and... that's it) so, i figured if i didn't mind minimizing to the taskbar, i could make the "window title" show song info pretty easily, without obscuring anything else on the screen. basically, this switches every two seconds between the artist and track title. it might just work for you, too!

CODE
$ifgreater($mod(%_time_remaining_seconds%,4),1,%artist%,%title%)


i realize it could probably be cleaner, but it's pretty short, so i didn't worry about it too much.

/dave
anza
Here's something I've made a while ago. Basically this just changes the length of the statusbar according to few rules:
* check if song playing is more than 10minutes
* check if it's played over 10min
* check if it's a vbr file
* check if it's more than 99kbps.

This is good for me, as my statusbar is as filled as it can be wink.gif I have it showing the bit- and samplerate, the extension of the file, the progress bar and a time elapsed/length display, and if the bitrate is under 100kbps (or vbr, which I indicate with a '~' in front of the bitrate) it messes up the statusbar, as there comes a nasty space between progress bar and the length biggrin.gif Well maybe you got the point..
It also shows <PAUSED> centered on the progress bar when the song is paused (duh).

But to the code now:

QUOTE
$puts(PROG_LEN,$ifgreater(%_time_total_seconds%,600,
$if($strcmp(%__extrainfo%,VBR),$ifgreater(%__bitrate%,99,$ifgreater(%_time_elapsed_seconds%,600,25,26),$ifgreater(%_time_elapsed_seconds%,600,26,27)),$ifgreater(%__bitrate%,99,$ifgreater(%_time_elapsed_seconds%,600,26,27),$ifgreater(%_time_elapsed_seconds%,600,27,28))),
$if($strcmp(%__extrainfo%,VBR),$ifgreater(%__bitrate%,99,$ifgreater(%_time_elapsed_seconds%,600,26,27),$ifgreater(%_time_elapsed_seconds%,600,27,28)),$ifgreater(%__bitrate%,99,$ifgreater(%_time_elapsed_seconds%,600,27,28),$ifgreater(%_time_elapsed_seconds%,600,28,29)))))

// the progress bar
$puts(PROG,$progress(%_time_elapsed_seconds%,%_time_total_seconds%,$get(PROG_LEN),$get(RED)'<'$select($add($mod(%_time_elapsed_seconds%,4),1),'—','\','|','/')'>',$get(GREY)=))

// show this when paused
$puts(P,$get(GREY)$repeat(=,$sub($div($get(PROG_LEN),2),3)))
$puts(PAUSE,$get(P)$get(RED)<PAUSED>$get(P))

// put all the stuff in one variable
$puts(PROG_PAUSE,$if(%_ispaused%,'['$get(PAUSE)']','['$get(PROG)']'))

// show the progress bar
$get(PROG_PAUSE)


It's REAL messy and pain in the ass to change the length, but at least it works smile.gif I would really appreciate it if someone could make it shorter for me, as I just don't bother to work with it anymore smile.gif
Bushwack
well here's the hashing function:
CODE

// the string to be hashed
$puts(KEY,%album%)

// seed value for the hash
//   changing this should give you radically different results
//    seeding with $rand() might be useful
$puts(HASH,3)

// assigns a numerical value to each letter
//    should expand fine if other characters are needed
$puts(COVA,1)
$puts(COVB,2)
$puts(COVC,3)
$puts(COVD,4)
$puts(COVE,5)
$puts(COVF,6)
$puts(COVG,7)
$puts(COVH,8)
$puts(COVI,9)
$puts(COVY,10)
$puts(COVJ,11)
$puts(COVK,12)
$puts(COVL,13)
$puts(COVM,14)
$puts(COVN,15)
$puts(COVO,16)
$puts(COVP,17)
$puts(COVQ,18)
$puts(COVR,19)
$puts(COVS,20)
$puts(COVT,21)
$puts(COVU,22)
$puts(COVV,23)
$puts(COVW,24)
$puts(COVX,25)
$puts(COVZ,26)

// pointer to current character
$puts(POS,0)

// each line adds one more character to the hash
//     function: HASH += HASH*KEY[POS]
//       fell free to come up with a better hash function I just made this one up
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))
$puts(HASH,$add($get(HASH),$mul($get(HASH),$get(COV$upper($substr($get(KEY),$put(POS,$add(1,$get(POS))),$get(POS)))))))

// $hex doesn't like negative numbers so take the absolute value
$puts(HASH,$replace($get(HASH),-,))

// remap the hash function into a colour code
$hex($mod($get(HASH),16777213),6)


Basically this will assign a random number to any unique string. Usage so far is to create a unique colour for every album or use it in a sorting string to enable a random album playback, fell free to come up with more ways to use it.


BONUS function, HSV->RGB conversion:
CODE

// S between 0 and 255
$puts(S,56)
// V between 0 and 255
$puts(V,128)
// H between 0 and 360
$puts(H,325)

$if($strcmp($get(S),0),$puts(R,$get(V))$puts(G,$get(V))$puts(B,$get(V)),
//else
$puts(I,$div($get(H),60))
$puts(F,$sub($div($mul($get(H),1000),60),$mul($div($get(H),60),1000)))
$puts(P,$div($mul($get(V),$sub(256,$get(S))),256))
$puts(Q,$div($mul($get(V),$sub(256,$div($mul($get(S),$get(F)),1000))),256))
$puts(T,$div($mul($get(V),$sub(256,$div($mul($get(S),$sub(1,$get(F))),1000))),256))

$if($strcmp($get(I),0),$puts(R,$get(V))$puts(G,$get(T))$puts(B,$get(P)),
$if($strcmp($get(I),1),$puts(R,$get(Q))$puts(G,$get(V))$puts(B,$get(P)),
$if($strcmp($get(I),2),$puts(R,$get(P))$puts(G,$get(V))$puts(B,$get(T)),
$if($strcmp($get(I),3),$puts(R,$get(P))$puts(G,$get(Q))$puts(B,$get(V)),
$if($strcmp($get(I),4),$puts(R,$get(T))$puts(G,$get(P))$puts(B,$get(V)),
$puts(R,$get(V))$puts(G,$get(P))$puts(B,$get(Q)))))))
)
$puts(R,$hex($get(R),2))
$puts(G,$hex($get(G),2))
$puts(B,$hex($get(B),2))

$get(B)$get(G)$get(R)


Basically the same as Canar's coverter except using HSV instead of HSL. I don't use colour codes much (at all) so I don't know what the difference is or if this even really works as it should (I just transcribed some c code I found) so use at your own risk.

Both these functions can also be found in this thread.

I also have a function that come up with a gradated colour based on byterate, but I think $transition has made that obsolete so I won't include that here.
LPTB
I was thinking about the undying random/shuffle thing, it can be easily implemented using the hash; However it would be much better if Peter could add $crc32 or some other function and perhaps %_system_time% parameter, than, every time I sart the player it would $crc32(album + artist + title + time) and I could play the list as ordered by the Hash. This also enables the random album as Bushwack suggested. The %_system_time% is to add randomness so it wouldn't play the same album/songs in same order and $crc32 is for effiecency reason, doing crc32 in C is quite fast while in script ...
Canar
QUOTE(anza @ Apr 25 2003 - 11:36 PM)
Here's something I've made a while ago. Basically this just changes the length of the statusbar according to few rules:
* check if song playing is more than 10minutes
* check if it's played over 10min
* check if it's a vbr file
* check if it's more than 99kbps.

It's REAL messy and pain in the ass to change the length, but at least it works smile.gif I would really appreciate it if someone could make it shorter for me, as I just don't bother to work with it anymore smile.gif

Try this:

CODE

$puts(LEN,29)
$puts(LEN,$ifgreater(%_time_total_seconds%,600,$sub($get(LEN),1),$get(LEN))
$puts(LEN,$ifgreater(%_time_elapsed_seconds%,600,$sub($get(LEN),1),$get(LEN))
$puts(LEN,$if($strcmp(%__extrainfo%,VBR),$sub($get(LEN),1),$get(LEN))
$puts(LEN,$ifgreater(%__bitrate%,99,$sub($get(LEN),1),$get(LEN))
$puts(PROG_LEN,$get(LEN))


Hopefully it won't conflict with any other variable named "LEN", and it'll let you change the length of any of these attributes by any amount. Say, if you wanted to include the string "VBR" with your vbr files, you could change the 1 in the VBR detector to 3. Change what LEN is set to initially to change the overall length. I hope this helps/works, because I haven't syntax checked it, but it ought to give you an idea for future improvements.
anza
Thanks Canar! I tried doing it somehow like that myself, but couldn't get it to work, I really don't understand why... Maybe it was a typo or something, but I knew someone here would get it to work smile.gif
BTW, there was a bug in your code wink.gif you should've had one ')' more on the four lines in the middle.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.