Comments (13)
@rn1d Version 5.2.1-prerelease8 is published, you can install it via NuGet. Thank you!
from drywetmidi.
@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.
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.
@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.
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.
🚀 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.
Hi @fwestberg,
Thank you for using the library. Can you provide me a file you want to get total length for?
from drywetmidi.
Of course – here is the file I used in the example above: https://we.tl/t-uNy1UvoSTa
from drywetmidi.
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.
That makes sense – and the code is exactly what I need. Thank you!
from drywetmidi.
Good news :) Let me know if you have any other questions about the library.
from drywetmidi.
@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.
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)
- Native64 dll not found on UWP HOT 2
- How do I know when i have added sufficient notes for a bar using the Pattern Builder Class HOT 14
- Getting instrument by channel HOT 2
- Add time offset for each notes during playback? HOT 2
- Generate drumming patterns HOT 10
- Read multiple MIDI files from stream HOT 17
- Issue in demo-scene in unity. HOT 7
- Anytime I retrieve a device from InputDevice.GetByIndex() it returns a new instance of that device. HOT 4
- Failing to Dispose() of an InputDevice results in never being able to use that device again. Until Unity restart. HOT 3
- Connection issues and how to debug them? HOT 5
- Can't sync midi file notes with audio file HOT 12
- HELP !!! Notes in panel to midi file?? HOT 9
- please help a noob HOT 6
- Remove all notes example from the README not working HOT 9
- Using wetdrymidi in C# project causes error CS0009
- InputDevice event listening crash HOT 2
- Crash when running in Unity on M2 MacBook HOT 3
- MidiDeviceException Internal error HOT 9
- Android Support
- Unity cannot exit after use HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from drywetmidi.