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>
9
//#include "libs/maxiFFT.h"
Dr-Dan's avatar
Dr-Dan committed
10

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//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];
26
//		}
27
//		return valOut;
28
//	}
29
//}
30

Dr-Dan's avatar
Dr-Dan committed
31
32
33
34
35
36
37
38
39
40
41
42
43
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");
44
	
Dr-Dan's avatar
Dr-Dan committed
45
46
47
48
	class_<vectorTools>("vectorTools")
	.constructor<>()
	.class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
	;
49
	
50
	//	class_<testVectorHolder>("testVectorHolder")
51
52
53
54
55
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
56
57
58
59
	//	.smart_ptr_constructor("shared_ptr<testVectorHolder>",&std::make_shared<testVectorHolder>)
	//	.function("at", &testVectorHolder::at)
	//	.function("coswave", &maxiOsc::coswave)
	//	;
60
61
62
	
	// -----------------------------------------
	
63
	//	class_<maxiTest>("maxiTest")
64
65
66
67
68
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
69
70
71
	//	.smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiTest>)
	//	.function("sumArray", &maxiTest::sumArray, allow_raw_pointers())
	//	;
72
73
	
	// maxi stuff
Dr-Dan's avatar
Dr-Dan committed
74
75
76
77
78
79
	class_<maxiSettings>("maxiSettings")
	.constructor<>()
	.class_function("setup", &maxiSettings::setup)
	;
	
	
80
	// MAXI OSC
Dr-Dan's avatar
Dr-Dan committed
81
	class_<maxiOsc>("maxiOsc")
82
83
84
85
86
87
	//	.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	.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)
	;
	
104
	// MAXI ENVELOPE
Dr-Dan's avatar
Dr-Dan committed
105
	class_<maxiEnvelope>("maxiEnvelope")
106
107
108
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
	
Dr-Dan's avatar
Dr-Dan committed
109
	.function("line", &maxiEnvelope::line)
110
	//	.function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
Dr-Dan's avatar
Dr-Dan committed
111
	.function("trigger", &maxiEnvelope::trigger)
112
113
114
115
	
	.property("amplitude", &maxiEnvelope::getAmplitude, &maxiEnvelope::setAmplitude)
	.property("valindex", &maxiEnvelope::getValindex, &maxiEnvelope::setValindex)
	
Dr-Dan's avatar
Dr-Dan committed
116
117
	;
	
118
119
	// MAXI DELAYLINE
	class_<maxiDelayline>("maxiDelayline")
120
	//	.constructor<>()
Dr-Dan's avatar
Dr-Dan committed
121
	.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
122
123
124
	.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
	.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
	;
125
	
126
127
	
	// MAXI FILTER
Dr-Dan's avatar
Dr-Dan committed
128
	class_<maxiFilter>("maxiFilter")
129
130
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
Dr-Dan's avatar
Dr-Dan committed
131
132
133
134
135
	.function("lores", &maxiFilter::lores)
	.function("hires", &maxiFilter::hires)
	.function("bandpass", &maxiFilter::bandpass)
	.function("lopass", &maxiFilter::lopass)
	.function("hipass", &maxiFilter::hipass)
136
137
138
	
	.property("cutoff", &maxiFilter::getCutoff, &maxiFilter::setCutoff)
	.property("resonance", &maxiFilter::getResonance, &maxiFilter::setResonance)
Dr-Dan's avatar
Dr-Dan committed
139
140
	;
	
141
	
142
143
	// MAXI MIX
	class_<maxiMix>("maxiMix")
144
145
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
146
147
148
149
150
	.function("stereo", &maxiMix::stereo, allow_raw_pointers())
	.function("quad", &maxiMix::quad,  allow_raw_pointers())
	.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
	;
	
151
152
153
154
155
156
157
158
159
	//	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
160
																														 //	.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>)
161
162
163
164
165
166
167
	
	.function("init", &maxiLagExp<double>::init)
	.function("addSample", &maxiLagExp<double>::addSample)
	.function("value", &maxiLagExp<double>::value)
	
	;
	
168
	// MAXI SAMPLE
Dr-Dan's avatar
Dr-Dan committed
169
	class_<maxiSample>("maxiSample")
170
171
172
	//	.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
173
	.function("getLength", &maxiSample::getLength)
Dr-Dan's avatar
Dr-Dan committed
174
	.function("setSample", &maxiSample::setSample)
175
	//	.function("getSummary", &maxiSample::getSummary)
Dr-Dan's avatar
Dr-Dan committed
176
	.function("isReady", &maxiSample::isReady)
177
	
Dr-Dan's avatar
Dr-Dan committed
178
179
	.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
	.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
180
	
181
182
183
	.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))
184
	
185
	.function("play4", &maxiSample::play4)
186
187
	
	
Dr-Dan's avatar
Dr-Dan committed
188
189
	.function("trigger", &maxiSample::trigger)
	.function("clear", &maxiSample::clear)
190
	
Dr-Dan's avatar
Dr-Dan committed
191
	//	.function("load", &maxiSample::load)
192
	//	.function("read", &maxiSample::read, allow_raw_pointers())
Dr-Dan's avatar
Dr-Dan committed
193
	;
194
195
196
	
	// MAXI MAP
	class_<maxiMap>("maxiMap")
197
198
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
199
200
201
	.function("linlin", &maxiMap::linlin)
	.function("linexp", &maxiMap::linexp)
	.function("explin", &maxiMap::explin)
202
	.function("clamp", &maxiMap::clamp<double>)
203
204
205
206
	;
	
	// MAXI DYN
	class_<maxiDyn>("maxiDyn")
207
208
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
209
210
	.function("gate", &maxiDyn::gate)
	.function("compressor", &maxiDyn::compressor)
211
212
213
214
215
	.function("compress", &maxiDyn::compress)
	.function("setAttack", &maxiDyn::setAttack)
	.function("setRelease", &maxiDyn::setRelease)
	.function("setThreshold", &maxiDyn::setThreshold)
	.function("setRatio", &maxiDyn::setRatio)
216
217
218
219
	;
	
	// MAXI ENV
	class_<maxiEnv>("maxiEnv")
220
221
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
222
	.function("ar", &maxiEnv::ar)
223
224
225
226
227
228
229
230
231
232
	//	.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)

233
234
235
236
	;
	
	// CONVERT
	class_<convert>("convert")
237
238
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
239
	.function("mtof", &convert::mtof)
240
	//	.class_function("mtof", &convert::mtof)
241
242
	;
	
243
	
244
245
	// MAXI DISTORTION
	class_<maxiDistortion>("maxiDistortion")
246
247
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
248
249
250
251
252
253
254
	.function("fastAtan", &maxiDistortion::fastatan)
	.function("atanDist", &maxiDistortion::atanDist)
	.function("fastAtanDist", &maxiDistortion::fastAtanDist)
	;
	
	// MAXI FLANGER
	class_<maxiFlanger>("maxiFlanger")
255
256
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
257
258
259
260
261
	.function("flange", &maxiFlanger::flange)
	;
	
	// MAXI CHORUS
	class_<maxiChorus>("maxiChorus")
262
263
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
264
265
266
267
	.function("chorus", &maxiChorus::chorus)
	;
	
	// MAXI ENVELOPE FOLLOWER
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
	//	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")
286
	//	.constructor<>()
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
332
	.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)
333
334
	;
	
335

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