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; NetAddr.langPort;
OSCFunc.trace(true); OSCFunc.trace(true);
OSCFunc.trace(false);
( (
// To send OSC
~n = NetAddr("127.0.0.1", 57120);
// Initialize the the receiver via SLIP decoder // Initialize the the receiver via SLIP decoder
~receiverPath = "/dev/ttyACM0"; ~receiverPath = "/dev/ttyACM0";
//~baudRate = 115200;
~baudRate = 230400; ~baudRate = 230400;
OSCFunc.trace(true); // debug osc OSCFunc.trace(true); // debug osc
@ -33,14 +38,32 @@ OSCFunc.trace(false);
~razmerja = [ ~razmerja = [
// Core // Core
[1, nil], [1, nil],
//[6, 1], // Leva/desna roka
[6, 1], [3, 1],
[3, 6], [4, 1],
[7, nil] // Leva/desna rama
].do({ |par| [5, 1],
var s = AHRSensor.new(par[0], par[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); ~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)); ~senzorji.put(1, AHRSensor.new(1));
@ -54,10 +77,8 @@ OSCFunc.trace(false);
// Olimex test // Olimex test
//~senzorji.put(9, AHRSensor.new(9)); //~senzorji.put(9, AHRSensor.new(9));
//~senzorji.postln;
~decoder = SLIPDecoder.new(~receiverPath); ~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 // Midi naprava
MIDIClient.init; MIDIClient.init;
@ -73,27 +94,33 @@ MIDIClient.destinations;
~decoder.trace(true); // debug slip decoder ~decoder.trace(true); // debug slip decoder
~decoder = SLIPDecoder.new(~ttyInput.string, ~baudRate); ~decoder = SLIPDecoder.new(~ttyInput.string, ~baudRate);
~decoder.start; ~decoder.start;
butt.string_("Stop") ~startStopBtn.string_("Stop")
}, { }, {
// Else stop the decoder // Else stop the decoder
~decoder.stop; ~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_( ~w.layout_(
VLayout( GridLayout.rows(
HLayout(
// HEADER; serial path, buttons // HEADER; serial path, buttons
[
StaticText().string_("Serial path: "), StaticText().string_("Serial path: "),
~ttyInput, [~ttyInput, columns: 7],
Button().string_("Start").action_(~startStopDecoder); ~startStopBtn,
), // Gumb za referencni quat na vseh
~btnRefAll
],
// Sensor rows // Sensor rows
GridLayout.rows(*~elementi.flatten) *~elementi.flatten
) )
); );
@ -103,41 +130,55 @@ MIDIClient.destinations;
}); });
~w.front; ~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 // OSC listeners for sensors
~senzorji.collect({ |s| ~senzorji.collect({ |s|
var oscHeader = "/ww/" ++ s.id, var oscHeader = "/ww/" ++ s.id,
senzor = ~senzorji[s.id]; senzor = ~senzorji[s.id];
// Quat listener // 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; var q;
// We get X Y Z W, but supercollider has W X Y Z! // 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 // Count quat events
Routine { Routine {
var quatD; var quatD;
// Stetje dogodkov
senzor.eps = senzor.eps + 1; senzor.eps = senzor.eps + 1;
senzor.quat = q;
// Nov quaternion!
senzor.setQuat(q);
senzor.refreshGuiQuat; senzor.refreshGuiQuat;
//quatD = senzor.calibQuat.conjugate * q; // razlika od parenta
quatD = senzor.calibQuat.reciprocal * q; //quatD = q;
senzor.updateEuler(quatD); quatD = senzor.relQuat;
senzor.refreshGuiEuler;
// Relativni euler koti (glede na starsa) senzor.updateEuler(quatD);
if (senzor.parent != nil) { //senzor.rotateVector(quatD);
senzor.updateEulerD(q);
senzor.refreshGuiEulerD; 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); }.play(AppClock);
}, oscHeader ++ "/quat"); }, oscHeader ++ "/quat");
// Acceleration listener // 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; var a;
a = msg.at((1..3)); a = msg.at((1..3));
Routine { Routine {
@ -150,14 +191,15 @@ MIDIClient.destinations;
xyz = sqrt((xy * xy) + (a[2] * a[2])); xyz = sqrt((xy * xy) + (a[2] * a[2]));
senzor.accelSum = xyz; 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; senzor.refreshGuiAccel;
}.play(AppClock); }.play(AppClock);
}, oscHeader ++ "/acc"); }, oscHeader ++ "/acc");
// Battery listener // 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]; var b = msg[1];
// Since we get a battery reading every second, use this as the events/s refresh // Since we get a battery reading every second, use this as the events/s refresh
Routine { Routine {
@ -185,13 +227,11 @@ AppClock.sched(0, {
~decoder.stop; ~decoder.stop;
~decoder.start; ~decoder.start;
OSCFunc.freeAll;
~decoder.rate;
/********** /**********
* SOUND! * * SOUND! *
*********/ *********/
~e = Env([1, 0.2, 0]); ~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; accSum = accSum - 0.5;
switch (id, switch (id,
4, { 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) // MIDI MAP IV (II)
( (
~map = "IV"; ~map = "IV (2)";
"MIDI MAP IV (II) !!!".postln; "MIDI MAP IV (II) !!!".postln;
~senzorji.keys.do({ |id| ~senzorji.keys.do({ |id|
@ -232,10 +232,10 @@ OSCFunc.trace(false); // debug osc
switch (id, switch (id,
4, { 4, {
// Quick slots 1-3 // Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor); ~sendMidi.value(0, 16, -10 + (yaw * 150));
}, },
3, { 3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor)); ~sendMidi.value(0, 17, (roll * 150));
} }
); );
}, "/euler/" ++ id); }, "/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| ~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort| 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| ~senzorji.keys.do({ |id|
OSCdef.new((\eulerMIDI ++ id).asSymbol, { |msg, time, addr, recvPort| 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); yaw = msg[3].sin.linlin(-pi, pi, 0, 1);
// BITCRUSH EFEKT // BITCRUSH EFEKT
/*
switch (id, switch (id,
4, { 4, {
// Quick slots 1-3 // Quick slots 1-3
~sendMidi.value(0, 16, (-15 + (yaw * 150)).floor); ~sendMidi.value(0, 16, (-10 + (yaw * 150)).floor);
}, },
3, { 3, {
~sendMidi.value(0, 17, (-15 + (roll * 150).floor)); ~sendMidi.value(0, 17, (-25 + (roll * 150).floor));
} }
); );
*/
}, "/euler/" ++ id); }, "/euler/" ++ id);
OSCdef.new((\accMIDI ++ id).asSymbol, { |msg, time, addr, recvPort| 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); accSum = msg[4].linlin(0, 50, 0, 1);
switch (id, switch (id,
3, { 1, {
~sendMidi.value(0, 16, (accX * 127)); /*
~sendMidi.value(0, 17, (accY * 127)); ~sendMidi.value(0, 16, 40 + (accY * 150));
~sendMidi.value(0, 17, 40 + (accZ * 150));
*/
} }
); );
}, "/acc/" ++ id); }, "/acc/" ++ id);