• Home
  • CV
  • Notes

On this page

  • Overview

Creating music with GM package

Music
Experimenting with the GM R package to create music.
Author

Sheng Long

Updated

October 6, 2025

library(gm)

Overview

I saw the gm package on this Bluesky post and thought I’d give it a try. Here’s the reference document.


Create simple music:

music <- 
  Music() +
  Meter(4, 4) +
  Line(c("C5", "D5", "E5", "F5"))
  
show(music)

Let’s try something a bit more complicated:

moon <- Music() + 
  Meter(4, 4) + 
  Key(2) + 
  Line(
    pitches = c("A3", "B3", "D4", "E4", "F#4", "A4", "B4"),
    durations = c("quarter.", "eighth", "eighth", "eighth", "eighth", "eighth", "whole")
  )

show(moon)

Note that the above is the opening ascent of 「彩云追月」 (“Colorful Clouds Chasing the Moon”)1.

1 Taken from Pentatonic Xuangong 旋宮 Transformations in Chinese Music by Nathan L. Lam

© 2024 Sheng Long

 

This website is built with , , Quarto, fontawesome, iconify.design, and faviconer.