Documentation/fb
namespace

fb

js/foo_uie_jsplitter.js:197

Functions for controlling foobar2000 and accessing it's data.

property

AlwaysOnTop

js/foo_uie_jsplitter.js:203
AlwaysOnTop: boolean

Example

fb.AlwaysOnTop = !fb.AlwaysOnTop; // Toggles the current value.
propertyreadonly

ComponentPath

js/foo_uie_jsplitter.js:211
ComponentPath: string

Example

console.log(fb.ComponentPath); // C:\Users\User\AppData\Roaming\foobar2000\user-components\foo_uie_jsplitter\
property

CursorFollowPlayback

js/foo_uie_jsplitter.js:220
CursorFollowPlayback: boolean
propertyreadonly

CustomVolume

js/foo_uie_jsplitter.js:223
CustomVolume: boolean

It can be used for displaying the volume from UPnP devices.
It will return a value of -1 when using a normal device and that also indicates that fb.Volume is writable.
When a custom volume control is active, you can not use fb.Volume and must use fb.VolumeUp() / fb.VolumeDown() / fb.VolumeMute().

propertyreadonly

FoobarPath

js/foo_uie_jsplitter.js:232
FoobarPath: string
propertyreadonly

IsPaused

js/foo_uie_jsplitter.js:238
IsPaused: boolean
propertyreadonly

IsPlaying

js/foo_uie_jsplitter.js:244
IsPlaying: boolean
property

PlaybackFollowCursor

js/foo_uie_jsplitter.js:250
PlaybackFollowCursor: boolean
propertyreadonly

PlaybackLength

js/foo_uie_jsplitter.js:253
PlaybackLength: float

Examples

console.log(fb.PlaybackLength); // 322.843414966166
console.log(Math.round(fb.PlaybackLength)); // 323
property

PlaybackTime

js/foo_uie_jsplitter.js:265
PlaybackTime: float

Example

fb.PlaybackTime = 60; // Jumps to the 1 minute mark.
propertyreadonly

ProfilePath

js/foo_uie_jsplitter.js:273
ProfilePath: string
property

ReplaygainMode

js/foo_uie_jsplitter.js:279
ReplaygainMode: number

0 - None
1 - Track
2 - Album
3 - Track/Album by Playback Order (only available in foobar2000 v1.3.8 and later) See ReplayGainMode enum

property

StopAfterCurrent

js/foo_uie_jsplitter.js:290
StopAfterCurrent: boolean

Example

fb.StopAfterCurrent = !fb.StopAfterCurrent; // Toggles the current value.
propertyreadonly

Version

js/foo_uie_jsplitter.js:298
Version: string

Example

console.log(fb.Version)
// 1.4.1
property

Volume

js/foo_uie_jsplitter.js:308
Volume: float

Example

fb.Volume = 0; // Sets the volume to max. -100 is the minimum.
method

AcquireUiSelectionHolder

js/foo_uie_jsplitter.js:316
AcquireUiSelectionHolder()

Returns

FbUiSelectionHolder
method

AddDirectory

js/foo_uie_jsplitter.js:321
AddDirectory()
method

AddFiles

js/foo_uie_jsplitter.js:324
AddFiles()
method

AddLocationsAsync

js/foo_uie_jsplitter.js:327
AddLocationsAsync(locations)

Converts one or more paths to a list of metadb_handles.
The function returns immediately; specified callback on_locations_added receives results when the operation has completed.

Parameters

NameTypeDescription
locationsArray<string>

must be an array of strings and it can contain file paths, playlists or urls.

Returns

number

task id (see first parameter of on_locations_added)

Example

function on_mouse_lbtn_dblclk() {
    var files = ["z:\\1.mp3", "z:\\2.flac"];
    var task_id = fb.AddLocationsAsync(files);
    console.log("got task_id", task_id);
}

function on_locations_added(task_id, handle_list) {
    console.log("callback task_id", task_id);
    console.log(handle_list.Count);
}
method

CheckClipboardContents

js/foo_uie_jsplitter.js:347
CheckClipboardContents()

Checks Clipboard contents are handles or a file selection from Windows Explorer. Use in conjunction with fb.GetClipboardContents.

Returns

boolean
method

ClearPlaylist

js/foo_uie_jsplitter.js:355
ClearPlaylist()

Clears active playlist.
If you wish to clear a specific playlist, use plman.ClearPlaylist(playlistIndex).

method

CopyHandleListToClipboard

js/foo_uie_jsplitter.js:361
CopyHandleListToClipboard(handle_list)

Note: items can then be pasted in other playlist viewers or in Windows Explorer as files.

Parameters

NameTypeDescription
handle_listFbMetadbHandleList

Returns

boolean

Examples

<caption>Copy playlist items</caption>
let handle_list = plman.GetPlaylistSelectedItems(plman.ActivePlaylist);
fb.CopyHandleListToClipboard(handle_list);
<caption>Cut playlist items</caption>
let ap = plman.ActivePlaylist;
if (!plman.GetPlaylistLockedActions(ap).includes('RemoveItems')) {
   let handle_list = plman.GetPlaylistSelectedItems(ap);
   if (fb.CopyHandleListToClipboard(handle_list)) {
       plman.UndoBackup(ap);
       plman.RemovePlaylistSelection(ap);
   }
 }
method

CreateContextMenuManager

js/foo_uie_jsplitter.js:383
CreateContextMenuManager()

Returns

ContextMenuManager

Example source

methoddeprecated

CreateHandleList

js/foo_uie_jsplitter.js:390
CreateHandleList()
Deprecated.

Returns an empty handle list.
Deprecated: use FbMetadbHandleList constructor instead.

Returns

FbMetadbHandleList
method

CreateMainMenuManager

js/foo_uie_jsplitter.js:400
CreateMainMenuManager()

Returns

MainMenuManager

Example source

method

CreateProfiler

js/foo_uie_jsplitter.js:407
CreateProfiler(name)

Parameters

NameTypeDescription
name = ''optionalstring

Will be shown in console when used with Print method.

Returns

FbProfiler
method

DoDragDrop

js/foo_uie_jsplitter.js:413
DoDragDrop(window_id, handle_list, effect, options)

Invokes drag-n-drop operation (see https://docs.microsoft.com/en-us/windows/win32/api/ole2/nf-ole2-dodragdrop).

Quick tips:
- If you need only to drag from your panel with copy (i.e. without physically moving them): use only fb.DoDragDrop(handles, DROPEFFECT_COPY | DROPEFFECT_LINK).
- If you need only to receive drop to your panel with copy: handle on_drop_*() callbacks, while setting action.effect argument to (DROPEFFECT_COPY | DROPEFFECT_LINK).

Full drag-n-drop interface description:
- Drag-n-drop interface is based on Microsoft IDropSource and IDropTarget interfaces, so a lot of info (including examples) could be gathered from MSDN (IDropSource, IDropTarget, DoDragDrop, DROPEFFECT).
- Drag operation is started with DoDragDrop (whether it is called by your panel, or externally) with okEffects argument supplied.
- DoDragDrop blocks code execution until the drag operation is finished (callbacks will be called properly though). It returns effect from Action.Effect from on_drag_drop after completion.
- (Spider Monkey Panel specific) Drag operation is canceled when any mouse button is pressed.
- (Spider Monkey Panel specific) All mouse callbacks are suppressed during drag operation (including on_mouse_lbtn_up, but excluding on_mouse_mbtn_up and on_mouse_rbtn_up).
- Every drag callback receives Action argument. Action.Effect contains okEffects from DoDragDrop call. Action.Effect should be changed to the desired effect in the callback. If the returned Action.Effect was not in okEffects or is equal to DROPEFFECT_NONE (=== 0), then drop will be denied: cursor icon will be changed, on_drag_drop won't be called after releasing lmbtn, on_drag_leave will be called instead.
- DROPEFFECT_LINK should be used as fallback in case effect argument does not have DROPEFFECT_COPY (===1), since some external drops only allow DROPEFFECT_LINK effect.
- Changing effect on key modifiers is nice (to be in line with native Windows behaviour): see the example below.

Note: due to the asynchronous nature of event handling, fb.DoDragDrop() might exit before on_drag_drop callback is triggered when dropping data on the same panel as the one that had a call to fb.DoDragDrop().

Related callbacks: on_drag_enter, on_drag_drop, on_drag_over, on_drag_leave

Parameters

NameTypeDescription
window_idnumber

unused

handle_listFbMetadbHandleList
effectnumber

Allowed effects.

options = undefinedoptionalobject

Customization options for the data displayed in the drag window.

options.show_text = trueoptionalboolean

If true, will add track count text.

options.use_album_art = trueoptionalboolean

If true, will use album art of the focused item from dragged tracks (if available)

options.use_theming = trueoptionalboolean

If true, will use Windows drag window style. Album art and custom image are resized to fit when Windows style is active.

options.custom_image = undefinedoptionalGdiBitmap

(or D2DBitmap if window.DrawMode == 1). Custom dragging image. Will be also displayed if use_album_art is true, but there is no album art available.

Returns

number

Effect that was returned in on_drag_drop.

Example source

method

EnableAdvancedLogging

js/foo_uie_jsplitter.js:457
EnableAdvancedLogging()

For future development purposes (e.g. verbose console output)

method

EnumerateMainMenuCommands

js/foo_uie_jsplitter.js:464
EnumerateMainMenuCommands()

Returns all main menu items recursivley.
It is a JSON array in string form so you need to use JSON.parse on the result.
Every item of the array is object with the following properties:
Checked: boolean
Disabled: boolean
FullPath: string, the same full path you'd supply to fb.RunMainMenuCommand
HiddenByDefault: boolean
Radio: boolean
Type: string ("Fixed" or "Dynamic")
Visible: boolean

Returns

string

Example

const menuCommands = JSON.parse(fb.EnumerateMainMenuCommands());

// list all checked commands in the console
menuCommands
    .filter(command => command.Checked)
    .forEach(({ FullPath }) => console.log(FullPath));
method

Exit

js/foo_uie_jsplitter.js:454
Exit()
method

GetActiveDSPs

js/foo_uie_jsplitter.js:488
GetActiveDSPs()

Returns array of active DSPs names.

Returns

Array<string>
method

GetAudioChunk

js/foo_uie_jsplitter.js:495
GetAudioChunk(requested_length, offset)

Parameters

NameTypeDescription
requested_lengthnumber
offset = 0optionalnumber

Returns

FbAudioChunk

Example source

method

GetClipboardContents

js/foo_uie_jsplitter.js:504
GetClipboardContents(window_id)

Note: clipboard contents can be handles copied to the clipboard in other components, from fb.CopyHandleListToClipboard or a file selection, from Windows Explorer and etc.

Performance note: validate clipboard content with fb.CheckClipboardContents before calling this method.

Parameters

NameTypeDescription
window_id = 0optionalnumber

unused

Returns

FbMetadbHandleList

Example

function on_mouse_rbtn_up(x, y) {
   let ap = plman.ActivePlaylist;
   let menu = window.CreatePopupMenu();
   menu.AppendMenuItem(!plman.GetPlaylistLockedActions(ap).includes('AddItems') && fb.CheckClipboardContents() ? MF_STRING : MF_GRAYED, 1, "Paste"); // see Flags.js for MF_* definitions
   let idx = menu.TrackPopupMenu(x, y);
   if (idx == 1) {
       let handle_list  = fb.GetClipboardContents();
       plman.InsertPlaylistItems(ap, plman.PlaylistItemCount(ap), handle_list );
   }
   return true;
}
method

GetDSPPresets

js/foo_uie_jsplitter.js:528
GetDSPPresets()

Available only in foobar2000 v1.4 and above. Throws a script error on v1.3. *
Returns a JSON array in string form so you need to use JSON.parse() on the result.
Related methods: fb.SetDSPPreset.

Returns

string

Example

let str = fb.GetDSPPresets();
let arr = JSON.parse(str);
console.log(JSON.stringify(arr, null, 4));
// [
//     {
//         "active": false,
//         "name": "High Filter"
//     },
//     {
//         "active": true,
//         "name": "R128 Compressor"
//     },
//     {
//         "active": false,
//         "name": "7.1 upmix"
//     }
// ]
method

GetFocusItem

js/foo_uie_jsplitter.js:557
GetFocusItem(force)

Parameters

NameTypeDescription
force = trueoptionalboolean

When true, it will use the first item of the active playlist if it is unable to get the focus item.

Returns

FbMetadbHandle
method

GetLibraryItems

js/foo_uie_jsplitter.js:563
GetLibraryItems()

Returns all Media Library items as a handle list.

Returns

FbMetadbHandleList
method

GetLibraryRelativePath

js/foo_uie_jsplitter.js:570
GetLibraryRelativePath(handle)

Note: do not use this while looping through a handle list. Use GetLibraryRelativePaths instead.

Returns an empty string when used on track not in Media Library

Parameters

NameTypeDescription
handleFbMetadbHandle

Returns

string

Example

// The foobar2000 Media Library is configured to watch "D:\Music" and the
// path of the now playing item is "D:\Music\Albums\Artist\Some Album\Some Song.flac"
let handle = fb.GetNowPlaying();
console.log(fb.GetLibraryRelativePath(handle)); // Albums\Artist\Some Album\Some Song.flac*
method

GetNowPlaying

js/foo_uie_jsplitter.js:586
GetNowPlaying()

Get handle of the now playing track.

Returns

?FbMetadbHandle

null, if nothing is being played.

method

GetOutputDevices

js/foo_uie_jsplitter.js:593
GetOutputDevices()

Available only in foobar2000 v1.4 and above. Throws a script error on v1.3. *
Returns a JSON array in string form so you need to use JSON.parse() on the result.
Related methods: fb.SetOutputDevice.

Returns

string

Example

let str = fb.GetOutputDevices();
let arr = JSON.parse(str);
console.log(JSON.stringify(arr, null, 4));
// [
//     {
//         "active": false,
//         "device_id": "{5243F9AD-C84F-4723-8194-0788FC021BCC}",
//         "name": "Null Output",
//         "output_id": "{EEEB07DE-C2C8-44C2-985C-C85856D96DA1}"
//     },
//     {
//         "active": true,
//         "device_id": "{00000000-0000-0000-0000-000000000000}",
//         "name": "Primary Sound Driver",
//         "output_id": "{D41D2423-FBB0-4635-B233-7054F79814AB}"
//     },
//     {
//         "active": false,
//         "device_id": "{1C4EC038-97DB-48E7-9C9A-05FDED46847B}",
//         "name": "Speakers (Sound Blaster Z)",
//         "output_id": "{D41D2423-FBB0-4635-B233-7054F79814AB}"
//     },
//     {
//         "active": false,
//         "device_id": "{41B86272-3D6C-4A5A-8907-4FE7EBE39E7E}",
//         "name": "SPDIF-Out (Sound Blaster Z)",
//         "output_id": "{D41D2423-FBB0-4635-B233-7054F79814AB}"
//     },
//     {
//         "active": false,
//         "device_id": "{9CDC0FAE-2870-4AFA-8287-E86099D69076}",
//         "name": "3 - BenQ BL3200 (AMD High Definition Audio Device)",
//         "output_id": "{D41D2423-FBB0-4635-B233-7054F79814AB}"
//     }
// ]
// Normally, one item in the array has "active" set to true,
// indicating the currently configured output device.
// If the configured output device is unavailable, the array
// may contain no active item.
method

GetQueryItems

js/foo_uie_jsplitter.js:644
GetQueryItems(handle_list, query)

Note: use try/catch to handle invalid queries. An empty handle list will be returned if the query is valid but there are no results.

Parameters

NameTypeDescription
handle_listFbMetadbHandleList
querystring

Returns

FbMetadbHandleList

Unsorted results.

Examples

let a = fb.GetQueryItems(plman.GetPlaylistItems(plman.ActivePlaylist), "rating IS 5");
let b = fb.GetQueryItems(fb.GetLibraryItems(), "rating IS 5");
method

GetSelection

js/foo_uie_jsplitter.js:660
GetSelection()

Gets now playing or selected item according to settings in "File>Preferences>Display>Selection viewers".

Returns

?FbMetadbHandle
method

GetSelections

js/foo_uie_jsplitter.js:667
GetSelections(flags)

Works like fb.GetSelection, but returns a handle list.

Parameters

NameTypeDescription
flags = 0optionalnumber

1 - no now playing

Returns

FbMetadbHandleList
method

GetSelectionType

js/foo_uie_jsplitter.js:675
GetSelectionType()

Retrieves what the selection type is.

Returns

number

see SelectionType enum
0 - undefined (no item)
1 - active_playlist_selection
2 - caller_active_playlist
3 - playlist_manager
4 - now_playing
5 - keyboard_shortcut_list
6 - media_library_viewer

method

IsLibraryEnabled

js/foo_uie_jsplitter.js:689
IsLibraryEnabled()

Returns

boolean
method

IsLibraryInitialised

js/foo_uie_jsplitter.js:694
IsLibraryInitialised()

Returns true if the library has already been initialized by this time

Returns

boolean
method

IsMainMenuCommandChecked

js/foo_uie_jsplitter.js:701
IsMainMenuCommandChecked(command)

Performance note: don't use in on_paint.

Parameters

NameTypeDescription
commandstring

Path to main menu item

Returns

boolean

true, if the item is checked.

Example

fb.RunMainMenuCommand("Playback/Scrobble Tracks"); // available with foo_scrobble
method

IsMetadbInMediaLibrary

js/foo_uie_jsplitter.js:712
IsMetadbInMediaLibrary(handle)

Parameters

NameTypeDescription
handleFbMetadbHandle

Returns

boolean

Example

let np = fb.GetNowplaying();
console.log(fb.IsMetadbInMediaLibrary(np)); // If false, playing track is not in Media Library.
method

LoadPlaylist

js/foo_uie_jsplitter.js:722
LoadPlaylist()

Loads playlist from file. Equivalent to File>Load Playlist....

method

Next

js/foo_uie_jsplitter.js:729
Next()
method

Pause

js/foo_uie_jsplitter.js:732
Pause()
method

Play

js/foo_uie_jsplitter.js:735
Play()
method

PlayOrPause

js/foo_uie_jsplitter.js:738
PlayOrPause()
method

Prev

js/foo_uie_jsplitter.js:741
Prev()
method

Random

js/foo_uie_jsplitter.js:744
Random()
method

RegisterMainMenuCommand

js/foo_uie_jsplitter.js:747
RegisterMainMenuCommand(id, name, description)

Registers a main menu item that will be displayed under main menu > File > JSplitter > Script commands > {Current panel name}.
Being main menu item means you can bind it to global keyboard shortcuts, standard toolbar buttons, panel stack splitter buttons and etc.
Execution of the correspoding menu item will trigger on_main_menu_dynamic callback.

Note: JSplitter uses a combination of panel name and command id to identify and bind the command. Hence all corresponding binds will fail if the id or the panel name is changed. This also means that collision WILL occur if there are two panels with the same name.

Related methods: fb.UnregisterMainMenuCommand
Related callbacks: on_main_menu_dynamic

Parameters

NameTypeDescription
idnumber
namestring
description = ''optionalstring
method

Restart

js/foo_uie_jsplitter.js:764
Restart()
method

RunContextCommand

js/foo_uie_jsplitter.js:767
RunContextCommand(command, flags)

Shows context menu for currently played track.

Parameters

NameTypeDescription
commandstring
flags = 0optionalnumber

0 - default (depends on whether SHIFT key is pressed, flag_view_reduced or flag_view_full is selected)
4 - flag_view_reduced
8 - flag_view_full. This can be useful if you need to run context commands the user may have hidden using File>Preferences>Display>Context Menu

Returns

boolean

Example

fb.RunContextCommand("Properties");
method

RunContextCommandWithMetadb

js/foo_uie_jsplitter.js:783
RunContextCommandWithMetadb(command, handle_or_handle_list, flags)

Shows context menu for supplied tracks.

Parameters

NameTypeDescription
commandstring
handle_or_handle_listFbMetadbHandle|FbMetadbHandleList

Handles on which to apply context menu

flagsoptionalnumber

Same flags as fb.RunContextCommand

Returns

boolean
method

RunMainMenuCommand

js/foo_uie_jsplitter.js:793
RunMainMenuCommand(command)

Parameters

NameTypeDescription
commandstring

Returns

boolean

Example

fb.RunMainMenuCommand("File/Add Location...");
method

SavePlaylist

js/foo_uie_jsplitter.js:802
SavePlaylist()
method

SetDSPPreset

js/foo_uie_jsplitter.js:805
SetDSPPreset(idx)

Available only in foobar2000 v1.4 and above. Throws a script error on v1.3.

Related methods: fb.GetDSPPresets.

Parameters

NameTypeDescription
idxnumber

Example

let str = fb.GetDSPPresets();
let arr = JSON.parse(str);
let idx; // find the required DSP from `arr` and assign it to `idx`
fb.SetDSPPreset(idx);
method

SetOutputDevice

js/foo_uie_jsplitter.js:820
SetOutputDevice(output, device)

Available only in foobar2000 v1.4 and above. Throws a script error on v1.3.

Related methods: fb.GetOutputDevices.

Parameters

NameTypeDescription
outputstring
devicestring

Example

// To actually change device, you'll need the device_id and output_id
// and use them with fb.SetOutputDevice.
let str = fb.GetOutputDevices();
let arr = JSON.parse(str);
// Assuming same list from above, switch output to the last device.
fb.SetOutputDevice(arr[4].output_id, arr[4].device_id);
method

ShowConsole

js/foo_uie_jsplitter.js:838
ShowConsole(show)

Shows foobar2000 console window or close it (if show=false).

Parameters

NameTypeDescription
show = trueoptionalboolean
method

ShowLibrarySearchUI

js/foo_uie_jsplitter.js:845
ShowLibrarySearchUI(query)

Opens the Library>Search window populated with the query you set.

Parameters

NameTypeDescription
querystring
method

ShowPictureViewer

js/foo_uie_jsplitter.js:852
ShowPictureViewer(image_path)

Opens the image viewer built in to foobar2000 and shows image file specified by image_path

Parameters

NameTypeDescription
image_pathstring

path of image file

method

ShowPlaylistSearchUI

js/foo_uie_jsplitter.js:859
ShowPlaylistSearchUI()

Opens the "Playlist Search" window

method

ShowPopupMessage

js/foo_uie_jsplitter.js:864
ShowPopupMessage(message, title)

Parameters

NameTypeDescription
messagestring
title = 'JSplitter'optionalstring
method

ShowPreferences

js/foo_uie_jsplitter.js:870
ShowPreferences()
method

Stop

js/foo_uie_jsplitter.js:873
Stop()
method

TitleFormat

js/foo_uie_jsplitter.js:876
TitleFormat(expression)

Performance note: if you use the same query frequently, try caching FbTitleFormat object (by storing it somewhere), instead of creating it every time.

Parameters

NameTypeDescription
expressionstring

Returns

FbTitleFormat
method

UnregisterMainMenuCommand

js/foo_uie_jsplitter.js:886
UnregisterMainMenuCommand(id, name, description)

Unregisters a main menu item.

Related methods: fb.RegisterMainMenuCommand

Parameters

NameTypeDescription
idnumber
method

VolumeDown

js/foo_uie_jsplitter.js:895
VolumeDown()
method

VolumeMute

js/foo_uie_jsplitter.js:898
VolumeMute()
method

VolumeUp

js/foo_uie_jsplitter.js:901
VolumeUp()