Greetings lex_nasa
As there is at last ONE person interested by some code by itself, some updates after 2 years
Improved:
will work with more version of foobar (including 1.0.3) without code mods, just need to setup the location if not default
we can stay in Preferences or other confusing windows without hassle
New:
foosq must be started before foobar to remove some dependency about version
IR remote control, you need to learn code if remote control <> mac-mini
there is a fadout with a nice curve while playing with remote control: next, random and next/previous albums functions, then, volume 100%
pop up window cd cover on top where we like if needed, if folder.jpg in dirs
your nice volume code is not implemented, TBD
cheers
Marae
;============================== Start FooSQ AutoIt script V 2010.1.8p ==================================
; Author Marae ; May 2008 - July 2010
; !!!!!!! CAUTION !!!!!! The Squeeze Center volume is reverted to 100% for every song
; - Freeware - / Sources provided / Use / Modify / Transmit / And the usual statements about responsabilities (no ones)
; IF YOU TRANSMIT this code, add in your script: "; Idea by Marae" , Thank you
; Tested with Transporter Firmware: 62, SC 7.2, Ethernet cable with WinXP SP2 on Mac-Mini, Autoit v3.3.6.1 - Foobar 1.03 - AMIP 2.67
; FooSQ grab infos from Foobar window title, then send "cli" command to SqueezeCenter (SC).
; The time needed with my settings for adding a new song/bufferize in SC is 10 sec.
; If we guess the next song, and we enqueue it 10 sec. before the end of the current one, it's gapless.
; Then FooSQ look for normal transition (remaining time pass by 0) or skip.
; AMIP guess the next song
; To install:
; 0.- Install autoit ( [url=http://www.autoitscript.com/autoit3/downloads.shtml]http://www.autoitscript.com/autoit3/downloads.shtml[/url] )
; 1.- Check "custom variables" below and modify those if needed, compile this script using "Compile Script to .exe" in Autoit start menu
; 2.- Put %path%/%playback_time_remaining_seconds%/%ispaused%/ in Foobar pref. Default User Interface - Window title
; 3.- Install AMIP, then restart Foobar.
; in Foobar Pref, Tools, Amip, Enable Amip, enable "Write song info to file" then File: C:\nextsong.txt and $next(%fn) in "Play:" Field
; 4.- Start Foobar, play a song, verify you have "Full path file name/Remaining sec./?/ [foobar2000 ...]" in window title, and C:\nextsong.txt is the next song. Quit Foobar
; 5.- SC must be running, start FooSQ, foobar will start ... Press play on your favorite song, Enjoy
; Other Foobar settings:
; Enable "Playback follows cursor" on and also the opposite in Playback menu
; WARNING: "Resume playback after restarting ..." in Preference Playback is NOT possible without desynchro
; Seekbar move, Volume, and more then one squeezebox not implemented
;BUG:
; if you disable some IP connectivity (e.g wifi) and use for exemple "File open" in a previously remote enabled location,
; foobar will freeze, then foosq will stop
; with this code it's possible to use the mac-mini remote control = IR
; IR keys
; right -> next song
; left -> toggle default / shuffle tracks
; up -> skip up previous album in PL, play new album now
; down -> skip down next album in PL, play new album now
; Alt - up -> Same but wait for the end of the current song. All PL album up/down disabled before to play new song (difficult to guess cursor pos. , foobar cannot return cursor pos)
; Alt - down -> Same
; menu -> Alt code for 5 sec
; center -> random skip in PL
; to use another remote control, find the IR codes:
; Command Prompt: "telnet 127.0.0.1 9090" (default)
; "listen 1" + Return
; play with your remote control (do not use the slim device one !!), then replace in this script $m_ir_*
; for fade out on IR next etc, set SC options, Player, audio, Volume control adjust
; Cli ref : file:///C:/Program%20Files/SqueezeCenter/server/HTML/EN/html/docs/cli-api.html
; V 0.1 initial
; V 0.2 add IR
; V 2010.1.3 next / previous album skip with IR, fade out when some IR interruption
; V 2010.1.5 choice for next / previous album : play now or wait for the end of the current song
; V 2010.1.6 album cd cover art
; V 2010.1.8 remove dependency about foobar version:(works with foobar windows handle #), foobar is considered idle when foobar title begin with:
; "foobar2000", and end with a number. Now we can go to foobar preferences without hassle.
; WARNING: to be shure to get the correct handle #, foobar NEED be started with foosq (msgbox provided if foobar is running)
; In rare case, you may see some Autoit error messages or foosq stop, just restart foosq again, then press OK
; --------------------------------------- Code Start ---------------------------------------
#include
#include
#include
#include
#include
#include
#include
; ----------- MANDATORY custom variables to check -----------------
; foobar default command
$m_fooexe = "c:\program files\foobar2000\foobar2000.exe"
; AMIP file for gapless
$m_amip = "C:\nextsong.txt"
;SC ip & port, if you change the default setting
$m_ip = "127.0.0.1"
$m_port = 9090
; ----------- Optional custom variables -----------------
; IR codes for remote control
$m_ir_alt = "77e1c0ce"
$m_ir_next = "77e160ce"
$m_ir_random = "77e1a0ce"
$m_ir_toggle = "77e190ce"
$m_ir_pl_down = "77e130ce"
$m_ir_pl_up = "77e150ce"
; M3U playlist files for playing next/previous album in a PL with remote control; work only with mac mini remote control if you don't change IR code
; Works well if songs in PLs are sorted like x:\Artist\Album AND one song exists only in one PL
; dir where you export all your PLS in M3U format(right click on a tab, Save all playlists...)
$m_plsd = "C:\audio\pls.m3u"
; CLEAN sometime inside dir if some PLs not used anymore
; to disable $m_plsd = ""
; check are made if dir exists and some PLs in also
; ALWAYS ON TOP: cover cd album art popup window size
; to disable:
; $m_size = 0
$m_size = 300
; horizontal pos, ok for screen 1360x768
$m_aah = 1033
; vertical
$m_aav = 396
; name of file containing the cover cd image in each directory
$m_jpg = "folder.jpg"
; ----------- End of custom variables -----------------
; Somewhere always in foobar title bar
$m_foo = "foobar2000"
; Start The TCP Services
TCPStartUp()
; Match windows title substring
Opt("WinTitleMatchMode", 2)
;Attempt to connect to SC
$m_tcp = TCPConnect($m_ip,$m_port)
If @error Then
MsgBox(0, "FooSQ Warning", "SqueezeCenter not responding")
Exit
EndIf
; foobar running ?
$m_ok = WinActivate ($m_foo)
if $m_ok <> 0 Then
; quit it, so we are shure to get the correct handle #
$m_w = MsgBox(1,"FooSQ Warning","Not allowed, Start FooSQ first." & @CRLF & @CRLF & "Press OK and Foobar will restart after 5 sec." & @CRLF & @CRLF & "Press Cancel to quit FooSQ")
if $m_w = 2 Then
Exit
EndIf
Run($m_fooexe & " /quit")
sleep(5000)
TCPSend($m_tcp,"stop" & @CRLF & "playlist clear" & @CRLF)
Endif
; start it
Run($m_fooexe, "", @SW_MAXIMIZE)
WinActivate ($m_foo)
WinWaitActive ( $m_foo )
WinSetState ( $m_foo, "", @SW_MAXIMIZE )
; foobar handle #
$m_fooh = WinGetHandle( $m_foo )
;vol has been to 0 during fade out
$m_dec = 0
;File name played
$m_f = ""
;Remaining time
$m_r = "0"
; Status: 0 -> stop ; 1 -> playing; 2 -> paused
$m_s = "0"
; Is paused: ? -> playing; 1 -> paused
$m_p = "?"
; Transition: 0 -> normal (not skipped)
$m_t = ""
; Length of windows title
$m_l = "0"
; Next file name for gapless
$m_n = ""
; Next file name already enqueued -> 1
$m_ne = ""
; new file name
$m_fn = ""
;ir
$m_ir = ""
$m_irn = 0
;art
$m_ojpgf = ""
$m_handle = 0
$m_search = 0
; file to send to SB
$m_sq=""
; number of foobar cursor press for next/previous album
$m_out=1
; Alt key pressed on IR remote control
$m_alt=0
; time [ms] when timer start for Alt stuff
$m_stimer=0
; don't allow more then one Alt up/down in PL before play, as I don't know where is the cursor
$m_noal = 0
; TUNING
; loop timer in ms
$m_lt= 90
; fill an array with PLs file names
if $m_plsd <> "" Then
Dim $a_plf
$a_plf=_FileListToArray($m_plsd,"*.m3u", 1)
If @Error Then
; no PLs saved
$m_plsd = ""
Else
; size then fill an array which will contain the number of PL, then the full PL paths
Dim $a_pln[$a_plf[0]+1]
$a_pln[0]=$a_plf[0]
for $i = 1 to $a_plf[0]
$a_pln[$i] = $m_plsd & "\" & $a_plf[$i]
next
; read the content of the first PL file in array a_pl
Dim $a_pl
$m_pln=1
_FileReadToArray($a_pln[$m_pln],$a_pl)
Endif
Endif
; receive notification
TCPSend($m_tcp,"listen 1" & @CRLF)
; main loop
While 1
; get title
$m_title = WinGetTitle($m_fooh)
if $m_title = "0" Then
; no foobar anymore ?
Exit
EndIf
; check if foobar have stopped so there are $m_foo in the beginning of foobar title and a number to the end
If StringRegExp ( $m_title, "^" & $m_foo & ".*[0-9]$" ) Then
$m_idle = 1
Else
$m_idle = 0
Endif
If $m_idle = 0 Then
; find new infos after transition
$a_tn = StringSplit($m_title, "/")
$m_fn = $a_tn[1]
$m_r = $a_tn[2]
$m_p = $a_tn[3]
Endif
Select
Case $m_idle = 1 AND $m_s <> "0"
; go to stop and clear now playing
$m_s = "0"
TCPSend($m_tcp,"stop" & @CRLF & "playlist clear" & @CRLF)
Case $m_idle = 0 AND $m_s = "0"
; from stop to start
$m_s = "1"
$m_f = $m_fn
; SC needs / and %20 for space
$m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20")
if $m_dec = 1 Then
$m_dec = 0
TCPSend($m_tcp,"mixer volume " & "100" & @CRLF)
EndIf
TCPSend($m_tcp, "playlist play " & $m_sq & @CRLF)
f_art()
$m_noal = 0
; song change or pause while playing
Case $m_idle = 0 AND $m_s = "1"
; goto pause
if $m_p = "1" Then
$m_s = "2"
TCPSend($m_tcp,"pause 1" & @CRLF)
Else
;
if $m_f <> $m_fn Then
$m_sq = StringReplace(StringReplace($m_fn, "\", "/"), " ", "%20")
if $m_t = "0" Then
if $m_fn <> $m_n Then
; normal transition, not next song
if $m_dec = 1 Then
$m_dec = 0
TCPSend($m_tcp,"mixer volume " & "100" & @CRLF)
EndIf
TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF)
f_art()
$m_noal = 0
Else
f_art()
Endif
Else
; next song after skip, random button or click on another song
if $m_dec = 1 Then
$m_dec = 0
TCPSend($m_tcp,"mixer volume " & "100" & @CRLF)
EndIf
TCPSend($m_tcp,"playlist play " & $m_sq & @CRLF)
f_art()
$m_noal = 0
Endif
$m_t = ""
$m_ne = ""
Else
if $m_r = "11" OR $m_r = "10" Then
; enqueue next song ( when remain 11 or 10 sec if title is late)
if $m_ne = "" Then
$m_amips = FileOpen($m_amip, 0)
If $m_amips = -1 Then
MsgBox(0, "FooSQ Warning", "AMIP next song file not found, read intro")
Exit
EndIf
$m_n = FileReadLine($m_amip)
FileClose($m_amip)
$m_sq = StringReplace(StringReplace($m_n, "\", "/"), " ", "%20")
TCPSend($m_tcp,"playlist insert " & $m_sq & @CRLF)
$m_ne = "1"
Endif
Endif
if $m_r = "0" OR $m_r = "1" Then
;remaining time pass by 0 (or 1 if title is late)
$m_t = "0"
Endif
Endif
$m_f = $m_fn
EndIf
; continue after pause
Case $m_idle = 0 AND $m_s = "2"
if $m_p = "?" Then
$m_s = "1"
TCPSend($m_tcp, "pause 0" & @CRLF)
EndIf
EndSelect
; check if Alt IR timer play for more then 5 sec
if $m_alt = 1 Then
if TimerDiff($m_stimer) >= 5000 Then
$m_alt = 0
Endif
Endif
; receive IR code
$m_data = TCPRecv ( $m_tcp, 2048 )
$m_search= StringInStr ( $m_data, "unknownir",2)
Select
Case $m_search > 0 AND $m_irn = 0
; first IR code received, need to disable the next one.
$m_ir = StringMid($m_data, $m_search +10 , 8)
Select
Case $m_ir = $m_ir_alt
; Alt key pressed
$m_alt = 1
; start timer
$m_stimer = TimerInit()
$m_irn = 1
Case $m_ir = $m_ir_next
;next
f_vol_dec()
Run($m_fooexe & " /next")
$m_irn = 1
Case $m_ir = $m_ir_random
;random
f_vol_dec()
Run($m_fooexe & " /rand")
$m_irn = 1
Case $m_ir = $m_ir_toggle
;toggle shuffle - normal
$m_sh = ControlGetText($m_fooh, "", "ComboBox1")
if $m_sh = "Default" Then
Run($m_fooexe & ' /"command:Shuffle (tracks)"')
$m_irn = 1
Endif
if $m_sh = "Shuffle (tracks)" Then
Run($m_fooexe & " /command:Default")
$m_irn = 1
Endif
Case $m_ir = $m_ir_pl_down AND $m_noal = 0 AND $m_plsd <> ""
; next album down in pl
; search current pos
$m_pos = _ArraySearch($a_pl, $m_f, 0, 0, 1, 0)
If @error Then
$a_pl = 0
For $i = 1 to $a_pln[0]
_FileReadToArray($a_pln[$i],$a_pl)
$m_pos = _ArraySearch($a_pl, $m_f, 0, 0, 1, 0)
if @error = 0 Then
ExitLoop
Endif
Next
Endif
;find path
Dim $szDrive, $szDir, $szFName, $szExt
$a_path = _PathSplit($m_f, $szDrive, $szDir, $szFName, $szExt)
$m_path0 = $a_path[2]
For $i = $m_pos + 1 to $a_pl[0]
$a_path = _PathSplit($a_pl[$i], $szDrive, $szDir, $szFName, $szExt)
if $a_path[2] <> $m_path0 Then
$m_out = $i - $m_pos
ExitLoop
Endif
Next
WinActivate ( $m_fooh )
WinWaitActive ( $m_fooh )
For $i = 1 to $m_out
Send("{DOWN}")
Next
if $m_alt = 0 Then
f_vol_dec()
Send("{ENTER}")
Else
$m_alt = 0
$m_noal = 1
Endif
$m_irn = 1
Case $m_ir = $m_ir_pl_up AND $m_noal = 0 AND $m_plsd <> ""
;next album up in pl
; search current pos
$m_pos = _ArraySearch($a_pl, $m_f, 0, 0, 1, 0)
If @error Then
$a_pl = 0
For $i = 1 to $a_pln[0]
_FileReadToArray($a_pln[$i],$a_pl)
$m_pos = _ArraySearch($a_pl, $m_f, 0, 0, 1, 0)
if @error = 0 Then
ExitLoop
Endif
Next
Endif
;find path
Dim $szDrive, $szDir, $szFName, $szExt
$a_path = _PathSplit($m_f, $szDrive, $szDir, $szFName, $szExt)
$m_path0 = $a_path[2]
$m_reach = 0
For $i = $m_pos to 1 step -1
$a_path = _PathSplit($a_pl[$i], $szDrive, $szDir, $szFName, $szExt)
if $a_path[2] <> $m_path0 Then
if $m_reach = 0 Then
$m_reach = 1
$m_path0=$a_path[2]
Else
ExitLoop
Endif
Endif
Next
WinActivate ( $m_fooh )
WinWaitActive ( $m_fooh )
$m_out = $m_pos -$i -1
For $i = 1 to $m_out
Send("{UP}")
Next
if $m_alt = 0 Then
f_vol_dec()
Send("{ENTER}")
Else
$m_alt = 0
$m_noal = 1
Endif
$m_irn = 1
EndSelect
Case $m_search > 0 AND $m_irn = 1
$m_irn = 0
Case $m_search = 0 AND $m_irn = 1
$m_irn = 0
EndSelect
sleep($m_lt)
WEnd
Exit
Func f_vol_dec()
$a_fo = StringSplit("99.4,98.8,98.3,97.8,97.1,96,95,93.8,92,90,87,83,78,72,65,57,48,38,27,15,0", ",")
WinActivate ( $m_fooh )
WinWaitActive ( $m_fooh )
For $i = 1 to $a_fo[0]
TCPSend($m_tcp,"mixer volume " & $a_fo[$i] & @CRLF)
; fade out speed
sleep(170)
Next
$m_dec = 1
EndFunc
; Func create cd album cover art
Func f_art()
if $m_size <> 0 Then
; get path and find jpg
Dim $szDrive, $szDir, $szFName, $szExt
$a_path = _PathSplit($m_fn, $szDrive, $szDir, $szFName, $szExt)
$m_path = $a_path[2]
$m_drive = $a_path[1]
$m_jpgf = $m_drive & $m_path & $m_jpg
$m_search = FileFindFirstFile($m_jpgf)
FileClose($m_search)
If $m_search = -1 Then
; no art anymore
if $m_handle <> 0 Then
; previous art ?
GUIDelete($m_handle)
$m_handle = 0
EndIf
Else
; do it only for different art
if $m_ojpgf <> $m_jpgf Then
;get current active windows
$m_ahandle=_WinAPI_GetForegroundWindow()
if $m_handle <> 0 Then
; kill previous art
GUIDelete($m_handle)
EndIf
$m_handle=GUICreate("AA", $m_size, $m_size, $m_aah, $m_aav, BitOR($WS_POPUP, $WS_SIZEBOX),$WS_EX_TOOLWINDOW)
GUICtrlSetColor(-1,0xFFFFFD)
WinSetOnTop("AA", "", 1)
GUICtrlCreatePic($m_jpgf, 0, 0, $m_size, $m_size)
GUISetState ()
;restore previous active window
WinActivate ($m_ahandle)
WinWaitActive ($m_ahandle)
EndIf
EndIf
;remember the current art
$m_ojpgf = $m_jpgf
Endif
EndFunc
; ============================================= End of script =====================================