A call to midiin->closePort() prior to the midiin->openPort(..) seems a
simple effective fix to the problem; but the downside to this is that it
will also shortly disconnect when calling it on the port that is already
opened, which may be undesirable behaviour. So, perhaps a more elegant
i'm not sure why it would be undesirable if you want to change the port
anyway.
solution could be to implement a (midi-close) command that calls
closePort()?
yes, this could work. and i think midi-init should also close the port
first if there's an open one already, because otherwise it won't work if
i change the port number in the script and recompile.
best,
gabor