Clearing TracksWindow and adding tracks by ID
Clearing TracksWindow and adding tracks by ID
The MainTracksWindow object provides a way to add tracks but without an easy way to remove them.
Here's the API:
http://www.mediamonkey.com/wiki/index.p ... acksWindow
The closest is the RemoveSelectedTracks function, but for that, all tracks need to be selected (perhaps there's a function that does that?)
What's the best way of clearing the list? *EDIT* I understand this is on the wishlist, so what's the best workaround?
Also, while we're on the topic, is there any TracksWindow equivalent to the AddTrackById from the PlayList object? I imagine it's much quicker to add tracks selectively by ID (they were previously stored in this way), rather than scan the database painstakingly looking for each ID. Unfortunately, as I'm using a TracksWindow object, I don't have the features that would be available to me with the Playlist object.
Maybe there's a way to convert an ID number into a SongData object (which TracksWindow can easily handle) ?
Here's the API:
http://www.mediamonkey.com/wiki/index.p ... acksWindow
The closest is the RemoveSelectedTracks function, but for that, all tracks need to be selected (perhaps there's a function that does that?)
What's the best way of clearing the list? *EDIT* I understand this is on the wishlist, so what's the best workaround?
Also, while we're on the topic, is there any TracksWindow equivalent to the AddTrackById from the PlayList object? I imagine it's much quicker to add tracks selectively by ID (they were previously stored in this way), rather than scan the database painstakingly looking for each ID. Unfortunately, as I'm using a TracksWindow object, I don't have the features that would be available to me with the Playlist object.
Maybe there's a way to convert an ID number into a SongData object (which TracksWindow can easily handle) ?
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.
Re: Clearing TracksWindow and adding tracks by ID
What's that sound I hear? Is it the sigh of relief as I realise that weeks of coding haven't been wasted? I think I may have semi-solved the second issue, and sort of solved the first issue (albeit a bit kludgily):
The idea is to clear the list by going to another node and swapping back.
Very simple, but does the trick under some circumstances. Maybe there's an even better way though?
(Make sure not to recall the OnFillTracksFunct function, since the 3 lines of code will automatically do that if you have a OnFillTracksFunct event call when clicking on a node.)
The idea is to clear the list by going to another node and swapping back.
Code: Select all
SDB.Objects("keepnode") = SDB.MainTree.CurrentNode
SDB.MainTree.CurrentNode = SDB.MainTree.Node_Library ' Or some other node which is blank
SDB.MainTree.CurrentNode = SDB.Objects("keepnode")
(Make sure not to recall the OnFillTracksFunct function, since the 3 lines of code will automatically do that if you have a OnFillTracksFunct event call when clicking on a node.)
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.
Re: Clearing TracksWindow and adding tracks by ID
I've not tried this, but to clear the window you could try this...This should return no results (as all tracks have positive IDs) and therefore clear the window.
Similarly, if you have an array of IDs that you want to add you could do something like this...Probably not the quickest query if you've a long list, but it should do the trick.
The way to turn an ID into a SongData is like this...
Code: Select all
Dim Tracks : Set Tracks = SDB.MainTracksWindow
Tracks.AddTracksFromQuery("WHERE ID<0")
Tracks.FinishAdding
Similarly, if you have an array of IDs that you want to add you could do something like this...
Code: Select all
Dim Tracks : Set Tracks = SDB.MainTracksWindow
Tracks.AddTracksFromQuery("WHERE ID IN("&arr.Join(",")&")")
Tracks.FinishAdding
The way to turn an ID into a SongData is like this...
Code: Select all
Dim song : Set song = Nothing
Dim iter : Set iter = SDB.Database.QuerySongs("AND Songs.ID = "&id)
If Not (iter.EOF) Then
Set song = iter.Item
End If
Set iter = Nothing
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Clearing TracksWindow and adding tracks by ID
Nope, this won't work, because it's simply adding zero tracks to the existing list. One needs to swap nodes.trixmoto wrote:I've not tried this, but to clear the window you could try this...This should return no results (as all tracks have positive IDs) and therefore clear the window.Code: Select all
Dim Tracks : Set Tracks = SDB.MainTracksWindow Tracks.AddTracksFromQuery("WHERE ID<0") Tracks.FinishAdding
Hmm... it works out quite quick. Actually, it's as quick as if you try "id=0 or id=1 or id=2 or id=3 ......" etc.Similarly, if you have an array of IDs that you want to add you could do something like this...Probably not the quickest query if you've a long list, but it should do the trick.Code: Select all
Dim Tracks : Set Tracks = SDB.MainTracksWindow Tracks.AddTracksFromQuery("WHERE ID IN("&arr.Join(",")&")") Tracks.FinishAdding
But it has the advantage that MM/SQlite will only allow 999 tracks through that method. Your way allows unlimited tracks (thanks so much - this will really make my life easier, since I was going to split up queries into groups of 999 each!).
The only thing now is whether to use QuerySongs or AddTracksFromQuery. Both have their quirks and advantages. AddTracksFromQuery is around 3 times quicker than QuerySongs, but it has the disadvantage that you need to wait for the tracks to finish filling the window before the UI gives you control back. This can get very painful with 100,000 or more tracks.
QuerySongs on the other hand starts adding tracks to the window immediately (albeit slowly) and also lets you change node in the middle. So although it's 3 times slower, it feels much quicker. However, there's the other drawback, that if you quickly switch between nodes with lots of tracks in them, they get confused, and the new node will add tracks from the old node's query! I've experimented with a number of things, to no avail (e.g. trying to halt the old query, but now I'm getting dupes from the new query into itself (brain fries)).
In fact, you can find this bug (at least to a limited degree) if you quickly switch between nodes in standard Playlists/Autoplaylists. You'll see it when a different number of tracks appeared than the usual that the node should contain. I noticed this bug before I started to do any scripting.
Ah thanks. I'm guessing this will be no quicker than the other methods since it has to keeping rescanning the database for every ID that needs adding.The way to turn an ID into a SongData is like this...Code: Select all
Dim song : Set song = Nothing Dim iter : Set iter = SDB.Database.QuerySongs("AND Songs.ID = "&id) If Not (iter.EOF) Then Set song = iter.Item End If Set iter = Nothing
MegaDJ v2 - Lightning fast and easy to use search to replace the standard AutoPlaylist. Features include random jukebox style playlists, along with syncing, weighting options, and logic complete querying.
Re: Clearing TracksWindow and adding tracks by ID
I tried adding these lines to TweakMonkey (the "1.1" version posted 2008 Feb 10) at the beginning of the Shutdown subroutine, but they didn't seem to have any effect. Any thoughts? I don't know vbs, so maybe I missed something.twinbee wrote:What's that sound I hear? Is it the sigh of relief as I realise that weeks of coding haven't been wasted? I think I may have semi-solved the second issue, and sort of solved the first issue (albeit a bit kludgily):
The idea is to clear the list by going to another node and swapping back.
Very simple, but does the trick under some circumstances. Maybe there's an even better way though?Code: Select all
SDB.Objects("keepnode") = SDB.MainTree.CurrentNode SDB.MainTree.CurrentNode = SDB.MainTree.Node_Library ' Or some other node which is blank SDB.MainTree.CurrentNode = SDB.Objects("keepnode")
(Make sure not to recall the OnFillTracksFunct function, since the 3 lines of code will automatically do that if you have a OnFillTracksFunct event call when clicking on a node.)
I'm trying to get MM3 to open with the playlist, tracklist, and player display all cleared, and with the Genre node expanded but all its subnodes collapsed. If I manually select the Library node before shutting down, TweakMonkey takes care of the rest. I was hoping that this bit of code would have the same effect.
Re: Clearing TracksWindow and adding tracks by ID
Oops. The "guest" post is mine. I forgot to log in.
Re: Clearing TracksWindow and adding tracks by ID
When I put just this line from twinbee's post into a simple non-auto script, executing the script produced the desired effect of clearing the Track Window.
However, I can't figure how to get it to work as part of an auto script. I tried putting it in the Startup and Shutdown subs in TweakMonkey and also into a shutdown sub in a separate auto script, but nothing worked. Since I have no idea what I'm doing here, any suggestions would be a big help.
Also please let me know if I'm violating forum etiquette with these posts. I don't mean to of course, but I don't have a lot of experience in coder forums.
Code: Select all
SDB.MainTree.CurrentNode = SDB.MainTree.Node_Library
Also please let me know if I'm violating forum etiquette with these posts. I don't mean to of course, but I don't have a lot of experience in coder forums.
Re: Clearing TracksWindow and adding tracks by ID
I guess maybe you can't change the node on shutdown because it's shutting down therefore doesn't bother - this is just a guess though.
On startup there might be a conflict with some of the settings so maybe set a timer to wait maybe a second or two and then do it.
On startup there might be a conflict with some of the settings so maybe set a timer to wait maybe a second or two and then do it.
Download my scripts at my own MediaMonkey fansite.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
All the code for my website and scripts is safely backed up immediately and for free using Dropbox.
Re: Clearing TracksWindow and adding tracks by ID
That makes sense. Or maybe there's just not enough time for it to work. I'm beginning to see that this won't be as simple as I'd hoped. Anyway, thanks for the ideas.