- Tkinter GUI Application Development Blueprints(Second Edition)
- Bhaskar Chaudhary
- 196字
- 2021-06-24 18:35:14
Playing the drum machine
Now that we have a mechanism to load drum samples and a mechanism to define beat patterns in place, let's add the ability to play these beat patterns. In many ways, this is the core of our program.
Let's first understand the functionality that we want to achieve here.
Once the user has loaded one or more drum samples and has defined a beat pattern using the toggle buttons, we need to scan each column of the pattern to see if it finds a green button (a True value in our data structure).
If the value is True for a given location in the matrix, our code should play the corresponding drum sample before moving ahead. If two or more drum samples are selected in the same column, all the samples should play almost simultaneously.
Moreover, there should be a fixed time gap between the playing of each successive column, which will define the tempo of the music.
To achieve this functionality, we need to import the pygame module to play the sounds, and the time module to define the temporal gap between them.
- 數(shù)據(jù)庫系統(tǒng)原理及MySQL應(yīng)用教程(第2版)
- 深入核心的敏捷開發(fā):ThoughtWorks五大關(guān)鍵實(shí)踐
- Python快樂編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- 解構(gòu)產(chǎn)品經(jīng)理:互聯(lián)網(wǎng)產(chǎn)品策劃入門寶典
- Java 9 Concurrency Cookbook(Second Edition)
- Mastering ServiceNow(Second Edition)
- Java Web開發(fā)就該這樣學(xué)
- Solr Cookbook(Third Edition)
- Python+Tableau數(shù)據(jù)可視化之美
- JavaScript機(jī)器人編程指南
- TypeScript 2.x By Example
- Python 快速入門(第3版)
- 計(jì)算機(jī)系統(tǒng)解密:從理解計(jì)算機(jī)到編寫高效代碼
- Visual C++程序設(shè)計(jì)全程指南
- Elasticsearch實(shí)戰(zhàn)(第2版)