Last active
April 9, 2024 23:34
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output Google Sheet