Skip to content

Commit

Permalink
working wholestep_up method back in
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Oct 21, 2016
1 parent 9fa2946 commit 56bc342
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 9 deletions.
27 changes: 27 additions & 0 deletions spec/note_spec.cr
Expand Up @@ -56,4 +56,31 @@ describe Medley::Note do
end
end

describe ".wholestep_up" do
it "returns E when given D" do
note = Medley::Note.new("D")
note.wholestep_up.should eq "E"
end

it "returns G when given F" do
note = Medley::Note.new("F")
note.wholestep_up.should eq "G"
end

it "returns D# when given C#" do
note = Medley::Note.new("C#")
note.wholestep_up.should eq "D#"
end

it "returns Bb when given Ab" do
note = Medley::Note.new("Ab")
note.wholestep_up.should eq "Bb"
end

it "returns Dbb when given Cbb" do
note = Medley::Note.new("Cbb")
note.wholestep_up.should eq "Dbb"
end
end

end
38 changes: 29 additions & 9 deletions src/medley/note.cr
Expand Up @@ -4,16 +4,12 @@ module Medley
ALIASES = {"A##": "B", "B##": "C#", "C##": "D", "D##": "E",
"E##": "F#", "F##": "G", "G##": "A", "Abb": "G",
"Bbb": "A", "Cbb": "Bb", "Dbb": "C", "Ebb": "D",
"Fbb": "Eb", "Gbb": "F"}
"Fbb": "Eb", "Gbb": "F", "A#": "Bb", "B#": "C",
"C#": "Db", "D#": "Eb", "E#": "F", "F#": "G",
"G#": "Ab"}

def initialize(current_note : String)
@current_note = current_note
@previous_note = ""
end

def initialize(current_note : String, previous_note : String)
initialize(current_note)
@previous_note = previous_note
end

# true if it's a valid note letter with no modifiers
Expand Down Expand Up @@ -46,6 +42,21 @@ module Medley
@current_note
end

# Returns the root of the note
def root
@current_note[0].to_s
end

def next_root
idx = NOTE_NAMES.index(root) || -1
NOTE_NAMES[idx + 1]
end

# true if the root name is equal to the other note root
def root_matches?(other_note : Note)
root == other_note.root
end

# Returns the same note, but up a halfstep in most cases
# Without context of the Key, there's no telling if
# the note E should be E# or F. Since there's no triple sharps,
Expand All @@ -61,6 +72,7 @@ module Medley
when .double_sharp?
aliased = ALIASES[@current_note]
return "#{aliased}#"
else ""
end
end

Expand All @@ -75,12 +87,20 @@ module Medley
when .double_flat?
aliased = ALIASES[@current_note]
return "#{aliased}b"
else ""
end
end

def wholestep_up
new_note = Note.new(halfstep_up, @current_note)
new_note.halfstep_up
up_halfstep = Note.new(halfstep_up)
new_note = Note.new(up_halfstep.halfstep_up)
if new_note.double_sharp?
ALIASES[new_note.name]
elsif new_note.root_matches?(self)
new_note.next_root + name[1..-1]
else
new_note.name
end
end
end
end

0 comments on commit 56bc342

Please sign in to comment.