ModPlug Central

OpenMPT => Development Corner => Topic started by: Eddy67716 on January 10, 2022, 06:57:31

Title: How to tell if a pattern note 0 is no note or C0
Post by: Eddy67716 on January 10, 2022, 06:57:31
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?

Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Eddy67716 on January 10, 2022, 07:05:23
The language I am using is Java.
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Saga Musix on January 10, 2022, 08:05:13
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.
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Eddy67716 on January 10, 2022, 08:06:50
So if I 253 fill the note byte array before unpacking the data, that should do the trick?
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Saga Musix on January 10, 2022, 08:08:57
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)
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Eddy67716 on January 10, 2022, 09:27:33
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.
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Saga Musix on January 10, 2022, 09:31:12
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]++;
Title: Re: How to tell if a pattern note 0 is no note or C0
Post by: Eddy67716 on January 10, 2022, 20:22:27
Thanks, that works even better.