Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Timers - Click-number dependent triggering

Timers - Click-number dependent triggering

Scheduled Pinned Locked Moved C#
csharpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NietzscheDisciple
    wrote on last edited by
    #1

    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 in DrumAccent.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!

    B 1 Reply Last reply
    0
    • N NietzscheDisciple

      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 in DrumAccent.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!

      B Offline
      B Offline
      Brian Nottingham
      wrote on last edited by
      #2

      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.

      N 1 Reply Last reply
      0
      • B Brian Nottingham

        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.

        N Offline
        N Offline
        NietzscheDisciple
        wrote on last edited by
        #3

        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);			
        	}
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups