Sha256: 8168d38c3f1d0c5a94334ff6da0e20f45f2a29ab31e8d630a06fb358c73f7ce2
Contents?: true
Size: 1.35 KB
Versions: 68
Compression:
Stored size: 1.35 KB
Contents
// Package scale provides a sample implementation package scale import ( "strings" ) var chromaticScale = []string{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"} var flatChromaticScale = []string{"C", "Db", "D", "Eb", "E", "F", "Gb", "G", "Ab", "A", "Bb", "B"} var flatKeys = []string{"F", "Bb", "Eb", "Ab", "Db", "Gb", "d", "g", "c", "f", "bb", "eb"} // Scale returns a type of scale based on the inputs func Scale(tonic, interval string) []string { if interval == "" { interval = strings.Repeat("m", 12) } ft := formatTonic(tonic) scale := chromaticScale if flatKey(tonic, flatKeys) { scale = flatChromaticScale } start := findStart(ft, scale) return printScale(ft, interval, start, scale) } func printScale(tonic, interval string, start int, arr []string) []string { res := []string{tonic} for _, e := range interval[:len(interval)-1] { if e == 'm' { start++ } else if e == 'M' { start += 2 } else if e == 'A' { start += 3 } res = append(res, arr[start%12]) } return res } func findStart(tonic string, arr []string) int { for i := range arr { if arr[i] == tonic { return i } } return -1 } func flatKey(tonic string, arr []string) bool { return findStart(tonic, arr) > -1 } func formatTonic(tonic string) string { if len(tonic) == 1 { return strings.ToUpper(tonic) } return strings.Title(tonic) }
Version data entries
68 entries across 68 versions & 1 rubygems