Jump to content


Photo

Midi In & Valuebox: -12 to +12 with message.int_value

midi input message.int_value

  • Please log in to reply
4 replies to this topic

#1 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1544 posts
  • Gender:Male
  • Location:Spain

Posted 04 February 2018 - 13:10

Hi. I have created a valuebox that returns a value within the following range: -12 to +12

 

Through the midi_mapping of the vaulebox I have done the following:

rnt:add_midi_mapping {
  name = "Tools:PhraseTouch:Panel_1:Transpose:Transpose Valuebox",
  invoke = function( message )
    if message:is_abs_value() then
      vws["PHT_VAL_TRANS_1"].value = math.min( 12, math.max( message.int_value - 12, -12 ) )
    end
  end
}

math.min( 12, math.max( message.int_value - 12, -12 ) ) return returns the correct range, which is exactly this:

-12, -11 ... -2, -1, 00, 01, 02 ... +11, +12

The problem is that I can not return the correct range to fit the range of a rotating wheel, which is from 0 to 127. "0 to 127" corresponds to the value of "message.int_value".

 

Ok, I have tried to do the following:

 

math.min( 12, math.max( (message.int_value/(128/25) -12 ), -12 ) )

rnt:add_midi_mapping {
  name = "Tools:PhraseTouch:Panel_1:Transpose:Transpose Valuebox",
  invoke = function( message )
    if message:is_abs_value() then
      vws["PHT_VAL_TRANS_1"].value = math.min( 12, math.max( message.int_value/(128/25) - 12, -12 ) )
    end
  end
}

...but this returns the next range:

-12, -11 ... -2, -1, -0, 00, 01, 02 ... +11, +12

The operation also returns a "-0" a value that should not be. If you change the divisor to any other number, there always appears a 0 that should not be, -0 or +0, but should only return a "0" (neither negative nor positive).

 

Is there a different way to achieve this correctly? The intention is that the rotating wheel turns completely (-12 left, 0 up center, +12 right).

 

To be exact, this is the complete range that I want to return:

-12, -11, -10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 00, 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12

Note: I also use tostring and tonumber to adjust the values of the valuebox. But the problem is in the message.int_value of the midi_mapping


Edited by Raul (ulneiz), 04 February 2018 - 16:50.

:excl: Development of my tools: KangarooX120SamRenderPhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#2 4Tey

4Tey

    Big Masta Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPip
  • 535 posts
  • Gender:Male

Posted 04 February 2018 - 16:02

Personally I'd write maybe:

value = math.floor((message.int_value * 0.1875) + 0.5) - 12

where I assume message.int_value takes values through 0 to 127 and value gets values -12 to 12 but that probably isn't what you are looking for anyway.  Just sayin' Raul.



#3 joule

joule

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1836 posts
  • Gender:Not Telling

Posted 04 February 2018 - 16:42

With the risk of me misunderstanding.. If you want to "convert a value from one range to another", here is the formula: https://stackoverflo...intaining-ratio

#4 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1544 posts
  • Gender:Male
  • Location:Spain

Posted 04 February 2018 - 16:44

@4Tey. Ok, work perfectly! With math.floor you use a multiplier 24/128 = 0.1875.

 

I would have thought 25 instead of 24, because from -12 to +12 there are 25 values, counting 0. But no, they must be 24. Or 25/127. But no, they must be 24/128.

 

Thank you very much 4Tey!!!
 
@Joule. Thanks! All this information is very useful for specific mathematics. Sometimes I have trouble looking for certain things that are in English. Thanks for the link!
 
...
 
I consider the thread as already resolved...

Edited by Raul (ulneiz), 04 February 2018 - 16:51.

:excl: Development of my tools: KangarooX120SamRenderPhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler

#5 Raul (ulneiz)

Raul (ulneiz)

    Guruh Motha Fakka is Levitating and Knows Everything About Renoise Member

  • Normal Members
  • PipPipPipPipPipPipPipPipPipPipPipPipPip
  • 1544 posts
  • Gender:Male
  • Location:Spain

Posted 05 February 2018 - 02:11

value = math.floor( message.int_value * 25/128 ) - 12


:excl: Development of my tools: KangarooX120SamRenderPhraseTouch  |  GT16-Colors (old)

 

:excl: My API wishlist R3.1 (updated 24 July 2017):

Spoiler

 

:excl: My Renoise 3.1 wishlist (updated 26 September 2017):

Spoiler





Also tagged with one or more of these keywords: midi input, message.int_value