MusicTheory.jl
I’m happy to announce the new package MusicTheory.jl.
The goal of the package is to provide a foundation for representing musical objects in a Julian way.
The main challenge has been to find the right abstraction for each type of object.
[I deliberately have not looked in detail at other packages.]
Currently the package is based on the structures of “Western” music, and in particular on semitones (rather than smaller subdivisions).
Contributions in the form of Pull Requests are very welcome!
Outline
The package is based around Pitch
es, for example C♯[4]
, and Interval
s;
Everything else is constructed from these.
E.g. a scale is a way of dividing up an octave into a sequence of intervals; this sequence then repeats each octave. A natural way to represent this in Julia is thus a vector of Interval
s, representing the scale steps, wrapped into an infinite iterator. [The naturalness of this representation took a while to dawn!]
Features
- Pitches using scientific notation, e.g. C4 for middle C
- Intervals
- Arbitrary scales (modes)
- Notes and rests with durations
- Motifs using scale tones, such as arpeggios
Partially implemented
- Chords
- Triads
Desired features (not yet implemented)
- Iterate scales in a descending direction
- Ability to play notes
- Export to Lilypond, Midi, MusicXML
- Interaction with related Julia packages from the JuliaMusic org
Basic usage (see also the README)
julia> using MusicTheory, MusicTheory.PitchNames
julia> C♯
C♯
julia> typeof(C♯)
PitchClass
julia> C♯[4]
C♯₄
julia> typeof(C♯[4])
Pitch
julia> Interval(C[4], E[4])
Major 3rd
Example of using scales
julia> show(major_scale)
Interval[Major 2nd, Major 2nd, Minor 2nd, Major 2nd, Major 2nd, Major 2nd, Minor 2nd]
julia> scale = Scale(C[4], major_scale)
Scale{Pitch}(C₄, Dict{PitchClass, Interval}(C => Major 2nd, E => Minor 2nd, B => Minor 2nd, F => Major 2nd, D => Major 2nd, G => Major 2nd, A => Major 2nd))
julia> scale_tones = Base.Iterators.take(scale, 8) |> collect;
julia> show(scale_tones)
Pitch[C₄, D₄, E₄, F₄, G₄, A₄, B₄, C₅]