I then had a request to implement the same functionality with MagicNodes. A broader implementation would be for any node such as artist, or genre, or album, etc. The challenge is there's no comparable sdb.playlistbytitle( PlayList ) for nodes. After much experimenting, I came up with the method demonstrated in the sample code below. Upon right-clicking a node, I create a 'path' back up to the top of the tree and then save this path in the inifile. To get to the node, I then use FirstChildNode() and NextSiblingNode() methods. In order for this to work, each top level node must be expanded which causes a bit of change in the tree window.
The next problem is retrieving tracks from the maintrackswindow. No matter which of SDB.AllVisibleSongList, or SDB.CurrentSongList, or SDB.SelectedSongList,and SDB.MainTracksWindow.FinishAdding method I used, the code falls through before the tracks make it to the maintracks window. I got around that, sort of, with a timer to allow the trackswindow to fill up before copying to now playing.
My questions are:
1) is there a better, faster, cleaner way to save and retrieve tracks associated with a node (other than playlists) ?
2) What's the right method to ensure the maintrackswindow is completely filled? The timer method is hit and miss and introduces unnecessary time for small collections but misses tracks for really large collections.
Any and all help and suggestions are appreciated!
The code below is copied to the scripts\auto folder. Right click on a node and select "Save Node" to save it (to the ini file) and right click anywhere in the tree window and select "Play Saved Node" to retrieve and play.
Code: Select all
Option Explicit Sub OnStartup Dim itm Set itm = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,3,0) itm.Caption = "Save Node" itm.OnClickFunc = "Save_node" itm.UseScript = Script.ScriptPath itm.IconIndex = 25 itm.Visible = True Dim itm2 Set itm2 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,3,0) itm2.Caption = "Play Saved Node" itm2.OnClickFunc = "Get_Node" itm2.UseScript = Script.ScriptPath itm2.IconIndex = 25 itm2.Visible = True End Sub Sub Save_node(arg) dim c,p p = SDB.MainTree.currentnode.caption While not (SDB.MainTree.parentnode(SDB.MainTree.currentnode).caption = "") set SDB.MainTree.currentnode=SDB.MainTree.parentnode(SDB.MainTree.currentnode) p = SDB.MainTree.currentnode.caption & "\" & p wend sdb.inifile.stringvalue("Get_Node_Path","Path") = p End Sub Sub Get_Node(arg) Dim p : p = sdb.inifile.stringvalue("Get_Node_Path","Path") Dim a : a = split(p,"\") Dim i Set SDB.MainTree.CurrentNode = sdb.maintree.node_library If SDB.MainTree.CurrentNode.Visible Then SDB.MainTree.CurrentNode.Expanded=True End If For i = 0 to Ubound(a) Do If a(i)=SDB.MainTree.CurrentNode.Caption Then If i = Ubound(a) Then Exit For Else Exit Do End If End If If SDB.MainTree.NextSiblingNode(SDB.MainTree.CurrentNode) is Nothing Then Msgbox(a(i)& "Node not Found") Exit Sub End IF Set SDB.MainTree.CurrentNode = SDB.MainTree.NextSiblingNode(SDB.MainTree.CurrentNode) Loop If SDB.MainTree.CurrentNode.Visible Then SDB.MainTree.CurrentNode.Expanded=True End If Set SDB.MainTree.CurrentNode = SDB.MainTree.FirstChildNode(SDB.MainTree.CurrentNode) Next Dim Tmr : Set Tmr = SDB.CreateTimer( 1000*.5) Tmr.Enabled=true Script.RegisterEvent Tmr, "OnTimer", "PlayNow" SDB.Objects("PlayTimer") = tmr SDB.MainTracksWindow.FinishAdding End Sub Sub PlayNow(arg) SDB.Objects("PlayTimer").Enabled = False sdb.player.stop sdb.player.playlistclear sdb.player.playlistaddtracks(SDB.CurrentSongList) sdb.player.play End Sub