Link to home
Start Free TrialLog in
Avatar of jxharding
jxharding

asked on

play musical notes in vb, e.g. A, B, B#

someone i knew had qbasic long ago and he was able to do it

he assigned a key to a tone e.g.
COMPUTER KEY A = (musical)"A"
COMPUTER KEY B = (musical)"B"



etc.

is something like this possible in vb?

Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

You could use a multimedia control to play one of a set of sound (e.g.) ".wav" files according to which key is pressed.

Programmatic sound synthesis is not as fashionable (or easy) as it once was (e.g. on the Amstrad CPC464 built-in Basic). It's mostly done with sampling which gives a better sound, but of course requires the samples. DirectX would probably be necesssary, but it's an horrendous learning curve.
Avatar of Moglor
Moglor

ok here is some code.

Private Declare Function midiOutClose Lib "winmm.dll" (ByVal hMidiOut 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 midiOutShortMsg Lib "winmm.dll" (ByVal hMidiOut As Long, ByVal dwMsg As Long) As Long
Dim hMidiOut As Long

Private Sub Form_KeyPress(KeyAscii As Integer)
    SendMidiOut 144, KeyAscii, 100
End Sub

Private Sub Form_Load()
    midiOutOpen hMidiOut, 0, 0, 0, 0
End Sub

Private Sub SendMidiOut(MidiEventOut, MidiNoteOut, MidiVelOut)
    lowint = (MidiNoteOut * 256) + MidiEventOut
    VelOut = MidiVelOut * 256
    highint = VelOut * 256
    MidiMessage = lowint + highint
    midiOutShortMsg hMidiOut, MidiMessage
End Sub

Private Sub Form_Unload(Cancel As Integer)
    midiOutClose hMidiOut
End Sub
Avatar of jxharding

ASKER

thanks for the input!

modlor , i just cant figure out how your sub
sendmidiout works. when do i call it?

i forgot to mention the qbasic version worked on pc speaker, but who wants that these days?
thanks!
ASKER CERTIFIED SOLUTION
Avatar of Moglor
Moglor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think Moglor's comments are worth preserving.
thanks for the input
i cant get it to work, but im accepting it