Skip to content
Advertisement

Hexadecimal byte array from a Midi event to int

I’m trying to retrieve the tempo of a midi file through the javax.midi library.

JavaScript

What I am expected to receive is an array of three ex, because the Set Tempo meta message (which is this case, has just 3 bytes specifying a miliseconds amount. This is how the midi event returns

JavaScript

So if you join them you have 0x07A120 which is 500,000 ms, but Java returns in the print

JavaScript

First of all it is parsing it to decimal, and then I need to get this 500,000 number. I don’t know how to do it because first I need to join all the hex, and then I will have the number, but I don’t know how to do it.

Anyone can help me, please?

Advertisement

Answer

MetaMessage.getData() returns a byte array, which you turn into a list of bytes using Arrays.asList(), that’s why you print a list of bytes.

Below is a method that compute the tempo in beats per minute from a TEMPO MetaMessage. The mspq variable (milliseconds per quarter) is the value you seek.

JavaScript

Here you’ll find some more Midi utilities in java.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement