maxi_embind.h 6.8 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

class vectorTools {
public:
	//template <typename T>
	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");
24
	
Dr-Dan's avatar
Dr-Dan committed
25
26
27
28
	class_<vectorTools>("vectorTools")
	.constructor<>()
	.class_function("clearVectorDbl", &vectorTools::clearVectorDbl)
	;
29
	
Dr-Dan's avatar
Dr-Dan committed
30
31
32
33
34
35
	class_<maxiSettings>("maxiSettings")
	.constructor<>()
	.class_function("setup", &maxiSettings::setup)
	;
	
	
36
	// MAXI OSC
Dr-Dan's avatar
Dr-Dan committed
37
	class_<maxiOsc>("maxiOsc")
38
39
40
41
42
43
	//	.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
	.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)
	;
	
60
	// MAXI ENVELOPE
Dr-Dan's avatar
Dr-Dan committed
61
	class_<maxiEnvelope>("maxiEnvelope")
62
63
64
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelope>",&std::make_shared<maxiEnvelope>)
	
Dr-Dan's avatar
Dr-Dan committed
65
	.function("line", &maxiEnvelope::line)
66
	//	.function("line", &maxiEnvelope::line, allow_raw_pointers()) // if using array version
Dr-Dan's avatar
Dr-Dan committed
67
68
69
70
	.function("trigger", &maxiEnvelope::trigger)
	.property("amplitude", &maxiEnvelope::GetAmplitude, &maxiEnvelope::SetAmplitude)
	;
	
71
72
	// MAXI DELAYLINE
	class_<maxiDelayline>("maxiDelayline")
73
	//	.constructor<>()
Dr-Dan's avatar
Dr-Dan committed
74
	.smart_ptr_constructor("shared_ptr<maxiDelayline>",&std::make_shared<maxiDelayline>)
75
76
77
	.function("dl", select_overload<double(double, int, double)>(&maxiDelayline::dl))
	.function("dl", select_overload<double(double, int, double, int)>(&maxiDelayline::dl))
	;
78
	
79
80
	
	// MAXI FILTER
Dr-Dan's avatar
Dr-Dan committed
81
	class_<maxiFilter>("maxiFilter")
82
83
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFilter>",&std::make_shared<maxiFilter>)
Dr-Dan's avatar
Dr-Dan committed
84
85
86
87
88
89
90
	.function("lores", &maxiFilter::lores)
	.function("hires", &maxiFilter::hires)
	.function("bandpass", &maxiFilter::bandpass)
	.function("lopass", &maxiFilter::lopass)
	.function("hipass", &maxiFilter::hipass)
	;
	
91
92
	// MAXI MIX
	class_<maxiMix>("maxiMix")
93
94
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMix>",&std::make_shared<maxiMix>)
95
96
97
98
99
	.function("stereo", &maxiMix::stereo, allow_raw_pointers())
	.function("quad", &maxiMix::quad,  allow_raw_pointers())
	.function("ambisonic", &maxiMix::ambisonic, allow_raw_pointers())
	;
	
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
	//	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)
	
	;
	
117
	// MAXI SAMPLE
Dr-Dan's avatar
Dr-Dan committed
118
	class_<maxiSample>("maxiSample")
119
120
121
	//	.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
122
	.function("getLength", &maxiSample::getLength)
Dr-Dan's avatar
Dr-Dan committed
123
	.function("setSample", &maxiSample::setSample)
124
	//	.function("getSummary", &maxiSample::getSummary)
Dr-Dan's avatar
Dr-Dan committed
125
	.function("isReady", &maxiSample::isReady)
126
	
Dr-Dan's avatar
Dr-Dan committed
127
128
	.function("playOnce", select_overload<double()>(&maxiSample::playOnce))
	.function("playOnce", select_overload<double(double)>(&maxiSample::playOnce))
129
	
130
131
132
	.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))
133
	
134
	.function("play4", &maxiSample::play4)
135
136
	
	
Dr-Dan's avatar
Dr-Dan committed
137
138
	.function("trigger", &maxiSample::trigger)
	.function("clear", &maxiSample::clear)
139
	
Dr-Dan's avatar
Dr-Dan committed
140
	//	.function("load", &maxiSample::load)
141
	//	.function("read", &maxiSample::read, allow_raw_pointers())
Dr-Dan's avatar
Dr-Dan committed
142
	;
143
144
145
	
	// MAXI MAP
	class_<maxiMap>("maxiMap")
146
147
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiMap>",&std::make_shared<maxiMap>)
148
149
150
151
152
153
154
155
	.function("linlin", &maxiMap::linlin)
	.function("linexp", &maxiMap::linexp)
	.function("explin", &maxiMap::explin)
	.function("clamp", &maxiMap::clamp)
	;
	
	// MAXI DYN
	class_<maxiDyn>("maxiDyn")
156
157
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDyn>",&std::make_shared<maxiDyn>)
158
159
160
161
162
163
	.function("gate", &maxiDyn::gate)
	.function("compressor", &maxiDyn::compressor)
	;
	
	// MAXI ENV
	class_<maxiEnv>("maxiEnv")
164
165
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnv>",&std::make_shared<maxiEnv>)
166
167
168
169
170
171
	.function("ar", &maxiEnv::ar)
	.function("adsr", &maxiEnv::adsr)
	;
	
	// CONVERT
	class_<convert>("convert")
172
173
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<convert>",&std::make_shared<convert>)
174
	.function("mtof", &convert::mtof)
175
	//	.class_function("mtof", &convert::mtof)
176
177
	;
	
178
	
179
180
	// MAXI DISTORTION
	class_<maxiDistortion>("maxiDistortion")
181
182
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiDistortion>",&std::make_shared<maxiDistortion>)
183
184
185
186
187
188
189
	.function("fastAtan", &maxiDistortion::fastatan)
	.function("atanDist", &maxiDistortion::atanDist)
	.function("fastAtanDist", &maxiDistortion::fastAtanDist)
	;
	
	// MAXI FLANGER
	class_<maxiFlanger>("maxiFlanger")
190
191
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiFlanger>",&std::make_shared<maxiFlanger>)
192
193
194
195
196
	.function("flange", &maxiFlanger::flange)
	;
	
	// MAXI CHORUS
	class_<maxiChorus>("maxiChorus")
197
198
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiChorus>",&std::make_shared<maxiChorus>)
199
200
201
202
203
	.function("chorus", &maxiChorus::chorus)
	;
	
	// MAXI ENVELOPE FOLLOWER
	class_<maxiEnvelopeFollower>("maxiEnvelopeFollower")
204
205
	//	.constructor<>()
	.smart_ptr_constructor("shared_ptr<maxiEnvelopeFollower>",&std::make_shared<maxiEnvelopeFollower>)
206
207
208
209
210
211
212
	.function("setAttack", &maxiEnvelopeFollower::setAttack)
	.function("setRelease", &maxiEnvelopeFollower::setRelease)
	.function("play", &maxiEnvelopeFollower::play)
	.function("reset", &maxiEnvelopeFollower::reset)
	;
	
};
Dr-Dan's avatar
Dr-Dan committed
213
#endif