Timers - Click-number dependent triggering
-
I've been working today on a metronome application in C#. I'm using a System.Windows.Forms.Timer variable named "Clock" as my timer. I've implemented basic tempo change functionality by means of a trackbar as follows.
//tbTempo values are in bpm - beats per minute
private void tbTempo_Scroll(object sender, System.EventArgs e)
{
Clock.Interval = 60000/(tbTempo.Value);
}I would now like to implement "accented beats". If a bar has 4 beats, I want the 4th beat to sound different from the preceding 3. Put another way, the first three ticks result in, say,
DrumNormal.wav
being played and the next tick results inDrumAccent.wav
being played. This is repeated till the user presses the "Stop" button. Could I get some tips on how I can implement this? Thanks! -
I've been working today on a metronome application in C#. I'm using a System.Windows.Forms.Timer variable named "Clock" as my timer. I've implemented basic tempo change functionality by means of a trackbar as follows.
//tbTempo values are in bpm - beats per minute
private void tbTempo_Scroll(object sender, System.EventArgs e)
{
Clock.Interval = 60000/(tbTempo.Value);
}I would now like to implement "accented beats". If a bar has 4 beats, I want the 4th beat to sound different from the preceding 3. Put another way, the first three ticks result in, say,
DrumNormal.wav
being played and the next tick results inDrumAccent.wav
being played. This is repeated till the user presses the "Stop" button. Could I get some tips on how I can implement this? Thanks!I think the modulus operator would work well for you in this situation. Without going into the details, if you have: int result = someValue % 4; Then result will be zero if and only if someValue is divisible by 4. I think you can use this information to build a solution to your problem.
-
I think the modulus operator would work well for you in this situation. Without going into the details, if you have: int result = someValue % 4; Then result will be zero if and only if someValue is divisible by 4. I think you can use this information to build a solution to your problem.
Brian, thanks for your suggestion. It did, indeed, work very well!
private void Clock_Tick(object sender, EventArgs e)
{
count++;if ((count % 4) == 0) AccentBeatBuffer.Play(0,0); else NormalBeatBuffer.Play(0,0); }