INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: [solved] Problem with simple (?) Math and InRange expression  (Read 1921 times)

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
[solved] Problem with simple (?) Math and InRange expression
« on: February 25, 2014, 06:16:16 pm »

For over an hour I'm trying to make a simple math expression work. I don't get it.

Goal
I'm trying to compare two values. I want to use the result of this comparison in a more complex expression to decide which value should be displayed.
Finally I'll use something like this:
   IfElse( IsRange( Math( [BPM manual] - replace([BPM calculated], /,, .) ) , 1-3 ), [BPM calculated], IsEmpty( [BPM manual] ), *[BPM calculated], 1, [BPM manual])

Current state

   Math(replace([BPM calculated], /,, .) - [BPM manual])

So, what I am trying to do is a simple subtraction. I used the wiki to figure out how to handle the replace expression to replace the local "," as decimal separator with "." to make the math expression work. It contains two user fields.

BPM calculated
It's an expression field which divides JRiver analyzed bpm value with 4. It looks like this:
   Math([BPM (analyzed)] / 4)

BPM manual
This is an user data integer field which only contains numbers with zero decimal places.

Current output with current state
15 - 15 = -45
33,25 - 16 = -99,75
15,25 - 16 = -45,75
33 - 16 = -99
42 - 22 = -126


Can anybody figure out what am I doing wrong?
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Problem with simple (?) math expression
« Reply #1 on: February 25, 2014, 07:23:54 pm »

What is [BPM (analyzed)]?
Logged
The opinions I express represent my own folly.

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: Problem with simple (?) math expression
« Reply #2 on: February 25, 2014, 07:39:43 pm »

It's the field which contains the result of MCs audio analyses which I renamed.
Logged

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: Problem with simple (?) math expression
« Reply #3 on: February 25, 2014, 07:42:40 pm »

OK, your question guided me to the solution. I was using a wrong field name at some place. Now it works.
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: [Solved] Problem with simple (?) math expression
« Reply #4 on: February 25, 2014, 07:49:47 pm »

And what type is BPM calculated defined as?

Ok, never mind.  Good.
Logged
The opinions I express represent my own folly.

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: [Solved] Problem with simple (?) math expression
« Reply #5 on: February 25, 2014, 07:55:11 pm »

Looks as if I'm unable to use the "InRange" Expression  :-\

This part of the expression now works correctly:
  Math(replace([BPM calculated], /,, .) - [bpm StFeder])

But I don't get a value "1" for my "InRange" expression even if the result of the above expression is in the defined range...
  IsRange(Math(replace([BPM calculated], /,, .) - [bpm StFeder]), 0-3)


Investigating :)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Problem with simple (?) range expression
« Reply #6 on: February 25, 2014, 07:58:56 pm »

The result of your Math() could also be a floating point, and as such, you'll have to do a Replace() on the result so any comma gets translated to period.
Logged
The opinions I express represent my own folly.

StFeder

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 1493
  • Fight! You may win. If you don't, you already lost
Re: Problem with simple (?) range expression
« Reply #7 on: February 25, 2014, 08:14:48 pm »

I was thinking about this to. Now I ended up with this one:

IfElse( IsRange( Math( abs( replace( [BPM calculated], /,, .) - [bpm StFeder])), 0-3), [BPM calculated], IsEmpty( [BPM StFeder] ), *[BPM calculated], 1, [BPM StFeder])

I had to eliminate the negative values using the math function abs( and then it worked. Looks as if the InRange expression does work with comma. Now the complete expression is finally doing its job :)

Thanks, MrC, for taking the time! Sometimes the right questions gives the solution. And you had the right one  8)
Logged

MrC

  • Citizen of the Universe
  • *****
  • Posts: 10462
  • Your life is short. Give me your money.
Re: Problem with simple (?) range expression
« Reply #8 on: February 25, 2014, 08:20:47 pm »

Sure, no problem.

Because of the way the MC expression language parses and evaluates, no functions can "know" the difference between the comma used to separate the arguments, and a comma output as the result of field interpolation.

So, keep in mind the following:

    functionA( functionB( functionC() ) )

always evaluates FunctionC first, and then MC looks for the arguments to the FunctionB call.  And so on, to FunctionA.
Logged
The opinions I express represent my own folly.
Pages: [1]   Go Up