by Octopod » Fri Jun 24, 2005 6:38 pm
Hi,
Here is a new (and final?) version of the script.
Now the dialog proposes to reorder from 1 to N and allows you:
- No: "advanced" mode, specify the starting and increment values then go or abort
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
Hi,
Here is a new (and final?) version of the script.
Now the dialog proposes to reorder from 1 to N and allows you:
[list]Yes: go now[/list][list]No: "advanced" mode, specify the starting and increment values then go or abort[/list][list]Cancel: abort operation[/list]
Hope it will please some of you.
[code]' ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- -----
'
' "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
[/code]