music: Learn and Experiment With Music Theory

Jakcson Phillips

ROUGH DRAFT

  • Planning to add images to slides

  • So far when I try to play the chords / scales, they are all played immediately once the slideshow is rendered.

  • In the piano ASCII models, the played notes are supposed to be highlighted. Still trying to figure this out.

Overview

  • Aid for learning / using music theory
  • Build chords, scales, chord progressions
  • Visualize notes with ASCII plots

How?

  • music builds waveforms as matrices
  • Then passed to audio package

Building Chords

  • buildChord()

  • Arguments

    • root

    • chord

    • plot

    • play

    • formatNotation

  • buildProgression()

Example

buildChord(root = "E4",
           chord = "minor",
           plot = TRUE,
           play = FALSE)
   E4 minor chord

  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: E4 G4 B4 
buildProgression("Ab3", "major", plot = TRUE)

  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Ab3 C4 Eb4 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Bb3 Db4 F4 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: C4 Eb4 G4 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Db4 F4 Ab4 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Eb4 G4 Bb4 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: F4 Ab4 C5 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: G4 Bb4 Db5 


  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Ab4 C5 Eb5 
$Ab3major
[1] "Ab3" "C4"  "Eb4"

$Bb3minor
[1] "Bb3" "Db4" "F4" 

$C4minor
[1] "C4"  "Eb4" "G4" 

$Db4major
[1] "Db4" "F4"  "Ab4"

$Eb4major
[1] "Eb4" "G4"  "Bb4"

$F4minor
[1] "F4"  "Ab4" "C5" 

$G4diminished
[1] "G4"  "Bb4" "Db5"

$Ab4major
[1] "Ab4" "C5"  "Eb5"

Playing Scales

  • buildScale()

  • Arguments

    • root

    • scale

    • plot / play

    • pairs

    • formatNotation

Example

buildScale(root = "D4",
           scale = "major",
           descending = TRUE,
           plot = TRUE,
           play = FALSE)
   D4 major scale

  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: D5 C#5 B4 A4 G4 F#4 E4 D4 
buildScale(root = "Eb4",
           scale = "blues",
           plot = TRUE,
           play = FALSE)
   Eb4 blues scale

  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |  | | | |  |  | | | | | |  |  | | | |  |  | | | | | |  |  | 
  |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
  | C | D | E | F | G | A | B | C | D | E | F | G | A | B | C |

  Notes: Eb4 F#4 G#4 A4 Bb4 Db5 Eb5 

Building / Plotting Waveforms

  • note2freq()

    • Pass notes or scales to convert to exact frequency
  • freq2wave()

    • Passes frequencies to generate waveform object

    • mplot() to plot waveforms

  • Learning sound harmonics via visualization

Example

frequencies <- note2freq(buildChord("B4", "major"))

wave <- freq2wave(frequencies, BPM = 1600)

mplot(wave, main = "B4 Major Triad Frequencies")

Other Functions

  • Customize settings and format

    • Default octave

    • Custom tuning outside A=440

    • Sine, Square, and Saw wave

References & Repo

  • Gennatas E (2025). music: Learn and Experiment with Music Theory. R package version 0.1.3, https://github.com/egenn/music.
  • A guide to fundamental frequency and harmonics in music. iZotope. (n.d.). https://www.izotope.com/en/learn/fundamental-frequency-harmonics?srsltid=AfmBOoqOSSeWELzkYoWIFQZcfgsm4tZBjPLsgaEAXvdy1riP9Yh0KEwq
  • Sine, square, triangle, saw : Synth waveforms - perfect circuit. (n.d.-a). https://www.perfectcircuit.com/signal/difference-between-waveforms