Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here is how to play musical notes in vb6.

Status
Not open for further replies.

John Alexander

Programmer
Jun 26, 2018
7
US
Const NOTES_ON = &H90
Const MIDI_MAPPER = (-1)
Private Declare Function midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Private Declare Function midiOutOpen Lib "winmm.dll" (lphMidiOut As Long, _
ByVal udeviceid As Long, ByVal dwCallback As Long, ByVal dwInstance As Long, ByVal dwFlags As Long) As Long
Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut As Long) As Long

Dim Note1Play(200) As Long, Length1_Note(200) As Single
Dim Note2Play(200) As Long, Length2_Note(200) As Single
Dim Note3Play(200) As Long, Length3_Note(200) As Single
Dim Note4Play(200) As Long, Length4_Note(200) As Single
Dim NUMBEROFNOTES As Integer
Dim NUMBEROFNOTES1 As Integer, NUMBEROFNOTES2 As Integer, NUMBEROFNOTES3 As Integer

Private Sub Form_Load()
midiOpenError = midiOutOpen(hMidiOut, MIDI_MAPPER, 0, 0, 0)
midiMessageOut = NOTES_ON
midiData2 = 127

Happy_Birthday ' This calls sub Happy_Birthday to read in notes

For y = 1 To NUMBEROFNOTES
lowint = (Note1Play(y) * 256) + &H90
GoSub PlayVoice1

lowint = (Note2Play(y) * 256) + &H94
GoSub PlayVoice1

lowint = (Note3Play(y) * 256) + &H96
GoSub PlayVoice1

lowint = (Note4Play(y) * 256) + &H98
GoSub PlayVoice1

ThisTime = Timer
Do
Loop While ThisTime + Length1_Note(y) * 0.7 > Timer
Next y

ThisTime = Timer
Do
Loop While ThisTime + 0.3 > Timer
x = midiOutClose(hMidiOut)
End

PlayVoice1:
highint = (midiData2 * 256) * 256
MidiMessage = lowint + highint
x = midiOutShortMsg(hMidiOut, MidiMessage)
Return

End Sub

Private Sub Happy_Birthday()
NUMBEROFNOTES = 26

'******************** Data for Happy Birthday VOICE ONE **************************************

For y = 1 To 12 'G G A G >C <B G G A G D C
Note1Play(y) = Choose(y, 55, 55, 57, 55, 60, 59, 55, 55, 57, 55, 62, 60)
Length1_Note(y) = Choose(y, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82)
Next y
For y = 13 To 24 'G G >G E C C B A F F E C
Note1Play(y) = Choose(y - 12, 55, 55, 67, 64, 60, 60, 59, 57, 65, 65, 64, 60)
Length1_Note(y) = Choose(y - 12, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91)
Next y
For y = 25 To 26 ' D C
Note1Play(y) = Choose(y - 24, 62, 60)
Length1_Note(y) = Choose(y - 24, 0.91, 1.82)
Next y
'******************** Data for Happy Birthday VOICE Two **************************************

For y = 1 To 12 'F F E E E F F F F F B G
Note2Play(y) = Choose(y, 53, 53, 52, 52, 52, 53, 53, 53, 53, 53, 59, 55)
Length2_Note(y) = Choose(y, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82)
Next y
For y = 13 To 24 'E E >C C <G <G F F >C C C <G
Note2Play(y) = Choose(y - 12, 52, 52, 60, 60, 55, 55, 53, 53, 60, 60, 60, 55)
Length2_Note(y) = Choose(y - 12, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91)
Next y
For y = 25 To 26 ' B G
Note2Play(y) = Choose(y - 24, 59, 55)
Length2_Note(y) = Choose(y - 24, 0.91, 1.82)
Next y
'******************** Data for Happy Birthday VOICE Three ************************************

For y = 1 To 12 'B B >C C E D <B B B B F E
Note3Play(y) = Choose(y, 59, 59, 60, 60, 64, 62, 59, 59, 59, 59, 65, 64)
Length3_Note(y) = Choose(y, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82, 0.455, 0.455, 0.91, 0.91, 0.91, 1.82)
Next y
For y = 13 To 24 'C C E G E E C C A A G E
Note3Play(y) = Choose(y - 12, 60, 60, 64, 67, 64, 64, 60, 60, 69, 69, 67, 64)
Length3_Note(y) = Choose(y - 12, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91)
Next y
For y = 25 To 26
Note3Play(y) = Choose(y - 24, 65, 64)
Length3_Note(y) = Choose(y - 24, 0.91, 1.82)
Next y
'******************** Data for Happy Birthday VOICE Four *************************************
For y = 1 To 12 'G G G G G G G G G G G C
Note4Play(y) = Choose(y, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 55, 60)
Length4_Note(y) = Choose(y, 0.455, 0.455, 0.91, 0.91, 0.91, 0.182, 0.455, 0.455, 0.91, 0.91, 0.91, 0.182)
Next y
For y = 13 To 24 'G G G C C C F F F F G G
Note4Play(y) = Choose(y - 12, 55, 55, 55, 60, 60, 60, 53, 53, 53, 53, 55, 55)
Length4_Note(y) = Choose(y - 12, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91, 0.455, 0.455, 0.91, 0.91)
Next y
For y = 25 To 26 ' G C
Note4Play(y) = Choose(y - 24, 55, 60)
Length4_Note(y) = Choose(y - 24, 0.91, 1.82)
Next y

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top