1 /*
2     TiMidity++ -- MIDI to WAVE converter and player
3     Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
4     Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
5 
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with this program; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 
20 */
21 
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif /* HAVE_CONFIG_H */
25 
26 #if defined(HAVE_GETTIMEOFDAY)
27 #include <sys/types.h>
28 #include <sys/time.h>
29 #include <time.h>
30 #include "timidity.h"
31 #include "timer.h"
32 
33 #if defined(nec_ews)
34 #ifndef GETTIMEOFDAY_ONE_ARGUMENT
35 #define GETTIMEOFDAY_ONE_ARGUMENT
36 #endif /* GETTIMEOFDAY_ONE_ARGUMENT */
37 #endif
38 
get_current_calender_time(void)39 double get_current_calender_time(void)
40 {
41     struct timeval tv;
42     struct timezone dmy;
43 
44 #ifdef GETTIMEOFDAY_ONE_ARGUMENT
45     gettimeofday(&tv);
46 #else
47     gettimeofday(&tv, &dmy);
48 #endif
49 
50     return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0 ;
51 }
52 
53 #elif __MACOS__
54 
55 #include "timer.h"
get_current_calender_time(void)56 double get_current_calender_time(void)
57 {
58     UnsignedWide usec;
59     Microseconds(&usec);
60     return (double)usec.hi* 4294.967296 + (double)usec.lo / 1000000.0 ;
61 }
62 
63 #else /* Windows API */
64 
65 #include <sys/types.h>
66 #include <time.h>
67 #include <windows.h>
68 #include "timidity.h"
69 #include "timer.h"
70 #ifdef IA_NPSYN
71 #define GetTickCount() timeGetTime()
72 #endif
get_current_calender_time(void)73 double get_current_calender_time(void)
74 {
75     static DWORD tick_start;
76     static int init_flag = 0;
77 
78     if(init_flag == 0)
79     {
80 	init_flag = 1;
81 	tick_start = GetTickCount();
82 	return 0.0;
83     }
84 
85     return (GetTickCount() - tick_start) * (1.0/1000.0);
86 }
87 #endif
88