File tree Expand file tree Collapse file tree 4 files changed +51
-7
lines changed Expand file tree Collapse file tree 4 files changed +51
-7
lines changed Original file line number Diff line number Diff line change @@ -17,11 +17,14 @@ export Chord
17
17
18
18
export make_triad, is_triad
19
19
20
+ export Note, rest
21
+
20
22
21
23
include (" pitches.jl" )
22
24
include (" pitch_names.jl" )
23
25
include (" intervals.jl" )
24
26
include (" scales.jl" )
25
27
include (" chords.jl" )
26
28
include (" triads.jl" )
29
+ include (" notes.jl" )
27
30
end
Original file line number Diff line number Diff line change
1
+
2
+ struct Rest end
3
+
4
+ const NoteTypes = Union{Pitch, Chord{Pitch}, Rest}
5
+
6
+ """
7
+ struct Note
8
+
9
+ A note is a pitch and a duration.
10
+ The pitch can be a chord, or a rest
11
+ """
12
+ struct Note
13
+ pitch:: NoteTypes
14
+ duration:: Rational{Int}
15
+ end
16
+
17
+ # use / and * to specify durations:
18
+ Base.:(/ )(p:: NoteTypes , n:: Int ) = Note (p, 1 // n)
19
+ Base.:(* )(p:: NoteTypes , n:: Rational{Int} ) = Note (p, n)
20
+
21
+ const rest = Rest ()
22
+
23
+
Original file line number Diff line number Diff line change 1
- using MusicTheory . PitchNames
1
+ @testset " Notes with durations " begin
2
2
3
- @testset " Notes" begin
4
- note = C[4 ]
3
+ using MusicTheory. PitchNames
5
4
6
- @test PitchClass (note) == C
7
- @test accidental (note) == ♮
8
- @test octave (note) == 4
9
- end
5
+ n = C[4 ] / 8
6
+ @test n isa Note
7
+ @test n. pitch == C[4 ]
8
+ @test n. duration == 1 // 8
9
+
10
+ n = B[5 ] * 3 // 8
11
+ @test n. pitch == B[5 ]
12
+ @test n. duration == 3 // 8
13
+
14
+ n = rest / 4
15
+ @test n isa Note
16
+ @test n. pitch == rest
17
+ @test n. duration == 1 // 4
18
+ end
Original file line number Diff line number Diff line change
1
+ using MusicTheory. PitchNames
2
+
3
+ @testset " Pitches" begin
4
+ note = C[4 ]
5
+
6
+ @test PitchClass (note) == C
7
+ @test accidental (note) == ♮
8
+ @test octave (note) == 4
9
+ end
You can’t perform that action at this time.
0 commit comments