Hi All,
I wrote a guitar-related program, one of the options is a guitar tuner which works fine, each note is in a separate 3second wav file. However, when I tried to write an option to play a full chord i.e. play 6 files, one after the other, only the last one plays.
What I need, I think, is a way to delay starting the next file until the current one has finished. I have been using VB for a while, but have not used API's until this program, so I don't know much about them. I don't want code written for me, just need pointing in the right direction, maybe a tutorial that doesn't give me a headache trying to follow it. Can you help?

Recommended Answers

All 4 Replies

Well I would suggest getting the length of the wav file.... how long it plays in seconds, and then stick a timer control on your form, with it's interval set to 1000. That way the timer executes every second, and you set a static or public variable to increment every second. If the variable size is the same as (use greater than or equal to) the size of the file in seconds, don't try to play the next one, otherwise just exit sub.... that's how I would go about doing it.

Thanks for that, Comatose,
I did toy with that one, but I guess I'm not thinking clearly today, people keep interrupting me. I was trying to do it with the Timer function and got confusing results so I gave up and shot off at a tangent. Deja vu
However, I'll get back on it with your suggestion. Let you know how I get on. Thanks again.

Hi again,
just for the benefit of other viewers, here's a version which works - in this particular case there's no need to get the length of the wav files, since they are all the same size, the length is set with the Timer control interval property.
Thanks again Comatose for refocussing me. :)

Option Explicit
Dim NextNote As Integer
Private Const SND_ASYNC = &H1
Private Const SND_FILENAME = &H20000
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Private Sub cmdEchord_Click()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
NextNote = NextNote + 1

Select Case NextNote
Case Is = 1
PlaySound "C:\ChordWavs\E6.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Case Is = 2
PlaySound "C:\ChordWavs\E5.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Case Is = 3
PlaySound "C:\ChordWavs\E4.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Case Is = 4
PlaySound "C:\ChordWavs\E3.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Case Is = 5
PlaySound "C:\ChordWavs\E2.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Case Is = 6
PlaySound "C:\ChordWavs\E1.wav", ByVal 0&, SND_FILENAME Or SND_ASYNC
Timer1.Enabled = False
NextNote = 0
End Select
End Sub

It's always a pleasure :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.