r717: Made the highlighted text color of the menus WHITE
[cinelerra_cv/mob.git] / guicast / bctimer.C
blob0c23255954cd0cfd0c3b84020dc23527a97f46a4
1 #include "bctimer.h"
2 #include <sys/time.h>
3 #include <sys/types.h>
4 #include <unistd.h>
6 Timer::Timer()
10 Timer::~Timer()
14 int Timer::update()
16         gettimeofday(&current_time, 0);
17         return 0;
20 int64_t Timer::get_difference(struct timeval *result)
22         gettimeofday(&new_time, 0);
23         
24         result->tv_usec = new_time.tv_usec - current_time.tv_usec;
25         result->tv_sec = new_time.tv_sec - current_time.tv_sec;
26         if(result->tv_usec < 0) 
27         {
28                 result->tv_usec += 1000000; 
29                 result->tv_sec--; 
30         }
31         
32         return (int64_t)result->tv_sec * 1000 + (int64_t)result->tv_usec / 1000;
35 int64_t Timer::get_difference()
37         gettimeofday(&new_time, 0);
39         new_time.tv_usec -= current_time.tv_usec;
40         new_time.tv_sec -= current_time.tv_sec;
41         if(new_time.tv_usec < 0)
42         {
43                 new_time.tv_usec += 1000000;
44                 new_time.tv_sec--;
45         }
47         return (int64_t)new_time.tv_sec * 1000 + 
48                 (int64_t)new_time.tv_usec / 1000;
51 int64_t Timer::get_scaled_difference(long denominator)
53         get_difference(&new_time);
54         return (int64_t)new_time.tv_sec * denominator + 
55                 (int64_t)((double)new_time.tv_usec / 1000000 * denominator);
58 int Timer::delay(long milliseconds)
60         struct timeval delay_duration;
61         delay_duration.tv_sec = 0;
62         delay_duration.tv_usec = milliseconds * 1000;
63         select(0,  NULL,  NULL, NULL, &delay_duration);
64         return 0;