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

Skipping notes #297

Closed AldeRoberge closed 2 months ago

AldeRoberge commented 3 months ago

Very basic notes :

image

Exported :

image

Read :


using Melanchall.DryWetMidi.Core;
using Melanchall.DryWetMidi.Multimedia;
using Melanchall.DryWetMidi.MusicTheory;

namespace SongActor.Runtime;

public class SongActor
{
    public void PlaySong(string midiFilePath)
    {
                var midiFile = MidiFile.Read(path);

                using var outputDevice = new OutputDevice(track);
                using var playback = midiFile.GetPlayback(outputDevice);

                playback.Play();
        }
    }

    private class OutputDevice(Track track) : IOutputDevice
    {
        public event EventHandler<MidiEventSentEventArgs>? EventSent;

        private readonly Track _track = track;

        public void Dispose()
        {
        }

        public void PrepareForEventsSending()
        {
        }

        public void SendEvent(MidiEvent midiEvent)
        {
            // Send the MIDI event to the output device
            Console.WriteLine($"Sending MIDI event: {midiEvent} for track '{_track.Name}'.");
        }
    }
}

But for some reason, the first key I receive is F5 :

image

And then it keeps skipping more notes.

image

Notice there are no F5 notes in my midi file. For some reason, Ableton is 1 octave lower than what drywetmidi says it is.

At this point, I do not care much for an octave discrepancy, I just want to see all notes print in the console. Dialogue.mid.txt

Here is the .mid file attached, remove the .txt extension

I'm starting to think Ableton might be the culprit, its MIDI support is subpar, and I'm not happy with its limitation to only be able to export single tracks midi files ('version 0'). I will test tomorrow and try with a fresh confirmed working .mid file, and see if it has the same problem.

melanchall commented 3 months ago

Hello,

But for some reason, the first key I receive is F5

What is "key"? I don't see instructions in your code that print lines like "Key: N".

For some reason, Ableton is 1 octave lower than what drywetmidi says it is.

DWM uses the convention: note number 60 = C4. Other software may use another convention. That's OK, because MIDI specification doesn't specify a strict rule for that.

I sure DWM reads the file (and plays it) as is, without any corruptions. So yes, I think the problem is with Ableton.

melanchall commented 3 months ago

@AldeRoberge Any news?

AldeRoberge commented 3 months ago

Hey, I'll get back to you asap. Thanks for the quick answer, sorry for the delay, I have to get this fixed pretty soon.

melanchall commented 2 months ago

@AldeRoberge Can the issue be closed?

AldeRoberge commented 2 months ago

Hello, yes let's mark it as closed and I'll update with further information. I acquired FL Studio to attempt a fix for the error, which DWM is probably not the cause!

Thanks for your time and great product.