Page 1 of 2
Performance questions
Posted: Wed Jan 07, 2009 12:56 pm
by raybeau528
There's a major performance difference between right-clicking on a node/playlist and selecting PlayNow vs the simple script below which accomplishes the same thing. On my system, selecting 20,000 tracks takes on average 15 seconds to execute the script vs less than 1 second with PlayNow. I realize a script doesn't execute as fast as native code but in this case it's just one command
Code: Select all
sdb.player.playlistaddtracks(SDB.AllVisibleSongList)
that takes all the time and it's basically an API call that should do the same as PlayNow. Obviously it doesn't. But it shouldn't take 15x to 20x longer!
So my questions are:
1. Is this the best way, regarding performance, to do this?
2. Is there a scripting mechanism to initiate the playnow function that's available as a right-click function or a shortcut, ie Alt-Enter ?
Thanks!
Ray
Code: Select all
Option Explicit
Sub OnStartup
Dim itm3
Set itm3 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,0)
itm3.Caption = "Play Selection"
itm3.OnClickFunc = "PlaySelected"
itm3.UseScript = Script.ScriptPath
itm3.IconIndex = 25
itm3.Visible = True
End Sub
Sub PlaySelected(arg)
dim starttimer
starttimer=timer()
sdb.player.stop
sdb.player.playlistclear
sdb.player.playlistaddtracks(SDB.AllVisibleSongList)
sdb.player.play
msgbox(timer()-starttimer)
End Sub
Re: Performance questions
Posted: Wed Jan 07, 2009 1:10 pm
by ZvezdanD
raybeau528 wrote:Is there a scripting mechanism to initiate the playnow function that's available as a right-click function or a shortcut, ie Alt-Enter ?
Code: Select all
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "%{ENTER}"
Re: Performance questions
Posted: Wed Jan 07, 2009 1:19 pm
by Teknojnky
allvisiblesonglist is all songs in the track list, if you wanted
selected songs, then you probly want
http://www.mediamonkey.com/wiki/index.p ... edSongList instead
also,
the standard toolbar includes buttons for play selected now, next, and after.
look for the green buttons next to the podcast button.
Re: Performance questions
Posted: Wed Jan 07, 2009 1:34 pm
by raybeau528
Thanks ZvezdanD ! I'll give that a try right now!
Ray
Re: Performance questions
Posted: Wed Jan 07, 2009 8:56 pm
by raybeau528
I'm getting mixed results with the oShell.SendKeys function. If it's in a script where you right-click on a node and select the function with the send-keys command it works great. But if it's from a script that doesn't use a right-click on a node, it doesn't have the correct 'focus' to invoke the play-now function. Any ideas?
Ray
Re: Performance questions
Posted: Wed Jan 07, 2009 9:36 pm
by raybeau528
Here's a script to demonstrate the issue I mentioned in the previous post. Select a node in the tree and right-click the Save Node function. Then while focus is still in the tree, right-click the Play Saved Node function. The send-keys code works great. Change focus to the now playing window and select Play Saved Node function and the send-keys code won't initiate the NowPlaying feature. You can demonstrate this without the script. Click on a node in the tree to select tracks in the main tracks window. Set focus to the NowPlaying window. Clear any tracks. With focus still in the Now Playing window, press ALT-Enter. The tracks won't get copied to the Now Playing window. At least, not on mine!
Ray
Code: Select all
Option Explicit
Sub OnStartup
Dim itm
Set itm = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_Tree,0,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,0,0)
itm2.Caption = "Play Saved Node"
itm2.OnClickFunc = "Get_Node"
itm2.UseScript = Script.ScriptPath
itm2.IconIndex = 25
itm2.Visible = True
Dim itm3
Set itm3 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,0)
itm3.Caption = "Play Saved Node"
itm3.OnClickFunc = "Get_Node"
itm3.UseScript = Script.ScriptPath
itm3.IconIndex = 25
itm3.Visible = True
Dim itm4
Set itm4 = SDB.UI.AddMenuItem(SDB.UI.Menu_Pop_NP,0,0)
itm4.Caption = "Play Selection"
itm4.OnClickFunc = "PlaySelected"
itm4.UseScript = Script.ScriptPath
itm4.IconIndex = 25
itm4.Visible = True
End Sub
Sub Save_node(arg)
dim c,p
p = Trim(SDB.MainTree.currentnode.caption)
While not (SDB.MainTree.parentnode(SDB.MainTree.currentnode).caption = "")
set SDB.MainTree.currentnode=SDB.MainTree.parentnode(SDB.MainTree.currentnode)
p = Trim(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_NowPlaying
If SDB.MainTree.CurrentNode.Visible Then
SDB.MainTree.CurrentNode.Expanded=True
End If
For i = 0 to Ubound(a)
Do
If Trim(a(i))=Trim(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
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*1.25)
Tmr.Enabled=true
Script.RegisterEvent Tmr, "OnTimer", "PlayNow"
SDB.Objects("PlayTimer") = tmr
End Sub
Sub PlayNow(arg)
SDB.Objects("PlayTimer").Enabled = False
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "%{Enter}"
End Sub
Sub PlaySelected(arg)
Dim oShell
Set oShell = CreateObject("WScript.Shell")
oShell.SendKeys "%{enter}"
End Sub
Re: Performance questions
Posted: Wed Jan 07, 2009 10:56 pm
by raybeau528
Success! I was able to get this mostly working by adding a send.keys ctrl-A to select tracks which changed focus to the maintracks window.
Ray
Re: Performance questions
Posted: Thu Jan 08, 2009 1:48 pm
by raybeau528
Interesting observations:
1. If you set the "Play Now" action in tools/options/player, to either "Clear Tracks and Play Selected + Subsequent" or "Clear Tracks and Play Selected Only", the performance is really good. But if you set the "Play Now" action to "Play Selected Tracks Only", the performance is the same as the script code: sdb.player.playlistaddtracks(SDB.AllVisibleSongList), which is 15x-20x slower than the above.
2. The command, oShell.SendKeys "%{Enter}" (ALT+Enter), doesn't trigger the Play Now action (on my system). (Alt+Enter) is set as a hot key to Play Now. If I use just oShell.SendKeys "{Enter}" or oShell.SendKeys "{F12}" after setting F12 as a hot key to Play Now, it does work. Just can't get the Alt+Enter sendkeys to work.
Ray
Re: Performance questions
Posted: Thu Jan 08, 2009 2:26 pm
by Teknojnky
I still don't understand what your trying to accomplish that the 3 buttons on the toolbar don't do?
Also, how many tracks are you trying to add? If you are trying to hundreds or thousands of tracks to now playing, then yea the peformance is not so great as MM keeps a mediamonkey.m3u file of all the now playing tracks, so the larger the now playing, the large the m3u file that has to be managed/updated.
C:\Documents and Settings\UserName\Local Settings\Application Data\MediaMonkey.m3u
Re: Performance questions
Posted: Thu Jan 08, 2009 2:55 pm
by raybeau528
Technojnky,
The issues are primarily related to code within a script. The standard toolbar buttons don't apply.
Ray
Re: Performance questions
Posted: Thu Jan 08, 2009 3:38 pm
by Teknojnky
I see.
A hint, you do not need to use control a to select all files, when the tree node has the focus then all files will be selected with
sdb.currentsonglist
ie
sdb.player.playlistaddtracks(sdb.currentsonglist)
perhaps the performance your desiring may be there using that. (edit: actually I would guess it be the same, since your still adding a songlist object in any of the 3 methods, currentsonglist, selectedsonglist, allvisiblesonglist)
I would guess that the difference between 'play now' and playlistaddtracks(sdb.allvisiblesonglist) has to do with how the songs are added internally (by song id vs path or whatever).
Re: Performance questions
Posted: Thu Jan 08, 2009 4:05 pm
by Teknojnky
play selected only = queue next + advance track
perhaps the delay has more to do with inserting the selected tracks into an existing (now playing) songlist vs adding a whole new (now playing) songlist.
Re: Performance questions
Posted: Thu Jan 08, 2009 4:49 pm
by raybeau528
perhaps the delay has more to do with inserting the selected tracks into an existing (now playing) songlist vs adding a whole new (now playing) songlist.
I believe you are correct.
Re: Performance questions
Posted: Thu Jan 08, 2009 4:54 pm
by ZvezdanD
raybeau528 wrote:2. The command, oShell.SendKeys "%{Enter}" (ALT+Enter), doesn't trigger the Play Now action
I just tried and it works.
Re: Performance questions
Posted: Thu Jan 08, 2009 5:07 pm
by raybeau528
A hint, you do not need to use control a to select all files, when the tree node has the focus then all files will be selected with sdb.currentsonglist
True, except from a script the tree node doesn't maintain focus. You can work through some of the scripts I provided or just click on a node, then go to the now playing window, clear it, click on it, and press {Enter} or {Alt+Enter} and report what you find.
raybeau528 wrote:2. The command, oShell.SendKeys "%{Enter}" (ALT+Enter), doesn't trigger the Play Now action
I just tried and it works.
Please tell me more. Can you provide a sample script? Thanks!
Ray