-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathkey.go
47 lines (40 loc) · 909 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
36
37
38
39
40
41
42
43
44
45
46
47
// 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.
//
// https://en.wikipedia.org/wiki/Key_(music)
//
// Credit
//
// Charney Kaye
// <hi@charneykaye.com>
// https://charneykaye.com
//
// XJ Music
// https://xj.io
//
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)
}