Skip to content

Commit

Permalink
Allow intervals of octave and larger (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpsanders authored Jan 14, 2024
1 parent 3bc1a77 commit 75f9350
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ Interval( (n1, n2) ) = Interval(n1, n2)


function Base.:+(n::PitchClass, interval::Interval)

octave = (interval.number - 1) ÷ 7
reduced_interval = (interval.number - 1) % 7
interval = Interval(reduced_interval + 1, interval.quality)

new_tone = (tone(n) + tone(interval)) % 7

new_pitch_class = note_names[new_tone + 1]
new_octave = new_tone ÷ 7

new_semitone = semitone(n) + semitone(interval)
new_semitone = semitone(n) + semitone(interval) + 12 * octave
new_note = find_accidental(new_semitone % 12, new_pitch_class)

return new_note
Expand Down
4 changes: 4 additions & 0 deletions test/intervals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ end

@test C[4] + Interval(2, Major) == D[4]
@test B[4] + Interval(2, Major) == C♯[5]

@test C[4] + Interval(8, Perfect) == C[5]
@test C[4] + Interval(10, Minor) == E♭[5]
@test C[4] + Interval(15, Perfect) == C[6]
end

@testset "Sum of intervals" begin
Expand Down

0 comments on commit 75f9350

Please sign in to comment.