Jamal Bernhard wrote:
You can use the C function gettimeofday() to get a result in> I'm a newbie Cocoa programmer and wanted to create a simple
> beats-per-minute calculator where the user could click the mouse on
> downbeats and the running beats-per-minute would be displayed. Looking
> at the doentation, there is a format string (%F) that can be used
> with setCalendarFormat: to print the current number of milliseconds for
> an NSCalendarDate, but I don't see any methods that return the time with
> milliseconds. If you need precision in milliseconds (which you do for a
> BPM calculator), is there a good way of handling it? I'm supposing I
> could print the %F strings of two times, convert them both to int's and
> compare, but seems like there should be a better way.
microseconds, and then do with that what you will. Also, see the
comment at the bottom.
Unfortuantely, neither usleep() nor NSTimer can really give you hard>
> Similarly, if I wanted to create a metronome where the user would enter
> BPM, I would also need millisecond accurracy but NSTimer seems to only
> work at the granularity of seconds as well. Of course, I could just use
> a usleep() but I was wondering if there's any way to get better timer
> granularity than seconds.
guarantees. If you absolutely need millisecond accuracy, why not
generate a sound with the beats at the right intervals ahead of time,
and then send that to the speakers as one big sound?
You have access to the chip's timer, if you use a bit of assembly (mftb>
> Sorry if I'm missing something obvious here -- most of my programming
> experience is at the device driver level in the kernel where you have
> access to system clock ticks and so on.
and mftbu). If you want a Cocoa wrapper around it, try the OmniTimer
framework at [url]http://www.omnigroup.com/developer/gamedevelopment/[/url]