diff --git a/src/MusicTheory.jl b/src/MusicTheory.jl index 3d676c8..cb0b465 100644 --- a/src/MusicTheory.jl +++ b/src/MusicTheory.jl @@ -13,9 +13,11 @@ export Major_2nd, Minor_2nd, Major_3rd, Minor_3rd, Perfect_4th, Perfect_5th, export Scale export major_scale, natural_minor_scale, melodic_minor_scale, harmonic_minor_scale +export Chord include("notes.jl") include("intervals.jl") include("scales.jl") +include("chords.jl") end diff --git a/src/notes.jl b/src/notes.jl index 6adeb66..8dc027e 100644 --- a/src/notes.jl +++ b/src/notes.jl @@ -79,7 +79,7 @@ end PitchClass(n::PitchClass) = n - +Base.isless(n1::PitchClass, n2::PitchClass) = semitone(n1) < semitone(n2) Base.isless(n1::Pitch, n2::Pitch) = semitone(n1) < semitone(n2) diff --git a/test/intervals.jl b/test/intervals.jl new file mode 100644 index 0000000..feb600f --- /dev/null +++ b/test/intervals.jl @@ -0,0 +1,20 @@ +@testset "Intervals" begin + @test Interval(C[4], D[4]) == Interval(1, Major) + @test Interval(E[4], C[4]) == Interval(2, Major) + @test Interval(B[4], C[4]) == Interval(6, Major) + + @test Interval(B[4], C[5]) == Interval(1, Minor) + + @test Interval(B[4], B[4]) == Interval(0, Perfect) + @test Interval(B[4], B[5]) == Interval(7, Perfect) + +end + +@testset "Adding intervals" begin + @test C + Interval(1, Major) == D + @test C + Interval(2, Major) == E + @test C + Interval(6, Major) == B + + @test C[4] + Interval(1, Major) == D[4] + @test B[4] + Interval(1, Major) == C♯[5] +end \ No newline at end of file diff --git a/test/notes.jl b/test/notes.jl new file mode 100644 index 0000000..de23c79 --- /dev/null +++ b/test/notes.jl @@ -0,0 +1,9 @@ +using MusicTheory.NoteNames + +@testset "Notes" begin + note = C[4] + + @test PitchClass(note) == C + @test accidental(note) == ♮ + @test octave(note) == 4 +end diff --git a/test/scales.jl b/test/scales.jl new file mode 100644 index 0000000..cdcc12b --- /dev/null +++ b/test/scales.jl @@ -0,0 +1,8 @@ +@testset "Scales" begin + + scale = Scale(C[4], major_scale) + + scale_tones = Base.Iterators.take(scale, 8) |> collect + @test scale_tones == Pitch[C[4], D[4], E[4], F[4], G[4], A[4], B[4], C[5]] + +end \ No newline at end of file