Solved

building a Metronome

Posted on 2006-07-22
18
272 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:davenseopen
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 22

Assisted Solution

by:cookre
cookre earned 150 total points
ID: 17161957
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
 

Author Comment

by:davenseopen
ID: 17164174
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
 

Author Comment

by:davenseopen
ID: 17164482
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
ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 15

Accepted Solution

by:
Ryan_R earned 100 total points
ID: 17164656
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
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17164657
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
 
LVL 22

Expert Comment

by:cookre
ID: 17164714
You may want to generalize it with something like:

Initialize NextSound=1

TimerHandler:
Play sound NextSound
increment NextSound
if NextSound>NumberOfSounds NextSound=1
0
 

Author Comment

by:davenseopen
ID: 17164770
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
 
LVL 22

Expert Comment

by:cookre
ID: 17164941
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
 

Author Comment

by:davenseopen
ID: 17167995
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
 
LVL 1

Expert Comment

by:Error113
ID: 17170452
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
 

Author Comment

by:davenseopen
ID: 17172516
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
 
LVL 22

Expert Comment

by:cookre
ID: 17172520
Page refresh?  I don't recall seeing mention of anything webbish.



0
 
LVL 1

Expert Comment

by:Error113
ID: 17172603
hey i just assume people a subject is webrelated until otherwise said, regardless of category.
0
 

Author Comment

by:davenseopen
ID: 17172735
thanx anyway Error113 but the web version is already finished just not posted
0
 
LVL 22

Assisted Solution

by:cookre
cookre earned 150 total points
ID: 17172773
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
 

Author Comment

by:davenseopen
ID: 17172799
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
 

Author Comment

by:davenseopen
ID: 17172801
oh and I forgot to add Thanks ... you guys are always a great help ... keep up the excellent work
0
 
LVL 15

Expert Comment

by:Ryan_R
ID: 17173119
you're welcome, anytime
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
python sqlite question 11 46
move one pixel 4 67
VBSCRIPT string remove all characters to the right after extension 4 62
Difference between List and Array in Python 5 65
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question