Zadnja generalka

main
Jurij Podgoršek 2024-09-26 19:40:14 +02:00
parent a78110dc80
commit 7a2d2b8d29
2 changed files with 96 additions and 54 deletions

View File

@ -9,10 +9,15 @@ OSCRecorderGUI();
NetAddr.langPort;
OSCFunc.trace(true);
OSCFunc.trace(false);
(
// To send OSC
~n = NetAddr("127.0.0.1", 57120);
// Initialize the the receiver via SLIP decoder
~receiverPath = "/dev/ttyACM0";
//~baudRate = 115200;
~baudRate = 230400;
OSCFunc.trace(true); // debug osc
@ -33,14 +38,32 @@ OSCFunc.trace(false);
~razmerja = [
// Core
[1, nil],
//[6, 1],
[6, 1],
[3, 6],
[7, nil]
].do({ |par|
var s = AHRSensor.new(par[0], par[1]);
// Leva/desna roka
[3, 1],
[4, 1],
// Leva/desna rama
[5, 1],
[6, 1]
// Testni
//[7, 1]
/*
[6, 4]
*/
// Test
//[2, nil],
//[7, 2]
];
// Senzorji
~razmerja.do({ |par|
var s = AHRSensor.new(par[0]);
~senzorji.put(par[0], s);
~starsi.put(par[1], s);
});
// Starsi
~razmerja.do({ |par|
if (par[1] != nil) {
~senzorji[par[0]].parent = ~senzorji[par[1]];
};
});
/*
~senzorji.put(1, AHRSensor.new(1));
@ -54,10 +77,8 @@ OSCFunc.trace(false);
// Olimex test
//~senzorji.put(9, AHRSensor.new(9));
//~senzorji.postln;
~decoder = SLIPDecoder.new(~receiverPath);
~w = Window.new("Utopia || C²", Rect(300, ~senzorji.size * 60, 600, ~senzorji.size * 100),true);
~w = Window.new("Utopia || C²", Rect(300, ~senzorji.size * 60, 900, ~senzorji.size * 100),true);
// Midi naprava
MIDIClient.init;
@ -73,27 +94,33 @@ MIDIClient.destinations;
~decoder.trace(true); // debug slip decoder
~decoder = SLIPDecoder.new(~ttyInput.string, ~baudRate);
~decoder.start;
butt.string_("Stop")
~startStopBtn.string_("Stop")
}, {
// Else stop the decoder
~decoder.stop;
butt.string_("Start")
~startStopBtn.string_("Start")
};
);
};
~ttyInput = TextField().string_(~receiverPath).keyDownAction_({ |input, char| if (char == $\r, { ~startStopDecoder.value(~ttyInput); }); });
~startStopBtn = Button().string_("Start").action_(~startStopDecoder);
~ttyInput = TextField().string_(~receiverPath).keyDownAction_({ |input, char| if (char == $\r, { ~startStopDecoder.value; }); });
~btnRefAll = Button().string_("ref all").action_({
~senzorji.values.do({ | s | s.setRefQuat(); });
});
~w.layout_(
VLayout(
HLayout(
GridLayout.rows(
// HEADER; serial path, buttons
[
StaticText().string_("Serial path: "),
~ttyInput,
Button().string_("Start").action_(~startStopDecoder);
),
[~ttyInput, columns: 7],
~startStopBtn,
// Gumb za referencni quat na vseh
~btnRefAll
],
// Sensor rows
GridLayout.rows(*~elementi.flatten)
*~elementi.flatten
)
);
@ -103,41 +130,55 @@ MIDIClient.destinations;
});
~w.front;
// Automatic reflow
// does NOT work with layouts!
//~w.view.decorator = FlowLayout(~w.view.bounds);
// Pucamo stare listenerje
OSCdef.freeAll;
// OSC listeners for sensors
~senzorji.collect({ |s|
var oscHeader = "/ww/" ++ s.id,
senzor = ~senzorji[s.id];
// Quat listener
q = OSCdef.new((\quat ++ s.id), { |msg, time, addr, recvPort|
q = OSCdef.new((\quat ++ s.id).asSymbol, { |msg, time, addr, recvPort|
var q;
// We get X Y Z W, but supercollider has W X Y Z!
q = Quaternion.new(msg[4], msg[1], msg[2], msg[3]);
q = Quaternion.new(msg[1], msg[2], msg[3], msg[4]);
// Count quat events
Routine {
var quatD;
// Stetje dogodkov
senzor.eps = senzor.eps + 1;
senzor.quat = q;
// Nov quaternion!
senzor.setQuat(q);
senzor.refreshGuiQuat;
//quatD = senzor.calibQuat.conjugate * q;
quatD = senzor.calibQuat.reciprocal * q;
senzor.updateEuler(quatD);
senzor.refreshGuiEuler;
// razlika od parenta
//quatD = q;
quatD = senzor.relQuat;
// Relativni euler koti (glede na starsa)
if (senzor.parent != nil) {
senzor.updateEulerD(q);
senzor.refreshGuiEulerD;
};
senzor.updateEuler(quatD);
//senzor.rotateVector(quatD);
senzor.refreshGuiEuler;
//senzor.refreshGuiVector;
// Posljemo kot OSC, za lazje mapiranje v midi
~n.sendMsg("/euler/" ++ senzor.id, senzor.euler[0], senzor.euler[1], senzor.euler[2]);
//~n.sendMsg("/vector/" ++ senzor.id, senzor.vecF.x, senzor.vecF.y, senzor.vecF.z, senzor.vecT.x, senzor.vecT.y, senzor.vecT.z);
}.play(AppClock);
}, oscHeader ++ "/quat");
// Acceleration listener
q = OSCdef.new((\acc ++ s.id), { |msg, time, addr, recvPort|
q = OSCdef.new((\acc ++ s.id).asSymbol, { |msg, time, addr, recvPort|
var a;
a = msg.at((1..3));
Routine {
@ -150,14 +191,15 @@ MIDIClient.destinations;
xyz = sqrt((xy * xy) + (a[2] * a[2]));
senzor.accelSum = xyz;
~midi.control(s.id, 1, xyz);
// Poslji sumo
~n.sendMsg("/acc/" ++ senzor.id, senzor.accel[0], senzor.accel[1], senzor.accel[2], senzor.accelSum);
senzor.refreshGuiAccel;
}.play(AppClock);
}, oscHeader ++ "/acc");
// Battery listener
q = OSCdef.new((\acc ++ s.id), { |msg, time, addr, recvPort|
q = OSCdef.new((\bat ++ s.id).asSymbol, { |msg, time, addr, recvPort|
var b = msg[1];
// Since we get a battery reading every second, use this as the events/s refresh
Routine {
@ -185,13 +227,11 @@ AppClock.sched(0, {
~decoder.stop;
~decoder.start;
OSCFunc.freeAll;
~decoder.rate;
/**********
* SOUND! *
*********/
~e = Env([1, 0.2, 0]);
{[SinOsc.ar(50), SinOsc.ar(52.3)] * EnvGen.kr(~e, doneAction: Done.freeSelf)}.play;
s.boot;
{[SinOsc.ar(90), SinOsc.ar(122.3)]}.play;// * EnvGen.kr(~e, doneAction: Done.freeSelf)}.play;

View File

@ -205,7 +205,7 @@ OSCFunc.trace(false); // debug osc
accSum = accSum - 0.5;
switch (id,
4, {
~sendMidi.value(0, 18, (accSum * 256).floor);
//~sendMidi.value(0, 18, (accSum * 256).floor);
}
);
@ -216,7 +216,7 @@ OSCFunc.trace(false); // debug osc
// MIDI MAP IV (II)
(
~map = "IV";
~map = "IV (2)";
"MIDI MAP IV (II) !!!".postln;
~senzorji.keys.do({ |id|
@ -232,10 +232,10 @@ OSCFunc.trace(false); // debug osc
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor);
~sendMidi.value(0, 16, -10 + (yaw * 150));
},
3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor));
~sendMidi.value(0, 17, (roll * 150));
}
);
}, "/euler/" ++ id);
@ -262,7 +262,8 @@ OSCFunc.trace(false); // debug osc
(
"MIDI MAP V (III) !!!".postln;
~map = "V (3)";
"MIDI MAP V (3)".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
@ -310,7 +311,8 @@ OSCFunc.trace(false); // debug osc
(
"MIDI MAP VI (III) !!!".postln;
~map = "VI (3)";
"MIDI MAP VI (3) !!!".postln;
~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
@ -362,17 +364,15 @@ OSCFunc.trace(false); // debug osc
yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// BITCRUSH EFEKT
/*
switch (id,
4, {
// Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor);
~sendMidi.value(0, 16, (-10 + (yaw * 150)).floor);
},
3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor));
~sendMidi.value(0, 17, (-25 + (roll * 150).floor));
}
);
*/
}, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort|
@ -384,9 +384,11 @@ OSCFunc.trace(false); // debug osc
accSum = msg[4].linlin(0, 50, 0, 1);
switch (id,
3, {
~sendMidi.value(0, 16, (accX * 127));
~sendMidi.value(0, 17, (accY * 127));
1, {
/*
~sendMidi.value(0, 16, 40 + (accY * 150));
~sendMidi.value(0, 17, 40 + (accZ * 150));
*/
}
);
}, "/acc/" ++ id);