Hi
I'm trying to make a guitar player with c#. The design is finished, but the only thing that stands in my way for finishing this project is for letting the sound stop at a certain time.
So what i do is actually ask a couple of questions in my program, first the amount of beats per minute, the note and the beat(which is always in default 4/4).
i make a small calculation of how many seconds the note actually has to play:
time = beat*60/bpm;
this amount do i send to my function that plays the note:
private void playtab(int i, int j,long tijd)
{
long t0 = System.Environment.TickCount;
long t1 = t0 + tijd*1000;
string Playwav = pathname + _tabsnaam[i, j] + dataname;
Boolean gespeeld = true;
while (gespeeld == true)
{
_tabs[i, j].BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(128)))), ((int)(((byte)(128)))));
PlaySound(Playwav, new System.IntPtr(), PlaySoundFlags.SND_SYNC);
if (System.Environment.TickCount >= t1 )
{
PlaySound(Playwav,new System.IntPtr(),PlaySoundFlags.SND_NOSTOP);
_tabs[i, j].UseVisualStyleBackColor = true;
gespeeld = false;
}
}
}
for play sound i use:
[System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true,/* CharSet = CharSet.Unicode,*/ ThrowOnUnmappableChar = true)]
private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);
[System.Flags]
public enum PlaySoundFlags : int
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
can someone please tell me how i can make this work
thank you.