From 5a71b83447b821dcc87712cb932d7451c67bf6a6 Mon Sep 17 00:00:00 2001 From: "Thomas A. Poulsen" Date: Sat, 10 Jul 2021 17:48:49 +0200 Subject: [PATCH 1/3] Parse and test negative octaves. closes #144 --- src/note.jl | 12 +++++++----- test/note.jl | 2 ++ 2 files changed, 9 insertions(+), 5 deletions(-) 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..4bff5ba 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:88]) end @testset "copying notes" begin From 02afb226fb664c9a5f0c726a2ac43c3dcabdad81 Mon Sep 17 00:00:00 2001 From: "Thomas A. Poulsen" Date: Sun, 11 Jul 2021 07:55:12 +0200 Subject: [PATCH 2/3] Test more pitches --- test/note.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/note.jl b/test/note.jl index 4bff5ba..ad51a0b 100644 --- a/test/note.jl +++ b/test/note.jl @@ -30,7 +30,7 @@ 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:88]) + @test all([name_to_pitch(pitch_to_name(i)) == i for i in 0:255]) end @testset "copying notes" begin From 97413a7f4cf244b1f79d9ac86e33f6cc38a9e540 Mon Sep 17 00:00:00 2001 From: "Thomas A. Poulsen" Date: Sun, 11 Jul 2021 21:58:51 +0200 Subject: [PATCH 3/3] update version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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"