[Update -> v0.4 @ 2005-06-25] ReorderTracks.vbs

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

Moderators: Peke, Gurus

Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

[Update -> v0.4 @ 2005-06-25] ReorderTracks.vbs

Post by Octopod »

Hi,

Here is a very partial solution for re-ordering tracks.

All is explained in the file's header. I hope it could help some users even if there is a lot of inconvenience.

Scripts/Scripts.ini:

Code: Select all

[Reorder]
FileName=ReorderTracks.vbs
ProcName=ReorderTracks
Order=7
DisplayName=&Reorder selected tracks
Description=Reorder selected tracks from 1 to N
Language=VBScript
ScriptType=1
Shortcut=Shift+Alt+R
Scripts/ReorderTracks.vbs

Code: Select all

' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 
'
'                  "ReorderTracks.vbs", March-05-2004
'         VBScript for MediaMonkey 2.3.1 (or above), written by Octopod
'
' Purpose: 
' - Re-number SELECTED tracks from MM's tracklist if tracks are **not** part of
'   the library), according to the current sorting order from 1 to N
'
' Disavantages:
' - The tracks have to be explicitely selected because user must manually
'   follow on synchronize the ID3 tags (Ctrl+S) -- note that this will not add
'   these tracks to the library
' - Will not work with tracks already added to the library
'
' Advice:
' - If you cannot find any suitable sort using the columns to get the wanted
'   order: create a temporary playlist, drag&drop files to then within the 
'   playlist, select all (Ctrl+A) then apply the script and remove the files
'   from the playlist
'
' Notes:
' - Only tested with MP3s
' - Although this script should be safe, USE AT YOUR OWN RISK
'
' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 


' MM constant
NO=7


Sub ReorderTracks

  ' Get a list of songs to be exported
  Set list = SDB.SelectedSongList

  ' -- Do not use this block as the tracks need to be selected
  ' -- in order to follow on tags synchronization
  ' If list.count=0 Then
  '   Set list = SDB.AllVisibleSongList
  ' End If

  If list.count=0 Then
    res = SDB.MessageBox("Select tracks to be numbered", mtError, Array(mbOk))
    Exit Sub
  End If

  message="Reorder tracks from 1 to " + CStr(list.count) + "?"
  res = SDB.MessageBox(message, mtConfirmation, Array(mbYes, mbNo))
  If res=NO Then
    Exit Sub
  End If

  Dim i
  for i=0 to list.count-1 
    Set itm = list.Item(i)
    itm.TrackOrder = i+1
  next 'i

  res = SDB.MessageBox("Manual tags synchronization: Ctrl+S, cancellation: F5", mtWarning, Array(mbOk))

End Sub
Last edited by Octopod on Fri Jun 24, 2005 6:40 pm, edited 2 times in total.
Octopod
Image
jiri
Posts: 5417
Joined: Tue Aug 14, 2001 7:00 pm
Location: Czech Republic
Contact:

Post by jiri »

Two suggestions:
- you can update tags automatically in the loop using itm.WriteTags.
- you can update DB automatically using itm.UpdateDB.

Hope it helps,
Jiri
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

Post by Octopod »

jiri wrote: - you can update tags automatically in the loop using itm.WriteTags.
- you can update DB automatically using itm.UpdateDB.
This is what i was looking for! :D (seems these APIs are not documented though).

So, thanks to jiri, here is the really useful script version that works with all tracks (declared to library or not) and, above all, which is all automatic.

Hope this helps some users.

Code: Select all

' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 
'
'                "ReorderTracks.vbs", March-05-2004, v0.3
'         VBScript for MediaMonkey 2.3.1 (or above), written by Octopod
'
' Purpose: 
' - Re-number selected tracks (or visible if none) from MM's tracklist, 
'   according to the current sorting order, from 1 to N
'
' Advice:
' - If you cannot find any suitable sort using the columns to get the wanted
'   order: create a temporary playlist, drag&drop files to then within the 
'   playlist, then apply the script and remove the playlist
'
' Notes:
' - This script writes tags then immediately update the DB accordingly -- note 
'   that there is not impact on the DB for tracks that are not part of the 
'   library (particularly, the tracks are not auto-added to the library)
' - Only tested with MP3s
' - Although this script should be safe, USE AT YOUR OWN RISK
'
' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 


Sub ReorderTracks

  ' Get a list of songs to be numbered
  Set list = SDB.SelectedSongList
  
  ' Or all the visible ones
  If list.count=0 Then
     Set list = SDB.AllVisibleSongList
  End If

  If list.count=0 Then
    res = SDB.MessageBox("Select tracks to be numbered", mtError, Array(mbOk))
    Exit Sub
  End If

  message="Reorder tracks from 1 to " + CStr(list.count) + "?"
  res = SDB.MessageBox(message, mtConfirmation, Array(mbYes, mbNo))
  If res=mrNo Then
    Exit Sub
  End If

  Dim i
  for i=0 to list.count-1 
    Set itm = list.Item(i)
    itm.TrackOrder = i+1
    itm.WriteTags
    ' Synchronize DB if track is part of it
    If itm.ID>-1 Then
      itm.UpdateDB
    End If
  next 'i

End Sub
Last edited by Octopod on Sat Mar 05, 2005 6:39 pm, edited 2 times in total.
Octopod
Image
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

Post by Octopod »

Octopod wrote:(seems these APIs are not documented though).
OK, they are documented with ISDBSongData, sorry. :oops:
BTW, is there any API that could control the equalizer?
Octopod
Image
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

Post by Octopod »

ERRATUM
Just edited the previous script version (now v0.3) to avoid tracks from being added to the library.
Octopod
Image
phunkydizco
Posts: 42
Joined: Sun May 22, 2005 10:56 am

Post by phunkydizco »

How do I start your script? Isn't there a menu entry like in the magic nodes script?
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

phunkydizco wrote:How do I start your script? Isn't there a menu entry like in the magic nodes script?
If you did the changes in Scripts.ini, there should be an entry in Tools\Scripts -> Reorder selected tracks

BTW Warum schreib ich eigentlich alles auf englisch? :D
phunkydizco
Posts: 42
Joined: Sun May 22, 2005 10:56 am

Post by phunkydizco »

Sripts.ini is updated, but I can't find any entry. Perhaps you could tell me the german menu names ;)
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

phunkydizco wrote:Sripts.ini is updated, but I can't find any entry. Perhaps you could tell me the german menu names ;)
Extras -> Skripte/Scripts -> Reorder Selected Tracks.

Steht in der Scripts.ini zufällig die Zeile Order=7 noch woanders? Passt der Dateiname ReorderTracks.vbs?
phunkydizco
Posts: 42
Joined: Sun May 22, 2005 10:56 am

Post by phunkydizco »

Bei mir gibt es keinen Menüpunkt "Skripte/Scripts" unter "Extras". Muss ich das noch irgendwo einstellen?

In der Scipts.ini passt soweit alles.
onkel_enno
Posts: 2153
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno »

phunkydizco wrote:Bei mir gibt es keinen Menüpunkt "Skripte/Scripts" unter "Extras". Muss ich das noch irgendwo einstellen?
In der Scipts.ini passt soweit alles.
Nein, da musst du nix weiter einstellen.
Dann weiss ich aber auch nicht weiter Image
Octopod
Posts: 463
Joined: Tue Jun 10, 2003 9:09 am

v0.4

Post by Octopod »

Hi,

Here is a new (and final?) version of the script.

Now the dialog proposes to reorder from 1 to N and allows you:
  • Yes: go now
  • No: "advanced" mode, specify the starting and increment values then go or abort
  • Cancel: abort operation
Hope it will please some of you.

Code: Select all

' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 
'
'                "ReorderTracks.vbs", June-25-2005, v0.4
'         VBScript for MediaMonkey 2.4.1 (or above), written by Octopod
'
' Purpose: 
' - Re-number selected tracks (or visible if none) from MM's tracklist, 
'   according to the current sorting order, from 1 to N.
' - If you refuse, you'll be asked to input start and increment values.
'
' Advice:
' - If you cannot find any suitable sort using the columns to get the wanted
'   order: create a temporary playlist, drag&drop files to then within the 
'   playlist, then apply the script and remove the playlist
'
' Notes:
' - This script writes tags then immediately update the DB accordingly -- note 
'   that there is not impact on the DB for tracks that are not part of the 
'   library (particularly, the tracks are not auto-added to the library)
' - Only tested with MP3s
' - Although this script should be safe, USE AT YOUR OWN RISK
'
' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- 



Sub Reorder(tracks, start, inc)

  Dim i
  for i=0 to tracks.count-1 
    Set itm = tracks.Item(i)
    itm.TrackOrder = start+(inc*i)
    itm.WriteTags
    ' Synchronize DB only if track is part of it
    If itm.ID>-1 Then
      itm.UpdateDB
    End If
  next 'i

End Sub



Sub ReorderTracks

  ' Get a list of songs to be numbered
  Set list = SDB.SelectedSongList
  
  ' Or all the visible ones
  If list.count=0 Then
     Set list = SDB.AllVisibleSongList
  End If

  If list.count=0 Then
    res = SDB.MessageBox("Select tracks to be numbered", mtError, Array(mbOk))
    Exit Sub
  End If

  message="Reorder tracks from 1 to " + CStr(list.count) + "?"
  res = SDB.MessageBox(message, mtConfirmation, Array(mbYes, mbNo, MbCancel))
  If res=mrCancel Then
    Exit Sub
  End If

  If res=mrYes Then
    
    Reorder list,1,1
    
  Else 'mbNo
  
    ''' Create skinned dialog '''

    Set Form = SDB.UI.NewForm 
    Form.Common.SetRect 100, 100, 180, 140 
    Form.BorderStyle  = 3   ' Resizable 
    Form.FormPosition = 4   ' Screen Center 
    Form.Caption = "Advanced..."
          
    ' Create dialog controls

    Set Label1 = SDB.UI.NewLabel(Form) 
    Label1.Caption = "Start from..." 
    Label1.Common.Left = 10 
    Label1.Common.Top = 14 
         
    Set Edt1 = SDB.UI.NewEdit(Form) 
    Edt1.Common.Left = Label1.Common.Left + Label1.Common.Width +25
    Edt1.Common.Top = Label1.Common.Top -4
    Edt1.Common.Width = Form.Common.Width - Edt1.Common.Left -15
    Edt1.Common.ControlName = "Edit1" 
    Edt1.Text = "1" 
           
    Set Label2 = SDB.UI.NewLabel(Form) 
    Label2.Caption = "Increment by..." 
    Label2.Common.Left = Label1.Common.Left 
    Label2.Common.Top = Edt1.Common.Top + Edt1.Common.Height +14
         
    Set Edt2 = SDB.UI.NewEdit(Form) 
    Edt2.Common.Left = Edt1.Common.Left
    Edt2.Common.Top = Label2.Common.Top -4 
    Edt2.Common.Width = Edt1.Common.Width 
    Edt2.Common.ControlName = "Edit2" 
    Edt2.Text = "1" 

    ' Create buttons that close the window

    
    Set BtnOk = SDB.UI.NewButton(Form) 
    BtnOk.Caption = "&Ok" 
    BtnOk.Common.Top = Edt2.Common.Top + Edt2.Common.Height +10 
    BtnOk.UseScript = Script.ScriptPath 
    BtnOk.Default = True
    BtnOk.ModalResult = 1 
        
    Set BtnCancel = SDB.UI.NewButton(Form) 
    BtnCancel.Caption = "&Cancel" 
    BtnCancel.Common.Left = Form.Common.Width - BtnCancel.Common.Width -15 
    BtnOK.Common.Left = BtnCancel.Common.Left - BtnOK.Common.Width -10 
    BtnCancel.Common.Top = BtnOK.Common.Top 
    BtnCancel.UseScript = Script.ScriptPath 
    BtnCancel.Cancel = True
    BtnCancel.ModalResult = 2 
           
    If Form.showModal=1 Then
      On Error Resume Next
      Reorder list, Int(Edt1.Text), Int(Edt2.Text)
      If Err<>0 Then 
        ' Error occurred when converting to int
        res=SDB.MessageBox("Wrong parameter(s): operation canceled.", mtError, Array(mbOk))
      End If
    End If

  End If

End Sub
Octopod
Image
Bex
Posts: 6316
Joined: Fri May 21, 2004 5:44 am
Location: Sweden

Post by Bex »

Hi Octopod!

I've installed this script as instructed in the scripts folder and made the changes to my scripts.ini in file as stated in the very first post. But I dont get any entry in Tools->Sripts?

Edit!
I just found out why!
The ScriptType should be 0 and not 1

Add this to scripts.ini

Code: Select all

[Reorder]
FileName=ReorderTracks.vbs
ProcName=ReorderTracks
Order=7
DisplayName=&Reorder selected tracks
Description=Reorder selected tracks from 1 to N
Language=VBScript
ScriptType=0
Shortcut=Shift+Alt+R
Octopod, it could be a good thing to delete the first two codes and add the correct scripts.ini code to the third code!

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

Post by Bex »

This script is great!

And I just found out an easier way to sort tracks manually:
' Advice:
' - If you cannot find any suitable sort using the columns to get the wanted
' order: create a temporary playlist, drag&drop files to then within the
' playlist, then apply the script and remove the playlist
Just add them to the now playing list and sort them there. Then just highlight all tracks to update in the now playing window and update them.

Cheers
/Martin
Post Reply