|
A Question About MIDIs |
Mr. Big
Member #6,196
September 2005
|
Is there a way to get the value of the note the MIDI player is currently playing? |
miran
Member #2,407
June 2002
|
I have no experience with this, I'm just quoting the manual: extern void (*midi_msg_callback)(int msg, int byte1, int byte2); extern void (*midi_meta_callback)(int type, const unsigned char *data, int length); extern void (*midi_sysex_callback)(const unsigned char *data, int length); So yes, it is possible. You just write a midi_msg_callback and in it look out for note on messages. I've no idea what the different message constants are though, or what the meaning of byte1 and byte2 is. Probably looking at the Allegro source code would help... -- |
Mark Oates
Member #1,146
March 2001
|
those functions will work only if you catch the MIDI message as it's being sent (via allegro functions or any other source). what is it that you are trying to do? -- |
Mr. Big
Member #6,196
September 2005
|
I've finally figured out inverse kinematics, so I thought making a simulation of hands playing a piano could be quite amusing. Thanks in advance, |
Steve++
Member #1,816
January 2002
|
It helps to know that there are two basic events you are interested in - note on and note off. That is, there is one MIDI event that corresponds to pressing a piano key and there is another that corresponds to releasing it. How are you going to make the fingers find the keys - are you going to move the fingers directly and let the hands and the rest of the body follow? How will you know which fingers to use? A piano player knows which fingers to use by a combination of the finger number being written above certain notes and by reading ahead and making a good judgement based on experience (and perhaps some subconscious mathematics and logic). |
Shawn Hargreaves
The Progenitor
April 2000
|
You need to write your own MIDI message processor function, and set midi_msg_callback to point to it. Then when you play a MIDI file, Allegro will call your function each time a MIDI event happens, and you can look at that event to see what notes are starting or stopping. The format of MIDI messages is a well defined standard: http://en.wikipedia.org/wiki/MIDI |
Matt Smith
Member #783
November 2000
|
Steve++ makes a good point about predicting which fingers to use. I was going to do sth similar with a guitar neck. My plan depended on each string of the guitar having its own MIDI channel, but even that isn't a complete solution for which finger to use. If you want to make custom MIDI files, then you could use one MIDI channel per finger, and maybe use sysex events to move the hands in anticipation. You could write a program to automate this conversion, but it seems like too big a job for mere amusement. Piano teachers and pupils might want to buy such a program tho, so it could be worthwhile in the end |
Mr. Big
Member #6,196
September 2005
|
Well, I just put my fingers the way it feels convenient when I play the piano. Thanks for the help, guys! |
miran
Member #2,407
June 2002
|
No, that's not good. I don+'t know how to play a piano, but I can guess you need to know a bit ahead which notes you're going to play, so you don't run out of fingers at some point... -- |
Mr. Big
Member #6,196
September 2005
|
I can make it think several steps ahead. |
Shawn Hargreaves
The Progenitor
April 2000
|
You also need to know slightly ahead so you can move the finger near the right key in advance of pressing it - otherwise your fingers would have to teleport! |
Mr. Big
Member #6,196
September 2005
|
That's right. [EDIT] Making it really put the fingers in a good way could be quite an expensive process, but then, it can be precalculated once for a MIDI file and then used every time it plays. [EDIT] How do I write a... MIDI message processor function? |
|