Giter Club home page Giter Club logo

Comments (18)

melanchall avatar melanchall commented on July 19, 2024

Hi,

Thanks for your question! At now it's not possible, but I'll add corresponding event to the Playback class as soon as possible.

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

@ianespana , I've added EventPlayed event (09b7c45) to Playback class so you can react on every played event even without OutputDevice set. You can build the library from sources (develop branch) to try the new feature right now.

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

Perfect! I'll try it out and let you know if I find any issues. Thanks a lot!

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Sounds good :) Waiting for your response.

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

So, it works. But now I'm facing two new issues.
The first one is that I'm just stupid and was trying to reopen the same device again... Nevermind!

The second thing I'd like to as is if it's possible to get the MIDI's tick so I can implement a scroll bar to my program which moves forward as the song progresses

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

You can take current time in MIDI ticks via GetCurrentTime<MidiTimeSpan>() method of the Playback class.

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

I think I expressed wrong. I want an even to trigger on every tick of the MIDI clock so I can keep the scroll bar synced to the music, and also so I can avoid making another timer if one is already running

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Internal MIDI clock of playback run with interval of 1 ms. With such small timer interval it's recommended to avoid some additional logic which can lead to playback latency. My suggestion right now is to create separate timer with interval of 10 ms for example and poll current time of playback.

But I'll think on adding some event that will be fired with the specified interval. For example, if you set interval to 100 ms, the event will be fired when playback position is advanced by 100 ms.

Thank you. I really appreciate that you share your experience and ask questions!

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

I'm going to create special class for this purpose which will run another high-resolution timer and watch current time of the specified playbacks.

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

Right. One more thing, is it possible to get the note information for inputdevices?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

is it possible to get the note information for inputdevices?

What do you mean? Receive note events via input device?

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

Yep, but figured it out. You can get the input event and cast it to NoteOnEvent, which has all the information I needed (and can't believe I didn't figure this out earlier...)

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Yes, that's how it should be done :)


I've added PlaybackCurrentTimeWatcher class to watch current position of playback(s). This class is singleton in order to prevent too many high resolution timers are created (which is not good since it can affect whole system performance).

Small example:

PlaybackCurrentTimeWatcher.Instance.AddPlayback(playback, TimeSpanType.Midi);
PlaybackCurrentTimeWatcher.Instance.CurrentTimeChanged += OnCurrentTimeChanged;
PlaybackCurrentTimeWatcher.Instance.Start();

// ...

private static void OnCurrentTimeChanged(object sender, PlaybackCurrentTimeChangedEventArgs e)
{
    foreach (var playbackTime in e.Times)
    {
        var playback = playbackTime.Playback;
        var time = (MidiTimeSpan)playbackTime.Time;

        Console.WriteLine($"Current time is {time}.");
    }
}

In this example we watch current time of playback and request to report time in Midi format which is ticks (and thus we cast received time to MidiTimeSpan). You can set any desired time format and cast to corresponding implementation of the ITimeSpan.

You can add multiple different playbacks to watch their current times. When you don't want to watch playback anymore remove it from the watcher:

PlaybackCurrentTimeWatcher.Instance.RemovePlayback(playback);

By default polling interval of watcher is 100 ms, but you can alter it:

PlaybackCurrentTimeWatcher.Instance.PollingInterval = TimeSpan.FromMilliseconds(50);

Please don't set too small intervals. I recommend to use the default value or something greater than 10 ms. Polling interval defines how often CurrentTimeChanged event will be fired. If you want to pause firing the event, call Stop method.

When your application is about to close, please dispose watcher to kill the internal timer:

PlaybackCurrentTimeWatcher.Instance.Dispose();

Thank you for making the library better! Waiting for your feedback on playback time watching.

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

@ianespana Did you try playback watcher?

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

@ianespana Please give me your feedback so we can proceed to either closing the issue or redesigning API.

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

Sorry @melanchall , I've been very busy and haven't been able to try it yet. I will update my local version of the library today and give it a try. Thanks

from drywetmidi.

ianespana avatar ianespana commented on July 19, 2024

Works very well. Thanks a lot!

from drywetmidi.

melanchall avatar melanchall commented on July 19, 2024

Thank you for using the library! Feel free to open new issues or ask questions :)

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.