Create a vector for the notes of Jingle Bells. I like to do this by thinking about strings of notes for each bar of music and then using strsplit()
to convert this to a vector with each note as an entry. Here I am writing quite a fun, virtuoso version of Jingle Bells.
``` {r eval = FALSE} jbells_pitch <- paste( "E E E", "E E E", "E G C D", "E", "F F F F", "F E E E", "E D D E", "D G", "E E E", "E E E", "E G C D", "E", "F F F F", "F E E E E", "G G F D", "C", "G3 E D C", "G3", "G3 G3 G3 E D C", "A3", "A3 F E D", "B3", "G G F D", "E", "G3 E D C", "G3", "G3 E D C", "A3 A3", "A3 F E D", "G G G G A G F D", "C C5 B A G F G", "E E E G C D", "E E E G C D", "E F G A C E D F", "E C D E F G A G", "F F F F F F", "F E E E E E", "E D D D D E", "D D E F G F E D", "E E E G C D", "E E E G C D", "E F G A C E D F", "E C D E F G A G", "F F F F F F", "F E E E E E", "G C5 B A G F E D", "C C E G C5" )
jbells_pitch <- strsplit(jbells_pitch, " ")[[1]]
Now create a similar vector with the durations of each notes as proportion of a beat. This vector should be the same length as the notes vector. I like to do this with a line for each bar of music. ``` {r eval = FALSE} jbells_duration <- c( 1, 1, 2, 1, 1, 2, 1, 1, 1.5, 0.5, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1.5, 0.5, 4, 1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 1, 1, 1, 1, 4, 1, 1, 1, 1, 3, .5, .5, 1, 1, 1, 1, 4, 1, 1, 1, 1, 4, 1, 1, 1, 1, 4, 1, 1, 1, 1, 4, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 0.5, 0.5, 0.5, 0.5, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 1, 1, 0.33, 0.33, 0.33, 1, 0.33, 0.33, 0.33, 1, 1, 0.5, 0.5, 0.5, 0.5, 1, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 1, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 0.33, 0.33, 0.33, 2 )
To play or save, pick the right tempo and go:
``` {r eval = FALSE}
play_music(jbells_pitch, jbells_duration, tempo = 240)
save_music(jbells_pitch, jbells_duration, output_file = "jbells.wav", tempo = 240)
```
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.