-
Notifications
You must be signed in to change notification settings - Fork 4
/
music.go
40 lines (30 loc) · 885 Bytes
/
music.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
// Copyright 2012 Joe Wass. All rights reserved.
// Use of this source code is governed by the MIT license
// which can be found in the LICENSE file.
// MIDI package
// A package for reading Standard Midi Files, written in Go.
// Joe Wass 2012
// joe@afandian.com
/*
* Functions that deal with musical concepts.
*/
package midi
// import "fmt"
// Taking a signed number of sharps or flats (positive for sharps, negative for flats) and a mode (0 for major, 1 for minor)
// decide the key signature.
func keySignatureFromSharpsOrFlats(sharpsOrFlats int8, mode uint8) (key ScaleDegree, resultMode KeySignatureMode) {
// 0 is C.
var tmp int = int(DegreeC + sharpsOrFlats*7)
// Relative Minor.
if mode == MinorMode {
tmp -= 3
}
// Clamp to Octave 0-11.
for tmp < 0 {
tmp += 12
}
tmp = tmp % 12
resultMode = KeySignatureMode(mode)
key = ScaleDegree(tmp)
return
}