-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput_osx.cpp
102 lines (86 loc) · 2.2 KB
/
input_osx.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <assert.h>
#include <CoreFoundation/CFBundle.h>
#include "input.h"
#include <mach/mach.h>
#include <mach/mach_time.h>
float osx_x;
float osx_y;
float osx_down;
void inputDown(float down)
{
osx_down = down;
}
void inputXY(float X, float Y)
{
osx_x = X;
osx_y = Y;
}
void initInput(int _argc, char **_argv)
{
osx_x = 0.0f;
osx_y = 0.0f;
osx_down = 0.0f;
}
void readInputAxis(int axis, float *buffer, int size)
{
float src;
switch(axis)
{
case 0:
src = osx_x;
break;
case 1:
src = osx_y;
break;
case 2:
src = osx_down;
break;
default:
src = 0.0f;
break;
}
for(int i=0; i<size; i++)
buffer[i] = src;
}
using namespace std;
void populatePatchList(vector<string>& patches)
{
patches.push_back(getPatchLocation("rubberbass"));
}
std::string getPatchLocation(const char* patchname)
{
CFBundleRef Bundle = CFBundleGetMainBundle();
assert(Bundle);
CFURLRef patch = CFBundleCopyResourceURL(
Bundle,
CFStringCreateWithCString(kCFAllocatorDefault,
patchname,
kCFStringEncodingMacRoman),
CFSTR("pat"),
NULL);
CFStringRef path = CFURLCopyFileSystemPath(patch, kCFURLPOSIXPathStyle);
assert(path);
size_t pathlen = (CFStringGetLength(path) + 1) * sizeof(char);
char* cpath = (char*)malloc(pathlen);
CFStringGetCString(path, cpath, pathlen, kCFStringEncodingMacRoman);
assert(cpath);
string ret = string(cpath);
// The ptr is owned by the CFStringRef, but since we've copied it onto a
// std::string we can just free everything! Yeah!
free(cpath);
CFRelease(patch);
CFRelease(path);
return ret;
}
void populateLogList(vector<string>& log_list)
{
}
double hires_time()
{
mach_timebase_info_data_t info;
mach_timebase_info(&info);
uint64_t time = mach_absolute_time();
uint64_t nanoseconds = time * info.numer / info.denom;
return
(double)nanoseconds / 1000000000.0;
}