Comments (13)
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
🚀 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)
- 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
- MidiClock sync problem HOT 6
- MIDI Tempo changes count returns 1 but the song has 6 tempo changes. HOT 1
- add il2cpp mode HOT 5
- CustomChunk no mididata throw error HOT 4
- CSharp Code Error HOT 2
- MIDI File returns error: InvalidMetaEventParameterValueException HOT 1
- Unable to send Note-On event to device HOT 8
- Cannot get track name to change HOT 10
- How to use DryWetMidi in Visual Basic (VS 2022) ? HOT 20
- Plans for MIDI 2.0 Support? HOT 2
- Skipping notes HOT 3
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.