Giter Club home page Giter Club logo

Comments (13)

melanchall avatar melanchall commented on July 19, 2024

Hi,

You can try to download the project sources, copy them to your Unity solution and build it. There is the one file in the library code that, I think, will not be compiled – DryWetMidi/Smf/Utilities/IOUtilities.cs – since it uses WinAPI functions. To compile this file you need to eliminate WinAPI calls. Or I can prepare "good" file for you.

Let me know how integration the library into your project is going.

Max

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on July 19, 2024

Great, thanks to fast response!!

I have downloaded the source and imported the folder into my project. With this i can use some classes like MidiFile, but what i want its only get all notes on/off and the timesample of each note to i iterate bteween notes and sinc using the note time to sync with an audio file with same timesamples. You know a good way to this?
And seems some options from your examples is not available for me. Its because i using C#?

Something like this:

midiFile.GetTempoMap();
midiFile.GetTimedEvents();

(i still lookin into your wiki)
Edit: I working in a game like GuitarHero/RockBand xD
Edit 2: Basically is working, now i only need to get all of this output as is, like tracknames and notes:
http://prntscr.com/hnct0n
This is part of the debug logs using this code:

        MidiFile midi = MidiFile.Read(midiFilePath);        
        foreach (TrackChunk track in midi.GetTrackChunks())
        {
            Debug.Log("Track: " + track.ToString());
            foreach (MidiEvent ev in track.Events)
            {
                Debug.Log("MidiEvent: " + ev.ToString());
            }
        }

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Please clarify what do you need. You want to print track names and events?

There is no such thing like name of track in a MIDI file. But track chunk can contain Sequence/Track Name event. To get it you can use this code:

var trackName = trackChunk.Events
                          .OfType<SequenceTrackNameEvent>()
                          .FirstOrDefault()
                          ?.Text;

All events override ToString so output should be nice.

You said that you want to get notes with timestamps. You can use this code:

IEnumerable<Note> notes = midiFile.GetNotes();

Note class has Time property which is what you need.

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on July 19, 2024

Ohh man, it worked!

I needed to import classes "System.Linq" and "Melanchall.DryWetMidi.Smf.Interaction" to allow me to use GetNotes() and OfType.

Thaaank you for help for now.

Oh, just to know, to i use this on my game, i just neet to put your credits and copyright right?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

You are welcome :)

Feel free to open new issues if you have any questions about the library.

If you will put link to the library along with its name to your game I'll be very happy :) But it is completely up to you.

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on July 19, 2024

Hi,
Me again.
Just a little question. I did not found the note time equivalent to PCM timesamples to sync with Unity AudioSources. I can use seconds, but is not precise and Unity source only give me pcm samples and seconds.
Can you give me a tip about this?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Hi,

You can try to operate by seconds. To get note's time in this format use this code:

var tempoMap = midiFile.GetTempoMap();
var metricTime = note.TimeAs<MetricTimeSpan>(tempoMap);

Now you have note's time as an instance of the MetricTimeSpan class. Underlying measure of this class is number of microseconds. To access this value use the TotalMicroseconds property of the MetricTimeSpan.

You can also convert PCM sample number to microseconds too knowing sample rate of your audio. I think number of microseconds is the most accurate measure in your case.

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on July 19, 2024

Hi,
Thanks and i using this way you suggested but after some time breaking my head i see this metric time only give me a limited time. As example:

var metricTime = note.TimeAs<MetricTimeSpan>(tempoMap);

Using metricTime.Seconds only get a number 0 - 59, and not minutes and hours represented as seconds, only seconds until one minute, then get back to 0 where the correct should be 60, 61, 62...

Is this intentional?

The same with milliseconds, when we have on second in milliseconds, back to 0.

EDIT: Using note.TimedNoteOnEvent.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds and converting my song time to microseconds i done the sync.

But get as suggestion add a TotalMillis to tempo options too ;)

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Hi,

It is done intentionally that Hours returns number 0-23, Minutes and Seconds return number 0-59. Good suggestion to add properties like TotalSeconds, TotalMinutes and so on. Thank you :)

note.TimedNoteOnEvent.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds is totally equivalent to note.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds and I recommend to use the last one.

from drywetmidi.

mherbold avatar mherbold commented on July 19, 2024

Hello - Google search led me here to answer a similar question of mine, but GetNotes is apparently no longer a method of MidiFile. What is the current way to do this?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Hi,

GetNotes is an extension method for MidiFile. You need to add

using Melanchall.DryWetMidi.Interaction;

at the top of a class file in order to be able to use the method.

from drywetmidi.

mherbold avatar mherbold commented on July 19, 2024

Thanks for the quick reply! facepalm I should have been able to figure that one out without bugging you - sorry!

I'm now actually using trackChunk.GetNotes() instead, inside my track chunks loop. Mentioning it here so others can find this as well. Thank you!

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

🚀 Official DryWetMIDI asset has been released in Unity Asset Store so now you can use standard Unity ways to integrate the library. More info in the Using in Unity article.

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.