?
Solved

building a Metronome

Posted on 2006-07-22
18
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 5
  • 3
  • +1
18 Comments
 
LVL 22

Assisted Solution

by:cookre
cookre earned 600 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Accepted Solution

by:
Ryan_R earned 400 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 600 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
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…
Suggested Courses

777 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