Now our program has the ability to play any sound. But we don't just need to play a single sound. We need to play a pattern. Let's define a method called play_pattern, which reads our internal data structure and plays files accordingly (see code 3.06.py):
import time def play_pattern(self): self.now_playing = True while self.now_playing: play_list = self.get_is_button_clicked_list() num_columns = len(play_list[0]) for column_index in range(num_columns): column_to_play = self.get_column_from_matrix( play_list, column_index) for i, item in enumerate(column_to_play): if item: sound_filename = self.get_drum_file_path(i) self.play_sound(sound_filename) time.sleep(self.time_to_play_each_column()) if not self.now_playing: ...