-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfret.go
39 lines (36 loc) · 942 Bytes
/
fret.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package fret
import "fmt"
// Return all chromatic notes starting with baseNote
func GetChromaticNotes(baseNote string) []string {
notes := []string{"C", "D", "E", "F", "G", "A", "B"}
chromaticNotes := make([]string, 12)
for i, j := 0, 0; i < len(notes); i++ {
chromaticNotes[j] = notes[i]
j++
switch i {
case 2, 6:
break
default:
chromaticNotes[j] = notes[i] + "#"
j++
}
}
for i, n := range chromaticNotes {
if n == baseNote {
orderedNotes := append(chromaticNotes[i:], chromaticNotes[:i]...)
orderedNotes = append(orderedNotes, baseNote)
return orderedNotes
}
}
return []string{"Error: Wrong note name " + baseNote}
}
// Scramble and return notes for baseNote
func Scramble(baseNote string) string {
frets := [...]int{10, 3, 7, 2, 9, 5, 11, 1, 8, 4, 12, 6}
notes := GetChromaticNotes(baseNote)
ret := ""
for _, n := range frets {
ret += fmt.Sprintf("%2d:%-3s", n, notes[n])
}
return ret
}