aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/machine/usb
diff options
context:
space:
mode:
authordeadprogram <[email protected]>2022-07-20 17:13:44 +0200
committerRon Evans <[email protected]>2022-07-21 11:05:53 +0200
commit13ed58950f853e2886a572fdb038b98da76f6b3f (patch)
tree6e505a62f20667f4815d971c17dcb29603c8ffe8 /src/machine/usb
parent5271bd8cfaa3c617311a3178af603a2479016923 (diff)
downloadtinygo-13ed58950f853e2886a572fdb038b98da76f6b3f.tar.gz
tinygo-13ed58950f853e2886a572fdb038b98da76f6b3f.zip
machine/usb/midi: add NoteOn, NoteOff, and SendCC methods for more complete API
Signed-off-by: deadprogram <[email protected]>
Diffstat (limited to 'src/machine/usb')
-rw-r--r--src/machine/usb/midi/messages.go19
-rw-r--r--src/machine/usb/midi/midi.go1
2 files changed, 20 insertions, 0 deletions
diff --git a/src/machine/usb/midi/messages.go b/src/machine/usb/midi/messages.go
new file mode 100644
index 000000000..81f9b5a41
--- /dev/null
+++ b/src/machine/usb/midi/messages.go
@@ -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[:])
+}
diff --git a/src/machine/usb/midi/midi.go b/src/machine/usb/midi/midi.go
index 8e0b10c6b..3f3b2e3c4 100644
--- a/src/machine/usb/midi/midi.go
+++ b/src/machine/usb/midi/midi.go
@@ -12,6 +12,7 @@ const (
var Midi *midi
type midi struct {
+ msg [4]byte
buf *RingBuffer
rxHandler func([]byte)
waitTxc bool