Skip to content

Commit

Permalink
need to figure out how to do note aliases properly
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Sep 8, 2016
1 parent 0bbe77f commit ffdaa02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions spec/scales_spec.cr
Expand Up @@ -12,5 +12,10 @@ describe Medley::Scales do
scale = Medley::Scales.new("Fmaj")
scale.notes.should eq(["F", "G", "A", "Bb", "C", "D", "E", "F"])
end

it "returns an array of letters in D Major scale order" do
scale = Medley::Scales.new("Dmaj")
scale.notes.should eq(["D", "E", "F#", "G", "A", "B", "C#", "D"])
end
end
end
11 changes: 8 additions & 3 deletions src/medley/scales.cr
Expand Up @@ -34,9 +34,14 @@ module Medley
end
# TODO: find a better way to handle this
# need to do this because if the scale has A and A#, the A# should be Bb
#if @notes.select { |n| n[0].to_s == new_note[0].to_s }.any?
# new_note = Medley::Notes::ALIASES[new_note]
#end
# Problem is I need to replace the offending note with the alias.
# The @notes array could look like ["Gb", "G"] or ["A", "A#"]
# The offending note may not always be a b or #. How do I tell which note needs to be aliased? iterate over offending notes, and if an alias exists, then replace it and hope that was the right one?
if offending = @notes.find { |n| n[0] == new_note[0] && n.size > 1 }
new_note = Medley::Notes::ALIASES[new_note]
idx = @notes.index(offending)
@notes[idx] = new_note
end
@notes << new_note
note = Medley::Notes.new(@notes.last)
end
Expand Down

0 comments on commit ffdaa02

Please sign in to comment.