question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Total length of MIDI file

See original GitHub issue

Hey @melanchall,

Thanks for providing this library!

How would you go about getting the total length of a MIDI file? I’ve looked at the example you’ve provided in the README, but this gives you the timing of the last note-off event:

TempoMap tempoMap = midiFile.GetTempoMap();

TimeSpan midiFileDuration = midiFile.GetTimedEvents().LastOrDefault(e => e.Event is NoteOffEvent)?.TimeAs<MetricTimeSpan>(tempoMap) ?? new MetricTimeSpan();

I need the length of the file including any “unused space”.

2bars

In the scenario above, what I’m looking for is the value 768 ticks (96 ticks * 8 beats), but if I use the provided code, I get 696 (96 ticks * 7,25 beats (the position of the cursor)).

I’ve tried to look through the wiki, but I can’t seem to figure it out.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
melanchallcommented, Jun 14, 2021

@rn1d Version 5.2.1-prerelease8 is published, you can install it via NuGet. Thank you!

1reaction
melanchallcommented, Jun 20, 2021

🚀 5.2.1 version is released now!

Prerelease NuGet packages will be unlisted soon, so please update the package references to the new version.

Thanks for using the library!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to determine the length of a Standard Midi File
That equates to 1 hr 6 minutes and 40 seconds. As for when that was added, the MIDI Time Code document section carried...
Read more >
Standard MIDI-File Format Spec. 1.1, updated
MIDI Files are made up of -chunks-. Each chunk has a 4-character type and a 32-bit length, which is the number of bytes...
Read more >
How to calculate the time-length of a midi-file
I am trying to figure out a simple way to calculate the whole duration of the midi file (for example - total time...
Read more >
Standard MIDI File Structure
A standard MIDI file is composed of "chunks". It starts with a header chunk and is followed by one or more track chunks....
Read more >
Thread: Get Length of MIDI File
True, in a SMF (Standard Midi File) the length (duration in seconds) is not written anywhere. If you were to parse the file,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found