Solved

building a Metronome

Posted on 2006-07-22
18
269 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
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 …
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 …

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now