How it works...
The Handler class that is defined will be used to react to touch events. It expects one argument in the constructor, which is the speaker object that will handle audio playback. This object is saved to an attribute on the object instance. This class then defines a method that will be called each time a touch event has occurred. The method expects the first argument to be the name of the touchpad, and the second argument is a Boolean value that indicates the state of the touchpad.
When the method is called, it checks whether the pad is being touched; if so, it calls the play_file function to play the piano sound. The remainder of the code in the recipe supports the process of continually checking for new touch events and calls ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access