Skip to content

Conversation

twystd
Copy link
Contributor

@twystd twystd commented Nov 7, 2024

Hi,

This pull request implements some small cleanups for the midi plugin:

  • adds (fairly minimal) package godoc
  • reworks the SMPTE field decoding in the MThd header to more closely align with the wording of the MIDI file spec.
  • reworks the decoding of MIDI format 0 files to only decode the first MTrk chunk with any additional (superfluous) MTrk chunks being decoded as raw data. Again this more closely aligns with the MIDI file spec.

-24: 24,
-25: 25,
-29: 29,
-30: 30,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh what is this weird mapping? :) is stored as 2's compliment but the abs value is always used? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, welcome to the wonderful world of MIDI :-).

However, fair point and I've remapped them to strings for clarity because 29 is not 29 - it's actually "29.97 FPS and drop the occasional frame to keep things in sync". And also discovered a bug in the SMPTE offset event decoding while I was at it, so good call!

FYA: here's the relevant bit of the spec:

If bit 15 of is a one, delta-times in a file correspond to subdivisions of a second, in
a way consistent with SMPTE and MIDI time code. Bits 14 thru 8 contain one of the four
values -24, -25, -29, or -30, corresponding to the four standard SMPTE and MIDI time code
formats (-29 corresponds to 30 drop frame), and represents the number of frames per second.
These negative numbers are stored in two's complement form. The second byte (stored
positive) is the resolution within a frame: typical values may be 4 (MIDI time code resolution),
8, 10, 80 (bit resolution), or 100. This system allows exact specification of time-code-based
tracks, but also allows millisecond-based tracks by specifying 25 frames/sec and a resolution of
40 units per frame. If the events in a file are stored with bit resolution of thirty-frame time
code, the division word would be E250 hex.

and:

The new counting system counts from 0 to 29 for most seconds, but skips frame 0 and frame 1 for some
seconds, jumping directly from frame 29 of the previous second to frame 2 of the next second. This counting
system is called “drop frame.”

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh 29.97 i guess from the us electric grid? same thing shows up in other digital media formats :) i guess you could use sym float if you think ppl would like to use the value in queries etc.

Copy link
Contributor Author

@twystd twystd Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's from film to NTSC (TV) conversion - there's a whole long writeup here if you're interested.

re. sym float. I thought about it but the rate is actually 29.97002997 and drop a frame so however you code it you're going to end up writing a switch statement. Clarity seemed the better way to go.

Copy link
Owner

@wader wader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! looks good, just had some minor comments and questions

@wader
Copy link
Owner

wader commented Nov 9, 2024

Looks good to me! merge?

@twystd
Copy link
Contributor Author

twystd commented Nov 9, 2024

re. merge. I don't have anything else to add so I'm good to merge if you're happy :-)

@wader wader merged commit a4372cb into wader:master Nov 9, 2024
5 checks passed
@wader
Copy link
Owner

wader commented Nov 9, 2024

Thanks!

@twystd
Copy link
Contributor Author

twystd commented Nov 9, 2024

<smile> always a pleasure .. give my regards to the cats!

@twystd twystd deleted the midi-v0.2 branch November 9, 2024 17:35
@wader
Copy link
Owner

wader commented Nov 9, 2024

They say meowllo! image

@twystd
Copy link
Contributor Author

twystd commented Nov 9, 2024

Awwwww .. they're beautiful :-) :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants