Rhythm, continued: Drum machine tutorial

    • Read the Make a drum machine – Result sketch code. 
      In line 11, it seems to have two arrays in one array called “cells”: 
      let cells = [
        [0, 0, 0, 1], //cells[0] holds the snare pattern
        [1, 1, 1, 0] //cells[1] holds the kick pattern
      ];

      Then by using function playbeat(time), the lightened cells (cells[1]) will follow the instruction to play related sounds. These lightened cells will be detected exactly following the beat set before.  
      function playBeat(time) {
      // Make sure the sound files have been completely loaded
        if (kit.loaded) {
          let beat = Tone.Transport.position.split(":")[1];if (cells[0][beat]      ==1) {
            kit.player("snare").start(time);
          }
          if (cells[1][beat] == 1) {
            kit.player("kick").start(time);
          }
        }
      }
    • Starting form the Make it interactive – Result code:
      Here’s my sketch 3.
      I changed my patterns to some purple active circles but this sketch is still using the same 2-d array with previous ones ( only the initial status is changed). var cells = [
        [0, 1, 0, 1], //cells[0] holds the snare pattern
        [1, 0, 1, 0] //cells[1] holds the kick pattern
      ];

Leave a Reply

Your email address will not be published. Required fields are marked *