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

Time offset for firing note events? #23

Open
Lamby777 opened this issue May 19, 2024 · 5 comments
Open

Time offset for firing note events? #23

Lamby777 opened this issue May 19, 2024 · 5 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@Lamby777
Copy link

Lamby777 commented May 19, 2024

I'm making a game that involves rhythm mechanics but I want to be lenient on players who click slightly before the "note on" event. Is there some way that I could configure this addon to read ahead for note ons x milliseconds and delay note offs by y milliseconds?

Thanks for making this project btw

@Lamby777 Lamby777 changed the title Offset for firing note events? Time offset for firing note events? May 19, 2024
@nlaha
Copy link
Owner

nlaha commented May 21, 2024

This might require reworking how note events are passed to the user. Right now I use signals, but as you mentioned this isn't ideal for rhythm games that need to look at future events. Here are a couple ideas I had while thinking about this:

  • Similar to how audio is typically transferred, expose a stream that can be read into a buffer (so you can read note events in chunks), maybe use something like this: https://docs.godotengine.org/en/stable/classes/class_streampeer.html

  • Make a subclass of MidiPlayer with a function that looks for events within a certain "radius" of the current time and returns them as a list.

@nlaha nlaha added the enhancement New feature or request label May 23, 2024
@nlaha nlaha added the help wanted Extra attention is needed label Aug 14, 2024
@nlaha
Copy link
Owner

nlaha commented Aug 14, 2024

Marking this as "help wanted" because I probably won't implement it anytime soon. Here are a couple of issues I wanted to bring up for anyone looking to take on this feature:

  1. Midi event absolute times are calculated at play-time so fetching a "radius" of events isn't easy to implement without a lot of extra calculations
  2. The buffer solution could be easier to implement, but I worry it will be difficult for the user (developer) to implement in GDscript without a lot of boilerplate

@Renart-fox
Copy link

Hello ! A workaround to this issue that I tried was having 2 different MidiPlayer nodes, but that seems to crash the game.
I think that this could work, as the first MidiPlayer would be used to display the notes, and the second one would handle the audio start and help for player inputs.

@nlaha
Copy link
Owner

nlaha commented Oct 14, 2024

Hello ! A workaround to this issue that I tried was having 2 different MidiPlayer nodes, but that seems to crash the game. I think that this could work, as the first MidiPlayer would be used to display the notes, and the second one would handle the audio start and help for player inputs.

It's weird the game crashes with multiple MidiPlayer nodes. That's something I'll need to look into.

@maresc-g
Copy link

maresc-g commented Nov 7, 2024

You can also get the events the same way the MidiPlayer does, I did something like this to display all notes on the track

var time = 0
var microseconds_per_tick = tempo / division;
for event in track.get("events"):
if event['type'] == 'note':
	var event_delta = event['delta'] * microseconds_per_tick;
	var event_delta_seconds = event_delta / 1000000.0;
	event_delta_seconds /=speed_scale;
	time += event_delta_seconds
	if event['subtype'] == MIDI_MESSAGE_NOTE_ON:
		_note_on_events.append({ "note": event['note'], "time": time })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants