Tempo Script

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

Killjoy12
Posts: 100
Joined: Mon Jun 11, 2007 11:33 pm

Tempo Script

Post 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
Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post 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.
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design
Killjoy12
Posts: 100
Joined: Mon Jun 11, 2007 11:33 pm

Post 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
Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post by Big_Berny »

@Killjoy: Oh dear, what a b*llsh*t did I post here this morning... ;) But at least it helped! :)
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design
Teknojnky
Posts: 5537
Joined: Tue Sep 06, 2005 11:01 pm
Contact:

Post 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.
Killjoy12
Posts: 100
Joined: Mon Jun 11, 2007 11:33 pm

Post by Killjoy12 »

Hey - you were the one who did all the work!!

Thanks again. I'm very pleased with the support of this community.
Big_Berny
Posts: 1784
Joined: Mon Nov 28, 2005 11:55 am
Location: Switzerland
Contact:

Post 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.
Image
Scripts in use: Genre Finder / Last.fm DJ / Magic Nodes / AutoRateAccurate / Last.FM Node
Skins in use: ZuneSkin SP / Eclipse SP
AutoRateAccurate 3.0.0 (New) - Rates all your songs in less than 5 seconds!
About me: icoaching - internet | marketing | design
duckcubbie
Posts: 6
Joined: Fri Jan 18, 2008 12:46 pm
Contact:

Posting ?

Post by duckcubbie »

When will we get the script link to download? Thanks both of you for your hard work ! :D
Killjoy12
Posts: 100
Joined: Mon Jun 11, 2007 11:33 pm

Post 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.
Guest

Post by Guest »

Sorry but how do i create a file that is .vbs?
spacefish
Posts: 1427
Joined: Mon Jan 14, 2008 7:21 am
Location: Denmark

Post 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. :)
Image
MM Gold 3.0.3.1183 : Vista HP SP1 (x86) : Zen Stone (2GB)
Zekton: An original MM3 skin by Eyal.
Scripts in Use: Add/Remove PlayStat | Auto Album DJ | AutoRateAccurate | Backup
Case & Leading Zero Fixer | Classification & Genre Changer | Clean Scripts.ini | Clear
Field | Custom Report | Discogs Auto-Tag Web Search | Forget Crossfade | Invert
Selection/Select None | Last 100... | Lyricator | Lyrics to Instrumental | MonkeyRok
MusicBrainz Tagger | My Custom Nodes | Now Playing Art Node | Play History & Stats
Right Click for Reports | Right Click for Scripts | Right Click for Web | Stop After Current
WebNodes
carkey151
Posts: 24
Joined: Fri Jan 22, 2010 9:14 am

Re: Tempo Script

Post 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.
remusMax

Re: Tempo Script

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