views:

243

answers:

2

What i want to do is record the time of when a button has been pressed. All these times will be stored in an array. The program will then run through the array and look at the time values and then highlight the button states at those particular times during playback.

Hopefully this makes sense, whats the best way to do this?! Thanks in advance.

------------------ MORE DETAIL ------------------

the first thing that came up on my mind was... 'ah ha, timestamp', but then looking into the documentation, in a certain section in the timestamp page somewhere in the paragraph it states the following:

....You should not use it to determine the exact time at which the event occurred but should instead compare it to the timestamp of another acceleration event to determine the elapsed time between the events....

this is not great.. as i am assuming that it will not be accurate when it comes to playback of highlighting the buttons at the exact times of when the user had actually pressed them during record. Please let me know of what i should use and do.

+1  A: 

You can use CFAbsoluteTimeGetCurrent() to get the current time expressed as the number of seconds (as a double value, so fractional seconds will be there) since January 1, 2001 00:00:00 GMT.

Hence, you should record the value of CFAbsoluteTimeGetCurrent() at some point when your app starts, and then record its value every time a button is pressed. Then, by subtracting the time the app started from the time the button was pressed gives you the number of seconds the button was pressed since the app started. You can then play back the button presses at a later time by taking that time delta and adding it to the time when playback started.

Adam Rosenfield
This sounds great and feasible.I am going to use this method right now and see what happens during playback to see if the buttons highlight at the right times or not. They trigger sound, so if they are off beat then I will know. Thanks for very fast response.Also is there a way I can contact you directly?! When i click on someone's user name I can't seem to find a messaging system :| it would help if I wanted to update someone or ask for something specific.
Pavan
+1  A: 

The -[UIEvent timestamp] property will be the most accurate representation of when the touch actually occurred. If you use CFAbsoluteTimeGetCurrent() or the UNIX time() functions you will get the current time the moment function is called, not when the event actually occurred (which will be sometime earlier).

rpetrich