1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 10:33:53 +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,59 +36,70 @@ 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)
if N < 1 {
ctx.casio = true
} else {
d.FieldStrFn("manufacturer", func(d *decode.D) string {
d.BytesLen(1)
return fmt.Sprintf("%02X", data[0])
}, manufacturers)
return fmt.Sprintf("%02X", data[0])
}, manufacturers)
if N > 1 {
d.FieldStrFn("data", func(d *decode.D) string {
data := d.BytesLen(int(N) - 1)
if N > 1 {
d.FieldStrFn("data", func(d *decode.D) string {
d.BytesLen(int(N) - 1)
if data[len(data)-1] == 0xf7 {
ctx.casio = false
} else {
ctx.casio = true
}
if data[len(data)-1] == 0xf7 {
ctx.casio = false
} else {
ctx.casio = true
}
if data[len(data)-1] == 0xf7 {
return fmt.Sprintf("%v", data[1:len(data)-1])
} else {
return fmt.Sprintf("%v", data[1:])
}
})
if data[len(data)-1] == 0xf7 {
return fmt.Sprintf("%v", data[1:len(data)-1])
} else {
return fmt.Sprintf("%v", data[1:])
}
})
}
}
}
})
}
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))
if len(data) > 0 && data[len(data)-1] == 0xf7 {
ctx.casio = false
return fmt.Sprintf("%v", data[:len(data)-1])
} else {
ctx.casio = true
return fmt.Sprintf("%v", data)
}
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])
} else {
ctx.casio = true
return fmt.Sprintf("%v", data)
}
})
})
}
func decodeSysExEscape(d *decode.D, ctx *context) {
d.FieldUintFn("delta", vlq)
d.FieldU8("status")
d.FieldStrFn("data", func(d *decode.D) string {
return fmt.Sprintf("%v", 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)
return fmt.Sprintf("%v", data)
})
})
ctx.casio = true
ctx.casio = false
}