BPM not being interpreted correctly (Magic Nodes)

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

BPM not being interpreted correctly (Magic Nodes)

Post by Philby » Wed Sep 14, 2005 3:32 am

Hi,
I saw a posting recently in response to a request to group or classify tracks according to the BPM value. The Magic Node code looked something like this...

Allegro|filter:BPM<120 and BPM>80

(just as an example.)

This does nothing ! MN does not give any errors, but it does not filter the tracks according to their BPM value. ALL tracks show in the node, regardless of the BPM value.

I also want to apply a set of groupings according to the range of the BPM. I understand that the BPM is stored as a "Long" type, so I cannot understand why the values are not being interpreted correctly. Even trying them as quoted strings produced the same result.

Any ideas or other solutions ?
Regards
Philby

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Fri Sep 16, 2005 2:34 am

OK, I can do this for you.
Do you want me to set the tempo of each file according to the bpm or do you want me to create a node were the files are grouped by the bpm?

"Unknown" for BPM < 1
"Largo" for BPM between 0 and 56
"Andante" for BPM between 57 and 82
"Allegro" for BPM between 83 and 145
"Presto" for BPM > 145

BTW In MagicNodes there seems to be an error with SQLFilter and Filter and the Function getQualifierValue
But that's not my task.
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Fri Sep 16, 2005 3:05 am

onkel_enno
I dont wish to sound greedy, but BOTH options would be great !
Many thanks
Regards
Philby

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Fri Sep 16, 2005 3:15 am

Philby wrote:onkel_enno
I dont wish to sound greedy, but BOTH options would be great !
Many thanks
lol
If a update the tempo-tag, then you can use magic node, so I will do that.

EDIT:
Here it is:
Create a file SetTempo.vbs and paste the code into it.

Code: Select all

Option Explicit
REM "Unknown" for BPM < 1
REM "Largo" for BPM between 0 and 56
REM "Andante" for BPM between 57 and 82
REM "Allegro" for BPM between 83 and 145
REM "Presto" for BPM > 145

Dim SDB
Set SDB = CreateObject( "SongsDB.SDBApplication")

Dim KeyLargo
Dim KeyAndante
Dim KeyAllegro
Dim KeyPresto

Dim dsTemp
	Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Largo'")
	if not dsTemp.EOF then KeyLargo = dsTemp.ValueByIndex(0)
	Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Andante'")
	if not dsTemp.EOF then KeyAndante = dsTemp.ValueByIndex(0)
	Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Allegro'")
	if not dsTemp.EOF then KeyAllegro = dsTemp.ValueByIndex(0)
	Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Presto'")
	if not dsTemp.EOF then KeyPresto = dsTemp.ValueByIndex(0)
set dsTemp = Nothing

'Delete all Tempos
SDB.Database.ExecSQL("Delete from AddSongInfoInt WHERE DataType = 10101")

'Set all Tempos to Largo, where BPM between 0 and 56
if CStr(KeyLargo) <> "" then 
	SDB.Database.ExecSQL("INSERT INTO AddSongInfoInt (IDSong, DataType, IntData) Select Songs.ID, 10101, " & KeyLargo & " FROM Songs WHERE BPM BETWEEN 0 AND 56")
else
	MsgBox "Largo is not part of the Tempo-List"
end if

'Set all Tempos to Andante, where BPM between 57 and 82
if CStr(KeyAndante) <> "" then 
	SDB.Database.ExecSQL("INSERT INTO AddSongInfoInt (IDSong, DataType, IntData) Select Songs.ID, 10101, " & KeyAndante & " FROM Songs WHERE BPM BETWEEN 57 AND 82")
else
	MsgBox "Andante is not part of the Tempo-List"
end if

'Set all Tempos to Allegro, where BPM between 83 and 145
if CStr(KeyAllegro) <> "" then 
	SDB.Database.ExecSQL("INSERT INTO AddSongInfoInt (IDSong, DataType, IntData) Select Songs.ID, 10101, " & KeyAllegro & " FROM Songs WHERE BPM BETWEEN 83 AND 145")
else
	MsgBox "Allegro is not part of the Tempo-List"
end if

'Set all Tempos to Presto, where BPM between 0 and 56
if CStr(KeyPresto) <> "" then 
	SDB.Database.ExecSQL("INSERT INTO AddSongInfoInt (IDSong, DataType, IntData) Select Songs.ID, 10101, " & KeyPresto & " FROM Songs WHERE BPM > 145")
else
	MsgBox "Presto is not part of the Tempo-List"
end if

Set SDB = Nothing
When Double-Clicking the file it will be executed and the Database will be updated. Don't save the file in MediaMonkey\Scripts\Auto.
Please make a Backup of your Database before executing the script.
Give me your feedback!
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Sat Sep 17, 2005 6:31 am

onkel-enno
Thank you for taking the time to prepare this script.

When I ran it, I got 4 errors

"Largo is not part of the Tempo-List"
"Andante is not part of the Tempo-List"
"Allegro is not part of the Tempo-List"
"Presto is not part of the Tempo-List"

My knowledge of VBScript is limited. What exactly is the script tyring to do ?
Does it make my database structure non-standard ?
Will future updates of MM install OK ?
What will the Magic Node code need to look like to access the Tempo's ?

Thanks again for your help.
Regards
Philby

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Sat Sep 17, 2005 6:34 am

One more thing

I will no doubt be adding more tracks to my library over time. I will also need to have new track tempos correctly classified. I guess this is what the Magic Node will do - right ?
Regards
Philby

rovingcowboy
Posts: 14162
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy » Sat Sep 17, 2005 7:24 am

OKay now you got my intrest peaked.. :o :P

will this script make autoplaylists according to the tempo of the songs.
as well as set the temp of the songs by the bpm :-? 8)

if so that will help out a lot for the internet radio's to have fast paced hour and a slow paced hour.


I also added in the needed header to the script ini file and then put the settemp script in the scripts folder.

when i started media monkey i got all the same alerts as he did. and i can not find the link to click on under the scripts header on the tools menu.?

so what did we or what didn't we screw up :o :-? :(
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy 5 Android 5) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Mon Sep 19, 2005 1:06 am

OK,

A liitle bit of lateral thinking here.
The errors in the script are because the child "Tempo" node under "Classification" does not have these categories already set up. They need to be added. I did it by directly editing the List table in the mediamonkey.mdb.

Then onkel-enno's script works fine and all my Tempos are set correctly !

Happiness :D
Regards
Philby

rovingcowboy
Posts: 14162
Joined: Sat Oct 25, 2003 7:57 am
Location: (Texas)
Contact:

Post by rovingcowboy » Mon Sep 19, 2005 8:12 am

i need more step by steps i am not a programer i just mess with what i can which is very little in scripting.

so how do i do that what you did, and how do i get this script to show up in the script menu on the tools menu?

in other words.

way in over my













:-?
roving cowboy / keith hall. My skins http://www.mediamonkey.com/forum/viewto ... =9&t=16724 for some help check on Monkey's helpful messages at http://www.mediamonkey.com/forum/viewto ... 4008#44008 MY SYSTEMS.1.Jukebox WinXp pro sp 3 version 3.5 gigabyte mb. 281 GHz amd athlon x2 240 built by me.) 2.WinXP pro sp3, vers 2.5.5 and vers 3.5 backup storage, shuttle 32a mb,734 MHz amd athlon put together by me.) 3.Dell demension, winxp pro sp3, mm3.5 spare jukebox.) 4.WinXp pro sp3, vers 3.5, dad's computer bought from computer store. )5. Samsung Galaxy 5 Android 5) 6. amd a8-5600 apu 3.60ghz mm version 4 windows 7 pro bought from computer store.

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Sep 19, 2005 8:17 am

It sounds like you're supposed to execute this script outside of MM - is that correct?

ADDITION: Yes, you can run this script outside of MM and it classifies your tracks. After you've added the headings to the "Lists" table in the .mdb as mentioned above of course! :)

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Tue Sep 20, 2005 12:37 am

Hi Guys,

sorry for replying so late.

@rovingcowboy
If you want to add it to the scripts menu, you will have to edit the script and add the two bold lines

//code
Option Explicit

Sub SetTempo
REM "Unknown" for BPM < 1
REM "Largo" for BPM between 0 and 56
REM "Andante" for BPM between 57 and 82
REM "Allegro" for BPM between 83 and 145
REM "Presto" for BPM > 145
...
End Sub
//code

and add following to the scripts.ini:

Code: Select all

[SetTempo]
FileName=SetTempo.vbs
ProcName=SetTempo
Order=6
DisplayName=Set Tempo Script
Description=...
Language=VBScript
ScriptType=0
If you want to use other captions for the tempo, you could edit the Set dsTemp-Lines
Example:
Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Presto'")
->
Set dsTemp = SDB.Database.OpenSQL("SELECT ID FROM Lists WHERE IDListType = 1 AND TextData = 'Fast'")
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Mon Sep 26, 2005 6:18 am

To onkel_enno,
Many thanks for your efforts with this script. I have impemented it and it works well. I am now wanting to run this sort of logic without it processing my entire library. I have written a couple of simple scripts to set some Custom fields, and they work only on the tracks I have selected. I would really like to hook this Tempo setting logic into my script so that the Tempo gets set only on the tracks that are selected. Naturally I have the looping logic sorted out, but could you help with the lines to just set the track currently active (I use ITM.fieldname) ? I tried .....

ITM.Tempo = 'Presto' , but got a script error.

Many thanks
Regards
Philby

onkel_enno
Posts: 2146
Joined: Fri Jan 14, 2005 1:45 am
Location: Germany
Contact:

Post by onkel_enno » Mon Sep 26, 2005 6:43 am

@Philby

It should be s.th. like that:

Code: Select all

Dim Songs
Set Songs = SDB.SelectedSongList

Dim a
Dim SongIDs
for a = 0 to Songs.Count -1
	if SongIDs <> "" then SongIDs = SongIDs & ", "
	SongIDs = SongIDs & Songs.Item(a).ID
next

'Delete all Tempos
SDB.Database.ExecSQL("Delete from AddSongInfoInt WHERE DataType = 10101 AND IDSong IN (" & SongIDs & ")")

'Set all Tempos to Largo, where BPM between 0 and 56
if CStr(KeyLargo) <> "" then
   SDB.Database.ExecSQL("INSERT INTO AddSongInfoInt (IDSong, DataType, IntData) Select Songs.ID, 10101, " & KeyLargo & " FROM Songs WHERE (BPM BETWEEN 0 AND 56) AND (IDSong IN (" & SongIDs & "))")
else
   MsgBox "Largo is not part of the Tempo-List"
end if 
But I didn't try it!
Of course You'll have to complete the rest of the script!
Hope I could help
SansaMonkey - for SanDisk Sansa and Rockbox Users

Please no PMs for Questions which should be asked in the Forum. Thx

Philby
Posts: 155
Joined: Wed Aug 10, 2005 7:49 am

Post by Philby » Mon Sep 26, 2005 8:04 am

onkel_enno,
Thanks again for your prompt assistance.
As it is almost my bedtime, I will try this out tomorrow and let you know.
Regards
Philby

trixmoto
Posts: 10024
Joined: Fri Aug 26, 2005 3:28 am
Location: Hull, UK
Contact:

Post by trixmoto » Mon Sep 26, 2005 8:17 am

If you get a finished working version, please post it! :) cheers

Post Reply