TGC Codebase Backup



Midi Wind Chimes by NoteJam

22nd May 2005 23:24
Summary

Demo of a way to use midiOutShortMessage to play random midi notes under program control



Description

Program generates random numbers, and those numbers play midi notes. It sounds sort of like a wind chime. This is a demo program, to show the basics of making api midi calls, selecting what general midi instrument to use, and how to send note on and note off messages.

I use the method of setting velocity to zero, and play the same note to turn notes off.
This method is recognized by most midi sequencers, There is another method, where a different command is used for note off messages than was used for note on messages.

I picked this method, to keep things simple and more understandable for beginners at midi programming. To get this program to work, first you need to go check your audio mixers settings.

Your audio mixer settings are found by clicking on an icon at bottom right of your screen in windows 98 and windows xp. It looks like a yellow speaker icon in w98 and in xp first click on left most icon on tool bar, and then find a small blue icon.
Right click on the icon will give you options to open volume controls.

Make certain midi is not muted, and volume of midi, wave, and over all volume is set loud enough, then run the program. You can change the midi port number to cause the output to be sent to different midi devices. Also in the listing, you can change the instrument number to find out what it would sound like with different midi instruments.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    REM WINDCHIME BY NOTEJAM
Load Dll "WINMM.DLL",1
HANDLE = Make Memory(4)
PORT=1:REM CHANGE TO PORT YOU DESIRE -1=MIDIMAPPER, 1 TO ? = YOURS
CALL DLL 1,"midiOutOpen",HANDLE,PORT,0,0,0
rem to get the handle of the Midi Out port:
HMO As DWORD
HMO = *HANDLE
HERE:
note=rnd(72)+20:REM PICK A RANDOM NOTR
event = 192
INSTRUMENT=12:REM VIBES
lo = (INSTRUMENT*256)+event
Message=lo+hi
Call Dll 1, "midiOutShortMsg", HMO, Message
note=rnd(72)+30
event = 144
lo = (note*256)+event
vel = 127
hi=vel*65536
Message=lo+hi
rem put it out
Call Dll 1, "midiOutShortMsg", HMO, Message

WAIT 120

EVENT=144
VEL=0
LO=(NOTE*256)+EVENT
HI=VEL*256
Message=lo+hi
CALL DLL 1,"midiOutShortMsg",hmo,Message
GOTO HERE

REM HAVE Q KEY PRESS CAUSE JUMP TO EXIT: TO QUIT PROGRAM
EXIT:
DELETE MEMORY HANDLE
DELETE DLL 1
END