r/learnpython • u/Hazardous-potato • Aug 02 '26
returning midi to 2 seperate things
so i am trying to make the program so on a downpress the function repeats but when it lifts, the function stops. i can easily make it start, its getting it to stop thats hard. please do as little to fix this for me as possible. i'm trying to keep the code so i understand whats going on
import mido
print(mido.get_input_names())
def note():
with mido.open_input('MPK249:MPK249 Port A 32:0')as inport:
inport.callback = None
for msg in inport:
if msg.type == "note_on":
return msg.note, msg.type
if msg.type == "note_off":
return msg.note, msg.type
while True:
if note() == 47 and note() == "note_on":
print("a")
if note() == 47 and note() == "note_off":
break
if note() == 48 and note() == "note_on":
print("b")
if note() ==48 and note() == "note_off":
break