I don't mind sharing my code, but all I did was plagiarize
Steegy's original hard work and rename things more logically for my setup. Furthermore, I borrowed the config screen coordinates and translation code from something else in my scripts directory (I don't recall which script now). I hope it's not stepping on any toes to post it. The original work and inspiration are not mine, and all credit belongs to other people.
First, in /Scripts/Auto/ I created a file called
LinkedTracks.vbs (I changed the name because it made more sense to me that way and I didn't want to confuse my code with the original):
Code: Select all
Sub OnStartUp
Dim i : i = SDB.UI.AddOptionSheet("Linked Tracks", Script.ScriptPath, "InitSheet", "SaveSheet", -2)
End Sub
Sub InitSheet(Sheet)
Dim UI : Set UI = SDB.UI
Dim ini : Set ini = SDB.IniFile
Dim Label1 : Set Label1 = UI.NewLabel(Sheet)
Label1.Alignment = 1
Label1.Autosize = False
Label1.Common.SetRect 5,10,130,18
Label1.Common.ControlName = "CustomLabel"
Label1.Caption = Translate("Custom Field") & ":"
Dim DropDown1 : Set DropDown1 = UI.NewDropDown(Sheet)
DropDown1.Style = 2
DropDown1.Common.SetRect 140,6,200,21
DropDown1.Common.ControlName = "CustomField"
DropDown1.AddItem(CustomField(1))
DropDown1.AddItem(CustomField(2))
DropDown1.AddItem(CustomField(3))
DropDown1.AddItem(CustomField(4))
DropDown1.AddItem(CustomField(5))
DropDown1.ItemIndex = ini.IntValue("LinkedTracks", "CustomField")
Dim Checkbox1 : Set Checkbox1 = UI.NewCheckbox(Sheet)
Checkbox1.Common.SetRect 110,50,250,18
Checkbox1.Common.ControlName = "DisableCrossFade"
Checkbox1.Caption = "Disable Crossfade between linked tracks"
Checkbox1.Checked = ini.BoolValue("LinkedTracks", "DisableCrossFade")
End Sub
Sub SaveSheet(Sheet)
Dim ini : Set ini = SDB.IniFile
ini.IntValue("LinkedTracks", "CustomField") = Sheet.Common.ChildControl("CustomField").ItemIndex
ini.BoolValue("LinkedTracks", "DisableCrossFade") = Sheet.Common.ChildControl("DisableCrossFade").Checked
End Sub
Function Translate(str)
Translate = str
Dim dic : Set dic = SDB.Objects("LyrDict")
If Not (dic Is Nothing) Then
If dic.Exists(str) Then
Translate = dic.Item(str)
End If
End If
End Function
Function CustomField(i)
CustomField = SDB.IniFile.StringValue("CustomFields","Fld" & i & "Name")
End Function
If you go to Tools/Options/Player/Linked Tracks, you can select which Custom Field. It should pull the names of the fields from Library/Appearance if you've changed them. There's also a simple checkbox for whether or not to disable crossfading. It defaults to false.
In Scripts.ini, I added this:
Code: Select all
[LinkedTracks]
FileName=LinkedTracks.vbs
ProcName=LinkTracks
Order=1
Language=VBScript
ScriptType=2
And in the main /Scripts/ directory, I created another file called
LinkedTracks.vbs (yeah, I named it the same thing -- sorry, I guess that's confusing

I wasn't expecting to share it.):
Code: Select all
Sub LinkTracks
Dim ini : Set ini = SDB.IniFile
Dim CustomField : CustomField = ini.IntValue("LinkedTracks", "CustomField")
Dim CurrentCustom, NextCustom
Select Case CustomField
Case 0: CurrentCustom = SDB.Player.CurrentSong.Custom1
Case 1: CurrentCustom = SDB.Player.CurrentSong.Custom2
Case 2: CurrentCustom = SDB.Player.CurrentSong.Custom3
Case 3: CurrentCustom = SDB.Player.CurrentSong.Custom4
Case 4: CurrentCustom = SDB.Player.CurrentSong.Custom5
End Select
If SDB.Player.CurrentSongIndex + 1 < SDB.Player.PlaylistCount Then
Select Case CustomField
Case 0: NextCustom = SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom1
Case 1: NextCustom = SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom2
Case 2: NextCustom = SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom3
Case 3: NextCustom = SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom4
Case 4: NextCustom = SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).Custom5
End Select
End If
If Left(CurrentCustom, 3) = "LT_" Then
If Not SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True" Then
SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True"
SavePlayerStates
End If
If SDB.Player.CurrentSongIndex = SDB.Player.PlaylistCount - 1 Then
'Last song in playlist
PlayerStatesAsContinuous
Call AddOtherTiedSongs(CurrentCustom)
Else
If NextCustom <> CurrentCustom Or SDB.Player.PlaylistItems(SDB.Player.CurrentSongIndex + 1).TrackOrder > CurrentCustom Then
'Non-tied song comes after
Call AddOtherTiedSongs(CurrentCustom)
Else
'Tied song comes after
PlayerStatesAsContinuous
End If
End If
Else
If SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "True" Then
SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "False"
RestoreSavedPlayerStates
End If
End If
End Sub
Sub AddOtherTiedSongs(CurrentCustom)
Dim ini : Set ini = SDB.IniFile
Dim IndexForAdding
IndexForAdding = SDB.Player.CurrentSongIndex
Dim MySongs
Set MySongs = SDB.Database.QuerySongs("Songs.Custom" & CInt(ini.IntValue("LinkedTracks", "CustomField")) + 1 & "='" & DoubleUpSingleQuotes(CurrentCustom) & "' AND Songs.TrackNumber > '" & SDB.Player.CurrentSong.TrackOrderStr & "' ORDER BY Songs.TrackNumber ASC")
If MySongs.EOF Then
RestoreSavedPlayerStates
End If
Do While Not MySongs.EOF
IndexForAdding = IndexForAdding + 1
SDB.Player.PlaylistAddTrack MySongs.Item
SDB.Player.PlaylistMoveTrack SDB.Player.PlaylistCount - 1, IndexForAdding
MySongs.Next
Loop
End Sub
Sub RestoreSavedPlayerStates
SDB.Player.isAutoDJ = StringToBool(SDB.IniFile.StringValue("Player", "saved_isAutoDJ"))
SDB.Player.isShuffle = StringToBool(SDB.IniFile.StringValue("Player", "saved_isShuffle"))
SDB.Player.isRepeat = StringToBool(SDB.IniFile.StringValue("Player", "saved_isRepeat"))
SDB.Player.isCrossfade = StringToBool(SDB.IniFile.StringValue("Player", "saved_isCrossfade"))
SDB.IniFile.StringValue("Player", "saved_hasBeenSaved") = "False"
End Sub
Sub PlayerStatesAsContinuous
Dim ini : Set ini = SDB.IniFile
Dim DisableCrossFade : DisableCrossFade = ini.BoolValue("LinkedTracks", "DisableCrossFade")
SDB.Player.isAutoDJ = False
SDB.Player.isShuffle = False
SDB.Player.isRepeat = False
If DisableCrossFade Then
SDB.Player.isCrossfade = False
End If
End Sub
Sub SavePlayerStates
SDB.IniFile.StringValue("Player", "saved_isAutoDJ") = SDB.Player.isAutoDJ
SDB.IniFile.StringValue("Player", "saved_isShuffle") = SDB.Player.isShuffle
SDB.IniFile.StringValue("Player", "saved_isRepeat") = SDB.Player.isRepeat
SDB.IniFile.StringValue("Player", "saved_isCrossfade") = SDB.Player.isCrossfade
End Sub
Function StringToBool(InpuString)
If InpuString = "True" Then
StringToBool = True
Else
StringToBool = False
End If
End Function
Function DoubleUpSingleQuotes(strInput)
DoubleUpSingleQuotes = Replace(strInput, "'", "''")
End Function
I changed the "TG" prefix to "LT_", again to avoid potential confusion.
99% of this code is the work of others. I just tweaked it around to fit my needs.
das