You just need to use a
Timer
to call a method that plays the sound something like this
private void buttonBassDrum_Click(object sender, EventArgs e)
{
SoundPlayer soundToPlay = new SoundPlayer(Properties.Settings.Default.BassGuitar);
timer = new System.Threading.Timer(new TimerCallback(PlayBeat), soundToPlay, 0, 60000 / beatsPerMinute);
}
private void buttonSnareDrum_Click(object sender, EventArgs e)
{
SoundPlayer soundToPlay = new SoundPlayer(Properties.Settings.Default.BassDrum);
timer = new System.Threading.Timer(new TimerCallback(PlayBeat), soundToPlay, 0, 60000 / beatsPerMinute);
}
private void PlayBeat(Object soundToPlay)
{
SoundPlayer currentSound = (SoundPlayer)soundToPlay;
currentSound.Play();
}
this assumes that your ScrollBar value represents Beats Per Minute, and is stored in an int
beatsPerMinute
declared at form level, and that timer is declared as a System.Threading.Timer at your form level. I also used Application Settings to store the wav file location thus
Properties.Settings.Default.BassDrum
represents a wav file.
to change the beats per minute you could do this in your
scrollBar.Scroll
method
private void scrollBar1_Scroll(object sender, EventArgs e)
{
beatsPerMinute = scrollBar1.Value;
if(timer != null)
timer.Change(0, 60000 / beatsPerMinute);
}
Hope this helps