-
Notifications
You must be signed in to change notification settings - Fork 0
/
board.go
58 lines (50 loc) · 895 Bytes
/
board.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
package main
const (
NoteUnvoiced = iota
NoteRoot
NoteBlack
NoteGrey
)
type NoteType int
type Note struct {
String int
Fret int
Name string
Type NoteType
}
type FretBoard struct {
Name string
Tuning []string
Strings int
Frets int
StartingFret int
Notes []Note
}
func (f *FretBoard) SetNotes(notes []string, ntype NoteType) error {
var err error
notemap := map[string]bool{}
for i := range notes {
_, err = NotePosition(notes[i])
if err != nil {
return err
}
notemap[notes[i]] = true
}
for s := 0; s < f.Strings; s++ {
for fr := 0; fr < f.Frets+1; fr++ {
note, _ := GetNote(f.Tuning[s], fr)
if _, ok := notemap[note]; ok {
f.Notes = append(f.Notes, Note{
String: s,
Fret: fr,
Name: note,
Type: ntype,
})
}
}
}
return nil
}
func (f *FretBoard) Clear() {
f.Notes = nil
}