Giter Club home page Giter Club logo

Comments (13)

melanchall avatar melanchall commented on June 19, 2024 2

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

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024 1

@rn1d Thanks for pointing out the problem!

Hmm, I'll think how to handle the situation you've mentioned. I'm on vacation right now. I'll come back to the issue a couple of days later.

from drywetmidi.

rn1d avatar rn1d commented on June 19, 2024 1

This is a corner case, to be sure, and I am not expecting anything, I just wanted to chime in.
Enjoy your vacation! 🌴

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024 1

@rn1d I think now that this was a wrong decision to hide EOT event. This violates the principle of the library according to which it should be possible to get raw MIDI data as it present in a file without any transformations.

I suppose I'll expose the event. Thanks for your comment!

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024 1

I've added EndOfTrackStoringPolicy property to the ReadingSettings class. So I've decided to leave default behavior as is, BUT give ability to change it:

var midiFile = MidiFile.Read("file.mid", new ReadingSettings
{
    EndOfTrackStoringPolicy = EndOfTrackStoringPolicy.Store
});

With this code EndOfTrackEvent will be present in track chunks of the midiFile (if the event is present in an input file of course).

Changes are in develop branch. @rn1d I can build prerelease NuGet package, if you need it.

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024 1

🚀 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!

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

Hi @fwestberg,

Thank you for using the library. Can you provide me a file you want to get total length for?

from drywetmidi.

fwestberg avatar fwestberg commented on June 19, 2024

Of course – here is the file I used in the example above: https://we.tl/t-uNy1UvoSTa

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

I've examined your file. There are no events in it after time of 696 ticks, so the library gives you the correct result. I think the reason you see empty space at the end of file is MIDI editor you use. It expands visual representation of MIDI file to the end of last bar.

So your real task is get the length of a file in terms of bars occupied by MIDI data. You can do it with this code:

var tempoMap = midiFile.GetTempoMap();
var barBeatTimeOfLastEvent = midiFile.GetTimedEvents().Last().TimeAs<BarBeatTimeSpan>(tempoMap);

var totalBars = barBeatTimeOfLastEvent.Bars;

// If a bar is partially occupied, we need add it to the total count of bars
if (barBeatTimeOfLastEvent.Beats > 0 || barBeatTimeOfLastEvent.Ticks > 0)
    totalBars = barBeatTimeOfLastEvent.Bars + 1;

// Convert time span corresponding to total count of bars to ticks
var totalBarsInTicks = TimeConverter.ConvertTo<MidiTimeSpan>(new BarBeatTimeSpan(totalBars, 0), tempoMap);

With this code you'll get expected 768. Please let me know if your problem solved.

from drywetmidi.

fwestberg avatar fwestberg commented on June 19, 2024

That makes sense – and the code is exactly what I need. Thank you!

from drywetmidi.

melanchall avatar melanchall commented on June 19, 2024

Good news :) Let me know if you have any other questions about the library.

from drywetmidi.

rn1d avatar rn1d commented on June 19, 2024

@melanchall, firstly - thank you for sharing your library and answering questions!

A comment on this - I'm faced with a similar problem, but I think the solution you propose is not always correct. The basic idea, if I understand correctly, is to look at the last event and assume the next bar is the end. That assumption fails if there is more than one bar of silence after the last event. It makes a difference if you want to loop the original MIDI file.

There is a special event to signal the end of a track - EndOfTrackEvent.

Unfortunately, DryWetMidi doesn't make it available in the parsed MidiFile object. It is discarded when parsing MIDI data. https://github.com/melanchall/drywetmidi/blob/develop/DryWetMidi/Core/Chunks/TrackChunk.cs#L134

Ideally, this should be exposed somehow - at least the event should be included in the parsed track Event collection.

from drywetmidi.

rn1d avatar rn1d commented on June 19, 2024

Fantastic, thank you! If it's not too much trouble to build that pre release package, I would use it. If it's too much hassle - no worries, I'll wait for the next release.

from drywetmidi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.