Clearing TracksWindow and adding tracks by ID

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Clearing TracksWindow and adding tracks by ID

Re: Clearing TracksWindow and adding tracks by ID

by RonSD » Fri Jul 18, 2008 3:59 pm

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.

Re: Clearing TracksWindow and adding tracks by ID

by trixmoto » Fri Jul 18, 2008 5:42 am

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.

Re: Clearing TracksWindow and adding tracks by ID

by RonSD » Thu Jul 17, 2008 7:50 pm

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.

Code: Select all

    SDB.MainTree.CurrentNode = SDB.MainTree.Node_Library
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.

Re: Clearing TracksWindow and adding tracks by ID

by RonSD » Wed Jul 16, 2008 7:14 pm

Oops. The "guest" post is mine. I forgot to log in.

Re: Clearing TracksWindow and adding tracks by ID

by Guest » Wed Jul 16, 2008 7:09 pm

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.

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")
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.)
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.

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

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.

Re: Clearing TracksWindow and adding tracks by ID

by trixmoto » Fri Jul 11, 2008 4:41 am

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.

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.

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

Re: Clearing TracksWindow and adding tracks by ID

by twinbee » Thu Jul 10, 2008 9:01 pm

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.

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")
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.)

Clearing TracksWindow and adding tracks by ID

by twinbee » Thu Jul 10, 2008 1:05 am

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) ?

Top