Auto-Increment TrackNumbers 1.5 (2008-07-29) [MM3]

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Auto-Increment TrackNumbers 1.5 (2008-07-29) [MM3]

Post by Bex »

Script is Updated
Ver 1.5 (2008-07-29) [MM3 only]
- Added possibility to reset Counter on Album Change (multiple albums can be tagged in one go)
- Fixed small bug with leading zero


Enjoy!
/Bex
-------------------------------------------------------------------------------------
Script is Updated
Ver 1.4 (2008-06-02) [MM3 only]
- Added possibility to either Add or Remove DiscNumber

Image


Enjoy!
/Bex
-------------------------------------------------------------------------------------
BugFix
Ver 1.3 (2008-06-01) [MM3 only]
- Made a separate installation of the script which doesn't replace the original one

-------------------------------------------------------------------------------------
BugFix
Ver 1.2 (2008-06-01) [MM3 only]
- Fixed Access Violation Error

-------------------------------------------------------------------------------------
I have modified the existing Auto-Increment TrackNumbers script, which is shipped with MM, so it optionally caters for Leading Zeros.
I've also added a shortCut CTRL+1 for easier execution of the script.

Screen shot:
Image

If "Add leading zero" is applied then then the track number is left padded with as many zeros that is needed. Meaning that if you select:
1 to 99 tracks:
1-9 is getting one leading zero added
100 or more tracks:
1-9 is getting two leading zeros added
10-99 is getting one leading zeros added

If you select "Only if 10 tracks or more are selected" then selecting 1 to 9 tracks doesn't add any leading zero, otherwise does it work as above.


Enjoy!
/Bex
___________________________________________________________

Code: Select all

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' 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)<2 Then
          Maxlength = 2
        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=   "0"& 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
___________________________________________________________

Download:
Latest version:
MM3 (Installer)
http://www.mediafire.com/?om2oiojjzyl


Installation Instructions:
- New Install:
MM3 (Installer)
Avoid "Product installation error"
- Vista Users:
- - To be able to install scripts you must Run MM as an administrator.
- - It means that you must right click the MM icon and select "Run as administrator" even if you are logged in as an administrator.
- All Users:
- - Check in your task manager that you only have one instance of MediaMonkey.exe running.

1. Download the zipped .mmip file and run it.
2. Restart MediaMonkey!
3. To execute the script use the shortcut CTRL+1
Last edited by Bex on Sat Jan 17, 2009 5:18 pm, edited 14 times in total.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Seeker
Posts: 264
Joined: Tue Jul 10, 2007 3:17 pm

Post by Seeker »

Given this ships with MM, will this version be in 3.0.3 ???
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Well, I don't know. I only changed it to cater for Leading Zeros! :)
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Kilmatead
Posts: 206
Joined: Mon Apr 07, 2008 2:16 pm
Location: Dublin

Post by Kilmatead »

Running this script causes an "Access Violation at address 41F9E400 Read of Address" error when closing MM, which then needs to be terminated from the task manager.

If this script is not run (in a given session) no error occurs.

Vista x64 (MM .1179), no problems with any other script, and is definitely related only to the execution of AutoIncTrackN.vbs. Admin, or no Admin.

Something to ponder over breakfast.

How might I retrieve the "original" version?
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Sorry for that but It's really a simple change I've done so it shouldn't cause any trouble. I'll have a look immediately though!

For now I'm afraid that you have to install MM over your existing installation but I'll upload the original script in a few minutes!
Last edited by Bex on Sun Jun 01, 2008 8:04 pm, edited 1 time in total.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

This is the original script. Download it and extract the AutoIncTrackN.vbs file to your "MediaMonky/Script" folder. If the file exist just overwrite it.

http://home.online.no/~kar-m-kr/AutoIncTrackN.vbs.zip
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

BugFix
Ver 1.2 (2008-06-01) [MM3 only]
- Fixed Access Violation Error
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
cadmanmeg
Posts: 309
Joined: Sun Nov 19, 2006 5:28 am

Post by cadmanmeg »

I get an error on install that goes: "Invalid product installation package"! upon initial download, it wanted to force it to a zip file but I saw that it was a mmip file and therefore deleted the 'zip' at the end. On second try, I just let it do its thing. Then I changed the name of file by taking the '.zip' out and leaving the "AutoIncTrackN.1.2.mmip". Still didn't work. The file size shows at just over 2kb. Any suggestions or can you send this to me directly? Thanks much!
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Just download and run. Don't rename anything.
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Script is UpdatedBugFix
Ver 1.4 (2008-06-02) [MM3 only]
- Added possibility to either Add or Remove DiscNumber


Enjoy!
/Bex
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Debby747
Posts: 14
Joined: Fri Sep 07, 2007 11:15 am
Location: Germany

Post by Debby747 »

Very nice script, Bex, thank you!

Do you think it's possible to enhance the script to re-number the tracks of several albums at once?
Always starting with one again when a new album is detected.

Best regards,
D.
"There's a certain detail seen here."
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Thanks!

That would be possible. I'm a bit busy now but I'll put it on my todo-list. :)
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: Auto-Increment TrackNumbers 1.5 (2008-07-29) [MM3]

Post by Bex »

Script is Updated
Ver 1.5 (2008-07-29) [MM3 only]
- Added possibility to reset Counter on Album Change (multiple albums can be tagged in one go)
- Fixed small bug with leading zero


Enjoy!
/Bex
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Debby747
Posts: 14
Joined: Fri Sep 07, 2007 11:15 am
Location: Germany

Re: Auto-Increment TrackNumbers 1.5 (2008-07-29) [MM3]

Post by Debby747 »

Thank you very much, Bex!
Works like a charm.

Kind regards,
D.
"There's a certain detail seen here."
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Re: Auto-Increment TrackNumbers 1.5 (2008-07-29) [MM3]

Post by Bex »

Glad you liked it!
Advanced Duplicate Find & Fix Find More From Same - Custom Search. | Transfer PlayStat & Copy-Paste Tags/AlbumArt between any tracks.
Tagging Inconsistencies Do you think you have your tags in order? Think again...
Play History & Stats Node Like having your Last-FM account stored locally, but more advanced.
Case & Leading Zero Fixer Works on filenames too!

All My Scripts
Post Reply