If I request a SysEx dump but the intended instrument is turned off the program keeps waiting endlessly. Is there a way to avoid it? #618
-
|
Code looks like this: # SEND dump request
self.msg_send(message) # this is a method I wrote that just sends messages thru the currently active port
# CATCH answer
with md.open_input(self.cur_in_port) as port: # .cur_in_port is the currently active input port saved as a Class attribute
message = port.receive()I tried with |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
I edited your message slightly to enable syntax highlighting. When opening a with mido.open_input() as port:
for message in port:
# do something with each "message"Tangentially, know that The best way to avoid these blocking issues altogether and my personal favorite is to pass a Hope it helps you reach your synthesizer collection control goal ;) |
Beta Was this translation helpful? Give feedback.
-
|
I've got the worse of two worlds: I'm an old person, AND a very inexperienced programmer, ha ha ha. So, the 'callback function' concept is kinda obscure and esoteric to me. Nevertheless, I'm very grateful for the recomendation and more than willing to give it a serious try. Still, if you have anything in the way of a written example —additional to the code indluded in the docs— it'll be also deeply appreciated, my man. Thanks! |
Beta Was this translation helpful? Give feedback.
I edited your message slightly to enable syntax highlighting.
When opening a
portusing thewithstatement, you have to enumerate themessagesfrom theport.No need for
receive()norpoll():Tangentially, know that
receive()is blocking by default (waiting for a message).You can use
receive(block=False)orpoll()but you may run into the opposite issue if the instrument takes some time to respond.The best way to avoid these blocking issues altogether and my personal favorite is to pass a
callback functionto theportinstead.The function will then be called asynchronously upon incoming …