MyNixOS website logo
Description

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

Metadata

Version

0.1.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows