Author Topic: How to tell if a pattern note 0 is no note or C0  (Read 224 times)

Offline Eddy67716

  • Shy artist
  • Posts: 5
  • Operating System: Windows 10
How to tell if a pattern note 0 is no note or C0
« 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?

Offline Eddy67716

  • Shy artist
  • Posts: 5
  • Operating System: Windows 10
Re: How to tell if a pattern note 0 is no note or C0
« Reply #1 on: January 10, 2022, 07:05:23 »
The language I am using is Java.

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 7,431
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 10 x64
Re: How to tell if a pattern note 0 is no note or C0
« Reply #2 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.
» 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.

Offline Eddy67716

  • Shy artist
  • Posts: 5
  • Operating System: Windows 10
Re: How to tell if a pattern note 0 is no note or C0
« Reply #3 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?

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 7,431
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 10 x64
Re: How to tell if a pattern note 0 is no note or C0
« Reply #4 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)
» 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.

Offline Eddy67716

  • Shy artist
  • Posts: 5
  • Operating System: Windows 10
Re: How to tell if a pattern note 0 is no note or C0
« Reply #5 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.

Offline Saga Musix

  • OpenMPT Developers
  • *****
  • Posts: 7,431
  • aka Jojo
    • Download music, samples, VST plugins: Saga Musix Website
  • Operating System: Windows 10 x64
Re: How to tell if a pattern note 0 is no note or C0
« Reply #6 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:
Code: [Select]
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.

Offline Eddy67716

  • Shy artist
  • Posts: 5
  • Operating System: Windows 10
Re: How to tell if a pattern note 0 is no note or C0
« Reply #7 on: January 10, 2022, 20:22:27 »
Thanks, that works even better.