Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving scale stuff to separate class
- Loading branch information
Showing
4 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |