first commit
This commit is contained in:
51
sc55text.py
Normal file
51
sc55text.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import sys
|
||||
import re
|
||||
|
||||
def create_text_sysex(text):
|
||||
if not text:
|
||||
text = "EMPTY"
|
||||
|
||||
if len(text) > 32:
|
||||
print("Text cannot be longer than 32 symbols.")
|
||||
sys.exit(1)
|
||||
|
||||
model_id = 0x45
|
||||
address = [0x10, 0x00, 0x00]
|
||||
|
||||
text_bytes = [ord(char) for char in text]
|
||||
|
||||
def calc_checksum(addr, payload):
|
||||
total = sum(addr) + sum(payload)
|
||||
return (128 - (total % 128)) % 128
|
||||
|
||||
checksum = calc_checksum(address, text_bytes)
|
||||
|
||||
full_packet = bytes([0xF0, 0x41, 0x10, model_id, 0x12] + address + text_bytes + [checksum] + [0xF7])
|
||||
|
||||
return full_packet
|
||||
|
||||
def sanitize_filename(text):
|
||||
name = text.replace(" ", "_")
|
||||
name = re.sub(r'[\\/*?:"<>|]', "", name)
|
||||
name = name.strip(". ")
|
||||
return name if name else "output"
|
||||
|
||||
if __name__ == "__main__":
|
||||
input_text = " ".join(sys.argv[1:])
|
||||
|
||||
if not input_text:
|
||||
print("Usage: python sc55text.py [text]")
|
||||
sys.exit(1)
|
||||
|
||||
sysex_data = create_text_sysex(input_text)
|
||||
|
||||
safe_name = sanitize_filename(input_text)
|
||||
filename = f"{safe_name}.syx"
|
||||
|
||||
try:
|
||||
with open(filename, "wb") as f:
|
||||
f.write(sysex_data)
|
||||
print(f"Output file: {filename}")
|
||||
print("HEX:", " ".join(f"{b:02X}" for b in sysex_data))
|
||||
except Exception as e:
|
||||
print(f"Error occurred while saving the file: {e}")
|
||||
Reference in New Issue
Block a user