Hello everyone,
I'm developing a chord recognition app for string instruments, it's just a sketch so far, I'm just trying to have a working version, first, but already I'm stuck on the MIDI playing part.

I'm using the same logic as the script that plays MIDI in the "misc" examples. When you press the blue note on the upper left, it should play the current selected frets, but instead it does a "clang" sound, like the sound is being cut short.

But if I place a breakpoint on the play() function, and then just press the |> button to let the script continue, it works as expected (i.e. it plays the midi file).

Is this some kind of threading problem? I've tried a number of different approachs but nothing seems to work. I think I have to force the toolbar() callback to wait for the play() function to finish, or to start the play() function on an independent thread, but I don't know how (using threading doesn't solve it, as far as I could understand).

Can you point me in the right direction?

Here's a jist of my code so far: https://gist.github.com/0739086ce29214db520865e4d3d9118a

Note: It has to be run locally in order to be able to write 'output.mid' file. Also I haven't put a close button yet, so you need to swipe down w/2 fingers to exit.

Thanks in advance for any help, and any other criticisms about my code are most welcome. I'm just a noob, really.