Chris@150: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@150: Chris@150: /* Chris@150: Sonic Visualiser Chris@150: An audio file viewer and annotation editor. Chris@150: Centre for Digital Music, Queen Mary, University of London. Chris@150: This file copyright 2006 Chris Cannam. Chris@150: Chris@150: This program is free software; you can redistribute it and/or Chris@150: modify it under the terms of the GNU General Public License as Chris@150: published by the Free Software Foundation; either version 2 of the Chris@150: License, or (at your option) any later version. See the file Chris@150: COPYING included with this distribution for more information. Chris@150: */ Chris@150: Chris@150: #include "System.h" Chris@150: Chris@150: #ifndef _WIN32 Chris@150: #include Chris@150: #endif Chris@150: Chris@150: #include Chris@150: Chris@150: #ifdef _WIN32 Chris@150: Chris@150: extern "C" { Chris@150: Chris@150: void usleep(unsigned long usec) Chris@150: { Chris@150: ::Sleep(usec / 1000); Chris@150: } Chris@150: Chris@150: void gettimeofday(struct timeval *tv, void *tz) Chris@150: { Chris@150: union { Chris@150: long long ns100; Chris@150: FILETIME ft; Chris@150: } now; Chris@150: Chris@150: ::GetSystemTimeAsFileTime(&now.ft); Chris@150: tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL); Chris@150: tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL); Chris@150: } Chris@150: Chris@150: } Chris@150: Chris@150: #endif Chris@150: Chris@150: ProcessStatus Chris@150: GetProcessStatus(int pid) Chris@150: { Chris@150: #ifdef _WIN32 Chris@150: HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid); Chris@150: if (!handle) { Chris@150: return ProcessNotRunning; Chris@150: } else { Chris@150: CloseHandle(handle); Chris@150: return ProcessRunning; Chris@150: } Chris@150: #else Chris@150: if (kill(getpid(), 0) == 0) { Chris@150: if (kill(pid, 0) == 0) { Chris@150: return ProcessRunning; Chris@150: } else { Chris@150: return ProcessNotRunning; Chris@150: } Chris@150: } else { Chris@150: return UnknownProcessStatus; Chris@150: } Chris@150: #endif Chris@150: } Chris@150: Chris@150: double mod(double x, double y) { return x - (y * floor(x / y)); } Chris@150: float modf(float x, float y) { return x - (y * floorf(x / y)); } Chris@150: Chris@150: double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; } Chris@150: float princargf(float a) { return modf(a + M_PI, -2 * M_PI) + M_PI; } Chris@150: