Skip to content

Commit b1f88c5

Browse files
authored
Add README (#10)
1 parent f5584ad commit b1f88c5

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,73 @@
1-
# MusicTheory
1+
# MusicTheory.jl
22

33
[![Build Status](https://github.com/dpsanders/MusicTheory.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/dpsanders/MusicTheory.jl/actions/workflows/CI.yml?query=branch%3Amain)
4+
5+
A Julia package for the basics of ("Western") music theory.
6+
(Currently) everything is based on semitones.
7+
8+
## Contents
9+
- Pitches with scientific notation, e.g. C4 for middle C
10+
- Intervals
11+
- Scales
12+
- Chords
13+
- Notes and rests with durations
14+
15+
## Pitches
16+
Pitch names are exported in the `MusicTheory.PitchNames` submodule.
17+
18+
Specifying just the name of a pitch gives a `PitchClass`, representing all notes of that
19+
pitch, e.g.
20+
```
21+
julia> C♯
22+
C♯
23+
24+
julia> typeof(C♯)
25+
PitchClass
26+
```
27+
28+
Indexing gives a pitch with a specific octave, e.g.
29+
```
30+
julia> C♯[4]
31+
C♯₄
32+
```
33+
34+
## Intervals
35+
The `Interval` type computes the interval between two pitches:
36+
```
37+
julia> Interval(C[4], E[4])
38+
Major 3rd
39+
```
40+
41+
## Scales
42+
General scales are supported; they are specified as a sequence of intervals dividing up an
43+
octave, e.g.
44+
```
45+
julia> show(major_scale)
46+
Interval[Major 2nd, Major 2nd, Minor 2nd, Major 2nd, Major 2nd, Major 2nd, Minor 2nd]
47+
```
48+
49+
The `Scale` type is a standard Julia iterator over the scale:
50+
```
51+
julia> scale = Scale(C[4], major_scale)
52+
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))
53+
54+
julia> scale_tones = Base.Iterators.take(scale, 8) |> collect;
55+
56+
julia> show(scale_tones)
57+
Pitch[C₄, D₄, E₄, F₄, G₄, A₄, B₄, C₅]
58+
```
59+
60+
## Notes
61+
Notes have a pitch and a duration, which is a rational number, e.g. `1 // 4` for a
62+
quarter note (crotchet). Rests are specified using `rest`, e.g.
63+
```
64+
julia> notes = [C[5] / 4, rest / 8, D[5] / 8]
65+
3-element Vector{Note}:
66+
Note(C₅, 1//4)
67+
Note(MusicTheory.Rest(), 1//8)
68+
Note(D₅, 1//8)
69+
```
70+
71+
## Author
72+
73+
Copyright David P. Sanders, 2024

0 commit comments

Comments
 (0)