Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LuaMidi.get_MIDI_tracks does not set duration on NoteEvents #2

Open
okiyama opened this issue Aug 15, 2018 · 4 comments
Open

LuaMidi.get_MIDI_tracks does not set duration on NoteEvents #2

okiyama opened this issue Aug 15, 2018 · 4 comments

Comments

@okiyama
Copy link

okiyama commented Aug 15, 2018

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.

@PedroAlvesV
Copy link
Owner

PedroAlvesV commented Aug 16, 2018

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.

@okiyama
Copy link
Author

okiyama commented Aug 16, 2018

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 :)

@PedroAlvesV
Copy link
Owner

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

@okiyama
Copy link
Author

okiyama commented Aug 16, 2018

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 :]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants