-
Notifications
You must be signed in to change notification settings - Fork 0
/
rnbo.py
82 lines (57 loc) · 2.46 KB
/
rnbo.py
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
"""
python wrapper for Max RNBO exported C++
rama gottfried, icst zhdk 2023
"""
import ctypes
import sys, os, numpy
if sys.platform == "darwin":
rnbo = ctypes.CDLL("libRNBOExportLib.dylib")
elif sys.platform.startswith('win'):
rnbo = ctypes.CDLL(os.path.abspath("RNBOExportLib.dll"))
# else for linux check later
def init(sampleRate, vectorSize):
# set arg types
rnbo.init.argtypes = [ctypes.c_int, ctypes.c_int]
rnbo.midiEvent.argtypes = [ctypes.c_int, ctypes.c_int]
rnbo.setParamValueById.argtypes = [ctypes.c_char_p, ctypes.c_double]
rnbo.getParamValueById.argtypes = [ctypes.c_char_p]
rnbo.setNormParamValueById.argtypes = [ctypes.c_char_p, ctypes.c_double]
rnbo.convertFromNormParamValueById.argtypes = [ctypes.c_char_p, ctypes.c_double]
rnbo.setParamValueByIdx.argtypes = [ctypes.c_int, ctypes.c_double]
rnbo.getParamValueByIdx.argtypes = [ctypes.c_int]
rnbo.setNormParamValueByIdx.argtypes = [ctypes.c_int, ctypes.c_double]
rnbo.convertFromNormParamValueByIdx.argtypes = [ctypes.c_int, ctypes.c_double]
# set return types
rnbo.getParamValueById.restype = ctypes.c_double
rnbo.convertFromNormParamValueById.restype = ctypes.c_double
rnbo.getParamValueByIdx.restype = ctypes.c_double
rnbo.convertFromNormParamValueByIdx.restype = ctypes.c_double
# init
rnbo.init(sampleRate, vectorSize)
# need to know vector size to init and setup vector return size
rnbo.rnbo_process_vec.restype = ctypes.POINTER(ctypes.c_double * vectorSize)
def clearState():
rnbo.clearState()
def printInfo():
rnbo.printInfo()
def midiEvent(pitch, velocity):
# midiEvent note and velocity
rnbo.midiEvent(pitch, velocity)
def setParamValueById(id, val):
rnbo.setParamValueById((id).encode('utf-8'), val)
def getParamValueById(id):
return rnbo.getParamValueById((id).encode('utf-8'))
def setNormParamValueById(id, val):
rnbo.setNormParamValueById((id).encode('utf-8'), val)
def convertFromNormParamValueById(id, val):
return rnbo.convertFromNormParamValueById((id).encode('utf-8'), val)
def setParamValueByIdx(idx, val):
rnbo.setParamValueByIdx(idx, val)
def getParamValueByIdx(idx):
return rnbo.getParamValueByIdx(idx)
def setNormParamValueByIdx(idx, val):
rnbo.setNormParamValueByIdx(idx, val)
def convertFromNormParamValueByIdx(idx):
return rnbo.convertFromNormParamValueByIdx(idx)
def process(): #just output for now
return numpy.array( rnbo.rnbo_process_vec().contents )