Turn R into a Drum Machine

Includes various functions for playing drum sounds. beat() plays a drum sound from one of the six included drum kits. tempo() sets spacing between calls to beat() in bpm. Together the two functions can be used to create many different drum patterns.


Travis build status

drumr: Turn R into a Drum Machine

drumr allows you to play drum beats from within R. At present the package contains only two functions -- beat(), which plays a beat from a given kit and drum, and tempo(), which sets the spacing between beats.

Installation

To install the development version of drumr, use the install_github function from the devtools package:

library(devtools)
install_github("jamesmartherus/drumr")

To install the latest release version of drumr, use the install.packages function:

install.packages("drumr")

Requirements

The beat function requires the audio package.

beat()

beat() takes two arguments - kit and drum. The kit argument selects a drumset, and the drum argument selects a specific piece from that kit. As present, there are four kits available:

Each kit includes four pieces:

  • kick: a standard bass drum strike
  • snare: a standard snare drum strike
  • hihat: a closed hihat cymbal
  • crash: a crash cymbal

Usage

beat(kit = "acoustic", drum = "snare")

tempo()

tempo() is a basic wrapper for Sys.time() that sets the time between calls to beat() in beats per minute (bpm). tempo() takes one argument - bpm.

Usage

tempo(bpm = 120)

Example Script

The following script will play a basic four-bar drum beat:

# Bars 1-3
for(i in 1:3){
  
  beat(drum="kick",kit="acoustic")
  
  tempo(240)
  
  beat(drum="kick",kit="acoustic")
  
  tempo(240)
  
  beat(drum="snare",kit="acoustic")
  
  tempo(240)
  
  beat(drum="kick",kit="acoustic")
  
  tempo(120)
  
  beat(drum="kick",kit="acoustic")
  
  tempo(240)
  
  beat(drum="snare",kit="acoustic")
  
  tempo(120)
  
}

#Bar 4
beat(drum="kick",kit="acoustic")

tempo(240)

beat(drum="kick",kit="acoustic")

tempo(240)

beat(drum="snare",kit="acoustic")

tempo(240)

beat(drum="kick",kit="acoustic")

tempo(120)

beat(drum="kick",kit="acoustic")

tempo(240)

beat(drum="snare",kit="acoustic")

tempo(240)

beat(drum="snare",kit="acoustic")

tempo(480)

beat(drum="snare",kit="acoustic")

Example with tidyverse

library(tidyverse)
library(drumr)

drum <- c("kick",
          "snare",
          "hihat",
          "crash")

pattern1 <- tribble(~drum,~notes,
        1,2,
        1,2,
        2,2,
        1,2,
        1,1,
        1,2,
        2,1) 

pattern2 <- tribble(~drum,~notes,
                 1,2,
                 1,2,
                 2,2,
                 1,1,
                 1,2,
                 2,2,
                 2,4) 

song <- bind_rows(map_dfr(seq_len(3), ~ pattern1), pattern2 )

 walk2(song$drum, song$notes,~  { beat(drum=drum[.x],kit="acoustic"); tempo(120 * .y) } )

Acknowledgments

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("drumr")

0.1.0 by James Martherus, 7 years ago


Browse source code at https://github.com/cran/drumr


Authors: James Martherus [aut, cre]


Documentation:   PDF Manual  


GPL-3 license


Imports audio, stringr


See at CRAN