03-27-2005, 04:30 AM
Here is a program that uses MIDI to simulate a torpedo coming at you and hitting you. The explosion kinda sucks, but oh well. It uses a modified version of keelings library. Here's the code:
The new PlayNote takes a pointer to the midi device so that it doesn't have to open and close a device any time you want to play a note. Here's the new PlayNote code:
Code:
'$include: 'midi.bi'
print "ahhhhh torpedo!"
dim hmidi as integer
hmidi = midiOpen
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, 1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 15
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, 1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 10
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, 1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 5
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, 1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .9, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .8, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .7, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .6, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .5, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .4, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .3, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .2, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
PlayNote hmidi, midiF, 7, .05, 5
PlayNote hmidi, midiFs, 7, .1, midiSynth_Voice
PlayNote hmidi, midiF, 7, .1, midiSeashore
sleep 0
print "boom"
PlayNote hmidi, midiF, 4, 0.5,midiGunshot
PlayNote hmidi, midiF, 7, .1, midiSeashore
PlayNote hmidi, midiF, 4, 2,midiHelicopter
PlayNote hmidi, midiF, 4, 4,midiSeashore
midiClose hmidi
'sleep
The new PlayNote takes a pointer to the midi device so that it doesn't have to open and close a device any time you want to play a note. Here's the new PlayNote code:
Code:
sub PlayNote (hMidi as integer, ByVal Note as integer, ByVal Octave as integer, _
ByVal Duration as single, ByVal Instrument as integer = 0, _
ByVal Volume as integer = 127)
dim t as single
MidiSetInstrument hMidi, Instrument
MidiNoteOn hMidi,Note,Octave, Volume
t = timer + Duration
do while t > timer
sleep 1
loop
MidiNoteOff hMidi, Note, Octave
end sub
.14159265358979323846264338327950288419716939937510582709445
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.
Glarplesnarkleflibbertygibbertygarbethparkentalelelangathaffendoinkadonkeydingdonkaspamahedron.