Page 1 of 1

Tempo Script

Posted: Sat Jan 12, 2008 9:58 pm
by Killjoy12
I am trying to set the Tempo based upon the BPM in an auto script. While it does set the tempo field as desired, it does not appear to be recognized by MM. For example, the Tempo will get set to 'Fast', but the tracks are still showing up under the Unknown Tempo node, and do not show up under the Fast node. This is even after a restart of MM.

It looks like tempo is a simple text field, but now I am thinking it is not. Can anyone give me an idea why this script does not work correctly?

Code: Select all

Sub OnStartup

   Dim SDB
   Set SDB = CreateObject( "SongsDB.SDBApplication")
   
   ' Set Tempo where BPM is known, and the Tempo has not been set.
   SDB.Database.ExecSQL("Update Songs Set Tempo = 'Very Slow' Where (Tempo = '' or Tempo = 'None') AND (BPM >= 0 and BPM <=56)")
   SDB.Database.ExecSQL("Update Songs Set Tempo = 'Slow' Where (Tempo = '' or Tempo = 'None') AND (BPM >= 57 and BPM <=82)")
   SDB.Database.ExecSQL("Update Songs Set Tempo = 'Moderate' Where (Tempo = '' or Tempo = 'None') AND (BPM >= 83 and BPM <=145)")
   SDB.Database.ExecSQL("Update Songs Set Tempo = 'Fast' Where (Tempo = '' or Tempo = 'None') AND (BPM >= 146 and BPM <=200)")
   SDB.Database.ExecSQL("Update Songs Set Tempo = 'Very Fast' Where (Tempo = '' or Tempo = 'None') AND (BPM >200)")
   
   Set SDB = Nothing 

End Sub

Posted: Sun Jan 13, 2008 3:48 am
by Big_Berny
Don't know why it doesn't work but you should change your BPM-ranges because not all values are covered:

Code: Select all

BPM >= 0 and BPM <= 56
BPM >= 57 and BPM <= 82
...
-->Problem: What happens with 56.5

Better:

Code: Select all

BPM >= 0 and BPM < 57
BPM >= 57 and BPM < 83
...
Anyway first you should fix your problem. Maybe you shouldn't use ExecSQL but load each song an use Song.Tempo. You could try this one:

Code: Select all

Sub OnStartup
	Dim Song
	SDB.Database.BeginTransaction
	Dim SongIter : Set SongIter = SDB.Database.QuerySongs("")

	Do While Not SongIter.EOF 
		Set Song = SongIter.Item
		if Song.Tempo = "None" or Song.Tempo = "" then
			if Song.BPM >= 0 and Song.BPM < 57 then
				Song.Tempo = "Very Slow"
				elseif Song.BPM >= 58 and Song.BPM < 83 then
					Song.Tempo = "Slow"
					elseif Song.BPM >= 83 and Song.BPM < 145 then
						Song.Tempo = "Moderate"
						elseif Song.BPM >= 146 and Song.BPM <= 200 then
							Song.Tempo = "Fast"
							elseif Song.BPM > 200 then
								Song.Tempo = "Very Fast"
							end if
						end if
					end if
				end if
			end if
			Song.UpdateDB
			Song.WriteTags
		end if
		SongIter.Next
	Loop
	Set SongIter = Nothing
	SDB.Database.Commit
end sub
Didn't tested it so I don't know if it works. And unfortunately I don't have time anymore today to test or change it but maybe it helps.

Posted: Sun Jan 13, 2008 3:31 pm
by Killjoy12
Thanks for the information - I now have this script working.

I am posting the final version of this script for anyone interested. Just add this to your Scripts\Auto folder and name as SetTempo.vbs

Code: Select all

Sub OnStartup
   Dim Song
   ' Set Tempo for non-podcasts, where BPM is known and the Tempo has not already been set.
   SDB.Database.BeginTransaction
   Dim SongIter : Set SongIter = SDB.Database.QuerySongs("")
   Do While Not SongIter.EOF
      Set Song = SongIter.Item
      if UCase(Song.Genre) <> UCase("Podcast") And UCase(Song.Tempo) = UCase("None") or Song.Tempo = "" And Song.BPM >= 0 Then
         if Song.BPM <= 56 then
            Song.Tempo = "Very Slow"
         elseif Song.BPM <= 82 then
            Song.Tempo = "Slow"
         elseif Song.BPM <= 145 then
            Song.Tempo = "Moderate"
         elseif Song.BPM <= 200 then
            Song.Tempo = "Fast"
         Else
            Song.Tempo = "Very Fast"
         end if
         Song.UpdateDB
         Song.WriteTags
      end if
      SongIter.Next
   Loop
   Set SongIter = Nothing
   SDB.Database.Commit
end sub

Posted: Sun Jan 13, 2008 3:36 pm
by Big_Berny
@Killjoy: Oh dear, what a b*llsh*t did I post here this morning... ;) But at least it helped! :)

Posted: Sun Jan 13, 2008 3:38 pm
by Teknojnky
putting

Code: Select all

SDB.ProcessMessages
on a line just before the LOOP command, it will make the script run smoother when processing large amounts of tracks.

Posted: Sun Jan 13, 2008 3:39 pm
by Killjoy12
Hey - you were the one who did all the work!!

Thanks again. I'm very pleased with the support of this community.

Posted: Sun Jan 13, 2008 4:41 pm
by Big_Berny
Well ok, but the elseif part was kind of... just WRONG! :)

But glad I could help. You're right it's a great community.

Posting ?

Posted: Fri Jan 18, 2008 2:16 pm
by duckcubbie
When will we get the script link to download? Thanks both of you for your hard work ! :D

Posted: Fri Jan 18, 2008 2:23 pm
by Killjoy12
I can't host files - the code is pasted above. You can just copy and paste it into a .vbs file in you Scripts\Auto folder.

Posted: Wed Jan 23, 2008 12:46 am
by Guest
Sorry but how do i create a file that is .vbs?

Posted: Wed Jan 23, 2008 4:08 am
by spacefish
@Guest: All you have to do is copy the text above and paste it in your favorite text editor. Click Save and when the program asks you for a file name, change .txt to .vbs

@Killjoy12: Thanks, this looks like it will come in handy after I've got all my BPMs set. :)

Re: Tempo Script

Posted: Mon Aug 08, 2011 12:36 pm
by carkey151
Can this script be modified to only monitor one folder instead of scanning the whole database at startup? Or, after startup, to run from "Tools/Scripts" only on selected tracks? I really like this script but as my database gets larger, it's taking a long time to scan at startup. An excellent script Killjoy12/Teknojnky. 5 stars. Thank you.

Re: Tempo Script

Posted: Thu Mar 31, 2016 1:25 pm
by remusMax
i've modified the original script to only process the selected files. i'm not sure if it's the most efficient but it works. To get MediaMonkey to register the new script on Windows10 i had to start media monkey by right clicking and "Run As Administrator".

Thank you and great community!!

add this to ..\MediaMonkey\Scripts\scripts.ini

Code: Select all


[SetTempo]
FileName=SetTempoSelected.vbs
ProcName=SetTempoFromBPM
Order=10
DisplayName=Set Tempo
Description=Set Selected Tracks Tempo based on BPM
Language=VBScript
ScriptType=0

in the ..\MediaMonkey\Scripts folder make a new file named SetTempoSelected.vbs with the following code

Code: Select all

Sub SetTempoFromBPM
   Dim Song, list
   ' Get list of selected tracks from MediaMonkey
  Set list = SDB.SelectedSongList 
  
 ' Process all selected tracks
  For i=0 To list.count-1
	Set Song = list.Item(i)
	  ' Set Tempo where BPM is known and the Tempo has not already been set.
	  if UCase(Song.Tempo) = UCase("None") or Song.Tempo = "" And Song.BPM >= 0 Then
		 if Song.BPM <= 56 then
			Song.Tempo = "Very Slow"
		 elseif Song.BPM <= 82 then
			Song.Tempo = "Slow"
		 elseif Song.BPM <= 145 then
			Song.Tempo = "Moderate"
		 elseif Song.BPM <= 200 then
			Song.Tempo = "Fast"
		 Else
			Song.Tempo = "Very Fast"
		 end if
		 Song.UpdateDB
		 Song.WriteTags
	  end if
   Next
    ' Write all back to DB and update tags
	list.UpdateAll
	
End sub