by Wim » Thu Nov 16, 2006 1:28 pm
Hi people,
I changed the script to avoid the timer problem. Seams to work

The original problem is still there (the hick up, no new info on that).
This script cycles through all pictures (album art) of the current song (if it has any) it always works in sequence (hence not renamed to AlbumArtShuffle).
Enjoy ...
Code: Select all
'-----------------------------OPEN-------------------------------------
Dim FSO : Set FSO=CreateObject("Scripting.FileSystemObject")
Dim SDB : Set SDB=CreateObject("SongsDB.SDBApplication")
While Not SDB.isRunning : WScript.Sleep 500 : Wend
'----------------------------------------------------------------------
Prepare
InstallScriptTo "Auto\CycleArtSetting.vbs" ,066, 141,"none"
InstallScriptTo "CycleArt.vbs" ,143, 246,_
"Script Successfully Installed!" &vbLf&_
"Go to " &vbLf&_
"Tools - Cycle Art" &vbLf&_
"to change the settings."
'------------------------------CLOSE-----------------------------------
SDB.ShutdownAfterDisconnect=True
Set FSO=Nothing : Set SDB=Nothing : Wscript.Quit
'%%%%%%%%%%%%%%%%% START OF SCRIPT INSTALLER %%%%%%%%%%%%%%%%%%
Sub InstallScriptTo(ScriptName, LineBegin, LineEnd, Message)
ScriptName=SDB.ApplicationPath & "Scripts\" & ScriptName
RenameOldScript(ScriptName)
Set TXT=FSO.OpenTextFile(WScript.ScriptFullName,1)
STR=TXT.ReadAll
TXT.Close
LNS=Split(STR,vbNewLine)
Set TXT=FSO.CreateTextFile(ScriptName, True)
For i=LineBegin-1 To LineEnd-1
TXT.WriteLine LNS(i)
Next
TXT.Close
If FSO.FileExists(ScriptName) And Message<>"none" Then _
SDB.MessageBox Message , 2, Array(4)
End Sub
Sub RenameOldScript(ScriptName)
If FSO.FileExists(ScriptName) Then _
FSO.MoveFile ScriptName, BakFile(ScriptName)
End Sub
Function BakFile(ScriptName)
Do
TMP=Left(ScriptName, Len(ScriptName)-3) & "old" & v
v=v+1
Loop While FSO.FileExists(TMP)
BakFile=TMP
End Function
Sub Prepare
RenameOldScript(SDB.ApplicationPath&"Scripts\CycleArt.vbs")
Set INI=SDB.Tools.IniFileByPath(SDB.ApplicationPath&"Scripts\Scripts.ini")
INI.StringValue("CycleArt","FileName")="CycleArt.vbs"
INI.StringValue("CycleArt","ProcName")="CycleArt"
INI.StringValue("CycleArt","Language")="VBScript"
INI.IntValue("CycleArt","ScriptType")=2
End Sub
'%%%%%%%%%%%%%%%%%% END OF SCRIPT INSTALLER %%%%%%%%%%%%%%%%%%%
'-------------------------------------------------------------------------------
' file to create a settings form for CycleArt
' Version 1.1
' date 16 nov 2006.
' Version 1.1 changed name from Rotate to Cycle
'-------------------------------------------------------------------------------
Sub OnStartup
MyScript = SDB.ApplicationPath & "scripts\CycleArt.vbs"
' setup menu values on tools
Set UI = SDB.UI
' Add a submenu to the Tools menu...
Set Mnu = UI.AddMenuItem( UI.Menu_Tools, -1, 1)
Mnu.Caption = "Cycle Art"
Mnu.Caption = "Cycle"
Mnu.OnClickFunc = "CycleNow"
Mnu.UseScript=MyScript
Mnu.IconIndex = 25
' and on the now playing popup.
Set Mnu = UI.AddMenuItem( UI.Menu_Pop_NP, -1, 1)
Mnu.Caption = "Cycle"
Mnu.OnClickFunc = "CycleNow"
Mnu.UseScript=MyScript
Mnu.IconIndex = 25
' Create our own option sheet
ind = SDB.UI.AddOptionSheet( "Cycle Art", Script.ScriptPath, "InitSheet", "SaveSheet", 0)
End Sub
Sub InitSheet( Sheet)
' Create a simple sheet with an edit line and a button
Set UI=SDB.UI
' checkbox want it ?
Set CbActive = UI.NewCheckBox(Sheet)
CbActive.Caption="Activate Cycle Art"
Cbactive.Common.ControlName = "cbActive"
Cbactive.Common.SetRect 50, 20, 200, 20
' Create a label on the form
Set Lbl = UI.NewLabel( Sheet)
Lbl.Common.SetRect 50, 40, 200, 20
Lbl.Caption = "Please set a value for the Cycle time (in seconds)"
' Create an edit line
Set Edt = UI.NewEdit( Sheet)
Edt.Common.SetRect 50, 60, 30, 20
Edt.Text = "40"
Edt.Common.ControlName = "tbTime"
' Retrieve already entered value from registry
Set Regs = SDB.Registry
If Regs.OpenKey( "Cycle Art", True) Then
If Regs.ValueExists( "RTime") Then
Edt.Text = Regs.StringValue( "RTime") / 1000
End If
If Regs.ValueExists( "Active") Then
CbActive.checked = Regs.StringValue( "Active")
End If
Regs.CloseKey
End If
End Sub
Sub SaveSheet( Sheet)
' Save entered value to registry in order to be able to shown it next time
Set Regs = SDB.Registry
Set Edt = Sheet.Common.ChildControl( "tbTime")
Set CbActive = Sheet.Common.ChildControl( "cbActive")
If IsNumeric(edt.text) Then
If Regs.OpenKey( "Cycle Art", True) Then
Regs.StringValue("RTime") = Edt.Text * 1000
Regs.StringValue( "Active") = CbActive.checked
Regs.CloseKey
End If
Else
SDB.MessageBox "Value '" & edt.text & "' is not a valid number'" , mtInformation, Array(mbOk)
End If
End Sub
'-------------------------------------------------------------------------------
' Script to Cycle the album art in mediamonkey
' Version 1.1
' date 16 nov 2006.
' Version 1.1 new setup, to get the timer right
' changed name from Rotate to Cycle
'-------------------------------------------------------------------------------
Sub OnStartup
CycleArt
End Sub
' Called from the menubars
Function CycleNow(Item)
If CanCycle Then
CycleArt
End If
End Function
Sub CycleArt
If CanCycle Then
StartTimer
End If
End Sub
Function CanCycle
CanCycle=true
' are all settings correct?
Set REG=SDB.Registry
If REG.OpenKey( "Cycle Art", True) Then
If REG.ValueExists( "Active") Then
CanCycle = REG.StringValue( "Active")
End If
End If
' pictures available
Set Sng=SDB.Player.CurrentSong
Set art=sng.AlbumArt
If art.count < 2 Then
CanCycle=false
End If
' don't cycle when stopped
If Not SDB.Player.isPlaying Then
CanCycle=false
End If
End Function
Sub StartTimer
Set REG=SDB.Registry
If REG.OpenKey("Cycle Art", True) Then
If REG.ValueExists( "RTime") Then
Rtime = REG.StringValue( "RTime")
Else
Rtime = 40000 ' Default is 40 seconds
End If
End If
Set Tmr = SDB.CreateTimer( Rtime ) ' Cycle in "Rtime" seconds
Script.RegisterEvent Tmr, "OnTimer", "TestTimer"
End Sub
Sub TestTimer( Timer)
' timer fired, do we still need it?
If canCycle Then
' yes, cycle picture
Cycle
Else
' no, stop the timer
Script.UnregisterEvents Timer ' Terminate usage of this timer
End If
End Sub
Sub Cycle
Dim MyPic
Dim ThisSong
Dim TmpPic
Set REG=SDB.Registry
If REG.OpenKey("Cycle Art", True) Then
ThisSong = REG.IntValue("CurrSong")
MyPic = REG.IntValue("LastPic")
End If
Set Sng=SDB.Player.CurrentSong
Set art=sng.AlbumArt
' set MyPic to 0 (first pic) when last pic, or new song
If ThisSong <> Sng.ID Then
MyPic = 0
Else
MyPic = MyPic + 1
End If
If MyPic >= art.count Then
MyPic = 0
End If
' if MyPic = 0, restarted, nothing to switch
If MyPic <> 0 Then
' the Cycle, change picture 0 with MyPic
Set tmppic = art.item(0)
Set art.item(0) = art.item(MyPic)
Set art.item(MyPic) = tmppic
art.UpdateDB
End If
' save the current state
REG.IntValue("CurrSong") = Sng.ID
REG.IntValue("LastPic") = MyPic
REG.CloseKey
End Sub
Hi people,
I changed the script to avoid the timer problem. Seams to work :)
The original problem is still there (the hick up, no new info on that).
This script cycles through all pictures (album art) of the current song (if it has any) it always works in sequence (hence not renamed to AlbumArtShuffle).
Enjoy ...
[code]
'-----------------------------OPEN-------------------------------------
Dim FSO : Set FSO=CreateObject("Scripting.FileSystemObject")
Dim SDB : Set SDB=CreateObject("SongsDB.SDBApplication")
While Not SDB.isRunning : WScript.Sleep 500 : Wend
'----------------------------------------------------------------------
Prepare
InstallScriptTo "Auto\CycleArtSetting.vbs" ,066, 141,"none"
InstallScriptTo "CycleArt.vbs" ,143, 246,_
"Script Successfully Installed!" &vbLf&_
"Go to " &vbLf&_
"Tools - Cycle Art" &vbLf&_
"to change the settings."
'------------------------------CLOSE-----------------------------------
SDB.ShutdownAfterDisconnect=True
Set FSO=Nothing : Set SDB=Nothing : Wscript.Quit
'%%%%%%%%%%%%%%%%% START OF SCRIPT INSTALLER %%%%%%%%%%%%%%%%%%
Sub InstallScriptTo(ScriptName, LineBegin, LineEnd, Message)
ScriptName=SDB.ApplicationPath & "Scripts\" & ScriptName
RenameOldScript(ScriptName)
Set TXT=FSO.OpenTextFile(WScript.ScriptFullName,1)
STR=TXT.ReadAll
TXT.Close
LNS=Split(STR,vbNewLine)
Set TXT=FSO.CreateTextFile(ScriptName, True)
For i=LineBegin-1 To LineEnd-1
TXT.WriteLine LNS(i)
Next
TXT.Close
If FSO.FileExists(ScriptName) And Message<>"none" Then _
SDB.MessageBox Message , 2, Array(4)
End Sub
Sub RenameOldScript(ScriptName)
If FSO.FileExists(ScriptName) Then _
FSO.MoveFile ScriptName, BakFile(ScriptName)
End Sub
Function BakFile(ScriptName)
Do
TMP=Left(ScriptName, Len(ScriptName)-3) & "old" & v
v=v+1
Loop While FSO.FileExists(TMP)
BakFile=TMP
End Function
Sub Prepare
RenameOldScript(SDB.ApplicationPath&"Scripts\CycleArt.vbs")
Set INI=SDB.Tools.IniFileByPath(SDB.ApplicationPath&"Scripts\Scripts.ini")
INI.StringValue("CycleArt","FileName")="CycleArt.vbs"
INI.StringValue("CycleArt","ProcName")="CycleArt"
INI.StringValue("CycleArt","Language")="VBScript"
INI.IntValue("CycleArt","ScriptType")=2
End Sub
'%%%%%%%%%%%%%%%%%% END OF SCRIPT INSTALLER %%%%%%%%%%%%%%%%%%%
'-------------------------------------------------------------------------------
' file to create a settings form for CycleArt
' Version 1.1
' date 16 nov 2006.
' Version 1.1 changed name from Rotate to Cycle
'-------------------------------------------------------------------------------
Sub OnStartup
MyScript = SDB.ApplicationPath & "scripts\CycleArt.vbs"
' setup menu values on tools
Set UI = SDB.UI
' Add a submenu to the Tools menu...
Set Mnu = UI.AddMenuItem( UI.Menu_Tools, -1, 1)
Mnu.Caption = "Cycle Art"
Mnu.Caption = "Cycle"
Mnu.OnClickFunc = "CycleNow"
Mnu.UseScript=MyScript
Mnu.IconIndex = 25
' and on the now playing popup.
Set Mnu = UI.AddMenuItem( UI.Menu_Pop_NP, -1, 1)
Mnu.Caption = "Cycle"
Mnu.OnClickFunc = "CycleNow"
Mnu.UseScript=MyScript
Mnu.IconIndex = 25
' Create our own option sheet
ind = SDB.UI.AddOptionSheet( "Cycle Art", Script.ScriptPath, "InitSheet", "SaveSheet", 0)
End Sub
Sub InitSheet( Sheet)
' Create a simple sheet with an edit line and a button
Set UI=SDB.UI
' checkbox want it ?
Set CbActive = UI.NewCheckBox(Sheet)
CbActive.Caption="Activate Cycle Art"
Cbactive.Common.ControlName = "cbActive"
Cbactive.Common.SetRect 50, 20, 200, 20
' Create a label on the form
Set Lbl = UI.NewLabel( Sheet)
Lbl.Common.SetRect 50, 40, 200, 20
Lbl.Caption = "Please set a value for the Cycle time (in seconds)"
' Create an edit line
Set Edt = UI.NewEdit( Sheet)
Edt.Common.SetRect 50, 60, 30, 20
Edt.Text = "40"
Edt.Common.ControlName = "tbTime"
' Retrieve already entered value from registry
Set Regs = SDB.Registry
If Regs.OpenKey( "Cycle Art", True) Then
If Regs.ValueExists( "RTime") Then
Edt.Text = Regs.StringValue( "RTime") / 1000
End If
If Regs.ValueExists( "Active") Then
CbActive.checked = Regs.StringValue( "Active")
End If
Regs.CloseKey
End If
End Sub
Sub SaveSheet( Sheet)
' Save entered value to registry in order to be able to shown it next time
Set Regs = SDB.Registry
Set Edt = Sheet.Common.ChildControl( "tbTime")
Set CbActive = Sheet.Common.ChildControl( "cbActive")
If IsNumeric(edt.text) Then
If Regs.OpenKey( "Cycle Art", True) Then
Regs.StringValue("RTime") = Edt.Text * 1000
Regs.StringValue( "Active") = CbActive.checked
Regs.CloseKey
End If
Else
SDB.MessageBox "Value '" & edt.text & "' is not a valid number'" , mtInformation, Array(mbOk)
End If
End Sub
'-------------------------------------------------------------------------------
' Script to Cycle the album art in mediamonkey
' Version 1.1
' date 16 nov 2006.
' Version 1.1 new setup, to get the timer right
' changed name from Rotate to Cycle
'-------------------------------------------------------------------------------
Sub OnStartup
CycleArt
End Sub
' Called from the menubars
Function CycleNow(Item)
If CanCycle Then
CycleArt
End If
End Function
Sub CycleArt
If CanCycle Then
StartTimer
End If
End Sub
Function CanCycle
CanCycle=true
' are all settings correct?
Set REG=SDB.Registry
If REG.OpenKey( "Cycle Art", True) Then
If REG.ValueExists( "Active") Then
CanCycle = REG.StringValue( "Active")
End If
End If
' pictures available
Set Sng=SDB.Player.CurrentSong
Set art=sng.AlbumArt
If art.count < 2 Then
CanCycle=false
End If
' don't cycle when stopped
If Not SDB.Player.isPlaying Then
CanCycle=false
End If
End Function
Sub StartTimer
Set REG=SDB.Registry
If REG.OpenKey("Cycle Art", True) Then
If REG.ValueExists( "RTime") Then
Rtime = REG.StringValue( "RTime")
Else
Rtime = 40000 ' Default is 40 seconds
End If
End If
Set Tmr = SDB.CreateTimer( Rtime ) ' Cycle in "Rtime" seconds
Script.RegisterEvent Tmr, "OnTimer", "TestTimer"
End Sub
Sub TestTimer( Timer)
' timer fired, do we still need it?
If canCycle Then
' yes, cycle picture
Cycle
Else
' no, stop the timer
Script.UnregisterEvents Timer ' Terminate usage of this timer
End If
End Sub
Sub Cycle
Dim MyPic
Dim ThisSong
Dim TmpPic
Set REG=SDB.Registry
If REG.OpenKey("Cycle Art", True) Then
ThisSong = REG.IntValue("CurrSong")
MyPic = REG.IntValue("LastPic")
End If
Set Sng=SDB.Player.CurrentSong
Set art=sng.AlbumArt
' set MyPic to 0 (first pic) when last pic, or new song
If ThisSong <> Sng.ID Then
MyPic = 0
Else
MyPic = MyPic + 1
End If
If MyPic >= art.count Then
MyPic = 0
End If
' if MyPic = 0, restarted, nothing to switch
If MyPic <> 0 Then
' the Cycle, change picture 0 with MyPic
Set tmppic = art.item(0)
Set art.item(0) = art.item(MyPic)
Set art.item(MyPic) = tmppic
art.UpdateDB
End If
' save the current state
REG.IntValue("CurrSong") = Sng.ID
REG.IntValue("LastPic") = MyPic
REG.CloseKey
End Sub
[/code]