by twinbee » Fri Jul 11, 2008 7:26 am
trixmoto wrote:I've not tried this, but to clear the window you could try this...
Code: Select all
Dim Tracks : Set Tracks = SDB.MainTracksWindow
Tracks.AddTracksFromQuery("WHERE ID<0")
Tracks.FinishAdding
This should return no results (as all tracks have positive IDs) and therefore clear the window.
Nope, this won't work, because it's simply adding zero tracks to the existing list. One needs to swap nodes.
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
Probably not the quickest query if you've a long list, but it should do the trick.
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.
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.
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
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.
[quote="trixmoto"]I've not tried this, but to clear the window you could try this...[code] Dim Tracks : Set Tracks = SDB.MainTracksWindow
Tracks.AddTracksFromQuery("WHERE ID<0")
Tracks.FinishAdding[/code]This should return no results (as all tracks have positive IDs) and therefore clear the window.
[/quote]
Nope, this won't work, because it's simply adding zero tracks to the existing list. One needs to swap nodes.
[quote]
Similarly, if you have an array of IDs that you want to add you could do something like this...[code] Dim Tracks : Set Tracks = SDB.MainTracksWindow
Tracks.AddTracksFromQuery("WHERE ID IN("&arr.Join(",")&")")
Tracks.FinishAdding[/code]Probably not the quickest query if you've a long list, but it should do the trick.
[/quote]
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.
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.
[quote]
The way to turn an ID into a SongData is like this...[code] 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[/code]
[/quote]
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.