MidiMessage::getKeySignature returns 253


(I couldn’t put getKeySignatureNumberOfSharpsOrFlats) into the title because it then is “not descriptive enough”)

I have a MidiMessage msg from a MIDI file. First, I assert that it’s indeed a key signature event: jassert(msg.isKeySignatureMetaEvent()). The assert passes. Then I call msg. getKeySignatureNumberOfSharpsOrFlats(). This returns 253, which would be quite a lot of sharps/flats! I think it should be -2.

Looking at the implementation, the function casts an uint8 from getMetaEventData to int using a C-style cast. Can this ever result in a negative number? (as described in the documentation for getKeySignatureNumberOfSharpsOrFlats)
I think it would work if you casted to an int8 (to get the wrap-around into the negatives).


Thanks, didn’t realise that it could be negative! Yes, the correct way to do it would indeed be to cast to an int8 first - I’ll sort that out…


Great, thank you!