Mail Archives: djgpp/1997/03/10/09:18:07
David Jenkins writes:
>Is it possible to detect when a certain sound is played in a midi file??
>
>I want to have the music in my demo affect something on the screen.
>Like make the background flash whever the drum is hit.
This can't be done with the standard API, but it's a simple modification
to the MIDI player. Edit midi.c, go to line 387 (the start of the
midi_note_on() function), and do whatever you have to...
Beware, though: some MIDI files use note-on messages with a volume of
zero to turn notes off (argh! why, when there's a different note-off
message?), so you should check for zero volumes.
Alternatively you could write a custom MIDI driver, which calls the
normal driver to play the sounds but also does special things in
response to note on messages. Eg. after install_sound(), write:
MIDI_DRIVER *old_driver = midi_driver;
midi_driver = &mydriver;
where mydriver is a MIDI_DRIVER structure you've filled in with all the
appropriate functions, along the lines of:
void my_key_on(int voice, inst, note, bend, vol, pan)
{
old_driver->key_on(voice, inst, note, bend, vol, pan);
// do cool stuff here
}
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Beauty is a French phonetic corruption of a short cloth neck ornament.
*/
- Raw text -