Skip to content

Instantly share code, notes, and snippets.

@andreasjansson
Created December 5, 2011 04:29
Show Gist options
  • Save andreasjansson/1432304 to your computer and use it in GitHub Desktop.
Save andreasjansson/1432304 to your computer and use it in GitHub Desktop.
library(rmidi)
library(magic)
midi.set.tempo(140)
ppq = midi.get.ppq()
an <- c(12, 0, 12, 11, 0,
11, 0, 11, 5, 0,
5, 0, 5, 8, 0,
8, 0, 8, 7, 0,
7, 0, 7, 12, 0,
12, 0, 12, 11, 0,
11, 0, 11, 5, 0,
5, 0, 5, 8, 0,
8, 0, 8, 7, 0,
7, 0, 7, 12, 0,
12, 0, 12, 13, 0,
13, 0, 13, 11, 0,
11, 0, 13, 12, 0,
12, 0, 12, 15, 0,
15, 0, 15, 5, 0,
5, 0, 5, 8, 0,
8, 0, 8, 7, 0,
7, 0, 7, 12, 0)
bd <- c(2, 1, 2)
bn <- c(0, 0, 10,
10, 10, 9,
9, 9, 5,
5, 5, 4,
4, 4, 3,
3, 3, 2,
2, 2, 5,
5, 5, 3,
3, 3, 7,
7, 7, 6,
6, 6, 1,
1, 1, 5,
5, 5, 3,
3, 3, 8,
8, 8, 1,
1, 1, 7,
7, 7, 5,
5, 5, 0)
dbd <- c(1.5, 1.5, 0.5, 0.5, 1, 1, 1, 1.5, 1.5)
dbn <- c(36, 36, 38, 38, 38,38,36,36, 36)
d2d <- c(1, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 1, 1.5, 1.5, 0.5, 0.5)
d2n <- c(36,36, 36, 38, 38,43, 42, 41, 36,38, 36, 38, 36)
a1 <- midi.note(0:(length(an) * 6 - 1), 1, an + 12 * 6)
a2 <- midi.note(0:(length(an) * 6 - 1), 1, an + 12 * 7, channel = 3)
m <- rbind(midi.note(0:180, 1, an + 12 * 6, channel = 0),
midi.note(45:530, 1, shift(an, -45) + 12 * 7, channel = 3),
midi.note(45 + head(cumsum(c(0, rep(bd, 27))), -1), bd, bn + 12 * 4, channel = 1),
midi.note(45 + head(cumsum(c(0, rep(bd, 27))), -1), bd, bn + 12 * 5, channel = 2),
midi.note(85 + cumsum(c(0, rep(dbd, length.out = 9 * 9 + 4))), dbd, dbn, channel = 5),
midi.note(180, 45, 7 + 12 * 6, channel = 3),
midi.note(225 + cumsum(c(0, rep(bd, 61))), bd, bn + 12 * 4, channel = 1),
midi.note(225 + cumsum(c(0, rep(bd, 61))), bd, bn + 12 * 5, channel = 2),
midi.note(225 + cumsum(c(0, rep(bd, 9))), bd, 36, channel = 5),
midi.note(270 + cumsum(c(0, rep(dbd, length.out = 9 * 7))), dbd, dbn, channel = 5),
midi.note(seq(270, 530, by = .5), .5, 51, channel = 5),
midi.note(seq(270, 530, by = .5), .5, 12 * 7, channel = 6),
midi.note(350:530, 1, shift(an, 10) + 12 * 6, channel = 0),
midi.note(350 + cumsum(c(0, rep(d2d, length.out = 9 * 26))), d2d, d2n, channel = 5)
)
m[,1] <- m[,1] * ppq / 2
play.c <- function() {
midi.play(m)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment