Timer class


#1

Trying to implement a timer on my recorder, so I can lock my FF and RW functions to it. Also so I can…ummmm…yeah… display the track time. (ie 00.00.00).

I put something together using the Timer class that counts like it should, but the speed’s not accurate.

I’m running startTimer(1)… so the callback should execute every millisecond. So, I thought: “hey, I’ll just increment my millisecond variable everytime it runs the callback and update the seconds and minutes accordingly.” But, what I didn’t think of was how long it would take to execute the code in one callback, so the timer runs slooooooww.

Any suggestions?

thanks in advance,

Elias


#2

I think you can’t use the Timer class to do what you need. I think you should program your own Timer, use the Thread class to do the count, and use the variable getMillisecondCounter() for exemple of the Time class… So the count is not pertubated by your commands… Because in the reality, I think it’s impossible that every value from 00.00.00 to 01.00.00 for example can be showed once, some milliseconds are jumped… :wink: The Timer class may not be used for this kind of synchronization…


#3

OK, I set everything up in it’s own thread… and I’m probably doing something else wrong here, but my call to getMilliseconds() doesn’t return anything but 0.

int ms;
Time *theTime;
theTime = new Time();

//run the thread
void run()
{
ms = theTime->getMilliseconds();
sendChangeMessage(this); //tell the main class that ms has changed
}

I’m probably not initializing the time object correctly?


#4

use getMillisecondsCounter() instead to see…


#5

Yes, the Timer class isn’t supposed to be accurate, it runs on the message loop so can be delayed by UI activity.

A handy function to use in your thread is: Time::waitForMillisecondCounter(), which is pretty accurate.


#6