Solved

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

Posted on 2003-12-09
7
330 Views
Last Modified: 2011-10-03
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?

0
Comment
Question by:jxharding
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
7 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 9911966
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.
0
 
LVL 1

Expert Comment

by:Moglor
ID: 9912364
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
0
 

Author Comment

by:jxharding
ID: 9912556
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!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Accepted Solution

by:
Moglor earned 125 total points
ID: 9912652
just start a new project, copy paste my code, then run it. when you press a key on the keyboard it will play piano notes.
i guess if you wanted to customize it further you could remove the Form_KeyPress sub and replace it with this...

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim i As Long
    Select Case KeyCode
    Case vbKeyA
        i = 55
    Case vbKeyB
        i = 88
    Case vbKeyC
        i = 44
    Case Else
        i = KeyCode
    End Select
   
    SendMidiOut 144, i, 100
End Sub
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 10144573
I think Moglor's comments are worth preserving.
0
 

Author Comment

by:jxharding
ID: 10144841
thanks for the input
i cant get it to work, but im accepting it
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 21 hours left to enroll

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question