pythonmultithreadingpyqtmidipiano

Threading in PyQt


I am developing a software which has a virtual piano and that can be controlled by a midi keyboard. What I'm trying to do is I want a thread watching the midi inputs ans when there is a data coming corresponding process should be triggered ( here playing the sound and animating the key). How can I do it with Qt Threading and events?


Solution

  • Here is a good page on how to use custom signals: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/new_style_signals_slots.html

    And here is a page showing how to use QThread: http://joplaete.wordpress.com/2010/07/21/threading-with-pyqt4/

    Thats pretty much all you need. You create the QThread with a run() function that will loop and monitor your midi port, and then emit a custom signal. You would start this thread with your application launch. And you would connect the QThread's custom signal that you created to a handlers on your main app or whatever widget should be notified.