Brother John’s Projects: Foobar2000 Scripting

The Columns’ Scripts in 0.8.3

Going through all the scripts one by one would be tedious. Therefore I settled on looking in detail at one example Display and Colour script each and then only listing the adapted scripts for all columns. Parts marked in grey are the same as in the 0.9 version, black parts are different.

Changing a Script in Detail

Example Display Script

Our example for adapting a Display Script is the one from the album view Track column. Below you see the 0.9 version. The line numbers don’t belong to the actual script. I added them for clarity only.

01 $if($and($get_global(isAlbum),$meta(album artist)),
02
03 $if(%isplaying%,
04 $get_global(cTxtVAPlay),
05 [...]

Line 1 is the first candidate to change. 0.8.3 doesn’t recognise $get_global(isAlbum) to access global variables, so we must use %_isAlbum% instead. The following $meta() was necessary to disable 0.9’s tag remapping, which doesn’t exist in 0.8.3. And while leaving it unchanged works we could use just the field name as well.

$if($and(%_isAlbum%,%album artist%),

Line 3 needs a minor change. In 0.8.3 the field to check for the currently playing song is called %_isplaying% with the leading underscore.

Line 4 is another global variable, but just using %_cTxtVAPlay% won’t work because we’re dealing with a colour variable. Those have to be enclosed in ASCII character number 3 or $char(3). Thus the changed line 4 reads:

%_cTxtVAPlay%,

Similar to the separator in the global variable definition script an alternative notation is

$char(3)%_cTxtVAPlay%$char(3),

with the disadvantage of decreased readability. This time you can copy & paste the correct character from the colour box next to the ... and Tools buttons.

And here is the next part of the 0.9 script.

04 [...]
05 $ifequal(%tracknumber%,1,$get_global(cTxtVA1),$get_global(cTxtVA))
06 )
07 [...]

Line 5 needs a couple of changes. First 0.8.3 has no $ifequal() function. But we can work around this issue with following construction:

$if($strcmp('a','b'),do sth,do sth else)

$Strcmp() compares two strings and returns true if they’re identical and false if they’re different. $Ifequal() essentially does the same.

Then we have %tracknumber% always returning a cleaned up tracknumber in 0.9. Remember the global variables script where we introduced the %_tracknum% variable containing such a cleaned up tracknumber. Here is one of the places where this comes in handy. The remainig part of the line needs some global colour variable replacing giving us finally:

$if($strcmp(%_tracknum%,'1'),%_cTxtVA1%,%_cTxtVA%)

And this is the rest of the 0.9 script.

07 [...]
08 [$meta(artist)' - ']$rgb()
09 )
10
11 %title%

In line 8 the first difference is the non-critical change from $meta(artist) to raw field. At the end of the line we switch back to default colour. In 0.8.3 this is not done by $rgb() but by a double ASCII number 3 character. The alternative notations for the changed line are:

[%artist%' - ']
[%artist%' - ']$char(3)$char(3)

Finally line 11 is another tag remapping issue. In 0.9 %title% gives us the track title or the filename if no title tag is present. In 0.8.3 we must do this manually using $if2().

$if2(%title%,%_filename%)

See below for the complete 0.8.3 Track script.

Example Colour Script

Concerning colour scripts two major differences exist between 0.8.3 and 0.9. First the script syntax and second the handling of custom column colour scripts. Here 0.9 starts with the global colours and changes them according to the custom script. 0.8.3 throws everything out of the window and acts as if the global script wouldn’t exist. This means we have to define all the colours in a custom script, no matter if they’re different from the global settings or not.

For porting the actual code I settled on dividing the 0.8.3 scripts into two sections: first the colour calculation and second colour assigning. The essence of the first part is replacing all the $set_style() commands with $puts(). The second part is copy & paste of the global script and either keeping the reference to the global colour variable or using the local variable defined in the first section. Let’s look at the album view RGain script to make this clear.

Here is the 0.9 script

01 $set_style(back,$get_global(cBgStd),$get_global(cBgSel))
02 $set_style(frame-right,1,$get_global(cFrmStd))
03
04 $if($get_global(isAlbum),
05 $ifequal(%tracknumber%,1,
06 $set_style(frame-top,1,$get_global(cFrmStd)),
07
08 $ifequal(%tracknumber%,%album tracks%,
09 $set_style(frame-bottom,1,$get_global(cFrmStd)),
10 ))
11 )

This whole script becomes the colour calculation section. Line 1 and 2 are simple unconditional references to global variables and can be moved to section two entirely. Lines 4 to 6 need a change to:

$if(%_isAlbum%,
$if($strcmp(%_tracknum%,'1'),
$puts(FRMtop,%_cFrmStd%),

First we need to replace $get_global() and $ifequal() by their 0.8.3 counterparts. The essential line is the last one. Instead of the $set_style() command to set the top frame colour directly, we now use $puts() to create a local variable holding the appropriate colour. Look at the $if() construction: FRMtop only exists when dealing with track one of an album. Otherwise there is no such variable.

Further down in the colour assigning section we now can use $get() to access those variables like this.

[...]
// line top
|$get(FRMtop)

// line right
|%_cFrmStd%

// line bottom
|$get(FRMbottom)

For all tracks except the first one of an album FRMtop doesn’t exist and returns nothing, meaning not to display a top frame. For the complete 0.8.3 script look below.

As a general rule every unconditional $set_style() (not set within some if-construction) can go dircetly to the assigning section as a reference to the appropriate global variables. Every conditional $set_style() goes into a local variable first and is accessed by $get() in the assigning section.

This whole approach might not produce optimal code and maximum speed, but it was quite easy to implement. However if we initially designed Dark Connection for 0.8.3 the colour scripts surely would look somewhat different.

In the following sections you find the Display and Colour scripts for every column. When configuring the columns, use alignment and filter string exactly as in the 0.9 version and don’t forget to tick Use custom colour spec where appropriate.

Album Mode Columns

The Artist/Album Column

Display script

// --- Album view ---
$if(%_isAlbum%
,
$select(%_tracknum%,
// Track 1
$if($strcmp(%__codec%,'ATSC A/52'),'dolby digital ac3',
$if($info(lame_version),'lame',
$lower(%__codec%)
))
' album {',
// Track 2
'   '$if2(%album artist%,$if2(%artist%,'<no artist>')),
// Track 3
'   '$if2(%album%,'<no album>'),
// Track 4
'   '['Disc '%disc%$tab()]$if2(%album date%,[%date%])$tab(),
// Track 5
'}'
),

// --- Single view ---
[%artist%]
)

Colour script

// ===== Calc colours =====
$if(%_isAlbum%,

// -- album mode --
// Text/bg colour
$ifgreater(%_tracknum%,4,
$puts(TXTstd,%_cTxtStd%)$puts(TXTsel,%_cTxtStd%)
$puts(BGstd,%_cBgStd%)$puts(BGsel,%_cBgStd%)
,
$if($strcmp(%_tracknum%,'1'),
$puts(TXTstd,%_cTxtStd%)$puts(TXTsel,%_cTxtStd%)
$puts(BGstd,%_cBgStd%)$puts(BGsel,%_cBgStd%)
,
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtTrk%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgTrk%)
))

// Top & bottom border
$if($strcmp(%_tracknum%,'1'),$puts(FRMtop,%_cFrmStd%),
$if($strcmp(%_tracknum%,'5'),$puts(FRMbottom,%_cFrmStd%),
$if($strcmp(%_tracknum%,$num(%album tracks%,1)),$puts(FRMbottom,%_cFrmStd%)
)))

$ifgreater(%_tracknum%,5,$puts(FRMright,%_cFrmStd%),)

,
// -- single mode --
$puts(FRMright,%_cFrmStd%)
$puts(TXTstd,%_cTxtStd%)$puts(TXTsel,%_cTxtSel%)
$puts(BGstd,%_cBg%)$puts(BGsel,%_cBgSel%)
)


// ===== Assign colours =====
// text
$get(TXTstd)

// text selected
|$get(TXTsel)

// background
|$get(BGstd)

// background selected
|$get(BGsel)

||

// line top
|$get(FRMtop)

// line right
|$get(FRMright)

// line bottom
|$get(FRMbottom)

The Tracknumber Column

Display script

$if(%_isplaying%
,
$if($strcmp($put(foo,$mod(%_time_elapsed_seconds%,8)),'0'),
'))))',
$select($get(foo),
%_cTxtDim%'('')))',
%_cTxtDim%'((''))',
%_cTxtDim%'((('')',
%_cTxtDim%'((((',
')'%_cTxtDim%'(((',
'))'%_cTxtDim%'((',
')))'%_cTxtDim%'('
))

,
$if(%_isAlbum%,
$ifgreater(%_tracknum%,15,
$hex(%tracknumber%,1),
%_cTxtDim%'0'$hex(%tracknumber%,1)
))
)

Colour script

// ===== Calc colours =====
$if(%_isAlbum%
,
// -- Album view
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtTrk%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgTrk%)

$if($strcmp(%_tracknum%,'1'),
$puts(TXTstd,%_cTxtStd%)$puts(TXTsel,%_cTxtStd%)
$puts(BGstd,%_cBgStd%)$puts(BGsel,%_cBgStd%)
$puts(FRMtop,%_cFrmStd%)
,

$if($strcmp(%_tracknum%,$num(%album tracks%,1)),
$puts(FRMbottom,%_cFrmStd%)
))

,
// -- Single view
$if(%isplaying%,
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtTrk%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgTrk%)
,
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtSel%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgSel%)
)
)


// ===== Assign colours =====
// text
$get(TXTstd)

// text selected
|$get(TXTsel)

// background
|$get(BGstd)

// background selected
|$get(BGsel)

||

// line top
|$get(FRMtop)

// line right
|

// line bottom
|$get(FRMbottom)

The Track Column

Display script

$if($and(%_isAlbum%,%album artist%),

$if(%_isplaying%,
%_cTxtVAPlay%,
$if($strcmp(%_tracknum%,'1'),%_cTxtVA1%,%_cTxtVA%)
)

[%artist%' - ']
)

$if2(%title%,%_filename%)

Colour script

// ===== Calc colours =====
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtSel%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgSel%)


$if(%_isAlbum%
,
// -- Album view
$if($strcmp(%_tracknum%,'1'),
$puts(TXTstd,%_cTxtStd%)$puts(TXTsel,%_cTxtSel%)
$puts(BGstd,%_cBgStd%)$puts(BGsel,%_cBgSel%)
$puts(FRMtop,%_cFrmStd%)
)

$if($strcmp(%_tracknum%,$num(%album tracks%,1)),
$puts(FRMbottom,%_cFrmStd%))
)


$if(%_isplaying%,
$puts(TXTstd,%_cTxtPlay%)$puts(TXTsel,%_cTxtPlay%)
$puts(BGstd,%_cBgPlay%)$puts(BGsel,%_cBgPlay%)
)


// ===== Assign colours =====
// text
$get(TXTstd)

// text selected
|$get(TXTsel)

// background
|$get(BGstd)

// background selected
|$get(BGsel)

||

// line top
|$get(FRMtop)

|

// line bottom
|$get(FRMbottom)

The Time Column

Display script

$if(%_time_remaining%,
'['%_time_remaining%']',
$if2(%_length%,'n/a')
)

Colour script

// ===== Assign colours =====
// text
%_cTxtStd%

// text selected
|%_cTxtSel%

// background
|%_cBgStd%

// background selected
|%_cBgSel%

||

// line top
|$if(%_isAlbum%,$if($strcmp(%_tracknum%,'1'),%_cFrmStd%)
)

|

// line bottom
|%_cFrmStd%

The RGain Column

Display script

$if(%_isAlbum%
,
$if2(%__replaygain_album_gain%,'n/a')
,
$if2(%__replaygain_track_gain%,'n/a')
)

Colour script

// ===== Calc colours =====
$if(%_isAlbum%,
$if($strcmp(%_tracknum%,'1'),
$puts(FRMtop,%_cFrmStd%),

$if($strcmp(%_tracknum%,$num(%album tracks%,2)),
$puts(FRMbottom,%_cFrmStd%))
))


// ===== Assign colours =====
// text
%_cTxtStd%

// text selected
|%_cTxtSel%

// background
|%_cBgStd%

// background selected
|%_cBgSel%

||

// line top
|$get(FRMtop)

// line right
|%_cFrmStd%

// line bottom
|$get(FRMbottom)

Single Mode Columns

The Artist Column

Display script

[%artist%]

The Title Column

Display script

$if(%_isplaying%
,
$if($strcmp($put(foo,$mod(%_time_elapsed_seconds%,8)),0),
'))))  ',
$select($get(foo),
%_cTxtDim%'('')))  ',
%_cTxtDim%'((''))  ',
%_cTxtDim%'((('')  ',
%_cTxtDim%'((((  ',
')'%_cTxtDim%'(((  ',
'))'%_cTxtDim%'((  ',
')))'%_cTxtDim%'(  '
))
)

$if2(%title%,%_filename%)

Colour Script

$if(%_isplaying%
,
$puts(TXTstd,%_cTxtPlay%)$puts(TXTsel,%_cTxtPlay%)
$puts(BGstd,%_cBgPlay%)$puts(BGsel,%_cBgPlay%)
,
$puts(TXTstd,%_cTxtTrk%)$puts(TXTsel,%_cTxtSel%)
$puts(BGstd,%_cBgTrk%)$puts(BGsel,%_cBgSel%)
)

// text
$get(TXTstd)

// text selected
|$get(TXTsel)

// background
|$get(BGstd)

// background selected
|$get(BGsel)

|||||

The Album Column

Display script

['('$num(%tracknumber%,2)')' ]
[%album%][', CD '%disc%]

The Time Column

Display script

$if(%_time_remaining%,
'['%_time_remaining%']',
$if2(%_length%,'n/a')
)

The RGain Column

Display script

$if2(%__replaygain_track_gain%,'n/a')