PedroAlvesV/LuaMidi

LuaMidi.get_MIDI_tracks does not set duration on NoteEvents

Opened this issue · 4 comments

Example program:

local LuaMidi = require ('LuaMidi');

local tracks = LuaMidi.get_MIDI_tracks("tetris.midi");
events = tracks[2]["events"]

for i=2, #events do
	console.log(events[i]:get_duration()); --no return value
end

Tetris.midi in a zip file.

On line 147 of LuaMidi.lua, the event table created for the new NoteEvent doesn't have duration information. I gave a look at raw_note myself but it was tough to determine how to find a duration from that.

I take it what needs to happen is looking at the difference between a NoteOn and NoteOff event, but I'm not familiar enough with the MIDI spec or how the data is being digested to really discern how to figure that information out.

Yes, this is correct. The thing is I haven't implemented it because it creates a problem I couldn't find time to think about, yet.

If you check API, you'll notice that LuaMidi abstracts NoteOn/NoteOff events and compiles them to NoteEvent. However, this class isn't, currently able to intercalate notes, but, only, to make them sequencial (a melody with all notes having the same duration) or simultaneous (basically, a chord).

What happens is that I can't, with the current abstraction, import a MIDI file that contains a simple note that starts while another is playing in the same track, because it can't be described in LuaMidi.

The way I see it, I have just a good option: to add manual/arbitrary NoteOn and NoteOff events, so LuaMidi would import tracks with less abstraction and use NoteEvents only when composing new tracks.

TL;DR: Yes, I can determine the duration, but it exposes a flaw I have to handle first.

I'm currently focused on college, but I think I could do that during my free time. If you have any other suggestion, I would appreciate to read it.

Ahh I see the problem, that does make sense. No, nothing really jumps to my mind for better solutions. For my purposes I was just going to switch to using Pete Billam's MIDI.lua. So don't stress to hard if this would take a lot of time for you.

Good luck with college too :)

Thanks, man.

I just read your link-bot repo. I have to fix this anyway to release a concise version of LuaMidi, so I'll be working on it starting tonight. If you want to migrate back in the future, it'd be nice to have some feedback, also haha

Awesome! Yeah I'll keep a watch on this, if you get things working I'll likely switch back. LuaMidi's API is much nicer :]