Page 1 of 1

A-B Looper 2.0 [MM2+3]

Posted: Wed Nov 30, 2005 11:52 am
by trixmoto
This script loops a song from your selected point A to point B. There is an installer for this script on my website.

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

Posted: Fri Feb 10, 2006 11:32 am
by trixmoto
New version (1.1) allows you to use the player skip buttons to move onto the next track, keeping the same loop. Use the player's stop button to break out of the loop.

ABLooper.vbs

Code: Select all

Update above
ABLooper2.vbs

Code: Select all

No longer necessary
N.B. Pausing is fine - this will not break out of the loop.

error msg

Posted: Sat Mar 08, 2008 4:59 am
by grammalvsu
When I try to use this script--when I try to press any button in the A-B Looper pop-up--I get the error message
"Error happened during script execution: Unknown Name"

I'm using mediamonkey 3.

Any ideas anyone?

thanks!

Re: error msg

Posted: Sat Mar 08, 2008 5:09 am
by drjboulder
grammalvsu wrote:When I try to use this script--when I try to press any button in the A-B Looper pop-up--I get the error message
"Error happened during script execution: Unknown Name"

I'm using mediamonkey 3.

Any ideas anyone?

thanks!
Trix has not updated this for MM3, a list of his scripts that are compatible for MM3 is here.

Posted: Sun Mar 09, 2008 5:33 am
by trixmoto
It is on my list to update though! :)

Posted: Sun Mar 09, 2008 5:55 am
by drjboulder
trixmoto wrote:It is on my list to update though! :)
This "List" of yours...
How the heck do you manage it
and are you on the payroll yet?
:wink:

Posted: Sun Mar 09, 2008 6:01 am
by trixmoto
It's just a very long text file! No pay for me, just a few very kind donations which help to pay for my website. :)

Posted: Mon Apr 28, 2008 4:14 pm
by trixmoto
New version (2.0) is now available to download from my website. I have made it compatible with MM3 and combined the two script files into a single one. :)

Re: A-B Looper 2.0 [MM2+3]

Posted: Sun Jul 27, 2008 8:33 am
by Owyn
Trixmoto:

Thanks for the script.

Minor problem. I normally use Options->Skins->Font Size:Extra Large in MM3 and the default dialog box is too small to contain the text.

Minor as the form is re-sizable and it is easy enough to adjust the default rectangle size in the script. Would be more elegant to check the font settings but I can't see how to do that.

---------
Later.
Ummm. Some other problems with the script. Sometimes the loop has no audio. Printing off the script now to take a good look at it. Also the re-sizable attribute does not work. Switched to fontsize=large for testing.

-----

Code: Select all

Form.Common.SetRect 100, 100, (2*midp)+20, 170
Makes everything visible at Extra Large. Still not sure why "Form.Borderstyle = 3" does not work.

Still seeing intermittent problems with audio in loops. May work for 0 to a few loops then the audio either breaks up or dissapears. The mini freq response in the player stays active. No problems seen so far using the +/- 5/30sec buttons (which are very handy). Might be output plugin (mp3pro.dll) or it's settings specific. Need to do more testing.

Re: A-B Looper 2.0 [MM2+3]

Posted: Mon Jul 28, 2008 10:01 am
by Owyn
Still trying to get reliable looping.

Found minor error in script. Test for less than 1 second loop should be

Code: Select all

 If c < 1000 Then 
Added new button to test seeking to A outside of loop.

Code: Select all

  Dim Btn0 : Set Btn0 = SDB.UI.NewButton(Form)
  Btn0.Caption = "A"
  Btn0.Common.Height = bheight
  Btn0.Common.Width = bwidth
  Btn0.Common.Top = Btn3.Common.Top
  Btn0.Common.Left = Btn1.Common.Left - Btn0.Common.Width -10
  Btn0.UseScript = Script.ScriptPath
  Btn0.OnClickFunc = "seekA"

Code: Select all

Sub seekA (BtnBA)
  Dim BtnA : Set BtnA = BtnBA.Common.TopParent.Common.ChildControl("BtnA")
  Dim a : a = Mid(BtnA.Caption,3,Len(BtnA.Caption)-2)
  SDB.Player.PlaybackTime = CLng(a)
End Sub
Works fine. Think I will also add a "-1s" button. I tend to just miss the point I want to set the A/B marker. :o

Tried turning off all smooth options in the output plugin. No impact, except functions were now really clunky. Turned smooth back on.

Will test with other plugins / media formats (wma, aac, ...).

Re: A-B Looper 2.0 [MM2+3]

Posted: Mon Jul 28, 2008 1:39 pm
by Owyn
Ok. Problem seems specific to the mp3pro input plugin. Using the MM3 mp3 input plugin works fine.

Also tested with wma, m4a and flac without observed problems.

A-B Looper with MM 4.1.4.1709

Posted: Mon Aug 25, 2014 4:10 pm
by rhartwig
Hi,

maybe I am to dumb but how do I get the A-B Looper 2.0 script going?

I installed it and read the (old) forum topics. I restarted MM but I get no extra window with A-B controls (not even in the background).

Question: Is there a special key I have to press to start the script or something else I missed?

Thanks in advance
R

Re: A-B Looper with MM 4.1.4.1709

Posted: Tue Aug 26, 2014 5:01 am
by popsmike
Click Tools - Scripts - ABLooper.
set it with the A button for IN and the B button for OUT

Re: A-B Looper with MM 4.1.4.1709

Posted: Tue Aug 26, 2014 5:02 pm
by rhartwig
Ah.. thanks.. I never thought of searching there :)