Code: Select all
'
' MediaMonkey Script
'
' NAME: ABLooper 2.0
'
' AUTHOR: trixmoto (http://trixmoto.net)
' DATE : 28/04/2008
'
' INSTALL: Copy to Scripts directory and add the following to Scripts.ini
' Don't forget to remove comments (') and set the order appropriately
'
' FIXES: Made compatible with MM3
'
' [ABLooper]
' FileName=ABLooper.vbs
' ProcName=ABLooper
' Order=11
' DisplayName=&ABLooper
' Description=Set current track looping A to B
' Language=VBScript
' ScriptType=0
'
Option Explicit
Sub ABLooper
Dim song : Set song = SDB.Player.CurrentSong
If song Is Nothing Then
Call SDB.MessageBox("ABLooper: You must be playing a song for it to be looped.",mtError,Array(mbOk))
End If
If Not (SDB.Player.isPaused) Then
SDB.Player.Pause
End If
Dim midp : midp = 165
Dim bheight : bheight = 23
Dim bwidth : bwidth = 35
Dim Form : Set Form = SDB.UI.NewForm
Form.Common.SetRect 100, 100, (2*midp)+20, 155
Form.BorderStyle = 3 ' Resizable
Form.FormPosition = 4 ' Screen Center
Form.Caption = "A-B Looper"
Dim Label2 : Set Label2 = SDB.UI.NewLabel(Form)
Label2.Caption = "Title: "&song.Title
Label2.Common.Left = 10
Label2.Common.Top = 14
Dim Label1 : Set Label1 = SDB.UI.NewLabel(Form)
Label1.Caption = "Artist: "&song.ArtistName
Label1.Common.Left = Label2.Common.Left
Label1.Common.Top = Label2.Common.Top + Label2.Common.Height +10
Dim Btn3 : Set Btn3 = SDB.UI.NewButton(Form)
Btn3.Caption = "&Play"
Btn3.Common.Height = bheight
Btn3.Common.Width = bwidth+15
Btn3.Common.Top = Label1.Common.Top + Label1.Common.Height +10
Btn3.Common.Left = midp - (Btn3.Common.Width/2)
Btn3.UseScript = Script.ScriptPath
Btn3.OnClickFunc = "playPause"
Btn3.Default = True
Dim Btn2 : Set Btn2 = SDB.UI.NewButton(Form)
Btn2.Caption = "-5s"
Btn2.Common.Height = bheight
Btn2.Common.Width = bwidth
Btn2.Common.Top = Btn3.Common.Top
Btn2.Common.Left = midp - (Btn3.Common.Width/2) - Btn2.COmmon.Width -10
Btn2.UseScript = Script.ScriptPath
Btn2.OnClickFunc = "seekB05"
Dim Btn1 : Set Btn1 = SDB.UI.NewButton(Form)
Btn1.Caption = "-30s"
Btn1.Common.Height = bheight
Btn1.Common.Width = bwidth
Btn1.Common.Top = Btn3.Common.Top
Btn1.Common.Left = midp - (Btn3.Common.Width/2) - Btn2.COmmon.Width - Btn1.Common.Width -20
Btn1.UseScript = Script.ScriptPath
Btn1.OnClickFunc = "seekB30"
Dim Btn4 : Set Btn4 = SDB.UI.NewButton(Form)
Btn4.Caption = "+5s"
Btn4.Common.Height = bheight
Btn4.Common.Width = bwidth
Btn4.Common.Top = Btn3.Common.Top
Btn4.Common.Left = midp + (Btn3.Common.Width/2) +10
Btn4.UseScript = Script.ScriptPath
Btn4.OnClickFunc = "seekF05"
Dim Btn5 : Set Btn5 = SDB.UI.NewButton(Form)
Btn5.Caption = "+30s"
Btn5.Common.Height = bheight
Btn5.Common.Width = bwidth
Btn5.Common.Top = Btn3.Common.Top
Btn5.Common.Left = midp + (Btn3.Common.Width/2) + Btn4.Common.Width +20
Btn5.UseScript = Script.ScriptPath
Btn5.OnClickFunc = "seekF30"
Dim BtnC : Set BtnC = SDB.UI.NewButton(Form)
BtnC.Caption = "Loop ("&Int(SDB.Player.CurrentSongLength/1000)&"s)"
BtnC.Common.Height = bheight
BtnC.Common.Width = 100
BtnC.Common.Top = Btn3.Common.Top + Btn3.Common.Height +10
BtnC.Common.Left = midp - (BtnC.Common.Width/2)
BtnC.Common.ControlName = "BtnC"
BtnC.UseScript = Script.ScriptPath
BtnC.ModalResult = 1
Dim BtnA : Set BtnA = SDB.UI.NewButton(Form)
BtnA.Caption = "A=0"
BtnA.Common.Height = bheight
BtnA.Common.Width = 100
BtnA.Common.Top = BtnC.Common.Top
BtnA.Common.Left = midp - (BtnC.Common.Width/2) - BtnA.Common.Width -10
BtnA.Common.ControlName = "BtnA"
BtnA.UseScript = Script.ScriptPath
BtnA.OnClickFunc = "setA"
Dim BtnB : Set BtnB = SDB.UI.NewButton(Form)
BtnB.Caption = "B="&SDB.Player.CurrentSongLength
BtnB.Common.Height = bheight
BtnB.Common.Width = 100
BtnB.Common.Left = midp + (BtnC.Common.Width/2) +10
BtnB.Common.Top = BtnC.Common.Top
BtnB.Common.ControlName = "BtnB"
BtnB.UseScript = Script.ScriptPath
BtnB.OnClickFunc = "setB"
If Form.showModal = 1 Then
Dim b : b = Mid(BtnB.Caption,3,Len(BtnB.Caption)-2)
Dim a : a = Mid(BtnA.Caption,3,Len(BtnA.Caption)-2)
Dim c : c = CLng(b)-CLng(a)
If c < 1 Then
Call SDB.MessageBox("ABLooper: [A] must be at least one second before [B].",mtError,Array(mbOk))
Else
Call SDB.MessageBox("ABLooper: To break out of the loop click stop on the player. Clicking 'Ok' will start the loop.",mtInformation,Array(mbOk))
Dim data : Set data = CreateObject("Scripting.Dictionary")
data.Item("a") = a
data.Item("b") = b
data.Item("i") = song.ID
Set SDB.Objects("ABLooperData") = data
SDB.Player.Play
If SDB.VersionHi > 2 Then
While SDB.Player.IsStartingPlayback
SDB.ProcessMessages
WEnd
End If
SDB.Player.PlaybackTime = CLng(a)
Dim tmr : Set tmr = SDB.CreateTimer(100)
Set SDB.Objects("ABLooperTimer") = tmr
Call Script.RegisterEvent(tmr,"OnTimer","theLoop")
End If
End If
End Sub
Sub theLoop(tmr)
Dim mess : mess = ""
Dim data : Set data = SDB.Objects("ABLooperData")
If data Is Nothing Then
mess = "no data"
Else
If Not SDB.Player.isPlaying Then
mess = "player stopped"
Else
If SDB.Player.CurrentSong.ID <> CLng(data.Item("i")) Then
mess = SDB.Player.CurrentSong.ID&" <> "&data.Item("i")
End If
End If
End If
'loop or exit
If mess = "" Then
Dim a : a = CLng(data.Item("a"))
Dim b : b = CLng(data.Item("b"))
If SDB.Player.PlaybackTime > b Then
SDB.Player.PlaybackTime = a
Else
If SDB.Player.PlaybackTime < a Then
SDB.Player.PlaybackTime = a
End If
End If
Else
Call Script.UnregisterEvents(tmr)
Set SDB.Objects("ABLooperTimer") = Nothing
Set SDB.Objects("ABLooperData") = Nothing
End If
End Sub
Sub playPause (ClickedBtn)
If SDB.Player.isPaused Then
ClickedBtn.Caption = "&Pause"
Else
ClickedBtn.Caption = "&Play"
End If
SDB.Player.Pause
End Sub
Sub seekB30 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime - 30000
End Sub
Sub seekB05 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime - 5000
End Sub
Sub seekF05 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime + 5000
End Sub
Sub seekF30 (ClickedBtn)
SDB.Player.PlaybackTime = SDB.Player.PlaybackTime + 30000
End Sub
Sub setA (BtnA)
Dim a : a = SDB.Player.PlaybackTime
BtnA.Caption = "A="&a
Dim BtnB : Set BtnB = BtnA.Common.TopParent.Common.ChildControl("BtnB")
Dim b : b = Mid(BtnB.Caption,3,Len(BtnB.Caption)-2)
Dim c : c = CLng(b)-CLng(a)
Dim BtnC : Set BtnC = BtnA.Common.TopParent.Common.ChildControl("BtnC")
BtnC.Caption = "Loop ("&Int(c/1000)&"s)"
End Sub
Sub setB (BtnB)
Dim b : b = SDB.Player.PlaybackTime
BtnB.Caption = "B="&b
Dim BtnA : Set BtnA = BtnB.Common.TopParent.Common.ChildControl("BtnA")
Dim a : a = Mid(BtnA.Caption,3,Len(BtnA.Caption)-2)
Dim c : c = Clng(b)-Clng(a)
Dim BtnC : Set BtnC = BtnB.Common.TopParent.Common.ChildControl("BtnC")
BtnC.Caption = "Loop ("&Int(c/1000)&"s)"
End Sub
Sub Install()
Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
If Not (inif Is Nothing) Then
inif.StringValue("ABLooper","Filename") = "ABLooper.vbs"
inif.StringValue("ABLooper","Procname") = "ABLooper"
inif.StringValue("ABLooper","Order") = "11"
inif.StringValue("ABLooper","DisplayName") = "&ABLooper"
inif.StringValue("ABLooper","Description") = "Set current track looping A to B"
inif.StringValue("ABLooper","Language") = "VBScript"
inif.StringValue("ABLooper","ScriptType") = "0"
SDB.RefreshScriptItems
End If
End Sub