-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTouch.ck
248 lines (213 loc) · 6.82 KB
/
Touch.ck
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//2-D touches
//singly linked list
public class Touch
{
// --------------- member variables ---------------
//these are mostly dictated by the TUIO protocol
// http://www.tuio.org/?specification
int id;
int FSeq;
//position
float x;
float y;
//velocity
float dxdt;
float dydt;
//acceleration
float a;
Touch @ nextTouch;
//UGen ugenInstance;
//Note to self, ugens have: gain() last() channels() chan()
// --------------- preconstructor ---------------
-1 => id;
-1 => FSeq;
//set default parameters
0 => x;
0 => y;
0 => dxdt;
0 => dydt;
0 => a;
//Debug output level
0 => int debug;
// --------------- member functions ---------------
//Private Functions---------------
//These 3 private functions serve as the multi-touch instrument
//They're responsible for audio synthesis
function void beginTouch()
{
if(debug > 1)
<<<"Touch.ck: beginTouch()",id>>>;
//connect to DAC and play note attack
//ugenInstance => dac;
//perform some prescribed attack (maybe based on parameters)
//for this base class it does nothing
}
function void updateTouch()
{
if(debug > 1)
<<<"Touch.ck: updateTouch()",id>>>;
//update parameters of UGen (using static functions)
//for this base class it does nothing
/*
for(0 => int i; i < ugenInstance.channels(); i++){
ugenInstance.chan(i).gain(transformPosition(x));
}
*/
}
function void endTouch()
{
if(debug > 1)
<<<"Touch.ck: endTouch()",id>>>;
//play note release and disconnect from DAC
//perform some prescribed release (maybe based on parameters)
//for this base class it does nothing
}
//Public Interface---------------
function Touch update(int id, int FSeq, float x, float y, float dxdt, float dydt, float a)
{
if(debug > 4)
<<<"Touch.ck, update():", id, "updating;", this.id, FSeq>>>;
if(id == this.id){
if(debug > 4)
<<<"Touch.ck, update(): Updated",id>>>;
//chuck the parameters
FSeq => this.FSeq;
x => this.x;
y => this.y;
dxdt => this.dxdt;
dydt => this.dydt;
a => this.a;
//update the UGen
updateTouch();
return this;//success
}
else if(id > this.id){
if(nextTouch == null){
if(debug > 2)
<<<"Touch.ck, updateTouch(): creating",id>>>;
createTouch(id,FSeq,x,y,dxdt,dydt,a) @=> nextTouch;
return this;
}
else {
nextTouch.update(id, FSeq, x, y, dxdt, dydt, a) @=> nextTouch;
return this;
}
}
else if(id < this.id){
createTouch(id, FSeq, x, y, dxdt, dydt, a) @=> Touch NewTouch;
this @=> NewTouch.nextTouch;
if(debug > 2)
<<<"Touch.ck, updatingTouch(): creating",id>>>;
return NewTouch;
}
else {
<<<"Touch.ck, update(): something went seriously wrong">>>;
return null;
}
}
function void aliveTouch(int id, int FSeq, int NumTouches)
{
aliveTouch(id,FSeq);
}
function void aliveTouch(int id, int FSeq)
{
if(debug > 4)
<<<"Touch.ck aliveTouch()",this.id,id,FSeq>>>;
if(id == this.id){
if(debug > 3)
<<<"Touch.ck, aliveTouch() updating:",id,this.FSeq,FSeq>>>;
FSeq => this.FSeq;
updateTouch();
}
else if(id > this.id){
if(nextTouch != null)
nextTouch.aliveTouch(id,FSeq);
else
<<<id,"Wasn't found in the list of Touches\n aliveTouch(),",this.id,",",FSeq>>>;
}
/*
else
createTouch(id, FSeq) @=> nextTouch;
}
else if(id < this.id){
createTouch(id, FSeq, x, y, dxdt, dydt, a) @=> Touch NewTouch;
nextTouch @=> NewTouch.nextTouch;
this @=> NewTouch.nextTouch;
}
else {
<<<"something went seriously wrong in aliveTouch()">>>;
//return null;
}
*/
}
function Touch cleanupTouches(int FSeq)
{
if(debug > 5)
<<<"Touch.ck cleanupTouches()",id,FSeq>>>;
if(nextTouch != null)
nextTouch.cleanupTouches(FSeq) @=> nextTouch;
if(FSeq > this.FSeq && this.id != -1){
spork ~ endTouch();
if(debug > 2)
<<<"Touch.ck cleanupTouches(): removing",id>>>;
//ChucK is garbage collected so this isn't a big deal, right?
return nextTouch;
}
//else case:
return this;
}
// --------------- static methods ---------------
//just a helper function that returns a new touch given the parameters
function Touch createTouch(int id, int FSeq)
{
if(debug > 1)
<<<"Touch.ck, createTouch():",id>>>;
Touch newTouch;
id => newTouch.id;
FSeq => newTouch.FSeq;
return newTouch;
}
function Touch createTouch(int id, int FSeq, float x, float y, float dxdt, float dydt, float a)
{
createTouch(id,FSeq) @=> Touch newTouch;
FSeq => newTouch.FSeq;
x => newTouch.x;
y => newTouch.y;
dxdt => newTouch.dxdt;
dydt => newTouch.dydt;
a => newTouch.a;
spork ~ newTouch.beginTouch();
//spork ~ newTouch.updateTouch();
return newTouch;
}
//The rest of these functions are just for performing
//manipulations between input paremeters and UGen parameters.
//not necessary, but I thought might be helpful (esp. if overridden)
function float transformPosition(float pos)
{
return pos;
}
function float transformPosition(float axis1, float axis2)
{
//euclidean distance
return Math.sqrt(axis1 * axis1 + axis2 * axis2);
}
function float transformPosition(float axis1, float axis2, float axis3)
{
//euclidean distance
return Math.sqrt(axis1 * axis1 + axis2 * axis2 + axis3 * axis3);
}
function float transformVelocity(float vel)
{
return vel;
}
function float transformVelocity(float axis1, float axis2)
{
//vector addition
return Math.sqrt(axis1 * axis1 + axis2 * axis2);
}
function float transformAcceleration(float acel)
{
return acel;
}
}