Page 1 of 1

Here is a script to create an Album Artists Node

Posted: Fri Jan 21, 2005 10:42 am
by jmaver

Code: Select all

' Adds an album artist field
'

Sub OnStartup
  Dim Tree
  Set Tree = SDB.MainTree

  Dim AlbArtNode
  Set AlbArtNode= Tree.CreateNode
  AlbArtNode.Caption = "Album Artists"
  AlbArtNode.IconIndex = 0
  AlbArtNode.UseScript = Script.ScriptPath
  AlbArtNode.OnFillChildren = "FillAlbumArtists"

  Tree.AddNode Tree.Node_Library, AlbArtNode, 2
  AlbArtNode.HasChildren = true
End Sub

Sub FillAlbumArtists(Node)
  Node.HasChildren = false
 Dim Tree, Iter
  Set Tree = SDB.MainTree
  Set Iter = SDB.Database.OpenSQL( "SELECT DISTINCT Artists.Artist, Artists.ID FROM (Albums INNER JOIN Artists ON Albums.IDArtist = Artists.ID) WHERE Albums.IDArtist <> 0 ORDER BY Artists.Artist" ) 

  While Not Iter.EOF
    Set NewNode = Tree.CreateNode
    NewNode.Caption = Iter.StringByIndex(0)
    NewNode.CustomData = Iter.ValueByIndex(1)
    NewNode.IconIndex = 0
    NewNode.UseScript = Script.ScriptPath
    NewNode.OnFillChildren = "FillAlbums"
    NewNode.OnFillTracksFunct = "FillArtistTracks"
    Tree.AddNode Node, NewNode, 3     '  Add as the last child
    NewNode.HasChildren = true
    Iter.Next
  WEnd
End Sub

Sub FillAlbums(Node)
  'Node.CustomData contains Artists.ID
  Node.HasChildren = false
 
  Set Tree = SDB.MainTree
  Set Iter = SDB.Database.OpenSQL( "SELECT Albums.Album, Albums.ID FROM Albums WHERE Albums.IDArtist= " & Node.CustomData & " Order BY Album")

  While Not Iter.EOF
    Set NewNode = Tree.CreateNode
    NewNode.Caption = Iter.StringByIndex(0)
    NewNode.CustomData = Iter.ValueByIndex(1)
    NewNode.IconIndex = 16
    NewNode.UseScript = Script.ScriptPath
    NewNode.OnFillTracksFunct = "FillTracks"
    Tree.AddNode Node, NewNode, 3     '  Add as the last child
    Iter.Next
  WEnd
End Sub

Sub FillArtistTracks( Node)
  'Node.CustomData contains Artists.ID
  Set Trcks = SDB.MainTracksWindow

  Trcks.AddTracksFromQuery( "and Songs.ID in (SELECT Songs.ID FROM Songs,Albums WHERE Songs.IDAlbum=Albums.ID AND Albums.IDArtist="& Node.CustomData & ")")
  Trcks.FinishAdding
End Sub

Sub FillTracks( Node)
  'Node.CustomData contains Albums.ID
  Set Trcks = SDB.MainTracksWindow

  Trcks.AddTracksFromQuery( "and Songs.ID in (SELECT ID FROM Songs WHERE IDAlbum="& Node.CustomData & ")")
  Trcks.FinishAdding
End Sub

Thanks

Posted: Wed Sep 07, 2005 5:25 am
by trixmoto
This is excellent, thank you!

Re: Thanks

Posted: Wed Sep 07, 2005 5:35 am
by onkel_enno
trixmoto wrote:This is excellent, thank you!
You can also use Magic Nodes for things like that.

Posted: Wed Sep 07, 2005 5:39 am
by rk
Yes, try Magic Nodes! It is highly flexible!

Posted: Thu Sep 08, 2005 3:48 am
by trixmoto
I now use Magic Nodes and agree it is great. I still use this script though because it uses the Artist icon and puts the node in the right place.

Posted: Thu Sep 08, 2005 3:53 am
by onkel_enno
trixmoto wrote:I now use Magic Nodes and agree it is great. I still use this script though because it uses the Artist icon and puts the node in the right place.
Same things can be done with MagicNodes.
KeyWords: "icon:" and "child of:"

Posted: Thu Sep 08, 2005 4:21 am
by trixmoto
I'm sure I'll learn to use Magic Nodes properly soon, but for now this script does the job. Cheers!