import time
import mido
import sys midi_channels = [
1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
1, 2, 3, 4, 5, 6, 7, 8
]
midi_ccs = [
20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43
] target_name = "MC-24"
outport_name = next((name for name in mido.get_output_names() if target_name in name), None)
inport_name = next((name for name in mido.get_input_names() if target_name in name), None)
if not outport_name or not inport_name:
print(f"MIDI device '{target_name}' not found or not connected.")
sys.exit(0)
outport = mido.open_output(outport_name)
inport = mido.open_input(inport_name)
print(f"Connected to {target_name}")
print("Sending settings to MIDI controller...") unlock_msg = mido.Message('aftertouch', channel=0, value=40)
outport.send(unlock_msg)
time.sleep(0.05) for i, ch in enumerate(midi_channels, start=0):
msg = mido.Message('control_change', channel=0, control=i+26, value=ch)
outport.send(msg)
time.sleep(0.05) for i, ch in enumerate(midi_channels, start=0):
msg = mido.Message('control_change', channel=0, control=i+26, value=ch)
outport.send(msg)
time.sleep(0.05) print("Waiting for confirmation...")
start = time.time()
confirmed = False
while time.time() - start < 1:
msg = inport.poll()
if msg and msg.type == 'song_select' and msg.song == 1:
confirmed = True
break
if confirmed:
print("All settings loaded successfully!")
else:
print("Error: confirmation not received.") import time
import mido
import sys
# === Define your settings ===
midi_channels = [
1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 13, 14, 15, 16,
1, 2, 3, 4, 5, 6, 7, 8
]
midi_ccs = [
20, 21, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43
]
# === Open MIDI ports with name filter ===
target_name = "MC-24"
outport_name = next((name for name in mido.get_output_names() if target_name in name), None)
inport_name = next((name for name in mido.get_input_names() if target_name in name), None)
if not outport_name or not inport_name:
print(f"MIDI device '{target_name}' not found or not connected.")
sys.exit(0)
outport = mido.open_output(outport_name)
inport = mido.open_input(inport_name)
print(f"Connected to {target_name}")
print("Sending settings to MIDI controller...")
# === Step 1. Unlock memory access (Aftertouch) ===
unlock_msg = mido.Message('aftertouch', channel=0, value=40)
outport.send(unlock_msg)
time.sleep(0.05)
# === Step 2. Send 24 MIDI channels ===
for i, ch in enumerate(midi_channels, start=0):
msg = mido.Message('control_change', channel=0, control=i+26, value=ch)
outport.send(msg)
time.sleep(0.05)
# === Step 3. Send 24 MIDI CC numbers ===
for i, cc in enumerate(midi_ccs, start=0):
msg = mido.Message('control_change', channel=0, control=i+50, value=cc)
outport.send(msg)
time.sleep(0.05)
# === Step 4. Wait for confirmation (F3 01) ===
print("Waiting for confirmation...")
start = time.time()
confirmed = False
while time.time() - start < 1:
msg = inport.poll()
if msg and msg.type == 'song_select' and msg.song == 1:
confirmed = True
break
if confirmed:
print("All settings loaded successfully!")
else:
print("Error: confirmation not received.")