Converting vb code to another language is not always straightforward. I needed to convert Ted's code to C# and it looked easy at first but I ran into trouble with the two lines:

xTem1 = TotalTempo \ (2 ^ 14) And 127 '14 bit shift

xTem2 = TotalTempo \ (2 ^ 7) And 127 ' 7 bit shift

The (2 ^ 14) is Math.Pow(2,14) in C# but *** the result is a double. it took a bit of "googling" to find how to get the result to an integer. here is the partial c# code that does the job

` int MyTempo = 80;`

int xTem1;

int xTem2;

int xTem3;

int TotalTempo;

TotalTempo = 60000000 / MyTempo;

xTem1 = TotalTempo / (int)(Math.Pow(2, 14)) & 127; // 14 bit shift

xTem2 = TotalTempo / (int)(Math.Pow(2, 7)) & 127; // 7 bit shift

xTem3 = TotalTempo & 127;

Maybe that will help with the Java, which is a lot like c#. Maybe it will not. I do not know Java well.

Regards, Richard

Perfect! Thank you Richard and Machael .I works perfectly now. Here is my JS code which is in syntax pretty similar to Java and C#!

==== tempo.js ====

function hex(yourNumber) {

hexString = yourNumber.toString(16);

if (hexString.length % 2) {

hexString = '0' + hexString;

}

return hexString;

}

function tempoPSR(MyTempo) {

var MyTempo, xTem1, xTem2, xTem3, TotalTempo;

TotalTempo = Math.floor(60000000 / MyTempo);

xTem1 = Math.floor(TotalTempo / Math.pow(2 , 14)) & 127; //14 bit shift

xTem2 = Math.floor(TotalTempo / Math.pow(2 , 7)) & 127; // 7 bit shift

xTem3 = TotalTempo & 127;

//---------- tempo sysEx

return [hex(0xF0), hex(0x43), hex(0x7E), hex(0x1), hex(0x0), hex(xTem1), hex(xTem2), hex(xTem3), hex(0xF7)].join(" ");

}

console.log(5, tempoPSR(5));

console.log(120, tempoPSR(120));

console.log(120.1, tempoPSR(120.1));

When I run it:

$ node tempo.js

5 'f0 43 7e 01 00 5c 36 00 f7'

120 'f0 43 7e 01 00 1e 42 20 f7'

120.1 'f0 43 7e 01 00 1e 3e 7f f7'