Skip to content

Commit

Permalink
midi: fixed gap in SequencerSpecificEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
twystd committed Aug 19, 2024
1 parent c5637f0 commit f1b888b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions format/midi/TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
- (?) add to probe group

- [ ] fix gaps
- [ ] SysExMessage
- [ ] SequencerSpecificEvent
- [x] SequencerSpecificEvent
- [ ] SMPTEOffset
- [ ] TimeSignature
- [ ] SysExMessage
- [ ] SysEx - 'continued' flag

- meta events
Expand Down
53 changes: 42 additions & 11 deletions format/midi/metaevents.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,18 +358,49 @@ func decodeSequencerSpecificEvent(d *decode.D) {
d.FieldU8("status")
d.FieldU8("event")

data := vlf(d)
if len(data) > 2 && data[0] == 0x00 {
d.FieldValueStr("manufacturer", fmt.Sprintf("%02X%02X", data[1], data[2]), manufacturers)
d.FieldStruct("message", func(d *decode.D) {
N := int(d.FieldUintFn("length", vlq))
data := d.PeekBytes(N)

if len(data) > 2 && data[0] == 0x00 {
d.FieldStrFn("manufacturer", func(d *decode.D) string {
d.BytesLen(3)
return fmt.Sprintf("%02X%02X", data[1], data[2])
}, manufacturers)

if len(data) > 3 {
d.FieldStrFn("data", func(d *decode.D) string {
d.BytesLen(N - 3)
return fmt.Sprintf("%v", data[3:])
})
}

if len(data) > 3 {
d.FieldValueStr("data", fmt.Sprintf("%v", data[3:]))
} else if len(data) > 0 {
d.FieldStrFn("manufacturer", func(d *decode.D) string {
d.BytesLen(1)
return fmt.Sprintf("%02x", data[0])
}, manufacturers)
if len(data) > 1 {
d.BytesLen(N - 1)
d.FieldStrFn("data", func(d *decode.D) string {
return fmt.Sprintf("%v", data[1:])
})
}
}
})

} else if len(data) > 0 {
d.FieldValueStr("manufacturer", fmt.Sprintf("%02x", data[0]), manufacturers)
if len(data) > 1 {
d.FieldValueStr("data", fmt.Sprintf("%v", data[1:]))
}
}
// data := vlf(d)
// if len(data) > 2 && data[0] == 0x00 {
// d.FieldValueStr("manufacturer", fmt.Sprintf("%02X%02X", data[1], data[2]), manufacturers)

// if len(data) > 3 {
// d.FieldValueStr("data", fmt.Sprintf("%v", data[3:]))
// }

// } else if len(data) > 0 {
// d.FieldValueStr("manufacturer", fmt.Sprintf("%02x", data[0]), manufacturers)
// if len(data) > 1 {
// d.FieldValueStr("data", fmt.Sprintf("%v", data[1:]))
// }
// }
}

0 comments on commit f1b888b

Please sign in to comment.