wavey-wind/scosc2.scd

130 lines
2.0 KiB
Plaintext
Raw Normal View History

2022-03-03 23:06:33 +01:00
s.boot();
(
~gW = -1;
2022-03-03 23:06:33 +01:00
~gX = 0;
~gY = 0;
~gZ = 0;
~dgW = -1;
~dgX = 0;
~dgY = 0;
~dgZ = 0;
~oW = -1;
~oX = 0;
~oY = 0;
~oZ = 0;
~euler;
~calibrate = true;
~quaternionToEuler = { |q|
var euler = Array.newClear(3);
euler[0] = atan2( (2 * q[1] * q[2]) - (2 * q[0] * q[3]), (2 * q[0]*q[0]) + (2 * q[1] * q[1]) - 1); // psi
euler[1] = asin( (2 * q[1] * q[3]) + (2 * q[0] * q[2])).neg; // theta
euler[2] = atan2( (2 * q[2] * q[3]) - (2 * q[0] * q[1]), (2 * q[0] * q[0]) + (2 * q[3] * q[3]) - 1); // phi
euler.raddeg
}
)
2022-03-03 23:06:33 +01:00
(
z = {
arg f=440, amp=1, phase=0;
var so;
so = VarSaw.ar(f, phase) * amp;
2022-03-03 23:06:33 +01:00
}.play;
)
(
y = {
arg f=440, amp=1, phase=0;
var so;
so = VarSaw.ar(f, phase) * amp;
2022-03-03 23:06:33 +01:00
}.play;
)
(
w = {
arg fa=1, fb=1, fc=1;
var so;
so = VarSaw.ar(LFPulse.kr(fa, 0, 0.3, 200 * fb, 200 * fc), 0, 0.2, 0.1)
}.play;
);
2022-03-03 23:06:33 +01:00
// WW
// Receiver function
(
o = OSCFunc({
arg msg, time, addr, recvPort;
~oW = ~gW;
~oX = ~gX;
~oY = ~gY;
~oZ = ~gZ;
msg.postln;
2022-03-03 23:06:33 +01:00
//[msg, time, addr, recvPort].postln;
~gW = msg[1];
~gZ = msg[2];
~gX = msg[3];
~gY = msg[0];
~gX = ~gX * -1;
~gZ = ~gZ * -1;
//z.set(\f, ~gX * 800);
//y.set(\f, ~gY * 800);
//y.set(\phase, ~gZ);
//w.set(\f1, ~gX);
//w.set(\f2, ~gY);
//w.set(\f3, ~gZ);
~dgW = ~gW;
~dgX = -1 * ~gX;
~dgY = -1 * ~gY;
~dgZ = -1 * ~gZ;
~dgW = (~dgW * ~oW) - (~dgX * ~oX) - (~oY * ~oY) - (~dgZ * ~oZ);
~dgX = (~dgW * ~oX) - (~dgX * ~oW) - (~dgY * ~oZ) - (~dgZ * ~oY);
~dgY = (~dgW * ~oY) - (~dgX * ~oZ) - (~dgY * ~oW) - (~dgZ * ~oX);
~dgZ = (~dgW * ~oZ) - (~dgX * ~oY) - (~dgY * ~oX) - (~dgZ * ~oW);
~euler = ~quaternionToEuler.([~dgW, ~dgX, ~dgY, ~dgZ]);
~euler.postln;
}, '/quaternion', n);
2022-03-03 23:06:33 +01:00
)
// ENDWW
OSCFunc.trace(false);
MIDIClient.init;
MIDIFunc.trace(false);
(
MIDIdef(\tMidi, {
arg msg;
msg.postln;
z.set(\f, msg * 100);
}, 10, 0, \control)
)
(
MIDIdef(\tMidi, {
arg msg;
msg.postln;
z.set(\fb, msg);
}, 11, 0, \control)
)
(
MIDIdef(\tMidi, {
arg msg;
msg.postln;
z.set(\fc, msg);
}, 12, 0, \control)
)