melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
540 stars 75 forks source link

Input Device #113

Closed dverriere closed 3 years ago

dverriere commented 3 years ago

Im trying to use InputDevice, and i observed taht the first event NoteOn is not received. I only get the NoteOff event. After that, all events are correctly received. Any idea ?

C# Vs 2019, Windows 10

Ps : thank you for all the job yoou do for us !

melanchall commented 3 years ago

Hi,

Thanks for using the library. Unfortunately my unit tests don't show any issues with InputDevice. Please show your code, how you get an instance of InputDevice and get events from it.

dverriere commented 3 years ago

I had yje idea to use the demo code you give . And ... i have the same problem. As you can see i m using a MPK249 from Akai.

using System; using Melanchall.DryWetMidi.Devices;

namespace TestInput { class Program { private static IInputDevice _inputDevice;

    static void Main(string[] args)
    {
        _inputDevice = InputDevice.GetByName("MPK249");
        _inputDevice.EventReceived += OnEventReceived;
        _inputDevice.StartEventsListening();

        Console.WriteLine("Input device is listening for events. Press any key to exit...");
        Console.ReadKey();

        (_inputDevice as IDisposable)?.Dispose();
    }

    private static void OnEventReceived(object sender, MidiEventReceivedEventArgs e)
    {
        var midiDevice = (MidiDevice)sender;
        Console.WriteLine($"Event received from '{midiDevice.Name}' at {DateTime.Now}: {e.Event}");
    }
}

}

dverriere commented 3 years ago

Ok my investigations showed me, that i have to wait for some delay (it seems me one second), to begin to hit a piano key. That delay disapear when the program is in memory and i rerun it. So my last question is : is there any solution to know that the api is ready ?

melanchall commented 3 years ago

I'm pretty sure it's related with your device (Akai MPK249). DryWetMIDI API (StartEventsListening) does all required actions. After method execution finished you can work with a device and receive events from it. But I suppose there are some special things about Akai keyboard or maybe how Windows works with this device. Maybe you need to install a driver for the keyboard?

Also I found similar issue on the web: https://forum.image-line.com/viewtopic.php?t=147266. It looks like users have missing first note with different Akai hardware.

melanchall commented 3 years ago

@dverriere Can the issue be closed or you have something to add?

dverriere commented 3 years ago

Ok you cant do anything for that poblem. Thank you for the good job !