I’m kinda trying to get a model to sort of dance to the beat and I need some way to signal when to move. Is there any way I could take a MIDI file of my choosing and have a model move its joints (or even 1 joint) in rythm with any instrument from a particular track?
Could it be done in real-time where I could play the MIDI in the background and have it feed some sort of beat into the model or should I just preprocess the MIDI file into a list of notes and times and constantly look that up while the music is playing? If anyone could help, it would be appreciated.
you need to detect the beat…“that’s all” … the “” because it can be tricky dependingon the soudn. there should be some algorithms for beat detection. for midi files it could be easier. there is a midimodule for python but i dont know much about it.
as soon as you detected the beat (if you’r not recording life music) you can play any animation you want on your actor. just write a small function which changes the animation,see the manual for this.
I understand that I would need to detect a beat in order to do what I want to do, the question is how would I go about detecting a beat? Is there some function in panda where I could call up the current note and see if it matches the specific pitch, velocity, or channel I want, then move if so?
Or would I have to preprocess the file into some sort of MIDI numeric array, and have it sort of loop through as the music is playing and just look up the array to know when to move? And if that is the case, how would I go about doing that?
I guess that’s really my main problem, how do I detect a beat?
You can detect the beat easily if you have access to the waveform.
For example, see this waveform:
This sound consists of two different drum types: a greater one and a lesser one.
You see the beats here? Where the amplitude is highest, the drum beat is usually.
First, download a python class that can read the waveform of an audio file.
Next, find out the maximum amplitude.
Next, put in a list all the moments when the amplitude is equal to or a little bit lower/higher than the maximum amplitude.
Don’t forget to round this list off and remove the double values.
And, you’re done!
If you have a MIDI file, it’s easier than that, because the MIDI header includes information about the time signature–that is, the number of quarter notes in each measure–and the length of time of a quarter note and so on. So you already know when the downbeats are–they’re at the beginning of each measure.
But you’ll have to look up how to decode this information from the MIDI file; Panda can’t do it for you. It’s not hard to read it. For instance, there is a program called PyKaraoke that decodes a MIDI file in Python to extract information like this.