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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sound - Piano

Status
Not open for further replies.

sflau

Programmer
Oct 18, 2001
87
HK
I want to write a VB program to act as a Piano, do anyone know where can I find the related information / coding for the following, please?

1. "How to control "play different sound while pressing different key.", including different tone and different time length."

2. How to save the playing sound?


 
ok, heres a link (not quite exactly what you want but)


and here is some code, (i cant remember where i got it from so ill just paste)

you will need 3 combos (cmboNote,cmboOct,cmboDec) a textbox (text1) 2 commandbuttons (command1,command2) a 2 labels (label1, label5)

Private Declare Function Beep Lib "kernel32" ( _
ByVal dwFreq As Long, _
ByVal dwDuration As Long _
) As Long

Private Const A1 = 55

Private Sub cmboDec_Click()
Calculate
End Sub

Private Sub cmboNote_Click()
Calculate
End Sub

Private Sub cmboOct_Click()
Calculate
End Sub

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Command2_Click()
Calculate
End Sub

Private Sub Form_Load()
Dim I As Integer
For I = 1 To 8
cmboOct.AddItem I
Next I
cmboOct.ListIndex = 3
For I = 0 To 10
cmboDec.AddItem I
Next I
cmboDec.ListIndex = 3
With cmboNote
.AddItem "A"
.AddItem "Bb"
.AddItem "B"
.AddItem "C"
.AddItem "Db"
.AddItem "D"
.AddItem "Eb"
.AddItem "E"
.AddItem "F"
.AddItem "F#"
.AddItem "G"
.AddItem "Ab"
.ListIndex = 3
End With
End Sub

Private Sub Calculate()
If cmboOct.ListIndex = -1 Or cmboNote.ListIndex = -1 Or cmboDec.ListIndex = -1 Then Exit Sub
Dim Temp As Double
Dim Temp2 As String
Dim returned
Temp = A1 * (2 ^ (cmboOct.ListIndex))
Temp = Temp * (2 ^ ((cmboNote.ListIndex) / 12))
Temp2 = Format(Temp, "#." & String(cmboDec.ListIndex, "#"))
If Right(Temp2, 1) = "." Then Temp2 = Left(Temp2, Len(Temp2) - 1)
Text1.Text = Temp2 & " Hertz"
returned = Beep(CDbl(Temp2), 500)
End Sub

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top