Performance questions

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Performance questions

Post 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
ZvezdanD
Posts: 3271
Joined: Thu Jun 08, 2006 7:40 pm

Re: Performance questions

Post 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}"
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Re: Performance questions

Post 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.
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post by raybeau528 »

Thanks ZvezdanD ! I'll give that a try right now!

Ray
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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






raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Re: Performance questions

Post 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
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post by raybeau528 »

Technojnky,

The issues are primarily related to code within a script. The standard toolbar buttons don't apply.

Ray
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Re: Performance questions

Post 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).
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Re: Performance questions

Post 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.
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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.
ZvezdanD
Posts: 3271
Joined: Thu Jun 08, 2006 7:40 pm

Re: Performance questions

Post 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.
Magic Nodes 4.3.3 / 5.2 RegExp Find & Replace 4.4.9 / 5.2  Invert Selection/Select None 1.5.1  Export/Create Playlists for Child Nodes 4.1.1 / 5.4.1  Expand Child Nodes/Expand All 1.1.2  Event Logger 2.7  Filtered Statistics Report 1.6  Track Redirection & Synchronization 3.4.2  Restore/Synchronize Database 3.1.8 / 4.0.1  Find Currently Playing Track 1.3.2  Queue List 1.2.1  Add to Library on Play 1.0.1  Tree Report for Child Nodes 1.1.1  Update Location of Files in Database 1.4.5 / 2.3  Inherit Child Playlists 1.0.3  Add Currently Playing/Selected Track(s) to Playlist 1.2
raybeau528
Posts: 401
Joined: Thu Sep 27, 2007 4:19 pm
Location: Connecticut

Re: Performance questions

Post 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
Post Reply