maxi_embind.h 7.83 KB
Newer Older
1
2
3
/*
 contains all bindings for use with emscripten
 */
Dr-Dan's avatar
Dr-Dan committed
4
5
6
#ifndef Maxi_Emscripten_maxi_embind_h
#define Maxi_Emscripten_maxi_embind_h

7
#include <emscripten.h>
Dr-Dan's avatar
Dr-Dan committed
8
#include <emscripten/bind.h>
Dr-Dan's avatar
Dr-Dan committed
9

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
extern "C" {
//	class arrayTest{
//		int int_sqrt(int x) {
//			return sqrt(x);
//		}
//	};
//	
//	arrayTest* a(){
//		return new arrayTest();
//	}
	
	int sumArray(double* arr, int size){
		double valOut = 0;
		for(int i = 0; i < size; i++){
			valOut += arr[i];
		}
		return valOut;
	}
}

Dr-Dan's avatar
Dr-Dan committed
30
31
32
33
34
35
36
37
38
39
40
41
42
class vectorTools {
public:
	static void clearVectorDbl(vector<double>& vecIn) {
		vecIn.clear();
	}
};

using namespace emscripten;

EMSCRIPTEN_BINDINGS(my_module) {
	register_vector<int>("VectorInt");
	register_vector<double>("VectorDouble");
	//	register_vector<float>("VectorFloat");
43
	
Dr-Dan's avatar
Dr-Dan committed
44
45
46
47
	class_<vectorTools>("vectorTools")
	.constructor<>()
	.class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
	;
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
//	class_<testVectorHolder>("testVectorHolder")
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
//	.smart_ptr_constructor("shared_ptr<testVectorHolder>",&std::make_shared<testVectorHolder>)
//	.function("at", &testVectorHolder::at)
//	.function("coswave", &maxiOsc::coswave)
//	;
	
	// -----------------------------------------
	
	class_<maxiTest>("maxiTest")
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
	.smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiTest>)
	.function("sumArray", &maxiTest::sumArray, allow_raw_pointers())
	;
	
	// maxi stuff
Dr-Dan's avatar
Dr-Dan committed
73
74
75
76
77
78
	class_<maxiSettings>("maxiSettings")
	.constructor<>()
	.class_function("setup", &maxiSettings::setup)
	;
	
	
79
	// MAXI OSC
Dr-Dan's avatar
Dr-Dan committed
80
	class_<maxiOsc>("maxiOsc")
81
82
83
84
85
86
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
	.smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiOsc>)
Dr-Dan's avatar
Dr-Dan committed
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
	.function("sinewave", &maxiOsc::sinewave)
	.function("coswave", &maxiOsc::coswave)
	.function("phasor", select_overload<double(double)>(&maxiOsc::phasor))
	.function("phasor", select_overload<double(double, double, double)>(&maxiOsc::phasor))
	.function("saw", &maxiOsc::saw)
	.function("triangle", &maxiOsc::triangle)
	.function("square", &maxiOsc::square)
	.function("pulse", &maxiOsc::pulse)
	.function("noise", &maxiOsc::noise)
	.function("sinebuf", &maxiOsc::sinebuf)
	.function("sinebuf4", &maxiOsc::sinebuf4)
	.function("sawn", &maxiOsc::sawn)
	.function("rect", &maxiOsc::rect)
	.function("phaseReset", &maxiOsc::phaseReset)
	;
	
103
	// MAXI ENVELOPE
Dr-Dan's avatar
Dr-Dan committed
104
	class_<maxiEnvelope>("maxiEnvelope")
105
106
107
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
	
Dr-Dan's avatar
Dr-Dan committed
108
	.function("line", &maxiEnvelope::line)
109
	//	.function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
Dr-Dan's avatar
Dr-Dan committed
110
111
112
113
	.function("trigger", &maxiEnvelope::trigger)
	.property("amplitude", &maxiEnvelope::GetAmplitude, &maxiEnvelope::SetAmplitude)
	;
	
114
115
	// MAXI DELAYLINE
	class_<maxiDelayline>("maxiDelayline")
116
	//	.constructor<>()
Dr-Dan's avatar
Dr-Dan committed
117
	.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
118
119
120
	.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
	.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
	;
121
	
122
123
	
	// MAXI FILTER
Dr-Dan's avatar
Dr-Dan committed
124
	class_<maxiFilter>("maxiFilter")
125
126
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
Dr-Dan's avatar
Dr-Dan committed
127
128
129
130
131
132
133
	.function("lores", &maxiFilter::lores)
	.function("hires", &maxiFilter::hires)
	.function("bandpass", &maxiFilter::bandpass)
	.function("lopass", &maxiFilter::lopass)
	.function("hipass", &maxiFilter::hipass)
	;
	
134
	
135
136
	// MAXI MIX
	class_<maxiMix>("maxiMix")
137
138
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
139
140
141
142
143
	.function("stereo", &maxiMix::stereo, allow_raw_pointers())
	.function("quad", &maxiMix::quad,  allow_raw_pointers())
	.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
	;
	
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
	//	class_<TemplateClass<int>>("IntTemplateClass")
	//	.constructor<int, int, int>()
	//	.function("getMember", &TemplateClass<int>::getMember)
	//	;
	
	class_<maxiLagExp<double>>("maxiLagExp")
	//	.constructor<>()
	//	.constructor<double, double>()
	.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>, allow_raw_pointers()) // not sure how to override constructors with smart_ptr
//	.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>)
	
	.function("init", &maxiLagExp<double>::init)
	.function("addSample", &maxiLagExp<double>::addSample)
	.function("value", &maxiLagExp<double>::value)
	
	;
	
161
	// MAXI SAMPLE
Dr-Dan's avatar
Dr-Dan committed
162
	class_<maxiSample>("maxiSample")
163
164
165
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiSample>",&std::make_shared<maxiSample>)
	//	.property("length", &maxiSample::getLength, &maxiSample::setLength) // no work???
Dr-Dan's avatar
Dr-Dan committed
166
	.function("getLength", &maxiSample::getLength)
Dr-Dan's avatar
Dr-Dan committed
167
	.function("setSample", &maxiSample::setSample)
168
	//	.function("getSummary", &maxiSample::getSummary)
Dr-Dan's avatar
Dr-Dan committed
169
	.function("isReady", &maxiSample::isReady)
170
	
Dr-Dan's avatar
Dr-Dan committed
171
172
	.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
	.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
173
	
174
175
176
	.function("play", select_overload<double()>(&maxiSample::play))
	.function("play", select_overload<double(double)>(&maxiSample::play))
	.function("play", select_overload<double(double, double, double)>(&maxiSample::play))
177
	
178
	.function("play4", &maxiSample::play4)
179
180
	
	
Dr-Dan's avatar
Dr-Dan committed
181
182
	.function("trigger", &maxiSample::trigger)
	.function("clear", &maxiSample::clear)
183
	
Dr-Dan's avatar
Dr-Dan committed
184
	//	.function("load", &maxiSample::load)
185
	//	.function("read", &maxiSample::read, allow_raw_pointers())
Dr-Dan's avatar
Dr-Dan committed
186
	;
187
188
189
	
	// MAXI MAP
	class_<maxiMap>("maxiMap")
190
191
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
192
193
194
195
196
197
198
199
	.function("linlin", &maxiMap::linlin)
	.function("linexp", &maxiMap::linexp)
	.function("explin", &maxiMap::explin)
	.function("clamp", &maxiMap::clamp)
	;
	
	// MAXI DYN
	class_<maxiDyn>("maxiDyn")
200
201
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
202
203
204
205
206
207
	.function("gate", &maxiDyn::gate)
	.function("compressor", &maxiDyn::compressor)
	;
	
	// MAXI ENV
	class_<maxiEnv>("maxiEnv")
208
209
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
210
211
212
213
214
215
	.function("ar", &maxiEnv::ar)
	.function("adsr", &maxiEnv::adsr)
	;
	
	// CONVERT
	class_<convert>("convert")
216
217
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
218
	.function("mtof", &convert::mtof)
219
	//	.class_function("mtof", &convert::mtof)
220
221
	;
	
222
	
223
224
	// MAXI DISTORTION
	class_<maxiDistortion>("maxiDistortion")
225
226
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
227
228
229
230
231
232
233
	.function("fastAtan", &maxiDistortion::fastatan)
	.function("atanDist", &maxiDistortion::atanDist)
	.function("fastAtanDist", &maxiDistortion::fastAtanDist)
	;
	
	// MAXI FLANGER
	class_<maxiFlanger>("maxiFlanger")
234
235
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
236
237
238
239
240
	.function("flange", &maxiFlanger::flange)
	;
	
	// MAXI CHORUS
	class_<maxiChorus>("maxiChorus")
241
242
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
243
244
245
246
247
	.function("chorus", &maxiChorus::chorus)
	;
	
	// MAXI ENVELOPE FOLLOWER
	class_<maxiEnvelopeFollower>("maxiEnvelopeFollower")
248
249
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelopeFollower>",&std::make_shared<maxiEnvelopeFollower>)
250
251
252
253
254
255
256
	.function("setAttack", &maxiEnvelopeFollower::setAttack)
	.function("setRelease", &maxiEnvelopeFollower::setRelease)
	.function("play", &maxiEnvelopeFollower::play)
	.function("reset", &maxiEnvelopeFollower::reset)
	;
	
};
Dr-Dan's avatar
Dr-Dan committed
257
#endif