1
1
mirror of https://github.com/wader/fq.git synced 2024-11-23 00:57:15 +03:00

midi: reworked SysEx events as struct with length field

This commit is contained in:
twystd 2024-08-18 21:13:12 -07:00
parent fdde5680fe
commit befdf1fc32
2 changed files with 47 additions and 36 deletions

View File

@ -19,7 +19,7 @@
- [x] SequencerSpecificEvent
- [x] SMPTEOffset
- [ ] TimeSignature
- [ ] SysExMessage
- [x] SysExMessage
- [ ] SysEx - 'continued' flag
- meta events

View File

@ -36,20 +36,22 @@ func decodeSysExEvent(d *decode.D, status uint8, ctx *context) {
func decodeSysExMessage(d *decode.D, ctx *context) {
d.FieldUintFn("delta", vlq)
d.FieldU8("status")
d.FieldStruct("message", func(d *decode.D) {
N := int(d.FieldUintFn("length", vlq))
data := d.PeekBytes(N)
N := vlq(d)
if N < 1 {
ctx.casio = true
} else {
d.FieldStrFn("manufacturer", func(d *decode.D) string {
data := d.BytesLen(1)
d.BytesLen(1)
return fmt.Sprintf("%02X", data[0])
}, manufacturers)
if N > 1 {
d.FieldStrFn("data", func(d *decode.D) string {
data := d.BytesLen(int(N) - 1)
d.BytesLen(int(N) - 1)
if data[len(data)-1] == 0xf7 {
ctx.casio = false
@ -65,14 +67,17 @@ func decodeSysExMessage(d *decode.D, ctx *context) {
})
}
}
})
}
func decodeSysExContinuation(d *decode.D, ctx *context) {
d.FieldUintFn("delta", vlq)
d.FieldU8("status")
d.FieldStrFn("data", func(d *decode.D) string {
data := vlf(d)
d.FieldStruct("message", func(d *decode.D) {
N := int(d.FieldUintFn("length", vlq))
d.FieldStrFn("data", func(d *decode.D) string {
data := d.BytesLen(N)
if len(data) > 0 && data[len(data)-1] == 0xf7 {
ctx.casio = false
return fmt.Sprintf("%v", data[:len(data)-1])
@ -81,14 +86,20 @@ func decodeSysExContinuation(d *decode.D, ctx *context) {
return fmt.Sprintf("%v", data)
}
})
})
}
func decodeSysExEscape(d *decode.D, ctx *context) {
d.FieldUintFn("delta", vlq)
d.FieldU8("status")
d.FieldStruct("message", func(d *decode.D) {
N := int(d.FieldUintFn("length", vlq))
d.FieldStrFn("data", func(d *decode.D) string {
return fmt.Sprintf("%v", vlf(d))
data := d.BytesLen(N)
return fmt.Sprintf("%v", data)
})
})
ctx.casio = true
ctx.casio = false
}