machine/usb/midi: add NoteOn, NoteOff, and SendCC methods for more complete API

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram
2022-07-20 17:13:44 +02:00
committed by Ron Evans
parent 5271bd8cfa
commit 13ed58950f
3 changed files with 22 additions and 2 deletions
+2 -2
View File
@@ -39,12 +39,12 @@ func main() {
led.Set(current)
if current {
for _, c := range chords[index].keys {
m.Write([]byte{0x08, 0x80, c, 0x40})
m.NoteOff(0, 0, c, 0x40)
}
index = (index + 1) % len(chords)
} else {
for _, c := range chords[index].keys {
m.Write([]byte{0x09, 0x90, c, 0x40})
m.NoteOn(0, 0, c, 0x40)
}
}
prev = current
+19
View File
@@ -0,0 +1,19 @@
package midi
// NoteOn sends a note on message.
func (m *midi) NoteOn(cable, channel, note, velocity uint8) {
m.msg[0], m.msg[1], m.msg[2], m.msg[3] = (cable&0xf<<4)|0x9, 0x90|(channel&0xf), note&0x7f, velocity&0x7f
m.Write(m.msg[:])
}
// NoteOff sends a note off message.
func (m *midi) NoteOff(cable, channel, note, velocity uint8) {
m.msg[0], m.msg[1], m.msg[2], m.msg[3] = (cable&0xf<<4)|0x8, 0x80|(channel&0xf), note&0x7f, velocity&0x7f
m.Write(m.msg[:])
}
// SendCC sends a continuous controller message.
func (m *midi) SendCC(cable, channel, control, value uint8) {
m.msg[0], m.msg[1], m.msg[2], m.msg[3] = (cable&0xf<<4)|0xB, 0xB0|(channel&0xf), control&0x7f, value&0x7f
m.Write(m.msg[:])
}
+1
View File
@@ -12,6 +12,7 @@ const (
var Midi *midi
type midi struct {
msg [4]byte
buf *RingBuffer
rxHandler func([]byte)
waitTxc bool