Skip to content

Commit

Permalink
Merge pull request #145 from tp2750/issue_144
Browse files Browse the repository at this point in the history
Parse and test negative octaves. closes #144
  • Loading branch information
Datseris authored Jul 11, 2021
2 parents dbd01f8 + 97413a7 commit 3464239
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MIDI"
uuid = "f57c4921-e30c-5f49-b073-3f2f2ada663e"
repo = "https://github.com/JuliaMusic/MIDI.jl.git"
version = "2.0.0"
version = "2.0.1"

[deps]
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
Expand Down
12 changes: 7 additions & 5 deletions src/note.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,18 @@ function name_to_pitch(name)
if length(pe) >= 2
if pe[2] == "#" || pe[2] == ""
x = 1
deleteat!(pe,2)
elseif pe[2] == "b" || pe[2] == ""
x = -1
deleteat!(pe,2)
end
end
if isdigit(first(last(pe)))
octave = parse(Int, join(filter(isdigit first, pe)))
else
octave = 4
if length(pe) == 1
push!(pe, string(4))
end


octave = parse(Int, join(pe[2:end]))

return pitch + x + 12(octave+1) # lowest possible octave is -1 but pitch starts from 0
end

Expand Down
2 changes: 2 additions & 0 deletions test/note.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ end

n = Note(0, 1, 1, 1)
@test pitch_to_name(n.pitch) == "C-1"

@test all([name_to_pitch(pitch_to_name(i)) == i for i in 0:255])
end

@testset "copying notes" begin
Expand Down

0 comments on commit 3464239

Please sign in to comment.