Comments (8)
Hi,
Welcome back! Watched the video, looks really nice! Great job :)
As for you problem, can you say what are actualTime
and position
variables? Please clarify your issue. As far as I understand the problem is you can miss some notes because their times don't equal times of notes in audio file, and so you should remember what note was played last and take next one. Is it correct?
Max
from drywetmidi.
@FabioZumbi12 Is your question still actual?
from drywetmidi.
Oh sorry,
Because a lot of notifications on my github i didnt have seen this :x
Still... but only for too near notes.
The position and actual time is in TotalMicroseconds
.
I not exact missing notes but some notes is near to next mutch than other, where on midi is the same time.
Edit.: A print to show what i mean: http://prntscr.com/i83jk4
from drywetmidi.
So your task is to get nearest note to the current position in audio file, yes?
For example:
Audio file | 1 2 3 4
MIDI file | a b c d
When current song pointer stays on note 1
in audio file the a
note in MIDI file should be played and b
for 2
, c
for 3
and d
for 4
? The problem is how to find nearest note to the specified time?
from drywetmidi.
The initial task its to get the exact time from song to note.
But i have a music playing in runtime, then i need to get the note using the song time. On my trys, using something like track.GetNotes().Where(note => note.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds == position)
but never is equals, then, i need to find the next or previous note near and too short than position, whitout repeat this note again.
The task need to get the nearest, if is not equals
.
U know what i mean with this explanation?
Thanks for your time and sorry for the delayed aswers.
from drywetmidi.
Now I got it, thanks! :)
What about this code:
var notes = midiFile.GetNotes().ToArray();
var usedNotes = new List<Note>();
// ...
// Find the note nearest to the current position (this should be done every frame)
Note nearestNote = null;
var distance = long.MaxValue;
foreach (var note in notes.Where(n => !usedNotes.Contains(n)))
{
var newDistance = Math.Abs(position - note.TimeAs<MetricTimeSpan>(tempo).TotalMicroseconds);
// Notes are returned by GetNotes in order of ascending times so we can stop the loop
// when current distance between position and note's time is not decreased
if (newDistance >= distance)
break;
distance = newDistance;
nearestNote = note;
}
if (nearestNote != null)
usedNotes.Add(nearestNote);
Can you test it and say whether it is faster than your solution or not?
from drywetmidi.
@FabioZumbi12 Is your problem solved?
from drywetmidi.
Sorry for the delay. I think yes changing the music speed. Thanks for help <3
from drywetmidi.
Related Issues (20)
- 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
- 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
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.