How to tell if a pattern note 0 is no note or C0

Started by Eddy67716, January 10, 2022, 06:57:31

Previous topic - Next topic

Eddy67716

I have been reverse engineering the .IT format and I am having troubles with decoding the pattern information.
In decoding the note, what code does Open MPT use to tell if a note, when it is 0; whether it is 'no note' or 'C0'? My code will always print C0. I want it to print __ if it is meant to be no note.
Or am I doing something else wrong?

Eddy67716


Saga Musix

While IT has an internal representation of "no note" (I think it was note 253), no note being present in the pattern data is simply indicated by the note bit in the status byte not being set, i.e. (StatusByte & 0x01) != 0 for new note data or (StatusByte & 0x10) != 0 for repeating the previous note. OpenMPT itself uses a different representation internally (0 = no note, 1 = C-0), so it's completely up to you whether you want to keep the ranges in your decoded data identical (i.e. 0 = C-0) or modify them like OpenMPT.
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

Eddy67716

So if I 253 fill the note byte array before unpacking the data, that should do the trick?

Saga Musix

That would be one way of doing it if you do not plan to process the note data any further, yes. If you plan to further mangle the note data and don't mind deviating from IT's own data representation a bit, I'd suggest to go with the approach OpenMPT uses though (i.e. add +1 to every note and assumine that 0 = no note when displaying / using the data)
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

Eddy67716

Thanks for that, I've added array[noteIndex]++ for the notes.
I also had to change the array from bytes to short which will double memory usage of unpacked data as well as reprogramming the note decoders a tiny bit, but it all works.
Thanks for your help.

Saga Musix

You could avoid the doubled memory by only incrementing the note data if it's in range [0...119]. Those are the regular notes, and everthing above that is "special" notes (note cut, note off, note off and the previosly-discussed "no note").

I'd suggest something like this:

if(array[noteIndex] >= 120 && array[noteIndex] < 253)
  array[noteIndex] = 252; // any note above and including 120 is "note fade"
else if(array[noteIndex] < 120)
  array[noteIndex]++;
» No support, bug reports, feature requests via private messages - they will not be answered. Use the forums and the issue tracker so that everyone can benefit from your post.

Eddy67716