annotate system/System.cpp @ 160:abaf3d7195ce

* experiment with finer zoom level changes when using h thumbwheel
author Chris Cannam
date Tue, 22 Aug 2006 14:18:28 +0000
parents 4b2ea82fd0ed
children 04baa690f90d
rev   line source
Chris@150 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@150 2
Chris@150 3 /*
Chris@150 4 Sonic Visualiser
Chris@150 5 An audio file viewer and annotation editor.
Chris@150 6 Centre for Digital Music, Queen Mary, University of London.
Chris@150 7 This file copyright 2006 Chris Cannam.
Chris@150 8
Chris@150 9 This program is free software; you can redistribute it and/or
Chris@150 10 modify it under the terms of the GNU General Public License as
Chris@150 11 published by the Free Software Foundation; either version 2 of the
Chris@150 12 License, or (at your option) any later version. See the file
Chris@150 13 COPYING included with this distribution for more information.
Chris@150 14 */
Chris@150 15
Chris@150 16 #include "System.h"
Chris@150 17
Chris@150 18 #ifndef _WIN32
Chris@150 19 #include <signal.h>
Chris@150 20 #endif
Chris@150 21
Chris@150 22 #include <iostream>
Chris@150 23
Chris@150 24 #ifdef _WIN32
Chris@150 25
Chris@150 26 extern "C" {
Chris@150 27
Chris@150 28 void usleep(unsigned long usec)
Chris@150 29 {
Chris@150 30 ::Sleep(usec / 1000);
Chris@150 31 }
Chris@150 32
Chris@150 33 void gettimeofday(struct timeval *tv, void *tz)
Chris@150 34 {
Chris@150 35 union {
Chris@150 36 long long ns100;
Chris@150 37 FILETIME ft;
Chris@150 38 } now;
Chris@150 39
Chris@150 40 ::GetSystemTimeAsFileTime(&now.ft);
Chris@150 41 tv->tv_usec = (long)((now.ns100 / 10LL) % 1000000LL);
Chris@150 42 tv->tv_sec = (long)((now.ns100 - 116444736000000000LL) / 10000000LL);
Chris@150 43 }
Chris@150 44
Chris@150 45 }
Chris@150 46
Chris@150 47 #endif
Chris@150 48
Chris@150 49 ProcessStatus
Chris@150 50 GetProcessStatus(int pid)
Chris@150 51 {
Chris@150 52 #ifdef _WIN32
Chris@150 53 HANDLE handle = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid);
Chris@150 54 if (!handle) {
Chris@150 55 return ProcessNotRunning;
Chris@150 56 } else {
Chris@150 57 CloseHandle(handle);
Chris@150 58 return ProcessRunning;
Chris@150 59 }
Chris@150 60 #else
Chris@150 61 if (kill(getpid(), 0) == 0) {
Chris@150 62 if (kill(pid, 0) == 0) {
Chris@150 63 return ProcessRunning;
Chris@150 64 } else {
Chris@150 65 return ProcessNotRunning;
Chris@150 66 }
Chris@150 67 } else {
Chris@150 68 return UnknownProcessStatus;
Chris@150 69 }
Chris@150 70 #endif
Chris@150 71 }
Chris@150 72
Chris@150 73 double mod(double x, double y) { return x - (y * floor(x / y)); }
Chris@150 74 float modf(float x, float y) { return x - (y * floorf(x / y)); }
Chris@150 75
Chris@150 76 double princarg(double a) { return mod(a + M_PI, -2 * M_PI) + M_PI; }
Chris@150 77 float princargf(float a) { return modf(a + M_PI, -2 * M_PI) + M_PI; }
Chris@150 78