Support for multiple beat patterns
Our drum program is now functional. You can load drum samples and define a beat pattern and our drum machine will play it.
Let us now extend our drum machine to create more than one pattern in the same program. This will provide us with the ability to play different patterns simply by changing the pattern number. This gives the user the ability to make different beats for the intro, verse, chorus, bridge, and other parts of a song.
![](https://static.packt-cdn.com/products/9781785889738/graphics/B04945_03_07.jpg)
At the very outset, we have an entry widget adjacent to the Pattern Number Spinbox widget. We want to display the current pattern number in that entry widget.
We accordingly create a method, display_pattern_name()
, which does this task (see code 3.08.py
):
def display_pattern_name(self): self.current_pattern_name_widget.config(state='normal') self.current_pattern_name_widget.delete(0, 'end') self.current_pattern_name_widget.insert(0, 'Pattern {}'.format(self.current_pattern.get())) self.current_pattern_name_widget...