Brother John’s Projects: Foobar2000 Scripting

Global Scripts in 0.8.3

Syntax for Global Variables

Global variables are defined on the Globals / Variables tab, and like in 0.9 don’t forget to tick Use global variables for display. The syntax for defining those variables, however, is different in 0.8.3. Variables are defined not by $set_global() but by a simple name=value with a separating special character between the individual definitions.

varname=valuevarname=valuevarname=valueetc.

The separator, that most likely shows up as a square box, is ASCII character number 7 or $char(7). If you want to, actually using $char(7) instead of the single square is valid but tends to clutter your script very quickly. Look at the top right corner of the Globals tab to find the character to copy & paste into the script.

Also, the $rgb() function to define colours doesn’t work in Globals / Variables. Instead we must use hexadecimal colour codes like in HTML. But in contrast to HTML Foobar2000 takes the colours backwards, i. e. in the order blue, green, red: bright red is not FF0000 but 0000FF.

Avoid these issues by using the ... button to open a standard Windows colour dialogue. Choose your colour and copy & paste it to the script from the box left to the button.

Now on to our actual script containing colour definitions and the album checking code. Let’s review two linesfrom the 0.9 script defining text colour and the colour for the red VA artist names.

$set_global(cTxtStd,$rgb(255,255,255))
$set_global(cTxtVA,$rgb(126,16,16,220,129,129))

According to 0.8.3 syntax we need to change this to

cTxtStd=ffffff
cTxtVA=10107E|8181DC

Especially note the second line where we used the extended $rgb() to specify text and selected text colour in one go. 0.8.3 separates the two colours with a pipe character (|). And here are the full colour definitions.

// --- Colours ---
// Text
cTxtStd=ffffff
cTxtSel=ffffff
cTxtTrk=000000
cTxtVA=10107E|8181DC
cTxtVA1=8181DC|8181DC
cTxtVAPlay=10107E|10107E
cTxtDim=A0A0A0|A0A0A0
cTxtPlay=ffffff

// Background
cBgStd=000000
cBgSel=10107E
cBgTrk=C8C8C8
cBgAlt=191919
cBgPlay=7F7D7A
cBg=$ifgreater($mod(%_playlist_number%,2),0,191919,000000)

// Frames
cFrmStd=2B2BFF
// --- End Colours ---

The cBg variable does not exist in the 0.9 version. As you probably see it contains the calculated value for the alternating background. As this calculation would have been necessary multiple times throughout the scripts, I decided to make it once and store the result in a new variable.

The colour definitions are followed by the check for album tracks.

// Check for album
$if($and(%tracknumber%,%album tracks%,%album%),
isAlbum=1
)

Here too we substitute $set_global(isAlbum,1) by isAlbum=1 and end the whole thing with the $char(7) character.

The last bit of script for the Variables tab is an addition to the 0.9 version. Because 0.8.3 doesn’t provide field remapping we don’t have an automatically cleaned up tracknumber available. If e. g. the tracknumber is stored as 1/15 or 3 of 12, accessing the %tracknumber% tag returns that whole string. Because the tracknumber is used frequently we build our own manual ‘tag remapping’ with this bit of Tagz code.

// Clean tracknumber
tracknum=$num(%tracknumber%,1)

From now on, whenever we need the tracknumber in an if-condition etc. we access the %_tracknum% variable instead of the %tracknumber% field.

Which brings us to the way to access global variables elsewhere, which is different from 0.9 as well. We don’t have $get_global() but access the variable like a field with a leading underscore in the name. Thus tracknum has to be accessed as %_tracknum% or isAlbum as %_isAlbum%.

Syntax for Colour Scripts

Forget everything you know about colour scripts. Foobar2000 0.8.3 is completely different from 0.9. Even the tab to enter the script has a different name: Colour. The colours are set in one single large statement using the following syntax.

text|selected text|background|selected background|non-focused selected background|left frame|top frame|right frame|bottom frame

The pipe character (|) separates the colours with everything from the non-focused background onwards being optional. Scripting may be used to set colours. E. g. you could use

$if(%_isplaying%,FFFFFF,000000)

to set the currently playing song to white and all others to black. Let’s have a look at our global colour script, that does exactly the same as the 0.9 version: White text on alternating black and dark grey background and dark red background for selected lines.

// text
%_cTxtStd%

// text selected
|%_cTxtSel%

// background
|%_cBg%

// background selected
|%_cBgSel%

// background selected inactive
|

// line left
|

// line top
|

// line right
|

// line bottom
|

I broke it up into individual lines and commented the purpose of each new colour. Otherwise getting lost between all the pipe characters is just too easy. More interesting things don’t happen. The script just takes over the colours from the global variables defined on the Variables tab. All the optional values can be empty or even left out completely. Though leaving out one optional value means you are forced to leave out all the following ones as well.