Advertisement
Guest User

Untitled

a guest
Feb 27th, 2021
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2. ' This file can be replaced in one of the future versions,
  3. ' so please if you want to modify it, make a copy, do your
  4. ' modifications in that copy and change Scripts.ini file
  5. ' appropriately.
  6. ' If you do not do this, you will lose all your changes in
  7. ' this script when you install a new version of MediaMonkey
  8. ' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  9.  
  10. ' Modified by Bex 2008-06-01
  11. ' Version 1.5
  12. ' - Added Reset Counter on Album Change
  13. ' Version 1.4
  14. ' - Added Add or Remove DiscNr
  15. ' Version 1.2
  16. ' - Fixed Access Violation Error
  17. ' Version 1.1
  18. ' - Added leading Zero Functionality
  19. ' - Added ShortCut CTRL+1
  20.  
  21.  
  22. ' This script fills in track #s incrementally
  23.  
  24. Sub AutoIncTracknrModify
  25. ' Define variables
  26. Dim list, itm, i, tmp
  27.  
  28. ' Get list of selected tracks from MediaMonkey
  29. Set list = SDB.CurrentSongList
  30. If list.Count=0 Then
  31. Exit Sub
  32. End If
  33.  
  34. Set UI = SDB.UI
  35.  
  36. ' Create the window to be shown
  37. Set Form = UI.NewForm
  38. Form.Common.SetRect 0, 0, 410, 240
  39. Form.FormPosition = 4 ' Screen Center
  40. Form.BorderStyle = 3 ' Dialog
  41. Form.Caption = SDB.Localize("Auto-increment Track #s")
  42.  
  43. Set Lbl = UI.NewLabel( Form)
  44. Lbl.Common.SetRect 10,15,370,40
  45. Lbl.AutoSize = False
  46. Lbl.Multiline = True
  47. 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
  48.  
  49. Set Lbl = UI.NewLabel( Form)
  50. Lbl.Common.SetRect 10,65,280,20
  51. Lbl.Caption = SDB.Localize("Start numbering from:")
  52.  
  53. Set SE = UI.NewSpinEdit( Form)
  54. SE.Common.SetRect Lbl.Common.Left+Lbl.Common.Width+10, 61, 50, 20
  55. SE.MinValue = 1
  56. SE.MaxValue = 9999
  57. SE.Value = 1
  58.  
  59. Set Lb2 = UI.NewLabel( Form)
  60. Lb2.Common.SetRect 260,65,280,20
  61. Lb2.Caption = SDB.Localize("Add Disc#:")
  62.  
  63. Set Edt = UI.NewEdit( Form)
  64. Edt.Common.SetRect 320,62,30,20
  65. Script.RegisterEvent Edt, "OnChange", "EditDiscnr"
  66.  
  67. Set Cbx3 = UI.NewCheckBox( Form)
  68. Cbx3.Common.ControlName = "Cbx3"
  69. Cbx3.Caption = "Remove existing Disc#"
  70. Cbx3.Common.SetRect 260,85,280,20
  71. Cbx3.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","RemoveDiscnr")
  72.  
  73. Set Cbx1 = UI.NewCheckBox( Form)
  74. Cbx1.Caption = "Add leading zero to Track#'s"
  75. Cbx1.Common.SetRect 10,85,200,20
  76. Cbx1.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero")
  77. Script.RegisterEvent Cbx1.Common, "OnClick", "ClickCbX1"
  78.  
  79. Set Cbx2 = UI.NewCheckBox( Form)
  80. Cbx2.Common.ControlName = "Cbx2"
  81. Cbx2.Caption = "Only if 10 tracks or more are selected"
  82. Cbx2.Common.SetRect 25,102,280,20
  83. Cbx2.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","OnlyIfTenOrMore")
  84. Cbx2.Common.Enabled = SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero")
  85.  
  86. Set Cbx4 = UI.NewCheckBox( Form)
  87. Cbx4.Common.ControlName = "Cbx3"
  88. Cbx4.Caption = "Reset Counter on AlbumChange"
  89. Cbx4.Common.SetRect 115,145,200,20
  90. Cbx4.Checked = SDB.IniFile.BoolValue("AutoIncTrackN","ResetCounter")
  91. '---------------------------------------------------------------------------
  92. Set Btn = UI.NewButton( Form)
  93. Btn.Caption = SDB.Localize("&OK")
  94. Btn.Common.SetRect 110,170,75,25
  95. Btn.ModalResult = 1
  96. Btn.Default = true
  97.  
  98. Set Btn = UI.NewButton( Form)
  99. Btn.Caption = SDB.Localize("&Cancel")
  100. Btn.Common.SetRect 220,170,75,25
  101. Btn.ModalResult = 2
  102. Btn.Cancel = true
  103.  
  104. If Form.ShowModal=1 then
  105. SDB.IniFile.BoolValue("AutoIncTrackN","AddLeadZero") =Cbx1.Checked
  106. SDB.IniFile.BoolValue("AutoIncTrackN","OnlyIfTenOrMore")=Cbx2.Checked
  107. SDB.IniFile.BoolValue("AutoIncTrackN","RemoveDiscnr") =Cbx3.Checked
  108. SDB.IniFile.BoolValue("AutoIncTrackN","ResetCounter") =Cbx4.Checked
  109. AddLeadZero =Cbx1.Checked
  110. OnlyIfTenOrMore =Cbx2.Checked
  111. RemoveDiscnr =Cbx3.Checked
  112. ResetOnAlbumChange=Cbx4.Checked
  113. number =SE.Value
  114. '--------------------------------------
  115. dim t(2),tme : t(0) = Timer()
  116. For i=0 To list.count-1
  117. trackcnt=trackcnt+1
  118. 'msgbox trackcnt
  119. If ResetOnAlbumChange Then CurAlbID=list.item(i).Album.ID
  120. If (trackcnt>1 And ResetOnAlbumChange And CurAlbID<>PrevAlbID) Then
  121. value=value & trackcnt-1 &" "
  122. trackcnt=1
  123. End If
  124. If i=list.count-1 Then
  125. value=value & trackcnt &" "
  126. End If
  127. If ResetOnAlbumChange Then PrevAlbID=CurAlbID
  128. Next
  129. t(1) = Timer()
  130. tme = "After first loop: " &FormatNumber(Round(t(1)-t(0),3),3) & VbNewLine
  131. 'msgbox value : exit sub
  132. a = Split(trim(value))
  133. For i=0 To Ubound(a)
  134. trackcnt=a(i)
  135. strt=0+stp
  136. stp =stp+trackcnt-1
  137. If AddLeadZero Then
  138. If Len(number+trackcnt)<3 Then
  139. Maxlength = 3
  140. Else
  141. Maxlength = Len(number+trackcnt)
  142. End If
  143. If OnlyIfTenOrMore Then
  144. Maxlength = Len(number+trackcnt-1)
  145. End If
  146. End If
  147. For j=strt To stp
  148. Set itm = list.Item(j)
  149. ' Swap the fields
  150. If Not Trim(Edt.Text)="" Then
  151. itm.DiscNumberStr = Edt.Text
  152. End If
  153. If RemoveDiscnr And Cbx3.common.Enabled Then
  154. itm.DiscNumberStr = ""
  155. End If
  156. itm.TrackOrderStr = LeftPadNr(number,Maxlength)
  157. number = number + 1
  158. Next
  159. stp=stp+1
  160. number=SE.Value
  161. Next
  162. t(2) = Timer()
  163. tme = tme & "After last loop: " &FormatNumber(Round(t(2)-t(1),3),3) & VbNewLine
  164. 'msgbox tme
  165. list.UpdateAll
  166. End If
  167. Script.UnregisterEvents Cbx1.Common
  168. Script.UnregisterEvents Edt
  169. End Sub
  170.  
  171. Sub EditDiscnr(Edt)
  172. Set ECTC = Edt.Common.TopParent.Common
  173. If Not Trim(Edt.Text)="" Then Enabled=False Else Enabled=True
  174. ECTC.ChildControl("Cbx3").Common.Enabled = Enabled
  175. Set ECTC = Nothing
  176. End Sub
  177.  
  178. Sub ClickCbX1(Cbx)
  179. Set CCTC = Cbx.Common.TopParent.Common
  180. CCTC.ChildControl("Cbx2").Common.Enabled = Cbx.Checked
  181. If Not Cbx.Checked Then CCTC.ChildControl("Cbx2").Checked = False
  182. Set CCTC = Nothing
  183. End Sub
  184.  
  185. Function LeftPadNr(Nr,lnght)
  186. Select Case lnght
  187. Case 1
  188. Nr = Nr
  189. Case 2
  190. If Nr<10 Then Nr= "00"& Nr
  191. Case 3
  192. If Nr<10 Then Nr= "00"& Nr
  193. If Nr>9 and Nr<100 Then Nr= "0"& Nr
  194. Case 4
  195. If Nr<10 Then Nr= "000"& Nr
  196. If Nr>9 and Nr<100 Then Nr= "00"& Nr
  197. If Nr>99 and Nr<1000 Then Nr= "0"& Nr
  198. Case 5
  199. If Nr<10 Then Nr="0000"& Nr
  200. If Nr>9 and Nr<100 Then Nr= "000"& Nr
  201. If Nr>99 and Nr<1000 Then Nr= "00"& Nr
  202. If Nr>999 and Nr<10000 Then Nr= "0"& Nr
  203. End Select
  204. LeftPadNr = Nr
  205. End Function
  206.  
  207. Sub Install()
  208. 'Add scripts.ini entries
  209. Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  210. Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  211. If Not (inif Is Nothing) Then
  212. inif.StringValue("AutoIncTracknrModify","Filename") = "AutoIncTracknrModify.vbs"
  213. inif.StringValue("AutoIncTracknrModify","Procname") = "AutoIncTracknrModify"
  214. inif.StringValue("AutoIncTracknrModify","Order") = "11"
  215. inif.StringValue("AutoIncTracknrModify","DisplayName") = "Auto-&increment Track #s..."
  216. inif.StringValue("AutoIncTracknrModify","Description") = "Sequentially numbers Tracks"
  217. inif.StringValue("AutoIncTracknrModify","Language") = "VBScript"
  218. inif.StringValue("AutoIncTracknrModify","ScriptType") = "0"
  219. inif.StringValue("AutoIncTracknrModify","Shortcut") = "CTRL+1"
  220. SDB.RefreshScriptItems
  221. End If
  222. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement