-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale.go
86 lines (75 loc) · 2.01 KB
/
scale.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package balafon
import (
"fmt"
"gitlab.com/gomidi/midi/v2/smf"
)
var notes = []string{"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}
func getPitch(note int) (step string, octave int) {
octave = (note / 12) - 1
noteIndex := note % 12
return notes[noteIndex], octave
}
var (
sharps = []string{"F", "C", "G", "D", "A", "E"}
flats = []string{"B", "E", "A", "D", "G", "C"}
)
func getScale(scale string) (func() smf.Message, []string, []string) {
switch scale {
// Major scales.
case "C", "CMaj":
return smf.CMaj, nil, nil
case "G", "GMaj":
return smf.GMaj, sharps[:1], nil
case "D", "DMaj":
return smf.DMaj, sharps[:2], nil
case "A", "AMaj":
return smf.AMaj, sharps[:3], nil
case "E", "EMaj":
return smf.EMaj, sharps[:4], nil
case "B", "BMaj":
return smf.BMaj, sharps[:5], nil
case "F#", "FsharpMaj":
return smf.FsharpMaj, sharps[:6], nil
case "F", "FMaj":
return smf.FMaj, nil, flats[:1]
case "Bb", "BbMaj":
return smf.BbMaj, nil, flats[:2]
case "Eb", "EbMaj":
return smf.EbMaj, nil, flats[:3]
case "Ab", "AbMaj":
return smf.AbMaj, nil, flats[:4]
case "Db", "DbMaj":
return smf.DbMaj, nil, flats[:5]
case "Gb", "GbMaj":
return smf.GbMaj, nil, flats[:6]
// Minor scales.
case "Am", "AMin":
return smf.AMin, nil, nil
case "Em", "EMin":
return smf.EMin, sharps[:1], nil
case "Bm", "BMin":
return smf.BMin, sharps[:2], nil
case "F#m", "FsharpMin":
return smf.FsharpMin, sharps[:3], nil
case "C#m", "CsharpMin":
return smf.CsharpMin, sharps[:4], nil
case "G#m", "GsharpMin":
return smf.GsharpMin, sharps[:5], nil
case "D#m", "DsharpMin":
return smf.DsharpMin, sharps[:6], nil
case "Dm", "DMin":
return smf.DMin, nil, flats[:1]
case "Gm", "GMin":
return smf.GMin, nil, flats[:2]
case "Cm", "CMin":
return smf.CMin, nil, flats[:3]
case "Fm", "FMin":
return smf.FMin, nil, flats[:4]
case "Bbm", "BbMin":
return smf.BbMin, nil, flats[:5]
case "Ebm", "EbMin":
return smf.EbMin, nil, flats[:6]
default:
panic(fmt.Sprintf("invalid scale %q", scale))
}
}