diff --git a/Project.toml b/Project.toml index 7c46726..c1d5c81 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/src/note.jl b/src/note.jl index b498ef1..8f2637e 100644 --- a/src/note.jl +++ b/src/note.jl @@ -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 diff --git a/test/note.jl b/test/note.jl index b912f4a..ad51a0b 100644 --- a/test/note.jl +++ b/test/note.jl @@ -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