官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 崇礼县| 安顺市| 鄯善县| 修水县| 武宁县| 鱼台县| 莱阳市| 福安市| 岳西县| 东乌珠穆沁旗| 德庆县| 齐齐哈尔市| 西丰县| 凤台县| 米林县| 华安县| 双牌县| 阿克苏市| 尼木县| 荥阳市| 油尖旺区| 武冈市| 翼城县| 龙口市| 呈贡县| 延寿县| 江达县| 盖州市| 中宁县| 怀来县| 岢岚县| 阳城县| 屏南县| 绩溪县| 上蔡县| 渑池县| 土默特左旗| 抚州市| 盘山县| 保定市| 安国市|