1
1
mirror of https://github.com/wader/fq.git synced 2024-11-22 07:16:49 +03:00

Mapped SMPTE frame rates to strings and fixed bug in SMPTE offset metaevent decoding (cf. https://github.com/wader/fq/pull/1023#discussion_r1833943323)

This commit is contained in:
twystd 2024-11-08 15:26:41 -08:00
parent c0930b8dcf
commit 8f12fc0ac5
15 changed files with 134 additions and 64 deletions

View File

@ -363,16 +363,16 @@ var manufacturers_extended = scalar.UintMapSymStr{
0x2127: "Expert Sleepers",
}
var framerates = scalar.UintMapSymUint{
0: 24,
1: 25,
2: 29,
3: 30,
var framerates = scalar.UintMapSymStr{
0: "24 FPS",
1: "25 FPS",
2: "29.97 FPS DF",
3: "30 FPS",
}
var fps = scalar.SintMapSymUint{
-24: 24,
-25: 25,
-29: 29,
-30: 30,
var fps = scalar.SintMapSymStr{
-24: "SMPTE 24 FPS",
-25: "SMPTE 25 FPS",
-29: "SMPTE 29.97 FPS DF",
-30: "SMPTE 30 FPS",
}

View File

@ -155,8 +155,8 @@ func decodeSMPTEOffset(d *decode.D) {
d.FieldUintFn("length", vlq, d.UintRequire(5))
d.FieldStruct("smpte_offset", func(d *decode.D) {
d.FieldU2("framerate", framerates)
d.FieldU6("hour")
d.FieldU3("framerate", framerates)
d.FieldU5("hour")
d.FieldU8("minute")
d.FieldU8("second")
d.FieldU8("frames")

View File

@ -35,3 +35,5 @@ fq -d midi 'grep_by(.event=="note_on") | [.time.tick, .note_on.note] | join(" ")
2. [Standard MIDI Files](https://midi.org/standard-midi-files)
3. [Standard MIDI File (SMF) Format](http://midi.teragonaudio.com/tech/midifile.htm)
4. [MIDI Files Specification](http://www.somascape.org/midi/tech/mfile.html)
5. [MIDI SMPTE Offset meta message](https://www.recordingblogs.com/wiki/midi-smpte-offset-meta-message)
6. [Somascape MIDI Files Specification](http://www.somascape.org/midi/tech/mfile.html#meta)

View File

@ -16,10 +16,20 @@ run: build
go run . -d midi dv format/midi/testdata/reference.mid
debug: build
go run . -d midi dv format/midi/testdata/midi/format-0x.mid
go run . -d midi dv format/midi/testdata/midi/format-0y.mid
go test ./format -run TestFormats/midi/testdata/format-0x.fqtest
go test ./format -run TestFormats/midi/testdata/format-0y.fqtest
# go run . -d midi dv format/midi/testdata/midi/smpte-timecode-24.mid
# go run . -d midi dv format/midi/testdata/midi/smpte-timecode-25.mid
# go run . -d midi dv format/midi/testdata/midi/smpte-timecode-29.mid
# go run . -d midi dv format/midi/testdata/midi/smpte-timecode-30.mid
go test ./format -run TestFormats/midi/testdata/smpte-timecode-24.fqtest
# go test ./format -run TestFormats/midi/testdata/smpte-timecode-25.fqtest
# go test ./format -run TestFormats/midi/testdata/smpte-timecode-29.fqtest
# go test ./format -run TestFormats/midi/testdata/smpte-timecode-30.fqtest
# go run . -d midi dv format/midi/testdata/midi/format-0x.mid
# go run . -d midi dv format/midi/testdata/midi/format-0y.mid
# go test ./format -run TestFormats/midi/testdata/format-0x.fqtest
# go test ./format -run TestFormats/midi/testdata/format-0y.fqtest
test: build
go test ./format -run TestFormats/midi

View File

@ -43,3 +43,5 @@ References
* Standard MIDI Files (https://midi.org/standard-midi-files)
* Standard MIDI File (SMF) Format (http://midi.teragonaudio.com/tech/midifile.htm)
* MIDI Files Specification (http://www.somascape.org/midi/tech/mfile.html)
* MIDI SMPTE Offset meta message (https://www.recordingblogs.com/wiki/midi-smpte-offset-meta-message)
* Somascape MIDI Files Specification (http://www.somascape.org/midi/tech/mfile.html#meta)

View File

@ -318,8 +318,8 @@ $ fq -d midi dv events/smpte-offset.mid
0x10| 54 | T | event: "smpte_offset" (84) 0x18-0x19 (1)
0x10| 05 | . | length: 5 0x19-0x1a (1)
| | | smpte_offset{}: 0x1a-0x1f (5)
0x10| 4d | M | framerate: 25 (1) 0x1a-0x1a.2 (0.2)
0x10| 4d | M | hour: 13 0x1a.2-0x1b (0.6)
0x10| 4d | M | framerate: "29.97 FPS DF" (2) 0x1a-0x1a.3 (0.3)
0x10| 4d | M | hour: 13 0x1a.3-0x1b (0.5)
0x10| 2d | - | minute: 45 0x1b-0x1c (1)
0x10| 3b | ; | second: 59 0x1c-0x1d (1)
0x10| 07 | . | frames: 7 0x1d-0x1e (1)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -142,8 +142,8 @@ $ fq -d midi dv reference.mid
0x0b0| 54 | T | event: "smpte_offset" (84) 0xbe-0xbf (1)
0x0b0| 05| .| length: 5 0xbf-0xc0 (1)
| | | smpte_offset{}: 0xc0-0xc5 (5)
0x0c0|4d |M | framerate: 25 (1) 0xc0-0xc0.2 (0.2)
0x0c0|4d |M | hour: 13 0xc0.2-0xc1 (0.6)
0x0c0|4d |M | framerate: "29.97 FPS DF" (2) 0xc0-0xc0.3 (0.3)
0x0c0|4d |M | hour: 13 0xc0.3-0xc1 (0.5)
0x0c0| 2d | - | minute: 45 0xc1-0xc2 (1)
0x0c0| 3b | ; | second: 59 0xc2-0xc3 (1)
0x0c0| 07 | . | frames: 7 0xc3-0xc4 (1)

View File

@ -1,31 +1,45 @@
$ fq -d midi dv midi/smpte-timecode-24.mid
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-24.mid (midi) 0x0-0x26 (38)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-24.mid (midi) 0x0-0x2f (47)
| | | header{}: 0x0-0xe (14)
0x00|4d 54 68 64 |MThd | tag: "MThd" 0x0-0x4 (4)
0x00| 00 00 00 06 | .... | length: 6 0x4-0x8 (4)
0x00| 00 00 | .. | format: 0 0x8-0xa (2)
0x00| 00 01 | .. | tracks: 1 0xa-0xc (2)
| | | division{}: 0xc-0xe (2)
0x00| e8 | . | fps: 24 (-24) 0xc-0xd (1)
0x00| e8 | . | fps: "SMPTE 24 FPS" (-24) 0xc-0xd (1)
0x00| 04 | . | resolution: 4 0xd-0xe (1)
| | | content[0:1]: 0xe-0x26 (24)
| | | [0]{}: track 0xe-0x26 (24)
| | | content[0:1]: 0xe-0x2f (33)
| | | [0]{}: track 0xe-0x2f (33)
0x00| 4d 54| MT| tag: "MTrk" 0xe-0x12 (4)
0x10|72 6b |rk |
0x10| 00 00 00 10 | .... | length: 16 0x12-0x16 (4)
| | | events[0:2]: 0x16-0x26 (16)
0x10| 00 00 00 19 | .... | length: 25 0x12-0x16 (4)
| | | events[0:3]: 0x16-0x2f (25)
| | | [0]{}: meta_event 0x16-0x22 (12)
| | | time{}: 0x16-0x17 (1)
0x10| 00 | . | delta: 0 0x16-0x17 (1)
| | | tick: 0
0x10| ff | . | status: 255 0x17-0x18 (1)
0x10| 03 | . | event: "track_name" (3) 0x18-0x19 (1)
0x10| 08 46 6f 72 6d 61 74| .Format| track_name: "Format 0" 0x19-0x22 (9)
0x20|20 30 | 0 |
| | | [1]{}: meta_event 0x22-0x26 (4)
0x10| 08 53 4d 50 54 45 20| .SMPTE | track_name: "SMPTE 24" 0x19-0x22 (9)
0x20|32 34 |24 |
| | | [1]{}: meta_event 0x22-0x2b (9)
| | | time{}: 0x22-0x23 (1)
0x20| 00 | . | delta: 0 0x22-0x23 (1)
| | | tick: 0
0x20| ff | . | status: 255 0x23-0x24 (1)
0x20| 2f | / | event: "end_of_track" (47) 0x24-0x25 (1)
0x20| 00| | .| | length: 0 0x25-0x26 (1)
0x20| 54 | T | event: "smpte_offset" (84) 0x24-0x25 (1)
0x20| 05 | . | length: 5 0x25-0x26 (1)
| | | smpte_offset{}: 0x26-0x2b (5)
0x20| 0d | . | framerate: "24 FPS" (0) 0x26-0x26.3 (0.3)
0x20| 0d | . | hour: 13 0x26.3-0x27 (0.5)
0x20| 2d | - | minute: 45 0x27-0x28 (1)
0x20| 3b | ; | second: 59 0x28-0x29 (1)
0x20| 07 | . | frames: 7 0x29-0x2a (1)
0x20| 27 | ' | fractions: 39 0x2a-0x2b (1)
| | | [2]{}: meta_event 0x2b-0x2f (4)
| | | time{}: 0x2b-0x2c (1)
0x20| 00 | . | delta: 0 0x2b-0x2c (1)
| | | tick: 0
0x20| ff | . | status: 255 0x2c-0x2d (1)
0x20| 2f | / | event: "end_of_track" (47) 0x2d-0x2e (1)
0x20| 00| | .|| length: 0 0x2e-0x2f (1)

View File

@ -1,31 +1,45 @@
$ fq -d midi dv midi/smpte-timecode-25.mid
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-25.mid (midi) 0x0-0x26 (38)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-25.mid (midi) 0x0-0x2f (47)
| | | header{}: 0x0-0xe (14)
0x00|4d 54 68 64 |MThd | tag: "MThd" 0x0-0x4 (4)
0x00| 00 00 00 06 | .... | length: 6 0x4-0x8 (4)
0x00| 00 00 | .. | format: 0 0x8-0xa (2)
0x00| 00 01 | .. | tracks: 1 0xa-0xc (2)
| | | division{}: 0xc-0xe (2)
0x00| e7 | . | fps: 25 (-25) 0xc-0xd (1)
0x00| e7 | . | fps: "SMPTE 25 FPS" (-25) 0xc-0xd (1)
0x00| 28 | ( | resolution: 40 0xd-0xe (1)
| | | content[0:1]: 0xe-0x26 (24)
| | | [0]{}: track 0xe-0x26 (24)
| | | content[0:1]: 0xe-0x2f (33)
| | | [0]{}: track 0xe-0x2f (33)
0x00| 4d 54| MT| tag: "MTrk" 0xe-0x12 (4)
0x10|72 6b |rk |
0x10| 00 00 00 10 | .... | length: 16 0x12-0x16 (4)
| | | events[0:2]: 0x16-0x26 (16)
0x10| 00 00 00 19 | .... | length: 25 0x12-0x16 (4)
| | | events[0:3]: 0x16-0x2f (25)
| | | [0]{}: meta_event 0x16-0x22 (12)
| | | time{}: 0x16-0x17 (1)
0x10| 00 | . | delta: 0 0x16-0x17 (1)
| | | tick: 0
0x10| ff | . | status: 255 0x17-0x18 (1)
0x10| 03 | . | event: "track_name" (3) 0x18-0x19 (1)
0x10| 08 46 6f 72 6d 61 74| .Format| track_name: "Format 0" 0x19-0x22 (9)
0x20|20 30 | 0 |
| | | [1]{}: meta_event 0x22-0x26 (4)
0x10| 08 53 4d 50 54 45 20| .SMPTE | track_name: "SMPTE 25" 0x19-0x22 (9)
0x20|32 35 |25 |
| | | [1]{}: meta_event 0x22-0x2b (9)
| | | time{}: 0x22-0x23 (1)
0x20| 00 | . | delta: 0 0x22-0x23 (1)
| | | tick: 0
0x20| ff | . | status: 255 0x23-0x24 (1)
0x20| 2f | / | event: "end_of_track" (47) 0x24-0x25 (1)
0x20| 00| | .| | length: 0 0x25-0x26 (1)
0x20| 54 | T | event: "smpte_offset" (84) 0x24-0x25 (1)
0x20| 05 | . | length: 5 0x25-0x26 (1)
| | | smpte_offset{}: 0x26-0x2b (5)
0x20| 2d | - | framerate: "25 FPS" (1) 0x26-0x26.3 (0.3)
0x20| 2d | - | hour: 13 0x26.3-0x27 (0.5)
0x20| 2d | - | minute: 45 0x27-0x28 (1)
0x20| 3b | ; | second: 59 0x28-0x29 (1)
0x20| 07 | . | frames: 7 0x29-0x2a (1)
0x20| 27 | ' | fractions: 39 0x2a-0x2b (1)
| | | [2]{}: meta_event 0x2b-0x2f (4)
| | | time{}: 0x2b-0x2c (1)
0x20| 00 | . | delta: 0 0x2b-0x2c (1)
| | | tick: 0
0x20| ff | . | status: 255 0x2c-0x2d (1)
0x20| 2f | / | event: "end_of_track" (47) 0x2d-0x2e (1)
0x20| 00| | .|| length: 0 0x2e-0x2f (1)

View File

@ -1,31 +1,45 @@
$ fq -d midi dv midi/smpte-timecode-29.mid
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-29.mid (midi) 0x0-0x26 (38)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-29.mid (midi) 0x0-0x2f (47)
| | | header{}: 0x0-0xe (14)
0x00|4d 54 68 64 |MThd | tag: "MThd" 0x0-0x4 (4)
0x00| 00 00 00 06 | .... | length: 6 0x4-0x8 (4)
0x00| 00 00 | .. | format: 0 0x8-0xa (2)
0x00| 00 01 | .. | tracks: 1 0xa-0xc (2)
| | | division{}: 0xc-0xe (2)
0x00| e3 | . | fps: 29 (-29) 0xc-0xd (1)
0x00| e3 | . | fps: "SMPTE 29.97 FPS DF" (-29) 0xc-0xd (1)
0x00| 04 | . | resolution: 4 0xd-0xe (1)
| | | content[0:1]: 0xe-0x26 (24)
| | | [0]{}: track 0xe-0x26 (24)
| | | content[0:1]: 0xe-0x2f (33)
| | | [0]{}: track 0xe-0x2f (33)
0x00| 4d 54| MT| tag: "MTrk" 0xe-0x12 (4)
0x10|72 6b |rk |
0x10| 00 00 00 10 | .... | length: 16 0x12-0x16 (4)
| | | events[0:2]: 0x16-0x26 (16)
0x10| 00 00 00 19 | .... | length: 25 0x12-0x16 (4)
| | | events[0:3]: 0x16-0x2f (25)
| | | [0]{}: meta_event 0x16-0x22 (12)
| | | time{}: 0x16-0x17 (1)
0x10| 00 | . | delta: 0 0x16-0x17 (1)
| | | tick: 0
0x10| ff | . | status: 255 0x17-0x18 (1)
0x10| 03 | . | event: "track_name" (3) 0x18-0x19 (1)
0x10| 08 46 6f 72 6d 61 74| .Format| track_name: "Format 0" 0x19-0x22 (9)
0x20|20 30 | 0 |
| | | [1]{}: meta_event 0x22-0x26 (4)
0x10| 08 53 4d 50 54 45 20| .SMPTE | track_name: "SMPTE 29" 0x19-0x22 (9)
0x20|32 39 |29 |
| | | [1]{}: meta_event 0x22-0x2b (9)
| | | time{}: 0x22-0x23 (1)
0x20| 00 | . | delta: 0 0x22-0x23 (1)
| | | tick: 0
0x20| ff | . | status: 255 0x23-0x24 (1)
0x20| 2f | / | event: "end_of_track" (47) 0x24-0x25 (1)
0x20| 00| | .| | length: 0 0x25-0x26 (1)
0x20| 54 | T | event: "smpte_offset" (84) 0x24-0x25 (1)
0x20| 05 | . | length: 5 0x25-0x26 (1)
| | | smpte_offset{}: 0x26-0x2b (5)
0x20| 4d | M | framerate: "29.97 FPS DF" (2) 0x26-0x26.3 (0.3)
0x20| 4d | M | hour: 13 0x26.3-0x27 (0.5)
0x20| 2d | - | minute: 45 0x27-0x28 (1)
0x20| 3b | ; | second: 59 0x28-0x29 (1)
0x20| 07 | . | frames: 7 0x29-0x2a (1)
0x20| 27 | ' | fractions: 39 0x2a-0x2b (1)
| | | [2]{}: meta_event 0x2b-0x2f (4)
| | | time{}: 0x2b-0x2c (1)
0x20| 00 | . | delta: 0 0x2b-0x2c (1)
| | | tick: 0
0x20| ff | . | status: 255 0x2c-0x2d (1)
0x20| 2f | / | event: "end_of_track" (47) 0x2d-0x2e (1)
0x20| 00| | .|| length: 0 0x2e-0x2f (1)

View File

@ -1,31 +1,45 @@
$ fq -d midi dv midi/smpte-timecode-30.mid
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-30.mid (midi) 0x0-0x26 (38)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: midi/smpte-timecode-30.mid (midi) 0x0-0x2f (47)
| | | header{}: 0x0-0xe (14)
0x00|4d 54 68 64 |MThd | tag: "MThd" 0x0-0x4 (4)
0x00| 00 00 00 06 | .... | length: 6 0x4-0x8 (4)
0x00| 00 00 | .. | format: 0 0x8-0xa (2)
0x00| 00 01 | .. | tracks: 1 0xa-0xc (2)
| | | division{}: 0xc-0xe (2)
0x00| e2 | . | fps: 30 (-30) 0xc-0xd (1)
0x00| e2 | . | fps: "SMPTE 30 FPS" (-30) 0xc-0xd (1)
0x00| 50 | P | resolution: 80 0xd-0xe (1)
| | | content[0:1]: 0xe-0x26 (24)
| | | [0]{}: track 0xe-0x26 (24)
| | | content[0:1]: 0xe-0x2f (33)
| | | [0]{}: track 0xe-0x2f (33)
0x00| 4d 54| MT| tag: "MTrk" 0xe-0x12 (4)
0x10|72 6b |rk |
0x10| 00 00 00 10 | .... | length: 16 0x12-0x16 (4)
| | | events[0:2]: 0x16-0x26 (16)
0x10| 00 00 00 19 | .... | length: 25 0x12-0x16 (4)
| | | events[0:3]: 0x16-0x2f (25)
| | | [0]{}: meta_event 0x16-0x22 (12)
| | | time{}: 0x16-0x17 (1)
0x10| 00 | . | delta: 0 0x16-0x17 (1)
| | | tick: 0
0x10| ff | . | status: 255 0x17-0x18 (1)
0x10| 03 | . | event: "track_name" (3) 0x18-0x19 (1)
0x10| 08 46 6f 72 6d 61 74| .Format| track_name: "Format 0" 0x19-0x22 (9)
0x20|20 30 | 0 |
| | | [1]{}: meta_event 0x22-0x26 (4)
0x10| 08 53 4d 50 54 45 20| .SMPTE | track_name: "SMPTE 30" 0x19-0x22 (9)
0x20|33 30 |30 |
| | | [1]{}: meta_event 0x22-0x2b (9)
| | | time{}: 0x22-0x23 (1)
0x20| 00 | . | delta: 0 0x22-0x23 (1)
| | | tick: 0
0x20| ff | . | status: 255 0x23-0x24 (1)
0x20| 2f | / | event: "end_of_track" (47) 0x24-0x25 (1)
0x20| 00| | .| | length: 0 0x25-0x26 (1)
0x20| 54 | T | event: "smpte_offset" (84) 0x24-0x25 (1)
0x20| 05 | . | length: 5 0x25-0x26 (1)
| | | smpte_offset{}: 0x26-0x2b (5)
0x20| 6d | m | framerate: "30 FPS" (3) 0x26-0x26.3 (0.3)
0x20| 6d | m | hour: 13 0x26.3-0x27 (0.5)
0x20| 2d | - | minute: 45 0x27-0x28 (1)
0x20| 3b | ; | second: 59 0x28-0x29 (1)
0x20| 07 | . | frames: 7 0x29-0x2a (1)
0x20| 27 | ' | fractions: 39 0x2a-0x2b (1)
| | | [2]{}: meta_event 0x2b-0x2f (4)
| | | time{}: 0x2b-0x2c (1)
0x20| 00 | . | delta: 0 0x2b-0x2c (1)
| | | tick: 0
0x20| ff | . | status: 255 0x2c-0x2d (1)
0x20| 2f | / | event: "end_of_track" (47) 0x2d-0x2e (1)
0x20| 00| | .|| length: 0 0x2e-0x2f (1)