-
Notifications
You must be signed in to change notification settings - Fork 0
/
TStick.scd
executable file
·216 lines (165 loc) · 5.81 KB
/
TStick.scd
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
/*
TStick SC synth/mapping version 0.8 -- Edu Meneses
Run on IDMIL MPU 002 (Sound Processing Unit) - Rpi 3B
This code is based on SuperCollider Tutorial: 12. Nintendo Wiimote
Eli Fieldsteel
Published on Sep 1, 2014
https://youtu.be/JRIUq-46V6M
*/
//s = Server.local;
(
// Server.local.options.numOutputBusChannels = 8; // change number of input and$
// Server.local.options.numInputBusChannels = 8;
// Server.internal.options.numOutputBusChannels = 8;
// Server.internal.options.numInputBusChannels = 8;
s.waitForBoot{
/*OSCdef.freeAll;
1.wait;*/
// ............................ Global variables ............................
~tstick = NetAddr.new("192.168.21.107", 8888); // NetAddr T-Stick
~lcd = NetAddr.new("127.0.0.1", 20000); // Setting LCD - Loopback NetAddr and Python code listening port
~tstick_output = 0;
~tstick_state = Array.fill(16,0);
~tstick_laststate = Array.fill(16,0);
~tstick_synth = Array.fill(16,0);
//~tstick_reduced = Array.fill(3,0); // reducing cap sensing to controls 4 variables in \addsaw
//~tstick_lastreduced = Array.fill(3,0);
~tstick_group = Group.new;
~lcd.sendMsg('/lcd', "GuitarAMI: ", 1, 1);
~lcd.sendMsg('/lcd', "Loading T-Stick demo", 2, 1);
~lcd.sendMsg('/lcd', "[ ]", 3, 1);
1.wait;
// ............................ SYNTH DEF ............................
/*
%%%%%% %%%%%%
%%%%%%%%%%% %%%%%%%%%%%
%%%%%%%%%%%%%%%%% T-STICK FOLDSAW %%%%%%%%%%%%%%%%%
%%%%%%%%%%% %%%%%%%%%%%
%%%%%% %%%%%%
*/
SynthDef.new(\foldsaw, {
arg freq=4, detune=1, atk=0.01, dec=0.3, rel=3, c1=1, c2=(-1), gate=1, mincf=40, maxcf=12000, minrq=0.002, maxrq=0.2, boost=1.25, amp=1, output=0;
var sig, env;
env = EnvGen.kr(Env.adsr(atk, dec, 0.5, rel),gate,doneAction:1);
sig = Saw.ar(
freq +
LFNoise1.kr(LFNoise1.kr(0.5!8).range(0.1,1)).bipolar(detune)
);
5.do{sig = (sig*boost).fold(-1.0,1.0)};
sig = BPF.ar(
sig,
LFNoise1.kr({ExpRand(0.005,0.05)}!8).exprange(mincf,maxcf),
LFNoise1.kr({ExpRand(0.1,0.75)}!8).range(minrq,maxrq)
);
sig = Splay.ar(sig) * env * amp * 2;
Out.ar(output,sig);
}).add;
~lcd.sendMsg('/lcd', "===", 3, 2);
/*
%%%%%% %%%%%%
%%%%%%%%%%% %%%%%%%%%%%
%%%%%%%%%%%%%%%%% T-STICK CHEAP FOLDSAW %%%%%%%%%%%%%%%%%
%%%%%%%%%%% %%%%%%%%%%%
%%%%%% %%%%%%
*/
SynthDef.new(\cheapfoldsaw, {
arg freq=4, detune=1, atk=0.01, dec=0.3, rel=3, c1=1, c2=(-1), gate=1, mincf=40, maxcf=12000, minrq=0.002, maxrq=0.2, boost=1.25, amp=1, output=0;
var sig, env;
env = EnvGen.kr(Env.adsr(atk, dec, 0.5, rel),gate,doneAction:1);
sig = Saw.ar(
freq +
LFNoise1.kr(LFNoise1.kr(0.5!1).range(0.1,1)).bipolar(detune)
);
5.do{sig = (sig*boost).fold(-1.0,1.0)};
sig = BPF.ar(
sig,
LFNoise1.kr({ExpRand(0.005,0.05)}!1).exprange(mincf,maxcf),
LFNoise1.kr({ExpRand(0.1,0.75)}!1).range(minrq,maxrq)
);
sig = Splay.ar(sig) * env * amp * 2;
Out.ar(output,sig);
}).add;
~lcd.sendMsg('/lcd', "====", 3, 5);
// ............................ STARTING SYNTHS ............................
0.4.wait;
for (0,15,{ // define number of Synths
arg i;
~tstick_synth[i] = Synth.newPaused(\cheapfoldsaw,[\freq, exprand(1,8), \atk, exprand(2,8), \rel, exprand(2,8), \output, ~tstick_output],~tstick_group);
}
);
~lcd.sendMsg('/lcd', "====", 3, 9);
// ............................ SYNTH COMMANDS ............................
// start synth
// ~tstick_synth[i].run;
// stop synth
// ~tstick_synth[i].run(false);
// ............................ DATA RECEIVING AND MAPPING ............................
// receiving T-Stick OSC accelerometer data and mapping to \foldsaw
OSCdef.new(\accelerometer, {
arg msg;
~tstick_group.set(
\detune, msg[1].linexp(-32000,32000,0.001,80), // pitch do acelerômetro
\maxrq, msg[2].linexp(-32000,32000,0.01,0.5), // roll do acelerômetro
);
}, 'TStick_202/raw/accl', recvPort:8000
);
// receiving T-Stick OSC gyroscope data and mapping to \foldsaw
OSCdef.new(\gyros, {
arg msg;
var temp;
temp = msg[1].fold(0,41) + msg[2].fold(0,41) + msg[3].fold(0,41);
~tstick_group.set(
\boost, temp.linlin(0,41,1,16), // aceleração do acelerômetro
);
//msg.postln;
}, 'TStick_201/raw/gyro', recvPort:8000
);
// running and pausing T-Stick synths
OSCdef.new(\addsaw, {
arg msg, temp, reduced;
temp = msg[1].asBinaryDigits ++ msg[2].asBinaryDigits;
for (0, 15, { arg i;
if(~tstick_state[i] != temp[i],
{
~tstick_state[i]=temp[i];
if(~tstick_state[i]==1,
{~tstick_synth[i].run.set(\gate,1);},
{~tstick_synth[i].set(\gate,0);});
}
);
});
}, 'TStick_201/raw/capsense', recvPort:8000
);
~lcd.sendMsg('/lcd', "====", 3, 13);
// ............................ T-STICK HANDSHAKING ............................
OSCdef.new(\tstickreturn, {
arg msg;
~tstickstatus = msg[1];
}, '/information'
);
~tstickroutine = Task(
{
{
~tstick.sendMsg('/status', 115); // send the OSC message
1.wait;
if(~tstickstatus==181,{~lcd.sendMsg('/lcd',"T", 0, 15)});
if(~tstickstatus==0,{~lcd.sendMsg('/lcd'," ", 0, 15)});
~tstickstatus = 0;
}.loop
}
).start;
~lcd.sendMsg('/lcd', "===", 3, 17);
// ............................ CHIME ............................
0.4.wait;
(dur:1, strum: 0.1, degree: [0,4,7]).play;
~lcd.sendMsg('/lcd', "Loading complete ", 2, 1);
(1.0).wait;
AppClock.sched(0.0,{
~lcd.sendMsg('/lcd', " T-Stick demo", 1, 1);
10; // delay between LCD updates
});
}; // end of "waitForBoot"
)
// DEBUG commands:
// ~debug = NetAddr.new("192.168.5.2", 57120); // NetAddr Mac Pro
// s.queryAllNodes;