Skip to content

Commit

Permalink
Add octaves.
Browse files Browse the repository at this point in the history
  • Loading branch information
brettbuddin committed Dec 28, 2016
1 parent a2f901c commit ba1b247
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
9 changes: 6 additions & 3 deletions scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,13 @@ func (s Scale) Transpose(i Interval) Transposer {
}

// NewScale returns a Scale built using a set of intervals
func NewScale(root Transposer, intervals []Interval) Scale {
func NewScale(root Transposer, intervals []Interval, octaves int) Scale {
scale := Scale{}
for _, i := range intervals {
scale = append(scale, root.Transpose(i))
for i := 0; i < octaves; i++ {
for _, v := range intervals {
scale = append(scale, root.Transpose(v))
}
root = root.Transpose(Octave(1))
}
return scale
}
23 changes: 12 additions & 11 deletions scale_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,30 @@ import (
type scaleTest struct {
root Pitch
intervals []Interval
octaves int
expected []string
}

var scaleTests []scaleTest

func init() {
scaleTests = []scaleTest{
{NewPitch(C, Natural, 4), ChromaticIntervals, []string{"C4", "Db4", "D4", "Eb4", "E4", "F4", "Gb4", "G4", "Ab4", "A4", "Bb4", "B4"}},
{NewPitch(C, Natural, 4), IonianIntervals, []string{"C4", "D4", "E4", "F4", "G4", "A4", "B4"}},
{NewPitch(C, Natural, 4), DorianIntervals, []string{"C4", "D4", "Eb4", "F4", "G4", "A4", "Bb4"}},
{NewPitch(C, Natural, 4), PhrygianIntervals, []string{"C4", "Db4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), LydianIntervals, []string{"C4", "D4", "E4", "Gb4", "G4", "A4", "B4"}},
{NewPitch(C, Natural, 4), MixolydianIntervals, []string{"C4", "D4", "E4", "F4", "G4", "A4", "Bb4"}},
{NewPitch(C, Natural, 4), AeolianIntervals, []string{"C4", "D4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), LocrianIntervals, []string{"C4", "Db4", "Eb4", "F4", "Gb4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), MajorIntervals, []string{"C4", "D4", "E4", "F4", "G4", "A4", "B4"}},
{NewPitch(C, Natural, 4), MinorIntervals, []string{"C4", "D4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), ChromaticIntervals, 1, []string{"C4", "Db4", "D4", "Eb4", "E4", "F4", "Gb4", "G4", "Ab4", "A4", "Bb4", "B4"}},
{NewPitch(C, Natural, 4), IonianIntervals, 1, []string{"C4", "D4", "E4", "F4", "G4", "A4", "B4"}},
{NewPitch(C, Natural, 4), DorianIntervals, 1, []string{"C4", "D4", "Eb4", "F4", "G4", "A4", "Bb4"}},
{NewPitch(C, Natural, 4), PhrygianIntervals, 1, []string{"C4", "Db4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), LydianIntervals, 1, []string{"C4", "D4", "E4", "Gb4", "G4", "A4", "B4"}},
{NewPitch(C, Natural, 4), MixolydianIntervals, 1, []string{"C4", "D4", "E4", "F4", "G4", "A4", "Bb4"}},
{NewPitch(C, Natural, 4), AeolianIntervals, 1, []string{"C4", "D4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), LocrianIntervals, 1, []string{"C4", "Db4", "Eb4", "F4", "Gb4", "Ab4", "Bb4"}},
{NewPitch(C, Natural, 4), MajorIntervals, 2, []string{"C4", "D4", "E4", "F4", "G4", "A4", "B4", "C5", "D5", "E5", "F5", "G5", "A5", "B5"}},
{NewPitch(C, Natural, 4), MinorIntervals, 1, []string{"C4", "D4", "Eb4", "F4", "G4", "Ab4", "Bb4"}},
}
}

func TestScales(test *testing.T) {
for i, t := range scaleTests {
scale := NewScale(t.root, t.intervals)
scale := NewScale(t.root, t.intervals, t.octaves)
actual := []string{}

for _, p := range scale {
Expand Down

0 comments on commit ba1b247

Please sign in to comment.