Skip to content

Instantly share code, notes, and snippets.

@drosenstark
Last active April 9, 2024 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drosenstark/3d10b7aad9f1ba4851887d04ab996e61 to your computer and use it in GitHub Desktop.
Save drosenstark/3d10b7aad9f1ba4851887d04ab996e61 to your computer and use it in GitHub Desktop.
Python Script Dumps a CSV to Disk with 255 Rows of "Roland Nibble Encoded" Values (see link in code)
#!/usr/bin/env python3
#
# Make255Values-RolandNibbleEncoding
# See https://mididesigner.com/qa/10040/roland-tr-8s-sysex-whats-what for what's what
import csv
# Convert decimal value to MSB and LSB hexadecimal values
def to_msb_lsb(value):
msb = value // 16
lsb = value % 16
return f"{msb:02X}", f"{lsb:02X}"
def calculate_spreadsheet_value(msb, lsb):
return (msb * 256) + lsb
def calculate_midi_value(msb, lsb):
return (msb * 128) + lsb
def main():
output_file = 'roland_nibble_mapping.csv'
with open(output_file, 'w', newline='') as csvfile:
csvwriter = csv.writer(csvfile)
csvwriter.writerow(['Row', 'MSB', 'LSB', 'MIDI Value', 'Spreadsheet', 'Named Tick'])
for row in range(256):
msb_hex, lsb_hex = to_msb_lsb(row)
# Hexadecimal to Decimal integers
msb = int(msb_hex, 16)
lsb = int(lsb_hex, 16)
value1 = calculate_midi_value(msb, lsb)
value2 = calculate_spreadsheet_value(msb, lsb)
named_tick = f"{value1} \ {msb_hex}-{lsb_hex}"
csvwriter.writerow([row, msb_hex, lsb_hex, value1, value2, named_tick])
if __name__ == '__main__':
main()
@drosenstark
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment