forked from go-music-theory/music-theory
/
key.go
35 lines (28 loc) · 744 Bytes
/
key.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
// The key of a piece is a group of pitches, or scale upon which a music composition is created in classical, Western art, and Western pop music.
package key
import (
"gopkg.in/music-theory.v0/note"
)
// Of a particular key, e.g. Of("C minor 7")
func Of(name string) Key {
k := Key{}
k.parse(name)
return k
}
// Key is a model of a musical key signature
type Key struct {
Root note.Class
AdjSymbol note.AdjSymbol
Mode Mode
}
/*
*
private */
func (this *Key) parse(name string) {
// determine whether the name is "sharps" or "flats"
this.AdjSymbol = note.AdjSymbolOf(name)
// parse the root, and keep the remaining string
this.Root, name = note.RootAndRemaining(name)
// parse the key mode
this.parseMode(name)
}