A Lua library for working with music theory concepts such as notes, intervals, chords, scales, etc.
Install via luarocks.
For development, you can install locally with e.g.:
luarocks --lua-version 5.4 make musictheory-*.rockspecmt = require 'musictheory'
-- create a note:
c4 = mt.Note'C4'
-- add intervals:
c4 + mt.Interval'P5' == Note'G4'
c4 + mt.Interval'm3' == Note'E♭4'
-- work out intervals between notes:
mt.Note'B4' - c4 == mt.Interval'M7'
-- pitch class:
c4.pitch_class == mt.PitchClass'C'
-- chords:
Cm = mt.Chord('C', 'min')
Cm.pitches == {mt.PitchClass'C', mt.PitchClass'E♭', mt.PitchClass'G'}
-- inversions (a.k.a. slash chords):
Cm:invert(1) == mt.Chord'Cmin/E♭'
Cm:invert(1).bass == mt.PitchClass'E♭'
Cm:invert(1).root == mt.PitchClass'C'There are more classes and methods. Have a look at the source code.
musictheory.lua is open-source and contributions in the form of issues, documentation, pull requests, unit tests, etc are welcome.
See LICENSE