mirror of
https://github.com/vsariola/sointu.git
synced 2025-05-28 03:10:24 -04:00
36 lines
610 B
Go
36 lines
610 B
Go
package tracker
|
|
|
|
import "fmt"
|
|
|
|
const baseNote = 20
|
|
|
|
var notes = []string{
|
|
"C-",
|
|
"C#",
|
|
"D-",
|
|
"D#",
|
|
"E-",
|
|
"F-",
|
|
"F#",
|
|
"G-",
|
|
"G#",
|
|
"A-",
|
|
"A#",
|
|
"B-",
|
|
}
|
|
|
|
// valueAsNote returns the textual representation of a note value
|
|
func valueAsNote(val byte) string {
|
|
octave := (val - baseNote) / 12
|
|
oNote := (val - baseNote) % 12
|
|
if octave < 0 || oNote < 0 || octave > 10 {
|
|
return "..."
|
|
}
|
|
return fmt.Sprintf("%s%d", notes[oNote], octave)
|
|
}
|
|
|
|
// noteValue return the note value for a particular note and octave combination
|
|
func getNoteValue(octave, note byte) byte {
|
|
return baseNote + (octave * 12) + note
|
|
}
|