sointu/tracker/music.go
vsariola adcf3ebce8 feat(sointu, tracker,...): restructure domain & tracker models
send targets are now by ID and Song has "Score" part, which is the notes for it. also, moved the model part separate of the actual gioui dependend stuff.

sorry to my future self about the code bomb; ended up too far and did not find an easy way to rewrite the history to make the steps smaller, so in the end, just squashed everything.
2021-02-28 14:24:54 +02:00

43 lines
689 B
Go

package tracker
import "fmt"
const baseNote = 20
var notes = []string{
"C-",
"C#",
"D-",
"D#",
"E-",
"F-",
"F#",
"G-",
"G#",
"A-",
"A#",
"B-",
}
func NoteStr(val byte) string {
if val == 1 {
return "..." // hold
}
if val == 0 {
return "---" // release
}
oNote := mod(int(val-baseNote), 12)
octave := (int(val) - oNote - baseNote) / 12
if octave < 0 {
return fmt.Sprintf("%s%s", notes[oNote], string(byte('Z'+1+octave)))
}
if octave >= 10 {
return fmt.Sprintf("%s%s", notes[oNote], string(byte('A'+octave-10)))
}
return fmt.Sprintf("%s%d", notes[oNote], octave)
}
func NoteAsValue(octave, note int) byte {
return byte(baseNote + (octave * 12) + note)
}