Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ' This file can be replaced in one of the future versions,
- ' so please if you want to modify it, make a copy, do your
- ' modifications in that copy and change Scripts.ini file
- ' appropriately.
- ' If you do not do this, you will lose all your changes in
- ' this script when you install a new version of MediaMonkey
- ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- ' Modified by Bex 2008-06-01
- ' Version 1.5
- ' - Added Reset Counter on Album Change
- ' Version 1.4
- ' - Added Add or Remove DiscNr
- ' Version 1.2
- ' - Fixed Access Violation Error
- ' Version 1.1
- ' - Added leading Zero Functionality
- ' - Added ShortCut CTRL+1
- ' This script fills in track #s incrementally
- Sub AutoIncTracknrModify
- ' Define variables
- Dim list, itm, i, tmp
- ' Get list of selected tracks from MediaMonkey
- Set list = SDB.CurrentSongList
- If list.Count=0 Then
- Exit Sub
- End If
- Set UI = SDB.UI
- ' Create the window to be shown
- Set Form = UI.NewForm
- Form.Common.SetRect 0, 0, 410, 240
- Form.FormPosition = 4 ' Screen Center
- Form.BorderStyle = 3 ' Dialog
- Form.Caption = SDB.Localize("Auto-increment Track #s")
- Set Lbl = UI.NewLabel( Form)
- Lbl.Common.SetRect 10,15,370,40
- Lbl.AutoSize = False
- Lbl.Multiline = True
- Lbl.Caption = SDB.LocalizedFormat( "This will modify the track# field in sequential order for the %d selected tracks. Do you want to proceed?", list.Count, 0, 0) ' TODO: Localize
- Set Lbl = UI.NewLabel( Form)
- Lbl.Common.SetRect 10,65,280,20
- Lbl.Caption = SDB.Localize("Start numbering from:")
- Set SE = UI.NewSpinEdit( Form)
- SE.Common.SetRect Lbl.Common.Left+Lbl.Common.Width+10, 61, 50, 20
- SE.MinValue = 1
- SE.MaxValue = 9999
- SE.Value = 1
- Set Lb2 = UI.NewLabel( Form)
- Lb2.Common.SetRect 260,65,280,20
- Lb2.Caption = SDB.Localize("Add Disc#:")
- Set Edt = UI.NewEdit( Form)
- Edt.Common.SetRect 320,62,30,20
- Script.RegisterEvent Edt, "OnChange", "EditDiscnr"
- Set Cbx3 = UI.NewCheckBox( Form)
- Cbx3.Common.ControlName = "Cbx3"
- Cbx3.Caption = "Remove existing Disc#"
- Cbx3.Common.SetRect 260,85,280,20
- Cbx3.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","RemoveDiscnr")
- Set Cbx1 = UI.NewCheckBox( Form)
- Cbx1.Caption = "Add leading zero to Track#'s"
- Cbx1.Common.SetRect 10,85,200,20
- Cbx1.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero")
- Script.RegisterEvent Cbx1.Common, "OnClick", "ClickCbX1"
- Set Cbx2 = UI.NewCheckBox( Form)
- Cbx2.Common.ControlName = "Cbx2"
- Cbx2.Caption = "Only if 10 tracks or more are selected"
- Cbx2.Common.SetRect 25,102,280,20
- Cbx2.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","OnlyIfTenOrMore")
- Cbx2.Common.Enabled = SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero")
- Set Cbx4 = UI.NewCheckBox( Form)
- Cbx4.Common.ControlName = "Cbx3"
- Cbx4.Caption = "Reset Counter on AlbumChange"
- Cbx4.Common.SetRect 115,145,200,20
- Cbx4.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","ResetCounter")
- '---------------------------------------------------------------------------
- Set Btn = UI.NewButton( Form)
- Btn.Caption = SDB.Localize("&OK")
- Btn.Common.SetRect 110,170,75,25
- Btn.ModalResult = 1
- Btn.Default = true
- Set Btn = UI.NewButton( Form)
- Btn.Caption = SDB.Localize("&Cancel")
- Btn.Common.SetRect 220,170,75,25
- Btn.ModalResult = 2
- Btn.Cancel = true
- If Form.ShowModal=1 then
- SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero") =Cbx1.Checked
- SDB.IniFile.BoolValue("AutoIncTrackN","OnlyIfTenOrMore")=Cbx2.Checked
- SDB.IniFile.BoolValue("AutoIncTrackN","RemoveDiscnr") =Cbx3.Checked
- SDB.IniFile.BoolValue("AutoIncTrackN","ResetCounter") =Cbx4.Checked
- AddLeadZero =Cbx1.Checked
- OnlyIfTenOrMore =Cbx2.Checked
- RemoveDiscnr =Cbx3.Checked
- ResetOnAlbumChange=Cbx4.Checked
- number =SE.Value
- '--------------------------------------
- dim t(2),tme : t(0) = Timer()
- For i=0 To list.count-1
- trackcnt=trackcnt+1
- 'msgbox trackcnt
- If ResetOnAlbumChange Then CurAlbID=list.item(i).Album.ID
- If (trackcnt>1 And ResetOnAlbumChange And CurAlbID<>PrevAlbID) Then
- value=value & trackcnt-1 &" "
- trackcnt=1
- End If
- If i=list.count-1 Then
- value=value & trackcnt &" "
- End If
- If ResetOnAlbumChange Then PrevAlbID=CurAlbID
- Next
- t(1) = Timer()
- tme = "After first loop: " &FormatNumber(Round(t(1)-t(0),3),3) & VbNewLine
- 'msgbox value : exit sub
- a = Split(trim(value))
- For i=0 To Ubound(a)
- trackcnt=a(i)
- strt=0+stp
- stp =stp+trackcnt-1
- If AddLeadZero Then
- If Len(number+trackcnt)<3 Then
- Maxlength = 3
- Else
- Maxlength = Len(number+trackcnt)
- End If
- If OnlyIfTenOrMore Then
- Maxlength = Len(number+trackcnt-1)
- End If
- End If
- For j=strt To stp
- Set itm = list.Item(j)
- ' Swap the fields
- If Not Trim(Edt.Text)="" Then
- itm.DiscNumberStr = Edt.Text
- End If
- If RemoveDiscnr And Cbx3.common.Enabled Then
- itm.DiscNumberStr = ""
- End If
- itm.TrackOrderStr = LeftPadNr(number,Maxlength)
- number = number + 1
- Next
- stp=stp+1
- number=SE.Value
- Next
- t(2) = Timer()
- tme = tme & "After last loop: " &FormatNumber(Round(t(2)-t(1),3),3) & VbNewLine
- 'msgbox tme
- list.UpdateAll
- End If
- Script.UnregisterEvents Cbx1.Common
- Script.UnregisterEvents Edt
- End Sub
- Sub EditDiscnr(Edt)
- Set ECTC = Edt.Common.TopParent.Common
- If Not Trim(Edt.Text)="" Then Enabled=False Else Enabled=True
- ECTC.ChildControl("Cbx3").Common.Enabled = Enabled
- Set ECTC = Nothing
- End Sub
- Sub ClickCbX1(Cbx)
- Set CCTC = Cbx.Common.TopParent.Common
- CCTC.ChildControl("Cbx2").Common.Enabled = Cbx.Checked
- If Not Cbx.Checked Then CCTC.ChildControl("Cbx2").Checked = False
- Set CCTC = Nothing
- End Sub
- Function LeftPadNr(Nr,lnght)
- Select Case lnght
- Case 1
- Nr = Nr
- Case 2
- If Nr<10 Then Nr= "00"& Nr
- Case 3
- If Nr<10 Then Nr= "00"& Nr
- If Nr>9 and Nr<100 Then Nr= "0"& Nr
- Case 4
- If Nr<10 Then Nr= "000"& Nr
- If Nr>9 and Nr<100 Then Nr= "00"& Nr
- If Nr>99 and Nr<1000 Then Nr= "0"& Nr
- Case 5
- If Nr<10 Then Nr="0000"& Nr
- If Nr>9 and Nr<100 Then Nr= "000"& Nr
- If Nr>99 and Nr<1000 Then Nr= "00"& Nr
- If Nr>999 and Nr<10000 Then Nr= "0"& Nr
- End Select
- LeftPadNr = Nr
- End Function
- Sub Install()
- 'Add scripts.ini entries
- Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
- Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
- If Not (inif Is Nothing) Then
- inif.StringValue("AutoIncTracknrModify","Filename") = "AutoIncTracknrModify.vbs"
- inif.StringValue("AutoIncTracknrModify","Procname") = "AutoIncTracknrModify"
- inif.StringValue("AutoIncTracknrModify","Order") = "11"
- inif.StringValue("AutoIncTracknrModify","DisplayName") = "Auto-&increment Track #s..."
- inif.StringValue("AutoIncTracknrModify","Description") = "Sequentially numbers Tracks"
- inif.StringValue("AutoIncTracknrModify","Language") = "VBScript"
- inif.StringValue("AutoIncTracknrModify","ScriptType") = "0"
- inif.StringValue("AutoIncTracknrModify","Shortcut") = "CTRL+1"
- SDB.RefreshScriptItems
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement