Sample Lyricist Tree Node script

From MediaMonkey Wiki
Jump to: navigation, search
' Sample Lyricist Tree script
' This script adds new Lyricist node that contains all lyricists in Library as its 
' subnodes. The script further allows to edit individual lyricist or drag&drop tracks
' to lyricist nodes.

Sub OnStartup
  Set Tree = SDB.MainTree

  Set Node = Tree.CreateNode
  Node.Caption = "Lyricist"
  Node.IconIndex = 0
  Node.UseScript = Script.ScriptPath
  Node.OnFillChildren = "FillLyricists"

  Tree.AddNode Tree.Node_Artist, Node, 1     ' Insert after the node
  Node.HasChildren = True
End Sub

Sub FillLyricists( Node)
  Set Tree = SDB.MainTree

  Node.HasChildren = false   ' To delete all old children

  Set Iter = SDB.Database.OpenSQL( "SELECT DISTINCT TextData FROM AddSongInfo WHERE DataType=200 Order BY TextData")

  While Not Iter.EOF
    Set NewNode = Tree.CreateNode
    NewNode.Caption = Iter.StringByIndex(0)
    NewNode.CustomData = Iter.StringByIndex(0)
    NewNode.IconIndex = 0
    NewNode.UseScript = Script.ScriptPath
    NewNode.OnFillTracksFunct = "FillLyricist"
    NewNode.OnEdited = "LyricistEdited"
    NewNode.OnDragDrop = "LyricistDragDrop"
    Tree.AddNode Node, NewNode, 3     '  Add as the last child
End Sub

Sub FillLyricist( Node)
  Set Trcks = SDB.MainTracksWindow

  Trcks.AddTracksFromQuery( "and Songs.ID in (SELECT IDSong FROM AddSongInfo WHERE DataType=200 AND TextData='" & Node.CustomData & "')")
End Sub

Sub LyricistEdited( Node, NewText)
  SDB.Database.ExecSQL( "UPDATE AddSongInfo SET TextData='" & NewText & "' WHERE DataType=200 and TextData='" & Node.CustomData & "'")
  Node.CustomData = NewText
  Node.Caption = NewText
End Sub

Function LyricistDragDrop( destNode, srcNode, SongList, DropType, Test)
  If Test Then
    LyricistDragDrop = 2         ' Move operation
    Dim i, itm
    For i=0 To SongList.Count-1
      Set itm = SongList.Item(i)
      itm.Lyricist = destNode.CustomData
  End If
End Function