HydrogenAudio

Hosted Forums => foobar2000 => 3rd Party Plugins - (fb2k) => Topic started by: iridescentaudio on 2019-03-09 19:22:54

Title: Columns UI questioni: setting style in a column for specific text strings
Post by: iridescentaudio on 2019-03-09 19:22:54
Hi, I've recently started using Columns UI, and so far I've managed to push past most of the stumbling blocks and made large leaps in usability compared to my previous Default UI layout, but for this specific problem I've made no progress (so I have to bite the bullet and ask for help!)

I have a File Extension column using the display script $ext(%path%), and style script is currently set_style(text,$rgb(255,255,255)) for white text. Due to the large number of different audio formats I use in foobar2000, from an ease-of-use perspective I wanted a way to colour this column according to the text string returned, e.g. MP3 appears red, OGG appears blue, etc. I was able to do something similar on a track ratings column to create different coloured hearts depending on rating (from grey to pink), for that I used multiple instances of $if($greater(%rating%, x),$set_style~, however a track rating is merely a number, and I can't figure out the correct syntax or logic for achieving something similar with specific phrases. I presume it involves an $if statement somehow, but after that I'm getting stuck. Any help would be greatly appreciated!

Also, small side question, is there a Discord server for foobar2000? I haven't found one so far.
Title: Re: Columns UI questioni: setting style in a column for specific text strings
Post by: Daeron on 2019-03-09 20:07:16
If you want colored text I'd suggest using $rgb() in the display tab instead. Takes less code and will allow you to color parts of the displayed string independently.

You can color a text red using:
Code: [Select]
$rgb(255,0,0)this text is red
This will return true, if CODEC contains the string 'MP3':
Code: [Select]
$strstr(%codec%,MP3)
Using those two you can create an $if() statement which will color the text red if CODEC contains 'MP3':
Code: [Select]
$if($strstr(%codec%,MP3),$rgb(255,0,0),)text

You can also get fancy and color things automatically based on the CRC32 checksum of the string:
Code: [Select]
$puts(string,%codec%)
$puts(value,$mod($crc32($get(string)),258))
$hsl($get(value),160,125)
$get(string)
But you may not like the colors. You can try adjusting the numbers 258, 160, 125 to get something closer to your liking. Also if you want to replace the string, edit %codec% in the code.

The titleformatting wiki is your #1 resource for problems like this:
https://wiki.hydrogenaud.io/index.php?title=Foobar2000:Title_Formatting_Reference

Title: Re: Columns UI question: setting style in a column for specific text strings
Post by: iridescentaudio on 2019-03-10 12:16:45
Thanks for the reply, great help! :)

After some experimentation I've come to the conclusion that using CRC32 checksum colours will work best for my purposes. I'm using a file extension column rather than a codec column (sorry if that wasn't clear); in hindsight using $if statements I'd have to manually input colour code rules for every file extension under the sun, which isn't as elegant a solution.

I modified the string from %codec% to $lower($ext(%path%)) - this neatly avoids the issue of e.g. 'MP3' and 'mp3' being differently coloured. I also bumped up the lightness value a bit to create more pastel shades which work better with my setup. Ultimately it doesn't look at all out of place ~ I'm pretty impressed, not gonna lie :)

Quote
The titleformatting wiki is your #1 resource for problems like this:

Trust me I've been cramming on that page as best as I can over the last week and have it bookmarked, but I could have spent many more hours pulling my hair out and not getting anywhere with this issue, and figured someone would have an answer. Fortunately it's one of the last things I wanted to achieve with the playlist so I'm glad to have got it sorted - thanks again.
Title: Re: Columns UI questioni: setting style in a column for specific text strings
Post by: Daeron on 2019-03-10 14:21:45
No worries about the wiki link, I just paste it everywhere so others can see it too.

You could also color based on the bitrate and whether the tracks are lossy, which is how I like it, but you might think otherwise:
Code: [Select]
$if($stricmp(%__encoding%,lossless),$rgb(0,128,255,0,128,255),
$ifgreater(%bitrate%,127,$rgb(180,0,0,180,0,0),)
$ifgreater(%bitrate%,191,$rgb(220,118,0,220,118,0),)
$ifgreater(%bitrate%,319,$rgb(100,180,0,60,160,20),))
$ifgreater(%bitrate%,987,$rgb(128,0,255,128,0,255),)
%codec%