Skip to content
/ fq Public
forked from wader/fq

Commit 2f2070e

Browse files
committed
midi: fixed lint warnings
1 parent 0b4be89 commit 2f2070e

File tree

5 files changed

+46
-11
lines changed

5 files changed

+46
-11
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ jsonl,
110110
macho_fat,
111111
[markdown](doc/formats.md#markdown),
112112
[matroska](doc/formats.md#matroska),
113+
[midi](doc/formats.md#midi),
113114
[moc3](doc/formats.md#moc3),
114115
[mp3](doc/formats.md#mp3),
115116
mp3_frame,

doc/formats.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
|`macho_fat` |Fat&nbsp;Mach-O&nbsp;macOS&nbsp;executable&nbsp;(multi-architecture) |<sub>`macho`</sub>|
8383
|[`markdown`](#markdown) |Markdown |<sub></sub>|
8484
|[`matroska`](#matroska) |Matroska&nbsp;file |<sub>`aac_frame` `av1_ccr` `av1_frame` `avc_au` `avc_dcr` `flac_frame` `flac_metadatablocks` `hevc_au` `hevc_dcr` `image` `mp3_frame` `mpeg_asc` `mpeg_pes_packet` `mpeg_spu` `opus_packet` `vorbis_packet` `vp8_frame` `vp9_cfm` `vp9_frame`</sub>|
85+
|[`midi`](#midi) |Standard&nbsp;MIDI&nbsp;file |<sub></sub>|
8586
|[`moc3`](#moc3) |MOC3&nbsp;file |<sub></sub>|
8687
|[`mp3`](#mp3) |MP3&nbsp;file |<sub>`id3v2` `id3v1` `id3v11` `apev2` `mp3_frame`</sub>|
8788
|`mp3_frame` |MPEG&nbsp;audio&nbsp;layer&nbsp;3&nbsp;frame |<sub>`mp3_frame_tags`</sub>|
@@ -867,6 +868,43 @@ $ fq 'grep_by(.id == "Tracks") | matroska_path' file.mkv
867868
- https://www.matroska.org/technical/codec_specs.html
868869
- https://wiki.xiph.org/MatroskaOpus
869870

871+
## midi
872+
Standard MIDI file.
873+
874+
### Notes
875+
876+
1. Only supports the MIDI 1.0 specification.
877+
2. Does only basic validation on the MIDI data.
878+
879+
### Sample queries
880+
881+
1. Extract the track names from a MIDI file
882+
```
883+
fq -d midi -d midi '.. | select(.event=="Track Name")? | "\(.name)"' twinkle.mid
884+
```
885+
886+
2. Extract the tempo changes from a MIDI file
887+
```
888+
fq -d midi '.. | select(.event=="Tempo")?.tempo' twinkle.mid
889+
```
890+
891+
3. Extract the key changes from a MIDI file
892+
```
893+
fq -d midi '.. | select(.event=="Key Signature")?.key' key-signatures.mid
894+
```
895+
896+
4. Extract NoteOn and NoteOff events:
897+
```
898+
fq -d midi 'grep_by(.event=="Note On" or .event=="Note Off") | "\(.event) \(.time.tick) \(.note)"' twinkle.mid
899+
```
900+
901+
### Authors
902+
- transcriptaze.development@gmail.com
903+
904+
### References
905+
906+
1. [The Complete MIDI 1.0 Detailed Specification](https://www.midi.org/specifications/item/the-midi-1-0-specification)
907+
870908
## moc3
871909
MOC3 file.
872910

format/midi/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.DS_Store
22
workdir
33
Makefile
4-
Makefile.midi
4+
TODO.md
55

format/midi/controllers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var controllers = scalar.UintMapSymStr{
6767
84: "Portamento Control",
6868
88: "High Resolution Velocity Prefix",
6969
91: "Effects 1 Depth (Reverb Send Level)",
70-
92: "Effects 2 Depth (Tremelo Depth)",
70+
92: "Effects 2 Depth (Tremolo Depth)",
7171
93: "Effects 3 Depth (Chorus Send Level)",
7272
94: "Effects 4 Depth (Celeste Depth)",
7373
95: "Effects 5 Depth (Phaser Depth)",

format/midi/midi.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ func decodeMThd(d *decode.D) {
8484
division := d.FieldU16("divisions")
8585
if division&0x8000 == 0x8000 {
8686
SMPTE := (division & 0xff00) >> 8
87-
if SMPTE != 0xe8 && SMPTE != SMPTE && SMPTE != 0xe6 && SMPTE != 0xe5 {
87+
if SMPTE != 0xe8 && SMPTE != 0xe7 && SMPTE != 0xe6 && SMPTE != 0xe5 {
8888
d.Errorf("invalid MThd division SMPTE timecode type %02X (expected E8,E7, E6 or E5)", SMPTE)
8989
}
9090
}
9191
})
9292
})
93-
94-
return
9593
}
9694

9795
func decodeMTrk(d *decode.D) {
@@ -140,23 +138,21 @@ func skipTo(d *decode.D, tag string) error {
140138
if string(bytes[0:4]) == tag {
141139
return nil
142140
} else {
143-
len := 8 + binary.BigEndian.Uint32(bytes[4:])
141+
length := 8 + binary.BigEndian.Uint32(bytes[4:])
144142

145-
d.SeekRel(8 * int64(len))
143+
d.SeekRel(8 * int64(length))
146144
}
147145
}
148146

149147
return fmt.Errorf("missing %v chunk", tag)
150148
}
151149

152150
func peekEvent(d *decode.D) (uint64, uint8, uint8) {
153-
delta := uint64(0)
154-
N := 3
151+
var delta uint64
152+
var N int = 3
155153

156154
for {
157155
bytes := d.PeekBytes(N)
158-
159-
// ... peek at delta value
160156
delta = 0
161157

162158
for i, b := range bytes[:N-2] {

0 commit comments

Comments
 (0)