• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to make Metronome?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to make Metronome?


  • Subject: Re: How to make Metronome?
  • From: "I. Savant" <email@hidden>
  • Date: Sat, 2 Sep 2006 20:06:31 -0400


Matt has contacted me off-list with his project source. The relevant code is here:


- (IBAction)slide:(id)sender{
sixty = 60;
beats = [view floatValue];
bpm = sixty / beats;
bpmtimer = [NSTimer scheduledTimerWithTimeInterval:bpm target:self selector:@selector(handletimer:) userInfo:nil repeats:YES];
[view setFloatValue:bpm];
}


- (void) handletimer: (NSTimer *) bpmtimer{
    NSSound *mysound = [NSSound soundNamed:@"Pop"];
	[mysound play];
}

Two problems and one warning jump right out at me. First, you're creating and starting a new timer every time the slider fires. If you slide it to one new position, you now have two running timers. That would certainly sound fairly inaccurate to me. :-)

Second, your bpm is (60 / [view floatValue]) ... then you set the view's floatValue to bpm ... so which value does 'view' display? Is it "beats" or "bpm"? It can't be both because they're two different things.

Finally, NSSound probably isn't the best thing to use here if you want really fast repetition. I may be wrong, but you might want to look into NSMovie / NSMovieView.

It's unlikely that you need any more accuracy than NSTimer for an audible metronome. The human brain is only capable of so much precision ... ;-)

  I hope this is helpful.

--
I.S.


On Sep 2, 2006, at 7:46 PM, AgentM wrote:


On Sep 2, 2006, at 6:47 PM, Matt wrote:

Hello

I am new to Cocoa. How can I make a metronome in cocoa? I tried using
NSTimer but it doesn't work - its very inaccurate. Any ideas?

Matt

Instead of relying on the timer to keep track of time, you should simply use it as an updating callback. Then in the timer callback, call [NSDate timeIntervalSinceReferenceDate] and subtract that from the last time that the callback was called. That is the duration of time that has past since the last callback. Now you know what you need to render. Good luck!


-M

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40gmail.com


This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: How to make Metronome?
      • From: John Pannell <email@hidden>
References: 
 >How to make Metronome? (From: Matt <email@hidden>)
 >Re: How to make Metronome? (From: "I. Savant" <email@hidden>)
 >Re: How to make Metronome? (From: AgentM <email@hidden>)

  • Prev by Date: Re: How to make Metronome?
  • Next by Date: Re: Re: How to make Metronome?
  • Previous by thread: Re: How to make Metronome?
  • Next by thread: Re: How to make Metronome?
  • Index(es):
    • Date
    • Thread