Add Music Timeline (Global Timeline) to Open Hexagon to enhance rhythm aspects #346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #335.
I've managed to implement the music timeline. Turns out that the timeline class that the pattern, event, and custom timelines use are based on
timeline2
, which is built to function as a relative timeline. So I had to actually create a brand new class that represents a global timeline. This was the trickiest part because there are things that the global timeline class does differently from timeline2. The global timeline:The global timeline is used to create the music timeline, and it functions almost like your typical timeline. The main difference comes in when you have to time your events. Instead of a wait function, you have to specify a specific time when the event will happen. If you want to use relative transformations, you can use simple math to recreate a waiting function.
There is now a "music pointer", which relays the current time that the song is playing. The music pointer will follow along with the music pitch and music changes. The music pointer works off milliseconds, rather than frame time (to account for precision in music). Due to an OpenAL limitation, the music pointer updates every 20ms. If precision is really important, I will go back and try to redo this pointer to work off the game logic instead of the SFML logic.
Speaking of Lua functions, here are all the new Lua functions that this pull request adds:
a_getMusicSeconds
: Grabs the value of the music pointer in secondsa_getMusicMilliseconds
: Grabs the value of the music pointer in milliseconds. Unlike the previous function, this returns an integer in case you're worried about floating-point error.a_evalTo
: Puts a Lua block of code onto the music timeline at a specific timestamp in seconds.a_evalToMs
: Puts a Lua block of code onto the music timeline at a specific timestamp in milliseconds.a_clearTimepoint
: Removes all events from that specific time point in the music timeline.a_clearTimepointMs
: Millisecond variant.a_clear
: Removes all events from the music timeline.There were a few more that I added than originally intended. I wanted to add clearing specifically for a timepoint for quality of life, and I added millisecond variants to ensure precision.