How to truncate (or ideally round) TBPM value?


#1

Hi,

I've tagged all my MP3 files using a free tool called MixMeister.

It has written the info into the TBPM tag to 2 decimal places. This is not quite in line with the ID3 standard (which states that the TBPM tag should contain an integer) and that is causing problems with other software.

I'd like to run an Action to conver all the TBPM values to integer.

Ideally I'd like to round the values - so, for example, that 140.25 would become 140, and 140.81 would become 141 - although guess that's quite a tall order!

So, alternatively, I'd just like to truncate the values by removing the decimal places and two following numbers, so 140.25 or 140.81 would just become 140.

I haven't quite worked out how to write custom actions, so would be very grateful if someone could suggest the correct syntax for me!

Thanks in advance,

Hercules


Rounding BPM value up or down
#2

Create an action group 'Round BPM to integer'.
Create following actions:
Action #1:
Action type: Format value
Field: BPM
Formatstring: $if($neql(%BPM%,$replace(%BPM%,'.',)),$replace(%BPM%,'.',),%BPM%'00')
Formatstring (alternative): $if($eql($strchr(%BPM%,'.'),0),%BPM%'00',$replace(%BPM%,'.',))

Action #2:
Action type: Format value
Field: BPM
Formatstring: $ifgreater($mod(%BPM%,100),49,$add($div(%BPM%,100),1),$div(%BPM%,100))

Testcases:
If BPM contains a decimal point, then it must have 2 decimals.
123 ==> 123
123.49 ==> 123
123.50 ==> 124
123.00 ==> 123
123.99 ==> 124

DD.20070122.1807
Edit. Changed erroneous 44 to 49.
DD.20120717.1513.CEST


#3

Thanks Detlev.

I've tried using that and it crashes my MP3Tag (v2.37a)!

I copied and pasted the text above so it's not a typo on my part.

I'm going to try to work out what the problem is, but am struggling to work out the syntax...

Is there a reference anywhere for all those commands/expressions you have used?

I can't find anything on this site... although have worked out, I think, that they are known as "regular expressions" or something like that...

Are these "regular expressions" a standard implementation, or has the support for them been custom coded by the MP3Tag developers?


#4

Have found some scripting help now, so having a look at that!

http://www.help.mp3tag.de/en/main_scripting.html


#5

My example should work with v2.37a, there is no new thing in the expressions.
Maybe there is another problem on your machine.
Try the latest Mp3tag development build and you will be fine.

There was no regular expression applied. The delivered code is simply all day Mp3tag programming script language.

When Mp3Tag is on the screen press the standard help key F1, and you will get the Mp3tag help pages. Even there are not all features well documented, it can help you to do your first steps with Mp3tag.

DD.20770122.2156


#6

Thanks again for the reply Detlev.

You're right, there may be a problem on my machine. I'll keep looking!

In the meanwhile, I've started messing about with some action scripts, and have come up with something that kinda works (although it assumes that there will always be 2 decimal places in every BPM tag so I'll need to check that is definitely true).

$ifgreater($right(%BPM%,2),49,$add($left(%BPM%,$sub($len(%BPM%),3)),1),$left(%BPM%,$sub($len(%BPM%),3)))

Anyway, thanks for your help, and for pointing me in the right direction.


#7

Oh, I see, you are a quick student!
If you generate BPM by Mixmeister, then 2 decimal places will be true always.

This might work too, but if you want proper rounding, then you have to check for greater than 44 in the reminder.

DD.20070122.2215


#8

I have a slightly new version, which allows different number formats for input BPM value, with or without decimal point, up to two decimal places.
Old BPM (Mixmeister) value will be saved into a new field BPM_MIXMEISTER for sure.

Testcases:
123 ==> 123
123. ==> 123
123.1 ==> 123
123.49 ==> 123
123.50 ==> 124
123.99 ==> 124

Action group 'Round BPM to integer'.
Action #1:
Action type: Format value
Field: BPM_MIXMEISTER
Formatstring: $if2(%BPM_MIXMEISTER%,%BPM%)

Action #2:
Action type: Format value
Field: BPM
Formatstring: $left($replace(%BPM%,'.',)'00',$add($len($div(%BPM%,1)),2))

Action #3:
Action type: Format value
Field: BPM
Formatstring: $ifgreater($mod(%BPM%,100),49,$add($div(%BPM%,100),1),$div(%BPM%,100))

DD.20070122.2344
Edit. Changed erroneous 44 to 49.
DD.20120717.1519.CEST


#9

Thanks once more Detlev.

By your prolific posting, I'm guessing/hoping you enjoyed my BPM challenge :wink:

I've just re-read your suggestions while referring to the scripting reference, and have realised that you are not rounding values above .44 upwards (which is what I initially thought before I understood how the functions worked :blush: ) but are rather, as you say, dividing and evaluating the remainder.

I like it - a neat solution :slight_smile:


#10

Also look there for the last challenge finding out the correct rounding formula:
BPM erst runden, dann ganzzahlig ausgeben

DD.20080516.1154.CEST