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

midi: added length field to TimeSignature struct

This commit is contained in:
twystd 2024-08-18 21:28:18 -07:00
parent befdf1fc32
commit ce02d6eafe
4 changed files with 33 additions and 89 deletions

View File

@ -14,11 +14,12 @@
- key changes
- notes
- (?) add to probe group
- (?) tick field
- [ ] fix gaps
- [x] SequencerSpecificEvent
- [x] SMPTEOffset
- [ ] TimeSignature
- [x] TimeSignature
- [x] SysExMessage
- [ ] SysEx - 'continued' flag

View File

@ -308,51 +308,7 @@ func decodeSMPTEOffset(d *decode.D) {
return uint64(data[4])
})
}
})
// d.FieldStruct("offset", func(d *decode.D) {
// data := vlf(d)
//
// if len(data) > 0 {
// rr := (data[0] >> 6) & 0x03
//
// switch rr {
// case 0:
// d.FieldValueUint("framerate", 24)
//
// case 1:
// d.FieldValueUint("framerate", 25)
//
// case 2:
// d.FieldValueUint("framerate", 29)
//
// case 3:
// d.FieldValueUint("framerate", 30)
//
// default:
// d.FieldValueUint("framerate", 0)
// }
//
// d.FieldValueUint("hour", uint64(data[0]&0x01f))
// }
//
// if len(data) > 1 {
// d.FieldValueUint("minute", uint64(data[1]))
// }
//
// if len(data) > 2 {
// d.FieldValueUint("second", uint64(data[2]))
// }
//
// if len(data) > 3 {
// d.FieldValueUint("frames", uint64(data[3]))
// }
//
// if len(data) > 4 {
// d.FieldValueUint("fractions", uint64(data[4]))
// }
// })
}
func decodeTimeSignature(d *decode.D) {
@ -360,28 +316,33 @@ func decodeTimeSignature(d *decode.D) {
d.FieldU8("status")
d.FieldU8("event")
d.FieldStruct("signature", func(d *decode.D) {
bytes := vlf(d)
N := int(d.FieldUintFn("length", vlq))
data := d.PeekBytes(N)
if len(bytes) > 0 {
d.FieldValueUint("numerator", uint64(bytes[0]))
}
d.FieldUintFn("numerator", func(d *decode.D) uint64 {
d.BytesLen(1)
return uint64(data[0])
})
if len(bytes) > 1 {
d.FieldUintFn("denominator", func(d *decode.D) uint64 {
d.BytesLen(1)
denominator := uint16(1)
for i := uint8(0); i < bytes[1]; i++ {
for i := uint8(0); i < data[1]; i++ {
denominator *= 2
}
d.FieldValueUint("denominator", uint64(denominator))
}
return uint64(denominator)
})
if len(bytes) > 2 {
d.FieldValueUint("ticksPerClick", uint64(bytes[2]))
}
d.FieldUintFn("ticksPerClick", func(d *decode.D) uint64 {
d.BytesLen(1)
return uint64(data[2])
})
if len(bytes) > 3 {
d.FieldValueUint("thirtySecondsPerQuarter", uint64(bytes[3]))
}
d.FieldUintFn("thirtySecondsPerQuarter", func(d *decode.D) uint64 {
d.BytesLen(1)
return uint64(data[3])
})
})
}
@ -405,10 +366,8 @@ func decodeEndOfTrack(d *decode.D) {
d.FieldUintFn("delta", vlq)
d.FieldU8("status")
d.FieldU8("event")
d.FieldAnyFn("data", func(d *decode.D) any {
vlf(d)
return nil
d.FieldUintFn("length", func(d *decode.D) uint64 {
return uint64(len(vlf(d)))
})
}
@ -447,19 +406,4 @@ func decodeSequencerSpecificEvent(d *decode.D) {
}
}
})
// 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:]))
// }
// }
}

View File

@ -189,4 +189,4 @@ $ ./fq -d midi d key-signatures.mid
0x100| 00 | . | delta: 0
0x100| ff | . | status: 255
0x100| 2f | / | event: 47
0x100| 00| | .| | data: null
0x100| 00| | .| | length: 0

View File

@ -24,20 +24,21 @@ $ ./fq -d midi dv test.mid
0x20| ff | . | status: 255 0x24-0x25 (1)
0x20| 51 | Q | event: 81 0x25-0x26 (1)
0x20| 03 07 a1 20 | ... | tempo: 500000 0x26-0x2a (4)
| | | [2]{}: TimeSignature 0x2a-0x2d (3)
| | | [2]{}: TimeSignature 0x2a-0x32 (8)
0x20| 00 | . | delta: 0 0x2a-0x2b (1)
0x20| ff | . | status: 255 0x2b-0x2c (1)
0x20| 58 | X | event: 88 0x2c-0x2d (1)
| | | signature{}: 0x2d-0x2d (0)
| | | numerator: 4
| | | denominator: 4
| | | ticksPerClick: 24
| | | thirtySecondsPerQuarter: 8
| | | signature{}: 0x2d-0x32 (5)
0x20| 04 | . | length: 4 0x2d-0x2e (1)
0x20| 04 | . | numerator: 4 0x2e-0x2f (1)
0x20| 02| .| denominator: 4 0x2f-0x30 (1)
0x30|18 |. | ticksPerClick: 24 0x30-0x31 (1)
0x30| 08 | . | thirtySecondsPerQuarter: 8 0x31-0x32 (1)
| | | [3]{}: EndOfTrack 0x32-0x36 (4)
0x30| 00 | . | delta: 0 0x32-0x33 (1)
0x30| ff | . | status: 255 0x33-0x34 (1)
0x30| 2f | / | event: 47 0x34-0x35 (1)
0x30| 00 | . | data: null 0x35-0x36 (1)
0x30| 00 | . | length: 0 0x35-0x36 (1)
| | | [1]{}: track 0x36-0x8e (88)
0x30| 4d 54 72 6b | MTrk | tag: "MTrk" 0x36-0x3a (4)
0x30| 00 00 00 50 | ...P | length: 80 0x3a-0x3e (4)
@ -116,6 +117,4 @@ $ ./fq -d midi dv test.mid
0x80| 00 | . | delta: 0 0x8a-0x8b (1)
0x80| ff | . | status: 255 0x8b-0x8c (1)
0x80| 2f | / | event: 47 0x8c-0x8d (1)
0x80| 00| | .| | data: null 0x8d-0x8e (1)
0x20| 04 04 02| ...| gap0: raw bits 0x2d-0x32 (5)
0x30|18 08 |.. |
0x80| 00| | .| | length: 0 0x8d-0x8e (1)