# Midi gurus -- rpn and nrpn question...



## Thonex (Jul 26, 2006)

I'm trying to get Cubase/Nuendo to send out a (n)rpn value of over 127... do you know how I can type in a number (say in the List editor) of a value of (say) 1245 and have that sent out via midi as a (n)rpn??

here is a little info about (n)rpn data:

The number of a rpn/nrpn message is between 0 – 16383.

Any (n)rpn message uses two bytes to represent the parameter number, for example in the
case of rpn messages CC 101 represents the MSB (most significant byte) and CC100 the LSB
(least significant byte). 

Any help would be most welcome.

THanks,

T


----------



## Tillenburg (Jul 27, 2006)

Hi,

I'll try to explain to you:
Value from 0 to 255 have 0 at MSB and the value for LSB, for example 134 = MSB 0 and LSB134.

Values from 256 to 511 have MSB 1 and LSB (Value-256), for example 400 = MSB 1 and LSB 400-256 = 144

Values from 512 to 767 have MSB 2 and LSB (Value-2*256), for example 600 has MSB 2 and LSB 600-2*256 = 600-512 = 88

In General the formula is:
Value divide through 256. The Result before the point is the value for MSB, the rest is the value for LSB.

So: 1245 : 256 = 4.86328125 or lets better say 4 with the rest of 221 (because 4*256 + 221 = 1245), So MSB = 4 and LSB = 221.

Hope you understand. and sorry, english is not my native language.

Best wishes
Ralf


----------



## Thonex (Jul 27, 2006)

Thanks Tillenburg,

You explained it very well. I guess rpn or nrpn is not what I should be using then.... I'm trying to find an easy way for an end user to type in a tempo value that can be transmitted via midi to Kontakt 2 in stand-alone mode.

I think Ill just use 2 CCs. One for the first part of the tempo and the second for the last part and the decimal part of the tempo. So if someone wanted a patch in K2 to play in synch with a DAW at 132.4 BPM... he would type this in his DAW's list editor

CC100 = 13
CC101 = 24

THe script would then shift_left the 13 to be 130 and then add 24 -- no need to devide the result by 10 because then I'd do a calculation to make it fit NI's convention of representing everything between 0-1000000.

Cheers.

T


----------



## Big Bob (Jul 27, 2006)

Hi Andrew,



> I think Ill just use 2 CCs. One for the first part of the tempo and the second for the last part and the decimal part of the tempo. So if someone wanted a patch in K2 to play in synch with a DAW at 132.4 BPM... he would type this in his DAW's list editor
> 
> CC100 = 13
> CC101 = 24
> ...



Perhaps you mean you would multiply CC100's value by 100 and then add CC101? This would give you an 'internal' value of 1324 which your code would 'know' was the tempo scaled by 10. Remember that the KSP only works with integers so if you want to hold values like 132.4, you have to scale them by 10. Of course in your final calculations you will have to perform a division by 10 to correct for this.

God Bless,

Bob


----------



## Thonex (Jul 27, 2006)

Big Bob @ Thu Jul 27 said:


> Hi Andrew,
> 
> 
> 
> ...



Hi Bob :smile: 

Multiplying by 10 would work of course... but wouldn't:

sh_left (13,1) give a result of 130 ?

Never mind... it's shifting left by bits.... something completely different.... so... x 10 it is :lol: 

T


----------



## Thonex (Jul 27, 2006)

A kind gentleman from the CUbase forum answered my call for nrpn info and wrote a little application to calculate for you... very cool. I'm not sure what language it is.. but it works 

Here is his post:



> Create a new text document
> Open
> Paste the following code
> Save and close
> ...




```
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE></TITLE>
<SCRIPT ID=clientEventHandlersVBS LANGUAGE=vbscript>
<!--

Sub c_recalc_onclick
  Dim d14, msb, lsb, s
  d14 = c_nrpn.value
  msb = int(d14/128)
  lsb = d14 mod 128
  s = "CC 100 = " & lsb & vbCrLf
  s = s & "CC 101 = " & msb & vbCrLf
  d14 = c_nrpnval.value
  msb = int(d14/128)
  lsb = d14 mod 128
  s = s & vbCrLf
  s = s & "CC 038 = " & lsb & vbCrLf
  s = s & "CC 006 = " & msb & vbCrLf
  c_output.value = s
End Sub

Sub window_onload
  c_nrpn.value = 0
  c_nrpnval.value = 0
End Sub

-->
</SCRIPT>
</HEAD>
<BODY>

<P>NRPN
:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<INPUT id=c_nrpn style="WIDTH: 100px; HEIGHT: 22px" size=12>&nbsp; (0-16383)</P>
<P>NRPN Value :&nbsp;&nbsp;<INPUT id=c_nrpnval style="WIDTH: 99px; HEIGHT: 22px" size=12>&nbsp;(0-16383)</P>
<P><INPUT type=button value=Recalc id=c_recalc></P>
<P><TEXTAREA id=c_output style="WIDTH: 184px; HEIGHT: 103px" rows=5 cols=19></TEXTAREA></P>

</BODY>
</HTML>
```


----------



## Big Bob (Jul 27, 2006)

> Multiplying by 10 would work of course... but wouldn't:
> 
> sh_left (13,1) give a result of 130 ?
> 
> Never mind... it's shifting left by bits.... something completely different.... so... x 10 it is



Hey Andrew,

You're mis-quoting me :wink: , I believe I said to multiply by 100 *not by 10*. !0 is what you divide by whenever you use the value ot Tempo later in a calculation.

Tempo := %CC[100] * 100 + %CC[101]

where the integer named Tempo contains the actual tempo scaled by 10. Thus for a tempo of 123.4 BPM, we expect the user to set CC100 = 12 and CC101 = 34. If so, Tempo = 1234 (which is ten times the 'real value' of 123.4), No?

Bobby


----------



## Thonex (Jul 27, 2006)

Big Bob @ Thu Jul 27 said:


> Hey Andrew,
> 
> You're mis-quoting me :wink: , I believe I said to multiply by 100 *not by 10*. !0 is what you divide by whenever you use the value ot Tempo later in a calculation.
> 
> ...



Yeah... when I wrote that I was writing off the top of my head... here is the code I used and you can see in the "beta" thread:


```
if (%CC_TOUCHED [100] = 1 or %CC_TOUCHED [101]= 1)
      $DawBPM := ((%CC[100])*100)+ %CC[101]
      
      $Percent_Dif := (($DawBPM*10)/($SmplBPM)) {GIves rough up to 1 percent}
      $Percent_Decimal := (($DawBPM*1000)/($SmplBPM))-($Percent_Dif*100)

......
```

THanks for looking out for me Bob.

Cheers,

T


----------

