maxi_embind.h 10.7 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
//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];
25
//		}
26
//		return valOut;
27
//	}
28
//}
29

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
	//	class_<testVectorHolder>("testVectorHolder")
50
51
52
53
54
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
55
56
57
58
	//	.smart_ptr_constructor("shared_ptr<testVectorHolder>",&std::make_shared<testVectorHolder>)
	//	.function("at", &testVectorHolder::at)
	//	.function("coswave", &maxiOsc::coswave)
	//	;
59
60
61
	
	// -----------------------------------------
	
62
	//	class_<maxiTest>("maxiTest")
63
64
65
66
67
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
68
69
70
	//	.smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiTest>)
	//	.function("sumArray", &maxiTest::sumArray, allow_raw_pointers())
	//	;
71
72
	
	// 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
	.function("trigger", &maxiEnvelope::trigger)
111
112
113
114
	
	.property("amplitude", &maxiEnvelope::getAmplitude, &maxiEnvelope::setAmplitude)
	.property("valindex", &maxiEnvelope::getValindex, &maxiEnvelope::setValindex)
	
Dr-Dan's avatar
Dr-Dan committed
115
116
	;
	
117
118
	// MAXI DELAYLINE
	class_<maxiDelayline>("maxiDelayline")
119
	//	.constructor<>()
Dr-Dan's avatar
Dr-Dan committed
120
	.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
121
122
123
	.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
	.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
	;
124
	
125
126
	
	// MAXI FILTER
Dr-Dan's avatar
Dr-Dan committed
127
	class_<maxiFilter>("maxiFilter")
128
129
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
Dr-Dan's avatar
Dr-Dan committed
130
131
132
133
134
	.function("lores", &maxiFilter::lores)
	.function("hires", &maxiFilter::hires)
	.function("bandpass", &maxiFilter::bandpass)
	.function("lopass", &maxiFilter::lopass)
	.function("hipass", &maxiFilter::hipass)
135
136
137
	
	.property("cutoff", &maxiFilter::getCutoff, &maxiFilter::setCutoff)
	.property("resonance", &maxiFilter::getResonance, &maxiFilter::setResonance)
Dr-Dan's avatar
Dr-Dan committed
138
139
	;
	
140
	
141
142
	// MAXI MIX
	class_<maxiMix>("maxiMix")
143
144
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
145
146
147
148
149
	.function("stereo", &maxiMix::stereo, allow_raw_pointers())
	.function("quad", &maxiMix::quad,  allow_raw_pointers())
	.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
	;
	
150
151
152
153
154
155
156
157
158
	//	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
159
																														 //	.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>)
160
161
162
163
164
165
166
	
	.function("init", &maxiLagExp<double>::init)
	.function("addSample", &maxiLagExp<double>::addSample)
	.function("value", &maxiLagExp<double>::value)
	
	;
	
167
	// MAXI SAMPLE
Dr-Dan's avatar
Dr-Dan committed
168
	class_<maxiSample>("maxiSample")
169
170
171
	//	.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
172
	.function("getLength", &maxiSample::getLength)
Dr-Dan's avatar
Dr-Dan committed
173
	.function("setSample", &maxiSample::setSample)
174
	//	.function("getSummary", &maxiSample::getSummary)
Dr-Dan's avatar
Dr-Dan committed
175
	.function("isReady", &maxiSample::isReady)
176
	
Dr-Dan's avatar
Dr-Dan committed
177
178
	.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
	.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
179
	
180
181
182
	.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))
183
	
184
	.function("play4", &maxiSample::play4)
185
186
	
	
Dr-Dan's avatar
Dr-Dan committed
187
188
	.function("trigger", &maxiSample::trigger)
	.function("clear", &maxiSample::clear)
189
	
Dr-Dan's avatar
Dr-Dan committed
190
	//	.function("load", &maxiSample::load)
191
	//	.function("read", &maxiSample::read, allow_raw_pointers())
Dr-Dan's avatar
Dr-Dan committed
192
	;
193
194
195
	
	// MAXI MAP
	class_<maxiMap>("maxiMap")
196
197
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
198
199
200
	.function("linlin", &maxiMap::linlin)
	.function("linexp", &maxiMap::linexp)
	.function("explin", &maxiMap::explin)
201
	.function("clamp", &maxiMap::clamp<double>)
202
203
204
205
	;
	
	// MAXI DYN
	class_<maxiDyn>("maxiDyn")
206
207
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
208
209
	.function("gate", &maxiDyn::gate)
	.function("compressor", &maxiDyn::compressor)
210
211
212
213
214
	.function("compress", &maxiDyn::compress)
	.function("setAttack", &maxiDyn::setAttack)
	.function("setRelease", &maxiDyn::setRelease)
	.function("setThreshold", &maxiDyn::setThreshold)
	.function("setRatio", &maxiDyn::setRatio)
215
216
217
218
	;
	
	// MAXI ENV
	class_<maxiEnv>("maxiEnv")
219
220
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
221
	.function("ar", &maxiEnv::ar)
222
223
224
225
226
227
228
229
230
231
	//	.function("adsr", &maxiEnv::adsr)
	.function("adsr", select_overload<double(double,double,double,double,double,long,int)>(&maxiEnv::adsr))
	.function("adsr", select_overload<double(double,int)>(&maxiEnv::adsr))
	.function("setAttack", &maxiEnv::setAttack)
	.function("setRelease", &maxiEnv::setRelease)
	.function("setDecay", &maxiEnv::setDecay)
	.function("setSustain", &maxiEnv::setSustain)
	
	.property("trigger", &maxiEnv::getTrigger, &maxiEnv::setTrigger)

232
233
234
235
	;
	
	// CONVERT
	class_<convert>("convert")
236
237
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
238
	.function("mtof", &convert::mtof)
239
	//	.class_function("mtof", &convert::mtof)
240
241
	;
	
242
	
243
244
	// MAXI DISTORTION
	class_<maxiDistortion>("maxiDistortion")
245
246
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
247
248
249
250
251
252
253
	.function("fastAtan", &maxiDistortion::fastatan)
	.function("atanDist", &maxiDistortion::atanDist)
	.function("fastAtanDist", &maxiDistortion::fastAtanDist)
	;
	
	// MAXI FLANGER
	class_<maxiFlanger>("maxiFlanger")
254
255
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
256
257
258
259
260
	.function("flange", &maxiFlanger::flange)
	;
	
	// MAXI CHORUS
	class_<maxiChorus>("maxiChorus")
261
262
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
263
264
265
266
	.function("chorus", &maxiChorus::chorus)
	;
	
	// MAXI ENVELOPE FOLLOWER
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
	//	class_<maxiEnvelopeFollowerType<double>>("maxiEnvelopeFollower")
	//	//	.constructor<>()
	//	.smart_ptr_constructor("shared_ptr<maxiEnvelopeFollower>",&std::make_shared<maxiEnvelopeFollowerType<double>>)
	//	.function("setAttack", &maxiEnvelopeFollowerType<double>::setAttack<double>)
	//	.function("setRelease", &maxiEnvelopeFollowerType<double>::setRelease)
	//	.function("play", &maxiEnvelopeFollowerType<double>::play)
	//	.function("reset", &maxiEnvelopeFollowerType<double>::reset)
	//	;
	
	// MAXI DC BLOCKER
	class_<maxiDCBlocker>("maxiDCBlocker")
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDCBlocker>",&std::make_shared<maxiDCBlocker>)
	.function("play", &maxiDCBlocker::play)
	;
	
	// MAXI SVF
	class_<maxiSVF>("maxiSVF")
285
	//	.constructor<>()
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
	.smart_ptr_constructor("shared_ptr<maxiSVF>",&std::make_shared<maxiSVF>)
	.function("setCutoff", &maxiSVF::setCutoff)
	.function("setResonance", &maxiSVF::setResonance)
	.function("play", &maxiSVF::play)
	;
	
	// MAXI KICK
	class_<maxiKick>("maxiKick")
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiKick>",&std::make_shared<maxiKick>)
	.function("play", &maxiKick::play)
	.function("setPitch", &maxiKick::setPitch)
	.function("setRelease", &maxiKick::setRelease)
	.function("trigger", &maxiKick::trigger)
	;
	
	// MAXI SNARE
	class_<maxiSnare>("maxiSnare")
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiSnare>",&std::make_shared<maxiSnare>)
	.function("play", &maxiSnare::play)
	.function("setPitch", &maxiSnare::setPitch)
	.function("setRelease", &maxiSnare::setRelease)
	.function("trigger", &maxiSnare::trigger)
	;
	
	// MAXI HATS
	class_<maxiHats>("maxiHats")
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiHats>",&std::make_shared<maxiHats>)
	.function("play", &maxiHats::play)
	.function("setPitch", &maxiHats::setPitch)
	.function("setRelease", &maxiHats::setRelease)
	.function("trigger", &maxiHats::trigger)
	;
	
	// MAXI MAXI CLOCK
	class_<maxiClock>("maxiClock")
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiClock>",&std::make_shared<maxiClock>)
	.function("ticker", &maxiClock::ticker)
	.function("setTempo", &maxiClock::setTempo)
	.function("setTicksPerBeat", &maxiClock::setTicksPerBeat)
	.function("isTick", &maxiClock::isTick)
	
	.property("tick", &maxiClock::getTick, &maxiClock::setTick)
332
333
	;
	
334

335
};
Dr-Dan's avatar
Dr-Dan committed
336
#endif