GML Is it possible to interpret midi-sequences as code?

Hello, everybody. First time poster here, I apologize if I'm posting this on the wrong board, or something of the sort. I'm gonna try not to make this too complicated.

I'm currently working on a project with rhythm game mechanics similar to the ones found in games like Guitar Hero. (Basically, notes descend from the top of the screen, and you have to press the right key once they reach a bar at the bottom.)
The mechanics themselves work fine, however, my process for charting each song is incredibly tedious. In order to spawn the notes for each song, I simply run a timeline that creates them at the appropriate time. So, basically, I have to look at the sheet music for the song I'm charting, look at the note I want to add, calculate the time between it and the previous note, convert that time to frames, then write the code for it (which thankfully is just calling a script called scr_note_[1-4]). This technically works fine, but it's not very practical, since every song takes hours to chart.

Now, I had an idea quite a while ago that would make this one heck of a lot easier, but I'm not sure how to program it, or if it's even possible with GML, it's just my "dream scenario", I guess.
My idea is as follows: Instead of manually calling each note, I'll simply create a midi-file based on the song, but change all the notes to only four different ones. I'll then import the midi into GMS2, and simply have it interpret these four notes as code. (So, when a note in the midi-sequence plays, it'll call the aforementioned script spawning the notes in-game.)
I'm aware it may be entirely impossible to do this, but I've seen people do crazier things in GMS. And, if it is impossible, does anyone have an idea of a simple way to achieve what I'm trying to achieve?

Any and all help is highly appreciated. Thank you for your time!
 

Alexx

Member
I'd write a little program that stores the times of keypresses into a text file.
You can then play your song and press the keys that you would like the player to press when they play your game.

Then just import the timings from the text file into your game.

If you'd like some help setting this up, I'm more than happy to assist.
 
MIDI data is just binary data. As long as you know the structure of the format, you can use file_bin_* functions to do whatever you want with that data. For your "dream scenario" you could probably use buffers to achieve something to that effect.

 
MIDI data is just binary data. As long as you know the structure of the format, you can use file_bin_* functions to do whatever you want with that data. For your "dream scenario" you could probably use buffers to achieve something to that effect.

That's very good to know! Thank you for the information. I'll look into that later.

I'd write a little program that stores the times of keypresses into a text file.
You can then play your song and press the keys that you would like the player to press when they play your game.

Then just import the timings from the text file into your game.

If you'd like some help setting this up, I'm more than happy to assist.
That's not a half-bad idea! Might have to make some edits and such, but it sounds like a far better method than what I'm currently dealing with. If you're willing to assist, then I'll gladly accept your help!
 

Alexx

Member
OK, I'll guide you through this the best I can.

First, you need to decide how accurate you need it to be.
A room speed of 60 should be OK and base presses off of that, incrementing by 1 each count, though using delta time would be better.

Second, decide how you are going to format your data for the text file.
I recommend a count since song start, and a string (based on binary for easy parsing).
So if your keys are Z X C V, pressing Z would be:
1000
Z and V would be:
1001

So like pressing X C at count 100 you data would be:
100
0110
Where 100 is your timing count and 0110 relates to your key presses.
You can then right this on key presses to your text file.

Are you familiar with opening and writing to a text file?
 
OK, I'll guide you through this the best I can.

First, you need to decide how accurate you need it to be.
A room speed of 60 should be OK and base presses off of that, incrementing by 1 each count, though using delta time would be better.

Second, decide how you are going to format your data for the text file.
I recommend a count since song start, and a string (based on binary for easy parsing).
So if your keys are Z X C V, pressing Z would be:
1000
Z and V would be:
1001

So like pressing X C at count 100 you data would be:
100
0110
Where 100 is your timing count and 0110 relates to your key presses.
You can then right this on key presses to your text file.

Are you familiar with opening and writing to a text file?
Yes, I know the basics of opening/writing to text files. Wouldn't say I'm an expert, but I used that to program a functional save/load system, so I'm not exactly "in the dark".
 

Alexx

Member
OK.
So, at the start of your program to "record your data":
Create a new text file for writing and open it.
Set an alarm for one frame and start a count. Start your music track at the same time.
When alarm triggers, restart alarm and increment the count.

Constantly check (Step Event is fine) which keypresses of ZXCV are.
If there is a keyboard press down, set some flag to true. (might need some tweeking to register 4 keypresses at once)
Check for all flags and generate a string, like "1001" for Z and C.
Write this string to the text file. Write a line break.
Write the count to the text file. Write a line break.

At song end close file.

This can all be done within one object, doesn't need to be anything fancy.

Have a go with this, and paste some of the output in a post so I can check it.
 
OK.
So, at the start of your program to "record your data":
Create a new text file for writing and open it.
Set an alarm for one frame and start a count. Start your music track at the same time.
When alarm triggers, restart alarm and increment the count.

Constantly check (Step Event is fine) which keypresses of ZXCV are.
If there is a keyboard press down, set some flag to true. (might need some tweeking to register 4 keypresses at once)
Check for all flags and generate a string, like "1001" for Z and C.
Write this string to the text file. Write a line break.
Write the count to the text file. Write a line break.

At song end close file.

This can all be done within one object, doesn't need to be anything fancy.

Have a go with this, and paste some of the output in a post so I can check it.
I'll give that a shot either later tonight, or tomorrow morning (It's getting kinda late in my timezone. :/). Thank you for your help, I'll report back once I've got some results!
 
Top