Skip to content

Commit

Permalink
moving scale stuff to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoertink committed Jun 15, 2016
1 parent 0cbac24 commit 74dac3c
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 15 deletions.
9 changes: 0 additions & 9 deletions spec/notes_spec.cr
@@ -1,15 +1,6 @@
require "./spec_helper"

describe Medley::Notes do
describe "#by_scale" do
pending "returns an array of letters in C major scale order" do
Medley::Notes.by_scale("Cmaj").should eq(["C", "D", "E", "F", "G", "A", "B", "C"])
end

pending "returns an array of letters in F major scale order" do
Medley::Notes.by_scale("Fmaj").should eq(["F", "G", "A", "Bb", "C", "D", "E", "F"])
end
end

describe ".halfstep_up" do
it "returns G# when given G" do
Expand Down
16 changes: 16 additions & 0 deletions spec/scales_spec.cr
@@ -0,0 +1,16 @@
require "./spec_helper"

describe Medley::Scales do

describe ".notes" do
it "returns an array of letters in C major scale order" do
scale = Medley::Scales.new("Cmaj")
scale.notes.should eq(["C", "D", "E", "F", "G", "A", "B", "C"])
end

it "returns an array of letters in F major scale order" do
scale = Medley::Scales.new("Fmaj")
scale.notes.should eq(["F", "G", "A", "Bb", "C", "D", "E", "F"])
end
end
end
6 changes: 0 additions & 6 deletions src/medley/notes.cr
Expand Up @@ -3,12 +3,6 @@ module Medley
NOTE_NAMES = %w(A B C D E F G)
ALIASES = {"B#": "C", "Cb": "B", "E#": "F", "Fb": "E"}

# 1 1 .5 1 1 1 .5
def self.by_scale(scale : String)
scale.match(/(\w+)(maj|min)/)

end

def initialize(current_note : String)
@current_note = current_note
end
Expand Down
38 changes: 38 additions & 0 deletions src/medley/scales.cr
@@ -0,0 +1,38 @@
module Medley
class Scales
PATTERNS = {
"maj": %w(1 1 .5 1 1 1 .5),
"min": %w(1 .5 1 1 .5 1 1)
}

@pattern : Array(String)
@root : String
#@notes : Array(String)

def initialize(scale : String)
scale.match(/(\w+)(maj|min)/)
@pattern = PATTERNS[$2]
@root = $1
@notes = [] of String
build_scale
end

def notes
@notes
end

private def build_scale
note = Medley::Notes.new(@root)
@notes << note.name
@pattern.each do |step|
case step
when "1"
@notes << note.wholestep_up
when ".5"
@notes << note.halfstep_up
end
note = Medley::Notes.new(@notes.last)
end
end
end
end

0 comments on commit 74dac3c

Please sign in to comment.