' (c) Alexey V. Vasilyev. St.Peterburg. Russia. 2008. ' avasilyev на домене sigmalab.ru ' ' Simple remote control for Foobar2000 / COM ' ' Requirements: ' COM server for Foobar http://wiki.hydrogenaudio.org/index.php?title=Foobar2000:Components_0.9/COM_Automation_Server_%28foo_comserver2%29#Documentation ' ' Also: ' You can exdend this script via command line: http://wiki.foobar2000.ru/foobar2000/commandline ' use method DoCommand() ' ' Licence: GPL ' 'Global variables Const brcActivate = 1, brcBegin = 2, brcBack = 3 , brcNext = 4, brcKeyPress = 5 Const brcKeyRelease = 6, brcIntegerInput = 7, brcTextInput = 8, brcTimer = 9, brcOutOfRange = 12 const btnStop = 1, btnPlay = 2, btnPause = 3 dim orderShuffle: orderShuffle = "Shuffle (tracks)" dim orderDefault: orderDefault = "Default" dim txtSep: txtSep = "-----------------------" + vbCrLf dim foobarexe: foobarexe = """%programfiles%\foobar2000\foobar2000.exe""" ' system objects dim fb2k dim playback dim settings On Error resume Next 'entry point main '************************* Functions ************************** sub main() CreatePlayback() '1. Detect which action that we have received select case BRCD.Action case brcActivate: case brcBegin 'Add timer object to detect changes done on PC BRC.startTimer(1000) case brcBack: BRC.UnLoad() exit sub case brcKeyPress KeyPress case else end select '2. Update display update end sub sub KeyPress() select case BRCD.Key case "f", "5": playback.Pause() case "<", "4": playback.Previous() case ">", "6": playback.Next() case "^", "2": settings.Volume = settings.Volume + 2 case "v", "8": settings.Volume = settings.Volume - 2 case "1" if playback.CanSeek then playback.SeekRelative( -30 ) case "3": if playback.CanSeek then playback.SeekRelative( 30 ) case "7": if settings.ActivePlaybackOrder <> orderShuffle then settings.ActivePlaybackOrder = orderShuffle else settings.ActivePlaybackOrder = orderDefault end if case "*": showHelp case else end select end sub sub update() dim text if playback.IsPlaying then BRC.go_Button = btnPause else BRC.go_Button = btnPlay end if 'Do not reflect the correct position only for a nicer UI BRC.go_Duration = playback.Length BRC.go_PlayerPostion = playback.Position dim name: name = playback.FormatTitle( "[$trim(%album artist%) - ]['[$trim(%album%)[ CD%discnumber%][ #%tracknumber%]]' ]%title%[ '//' %track artist%]" ) dim vol: vol = CStr(CInt(settings.Volume)) dim volbar: volbar = GetVolumeBar(vol) 'Construct a string with modifiers for UI control text = " Foobar 2000" + vbCrLf+ _ txtSep + _ " Order: " + settings.ActivePlaybackOrder + vbCrLf+ _ " Volume: " + vol + " <" + volbar + ">"+ vbCrLf+ _ txtSep + _ "" + name BRC.DisplayDialog text end sub function GetVolumeBar(vol) barsize=15 range=50.0 dim volbar size=(vol+range)/range * barsize if size < 0 then size = 0.0 volbar = StrDup( size , "|") + StrDup( barsize-size , " ") GetVolumeBar = volbar end function sub showHelp() dim help help = "1/3: Rewind/Forward" + vbCrLf + _ "2/8: Volume +/-" + vbCrLf + _ "5/OK: Play/Pause" + vbCrLf + _ "4/6: Previous/Next" + vbCrLf + _ "*: this Help" + vbCrLf + _ "7: Change play order" + vbCrLf + _ txtSep BRC.DisplayDialog help 'can error at here, but 'on error result next' makes pause for displaying Set objShell = CreateObject("WScript.Shell") WScript.Sleep 2000 end sub sub showOrders() dim orders set orders = settings.PlaybackOrders for idx=0 to orders.count-1 BRC.Debug orders.Item( idx ) next end sub ' ' another Foobar integration via command line. reserved for unsupported by COM server functions ' sub doCommand( command ) set wsh = CreateObject( "WScript.Shell" ) cmd = foobarexe + " /" + command BRC.Debug cmd wsh.Run(cmd ) end sub Sub CreatePlayback() dim ProgID ProgID = "Foobar2000.Application.0.7" 'BRC.Debug "Looking for existing instance..." set fb2k = CreateObject(ProgID ) if isnull(fb2k) then BRC.Debug "Failed to get foobar2000 Application object." end if set playback = fb2k.Playback if isnull(playback) then BRC.Debug "Failed to get playback." end if set settings = playback.Settings end sub Function StrDup(count, sample) Dim result Dim I result = "" For I = 1 To count result = result + sample Next StrDup = result 'return End Function