-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtime_signature.go
33 lines (29 loc) · 1.25 KB
/
time_signature.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
package midi
import (
"fmt"
"math"
)
// TimeSignature FF 58 04 nn dd cc bb Time Signature
// The time signature is expressed as four numbers. nn and dd
// represent the numerator and denominator of the time signature as it
// would be notated. The denominator is a negative power of two: 2
// represents a quarter-note, 3 represents an eighth-note, etc.
// The cc parameter expresses the number of MIDI clocks in a
// metronome click. The bb parameter expresses the number of
// notated 32nd-notes in a MIDI quarter-note (24 MIDI clocks). This
// was added because there are already multiple programs which allow a
// user to specify that what MIDI thinks of as a quarter-note (24 clocks)
// is to be notated as, or related to in terms of, something else.
type TimeSignature struct {
Numerator uint8
Denominator uint8
ClocksPerTick uint8
ThirtySecondNotesPerQuarter uint8
}
// Denum returns the notation denominator (which is not how it's stored in MIDI)
func (ts *TimeSignature) Denum() int {
return int(math.Exp2(float64(ts.Denominator)))
}
func (ts *TimeSignature) String() string {
return fmt.Sprintf("%d/%d - %d clocks per tick - %d", ts.Numerator, ts.Denum(), ts.ClocksPerTick, ts.ThirtySecondNotesPerQuarter)
}