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

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.

主站蜘蛛池模板: 铜陵市| 贵阳市| 科技| 雅江县| 洞头县| 长岛县| 田阳县| 武定县| 宜兰市| 舟曲县| 班玛县| 乐东| 景洪市| 祥云县| 比如县| 泾源县| 子洲县| 镇雄县| 珠海市| 仙桃市| 彰武县| 伊通| 安化县| 孟州市| 富阳市| 留坝县| 宜兴市| 临海市| 乌鲁木齐市| 忻州市| 宣威市| 崇阳县| 通河县| 高要市| 晋城| 泌阳县| 伊通| 农安县| 罗田县| 丰都县| 页游|