forked from mihow/bpmdj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.cpp
83 lines (72 loc) · 1.83 KB
/
common.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/****
BpmDj v4.2-pl4: Free Dj Tools
Copyright (C) 2001-2012 Werner Van Belle
http://bpmdj.yellowcouch.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. See the
GNU General Public License for more details.
See the authors.txt for a full list of people involved.
****/
#ifndef __loaded__common_cpp__
#define __loaded__common_cpp__
using namespace std;
#include <assert.h>
#include <errno.h>
#include <string.h>
#include <math.h>
#include "dirscanner.h"
#include "common.h"
#include "memory.h"
void common_init()
{
assert(sizeof(int)==4);
assert(sizeof(signed2)==2);
assert(sizeof(signed4)==4);
assert(sizeof(signed8)==8);
assert(sizeof(float8)==8);
assert(sizeof(float4)==4);
}
bool exists(QString fn)
{
FILE * f = fopen(fn.toAscii().data(),"rb");
if (f)
{
fclose(f);
return true;
}
return false;
}
float8 minimum(float8 a, float8 b)
{
if ( a < b ) return a;
else return b;
}
float8 abs_minimum(float8 a, float8 b)
{
if ( fabs(a) < fabs(b) ) return a;
else return b;
}
int clip(int val)
{
if (val<0) return -1;
if (val>0) return +1;
return 0;
}
QString readable(unsigned8 L)
{
if (L < 1024) return QString::number(L)+" bytes";
L/=1024;
if (L < 1024) return QString::number(L)+" kilobytes";
L/=1024;
if (L < 1024) return QString::number(L)+" megabytes";
L/=1024;
if (L < 1024) return QString::number(L)+" gigabytes";
L/=1024;
return QString::number(L)+" terabytes";
}
#endif // __loaded__common_cpp__