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

midi: Decoded NoteOff event

This commit is contained in:
twystd 2024-08-14 20:20:00 -07:00
parent d7ec38a2d3
commit cbd4a8a85a
3 changed files with 66 additions and 11 deletions

View File

@ -1,12 +1,13 @@
# TODO
- [ ] add to probe group
- [x] move delta into events
- [ ] discard unknown chunks
- [ ] tests
- [ ] format 0
- [ ] format 1
- [ ] format 2
- [ ] discard unknown chunks
- [x] move delta into events
- [ ] fix gaps
- (?) add to probe group
- formats
- [ ] format 0
@ -35,8 +36,10 @@
- [ ] sequencer specific event
- midi events
- [ ] note off
- [x] note off
- [ ] map note name
- [x] note on
- [ ] map note name
- [ ] polyphonic pressure
- [x] controller
- [ ] program change

View File

@ -108,6 +108,10 @@ var controllers = scalar.UintMapSymStr{
func decodeMIDIEvent(d *decode.D, status uint8) {
switch MidiEventType(status & 0xf0) {
case TypeNoteOff:
d.FieldStruct("NoteOff", decodeNoteOff)
return
case TypeNoteOn:
d.FieldStruct("NoteOn", decodeNoteOn)
return
@ -120,7 +124,6 @@ func decodeMIDIEvent(d *decode.D, status uint8) {
d.FieldStruct("ProgramChange", decodeProgramChange)
return
// TypeNoteOff MidiEventType = 0x80
// TypePolyphonicPressure MidiEventType = 0xa0
// TypeProgramChange MidiEventType = 0xc0
// TypeChannelPressure MidiEventType = 0xd0
@ -135,6 +138,18 @@ func decodeMIDIEvent(d *decode.D, status uint8) {
d.Bits(N)
}
func decodeNoteOff(d *decode.D) {
d.FieldUintFn("delta", vlq)
d.FieldUintFn("channel", func(d *decode.D) uint64 {
b := d.BytesLen(1)
return uint64(b[0] & 0x0f)
})
d.FieldU8("note")
d.FieldU8("velocity")
}
func decodeNoteOn(d *decode.D) {
d.FieldUintFn("delta", vlq)
d.FieldUintFn("channel", func(d *decode.D) uint64 {

View File

@ -7,7 +7,7 @@ $ ./fq -d midi dv test.mid
0x00| 00 01 | .. | [2]: 1 format 0x8-0xa (2)
0x00| 00 02 | .. | [3]: 2 tracks 0xa-0xc (2)
0x00| 00 60 | .` | [4]: 96 division 0xc-0xe (2)
| | | tracks[0:2]: 0xe-0x6a (92)
| | | tracks[0:2]: 0xe-0x8d (127)
| | | [0]{}: track 0xe-0x35 (39)
0x00| 4d 54| MT| tag: "MTrk" 0xe-0x12 (4)
0x10|72 6b |rk |
@ -37,10 +37,10 @@ $ ./fq -d midi dv test.mid
0x30| 00 | . | delta: 0 0x32-0x33 (1)
0x30| ff | . | status: 255 0x33-0x34 (1)
0x30| 2f | / | event: 47 0x34-0x35 (1)
| | | [1]{}: track 0x36-0x6a (52)
| | | [1]{}: track 0x36-0x8d (87)
0x30| 4d 54 72 6b | MTrk | tag: "MTrk" 0x36-0x3a (4)
0x30| 00 00 00 50 | ...P | length: 80 0x3a-0x3e (4)
| | | events[0:7]: 0x3e-0x6a (44)
| | | events[0:15]: 0x3e-0x8d (79)
| | | [0]{}: TrackName 0x3e-0x51 (19)
0x30| 00 | . | delta: 0 0x3e-0x3f (1)
0x30| ff| .| status: 255 0x3f-0x40 (1)
@ -76,10 +76,47 @@ $ ./fq -d midi dv test.mid
0x60| b0 | . | channel: 0 0x67-0x68 (1)
0x60| 06 | . | controller: "Data Entry (MSB)" (6) 0x68-0x69 (1)
0x60| 06 | . | value: 6 0x69-0x6a (1)
| | | [7]{}: NoteOff 0x6a-0x6f (5)
0x60| 83 60 | .` | delta: 480 0x6a-0x6c (2)
0x60| 80 | . | channel: 0 0x6c-0x6d (1)
0x60| 30 | 0 | note: 48 0x6d-0x6e (1)
0x60| 40 | @ | velocity: 64 0x6e-0x6f (1)
| | | [8]{}: NoteOn 0x6f-0x73 (4)
0x60| 00| .| delta: 0 0x6f-0x70 (1)
0x70|90 |. | channel: 0 0x70-0x71 (1)
0x70| 32 | 2 | note: 50 0x71-0x72 (1)
0x70| 48 | H | velocity: 72 0x72-0x73 (1)
| | | [9]{}: NoteOff 0x73-0x78 (5)
0x70| 83 60 | .` | delta: 480 0x73-0x75 (2)
0x70| 80 | . | channel: 0 0x75-0x76 (1)
0x70| 32 | 2 | note: 50 0x76-0x77 (1)
0x70| 40 | @ | velocity: 64 0x77-0x78 (1)
| | | [10]{}: NoteOn 0x78-0x7c (4)
0x70| 00 | . | delta: 0 0x78-0x79 (1)
0x70| 90 | . | channel: 0 0x79-0x7a (1)
0x70| 34 | 4 | note: 52 0x7a-0x7b (1)
0x70| 48 | H | velocity: 72 0x7b-0x7c (1)
| | | [11]{}: NoteOff 0x7c-0x81 (5)
0x70| 83 60 | .` | delta: 480 0x7c-0x7e (2)
0x70| 80 | . | channel: 0 0x7e-0x7f (1)
0x70| 34| 4| note: 52 0x7f-0x80 (1)
0x80|40 |@ | velocity: 64 0x80-0x81 (1)
| | | [12]{}: NoteOn 0x81-0x85 (4)
0x80| 00 | . | delta: 0 0x81-0x82 (1)
0x80| 90 | . | channel: 0 0x82-0x83 (1)
0x80| 35 | 5 | note: 53 0x83-0x84 (1)
0x80| 48 | H | velocity: 72 0x84-0x85 (1)
| | | [13]{}: NoteOff 0x85-0x8a (5)
0x80| 83 60 | .` | delta: 480 0x85-0x87 (2)
0x80| 80 | . | channel: 0 0x87-0x88 (1)
0x80| 35 | 5 | note: 53 0x88-0x89 (1)
0x80| 40 | @ | velocity: 64 0x89-0x8a (1)
| | | [14]{}: EndOfTrack 0x8a-0x8d (3)
0x80| 00 | . | delta: 0 0x8a-0x8b (1)
0x80| ff | . | status: 255 0x8b-0x8c (1)
0x80| 2f | / | event: 47 0x8c-0x8d (1)
0x20| 04 04 02| ...| gap0: raw bits 0x2d-0x32 (5)
0x30|18 08 |.. |
0x30| 00 | . | gap1: raw bits 0x35-0x36 (1)
0x50| 02 00 01 | ... | gap2: raw bits 0x5b-0x5e (3)
0x60| 83 60 80 30 40 00| .`.0@.| gap3: raw bits 0x6a-0x8e (36)
0x70|90 32 48 83 60 80 32 40 00 90 34 48 83 60 80 34|.2H.`.2@..4H.`.4|
0x80|40 00 90 35 48 83 60 80 35 40 00 ff 2f 00| |@..5H.`.5@../.| |
0x80| 00| | .| | gap3: raw bits 0x8d-0x8e (1)