maxi_embind.h 11 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
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");
43
	register_vector<char>("VectorChar");
Dr-Dan's avatar
Dr-Dan committed
44
	//	register_vector<float>("VectorFloat");
45
	
Dr-Dan's avatar
Dr-Dan committed
46 47 48 49
	class_<vectorTools>("vectorTools")
	.constructor<>()
	.class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
	;
50
	
51
	//	class_<testVectorHolder>("testVectorHolder")
52 53 54 55 56
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
57 58 59 60
	//	.smart_ptr_constructor("shared_ptr<testVectorHolder>",&std::make_shared<testVectorHolder>)
	//	.function("at", &testVectorHolder::at)
	//	.function("coswave", &maxiOsc::coswave)
	//	;
61 62 63
	
	// -----------------------------------------
	
64
	//	class_<maxiTest>("maxiTest")
65 66 67 68 69
	//	.constructor<>()
	/*
	 Using a smart_ptr_constructor ensures lifetime management  on the js side
	 by returning a smart_ptr when a constructor is used
	 */
70 71 72
	//	.smart_ptr_constructor("shared_ptr<maxiOsc>",&std::make_shared<maxiTest>)
	//	.function("sumArray", &maxiTest::sumArray, allow_raw_pointers())
	//	;
73 74
	
	// maxi stuff
Dr-Dan's avatar
Dr-Dan committed
75 76 77 78 79 80
	class_<maxiSettings>("maxiSettings")
	.constructor<>()
	.class_function("setup", &maxiSettings::setup)
	;
	
	
81
	// MAXI OSC
Dr-Dan's avatar
Dr-Dan committed
82
	class_<maxiOsc>("maxiOsc")
83 84 85 86 87 88
	//	.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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
	.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)
	;
	
105
	// MAXI ENVELOPE
Dr-Dan's avatar
Dr-Dan committed
106
	class_<maxiEnvelope>("maxiEnvelope")
107 108 109
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
	
Dr-Dan's avatar
Dr-Dan committed
110
	.function("line", &maxiEnvelope::line)
111
	//	.function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
Dr-Dan's avatar
Dr-Dan committed
112
	.function("trigger", &maxiEnvelope::trigger)
113 114 115 116
	
	.property("amplitude", &maxiEnvelope::getAmplitude, &maxiEnvelope::setAmplitude)
	.property("valindex", &maxiEnvelope::getValindex, &maxiEnvelope::setValindex)
	
Dr-Dan's avatar
Dr-Dan committed
117 118
	;
	
119 120
	// MAXI DELAYLINE
	class_<maxiDelayline>("maxiDelayline")
121
	//	.constructor<>()
Dr-Dan's avatar
Dr-Dan committed
122
	.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
123 124 125
	.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
	.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
	;
126
	
127 128
	
	// MAXI FILTER
Dr-Dan's avatar
Dr-Dan committed
129
	class_<maxiFilter>("maxiFilter")
130 131
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
Dr-Dan's avatar
Dr-Dan committed
132 133 134 135 136
	.function("lores", &maxiFilter::lores)
	.function("hires", &maxiFilter::hires)
	.function("bandpass", &maxiFilter::bandpass)
	.function("lopass", &maxiFilter::lopass)
	.function("hipass", &maxiFilter::hipass)
137 138 139
	
	.property("cutoff", &maxiFilter::getCutoff, &maxiFilter::setCutoff)
	.property("resonance", &maxiFilter::getResonance, &maxiFilter::setResonance)
Dr-Dan's avatar
Dr-Dan committed
140 141
	;
	
142
	
143 144
	// MAXI MIX
	class_<maxiMix>("maxiMix")
145 146
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
147 148 149 150 151
	.function("stereo", &maxiMix::stereo, allow_raw_pointers())
	.function("quad", &maxiMix::quad,  allow_raw_pointers())
	.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
	;
	
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
161
//	.smart_ptr_constructor("shared_ptr<maxiLagExp<double>>",&std::make_shared<maxiLagExp<double>>)
162 163 164 165 166 167 168
	
	.function("init", &maxiLagExp<double>::init)
	.function("addSample", &maxiLagExp<double>::addSample)
	.function("value", &maxiLagExp<double>::value)
	
	;
	
169
	// MAXI SAMPLE
Dr-Dan's avatar
Dr-Dan committed
170
	class_<maxiSample>("maxiSample")
171 172 173
	//	.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
174
	.function("getLength", &maxiSample::getLength)
175 176 177 178
//	.function("setSample", &maxiSample::setSample)
	.function("setSample", select_overload<void(vector<double>&)>(&maxiSample::setSample))
	.function("setSample", select_overload<void(vector<double>&, int)>(&maxiSample::setSample))

179
	//	.function("getSummary", &maxiSample::getSummary)
Dr-Dan's avatar
Dr-Dan committed
180
	.function("isReady", &maxiSample::isReady)
181
	
Dr-Dan's avatar
Dr-Dan committed
182 183
	.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
	.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
184
	
185 186 187 188
	.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))
	.function("play4", &maxiSample::play4)
189
	
Dr-Dan's avatar
Dr-Dan committed
190 191
	.function("trigger", &maxiSample::trigger)
	.function("clear", &maxiSample::clear)
192
	
193 194 195
//	.function("normalise", &maxiSample::normalise)
//	.function("autoTrim", &maxiSample::autoTrim)
	
Dr-Dan's avatar
Dr-Dan committed
196
	//	.function("load", &maxiSample::load)
197
	//	.function("read", &maxiSample::read, allow_raw_pointers())
Dr-Dan's avatar
Dr-Dan committed
198
	;
199 200 201
	
	// MAXI MAP
	class_<maxiMap>("maxiMap")
202 203
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
204 205 206
	.function("linlin", &maxiMap::linlin)
	.function("linexp", &maxiMap::linexp)
	.function("explin", &maxiMap::explin)
207
	.function("clamp", &maxiMap::clamp<double>)
208 209 210 211
	;
	
	// MAXI DYN
	class_<maxiDyn>("maxiDyn")
212 213
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
214 215
	.function("gate", &maxiDyn::gate)
	.function("compressor", &maxiDyn::compressor)
216 217 218 219 220
	.function("compress", &maxiDyn::compress)
	.function("setAttack", &maxiDyn::setAttack)
	.function("setRelease", &maxiDyn::setRelease)
	.function("setThreshold", &maxiDyn::setThreshold)
	.function("setRatio", &maxiDyn::setRatio)
221 222 223 224
	;
	
	// MAXI ENV
	class_<maxiEnv>("maxiEnv")
225 226
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
227
	.function("ar", &maxiEnv::ar)
228 229 230 231 232 233 234 235 236
	//	.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)
237
	
238 239 240 241
	;
	
	// CONVERT
	class_<convert>("convert")
242 243
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
244
	.function("mtof", &convert::mtof)
245
	//	.class_function("mtof", &convert::mtof)
246 247
	;
	
248
	
249 250
	// MAXI DISTORTION
	class_<maxiDistortion>("maxiDistortion")
251 252
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
253 254 255 256 257 258 259
	.function("fastAtan", &maxiDistortion::fastatan)
	.function("atanDist", &maxiDistortion::atanDist)
	.function("fastAtanDist", &maxiDistortion::fastAtanDist)
	;
	
	// MAXI FLANGER
	class_<maxiFlanger>("maxiFlanger")
260 261
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
262 263 264 265 266
	.function("flange", &maxiFlanger::flange)
	;
	
	// MAXI CHORUS
	class_<maxiChorus>("maxiChorus")
267 268
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
269 270 271 272
	.function("chorus", &maxiChorus::chorus)
	;
	
	// MAXI ENVELOPE FOLLOWER
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	//	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")
291
	//	.constructor<>()
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 333 334 335 336 337
	.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)
338 339
	;
	
340
	
341
};
Dr-Dan's avatar
Dr-Dan committed
342
#endif