building a Metronome

I'm looking to make a metronome for beat counting but not sure how I would do that. can anyone help here? Developing in VB.NET
davenseopenAsked:
Who is Participating?
 
Ryan_RConnect With a Mentor IT Systems AdministratorCommented:
set up a global variable

General Declarations()
Public nCount as Integer


Private Sub Timer1.Timer()
nCount = nCount + 1
Select Case nCount
       Case 1
              'play first beat sound
       case 2, 3, 4
               'play other beat sound
       case 5
                ncount = 0 ' restart the count
End Select
End Sub

be aware depending on how many beats per bar are set you will need to change the Case # from 2 - beats per bar, and the other one will be 1 plus the numberof beats per bar
0
 
cookreConnect With a Mentor Commented:
A rough outline to start would be:

* input field specifying beat time
* Start and stop buttons

When Start clicked, start timer whose interval is beat time converted to microseconds.

When timer fires, play click sound.

0
 
davenseopenAuthor Commented:
thats why I was thinking too but I want to have to different sounds one for the first beat and the second for the other 3 beats and possibly allow the user to specify the sounds for them.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
davenseopenAuthor Commented:
so after the first fire of the timer I want it to play the default src for the wav and then I want the source to change to the second wav then it has to go and start that again after the fourth firing
0
 
Ryan_RIT Systems AdministratorCommented:
change  that

use Case 2, 3 to play other beat sound

use case 4 separate to play beat sound and set nCount to 0 and forget case 5 otherwise you'll miss a beat
0
 
cookreCommented:
You may want to generalize it with something like:

Initialize NextSound=1

TimerHandler:
Play sound NextSound
increment NextSound
if NextSound>NumberOfSounds NextSound=1
0
 
davenseopenAuthor Commented:
sorry to jump off topic for a minute ..... is there a way to generate a certain tone like a 440 MHz tone using VB.Net?
I will try what you guys have said and then distribute points accordingly

ok cookre I get what your saying
0
 
cookreCommented:
A brazillian years ago, one could control the PC speaker directly.  But with the plethora of sound cards, the common thing to do now is to play a wav file and let the drivers worry about the details.

So, the short and easy answer is to surf around for the sounds you want or make your own with any of the many such canned programs out there.
0
 
davenseopenAuthor Commented:
yeh I just remember when I programmed in high school with Turbo Pascal that you could generate tones depending on the frequency the user inputted or a constant value that you had hard coded into the program.
0
 
Error113Commented:
You cant make a metronome in any language that is accurate on every computer. my suggestion? put a scroll bar allowing you to adjust the rate of sound.

I would only use javascript for this project, so you dont have to do refresh the page. simply use a 'SetInteval' clause to time when a sound is played. make the SetInteral method variable be based on a dynamic choice. they could even be simple text boxes. In this way you can create a dynamically timed metronome using just javascript with no page refreshing.
0
 
davenseopenAuthor Commented:
yeh i know what your sayin and when I thought about it it took 2 secs to construct the code .... but just so you know I am building a windows application in VB.NET if it was for web I would have chosen to do it in Javascript or Flash
0
 
cookreCommented:
Page refresh?  I don't recall seeing mention of anything webbish.



0
 
Error113Commented:
hey i just assume people a subject is webrelated until otherwise said, regardless of category.
0
 
davenseopenAuthor Commented:
thanx anyway Error113 but the web version is already finished just not posted
0
 
cookreConnect With a Mentor Commented:
Here's a snippet that should help you get started:
(I hope you can translate into VB.NET without too much difficulty)


[DllImport("winmm.dll")]
private static extern bool PlaySound(string lpszName,int hModule,int dwFlags);


System.Timers.Timer INITimer;
INITimer=new System.Timers.Timer();
INITimer.Elapsed+=new ElapsedEventHandler(INITimer_Elapsed);
INITimer.Interval=250;
INITimer.Enabled=true;

void INITimer_Elapsed(object source,ElapsedEventArgs evt)
{
 PlaySound("c:\\Windows\\Media\\Windows XP Menu Command.wav",0,1 );
}


The 250 microseconds corresponds to 240 beats per minute.  All the metronomes I looked at topped out at 208.









0
 
davenseopenAuthor Commented:
I already have it finished but I will take that into consideration I am going to distrubute the points here very shortly just in a rush at the moment ... mine tops out at 250 ... the points will be going to cookre and ryan r
0
 
davenseopenAuthor Commented:
oh and I forgot to add Thanks ... you guys are always a great help ... keep up the excellent work
0
 
Ryan_RIT Systems AdministratorCommented:
you're welcome, anytime
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.