Giter Club home page Giter Club logo

Comments (8)

melanchall avatar melanchall commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

@FabioZumbi12 Is your question still actual?

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

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.

FabioZumbi12 avatar FabioZumbi12 commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

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.

melanchall avatar melanchall commented on June 19, 2024

@FabioZumbi12 Is your problem solved?

from drywetmidi.

FabioZumbi12 avatar FabioZumbi12 commented on June 19, 2024

Sorry for the delay. I think yes changing the music speed. Thanks for help <3

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.