server.js and supercollider files updated for capacitive switch logic

master
Rob Canning 2022-08-31 15:55:49 +02:00
parent e01e4ed32a
commit d46b59458f
3 changed files with 109 additions and 43 deletions

View File

@ -17,8 +17,40 @@ the nodejs glue
- https://git.kompot.si/g1smo/pifcamp-2021/src/branch/master/osc32final
## GPIO / PINS
### ACCELEROMETER/GYRO
### CAPACATIVE TOUCH
GPIO:
momentary switchs
4 TOUCH0 - record to buffer 0
0 TOUCH1
2 TOUCH2
15 TOUCH3
toggle switchs
13 TOUCH4
14 TOUCH5
12 TOUCH6
27 TOUCH7
TOUCH0 + TOUCH3 = EULER ROTATION RESET
array of 16 values -
8 x data inputs +
8 x 0/1 values - first 4 momentary second 4 toggle
args: [
35, 56, 53, 47, 99, 106, 99, 48,
0, 0, 0, 0, 0, 0, 0, 0
]

43
gtr.scd
View File

@ -27,7 +27,7 @@ s.boot();
b = Buffer.alloc(s, s.sampleRate * 4.0, 1);
// load a test file
f = Buffer.read(s, thisProcess.nowExecutingPath.dirname
+/+ "sounds/selo-thunder-cicadas-01.wav");
+/+ "sounds/Front_Left.wav");
// Open port 57121 for ESP32 UDP OSC
thisProcess.openUDPPort(57121);
@ -135,13 +135,12 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
~granulator1 = Synth(\buf_grain, [\sndbuf, b, \envbuf, -1]); // granulate
~gtrIn = Synth(\dryIn); // dry audio signaL
))
));
~gtrIn.free;
// RUNME 4 ==========================================
// ----------------------------------------------------
( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <--
(( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <--
// ----------------------------------------------------
~pitchmode = 0; ~positionmode = 2; ~impulsemode = 0;
@ -165,7 +164,7 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
// RATE ------- X (roll [with PAN])
~granulator1.set(\sensorimpulse, msg[2].linlin(-1, 1, 5, 50));
~granulator1.set(\impulsemodeindex, ~impulsemode );
msg.postln;
//msg.postln;
}; , '/euler');
);
@ -173,30 +172,34 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
// button press mapping ///////////////////////////////
// ----------------------------------------------------
( p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// TODO toggle logic
p = OSCdef(\keys, { arg msg, time, addr, recvPort;
case
// BUTTON 1 ----> RECORD
{ msg[1] == 1 } { r.set( \t_trig, 1); msg.postln; } //
// BUTTON 2 ----> ZERO SENSORS (todo)
{ msg[5] == 0 } { ~granulator1.set(\positionmodeindex, 1 ); }
{ msg[5] == 1 } { ~granulator1.set(\positionmodeindex, 2 ); }
// BUTTON 0 && 3 RESET/ZERO SENSORS [in firmware]
// 1 && 2 RESET/ZERO SENSORS
// BUTTON 0 ----> RECORD TO BUFFER 0
{ msg[8] == 1 } { r.set( \t_trig, 1); msg.postln; } //
// BUTTON 3 ----> LOOP RECORDING MODE ON/OFF
{ msg[3] == 0 } { r.set(\l, 0); }
{ msg[3] == 1 } { r.set(\l, 1); }
// BUTTON 0 + 3 ----> ZERO EULER / MPU6050
// BUTTON 4 ----> OVERDUB MODE ON/OFF
{ msg[4] == 0 } { ~pitchmode, 1 ); }
{ msg[4] == 1 } { ~pitchmode, 2 ); }
// TOGGLE O ----> OVERDUB MODE ON/OFF
{ msg[12] == 0 } { r.set(\overdub, 0); }
{ msg[12] == 1 } { r.set(\overdub, 1); }
// TOGGLE 2
{ msg[14] == 0 } { ~granulator1.set(\positionmodeindex, 1 ); }
{ msg[14] == 1 } { ~granulator1.set(\positionmodeindex, 2 ); }
// TOGGLE 3 ----> LOOP RECORDING MODE ON/OFF
{ msg[15] == 0 } { r.set(\l, 0); }
{ msg[15] == 1 } { r.set(\l, 1); }
} , '/keys');
//msg.postln;
);
)
);
// ----------------------------------------------------
// ----------------------------------------------------

View File

@ -35,6 +35,13 @@ const DEBUG = true
// Odprti serijski OSC link
let scon = null
let buttonHeld = [false, false, false, false]
let buttonValue = [false, false, false, false]
let switchHeld = [false, false, false, false]
let switchValue = [false, false, false, false]
function openSerial() {
console.log('opening ', tty, baudrate)
@ -174,31 +181,55 @@ function eulerFromQuaternion(quaternion) {
return euler;
}
let switchHeld = false
let switchValue = false
var threshold = 20;
const sendAll = (msg, info, oscWS, osclients) => {
if (msg.address == '/keys') {
if (msg.args[0] == 1 && msg.args[1] == 1 ) {
// keys 0 + 3 = euler reset
if (msg.args[0] <= threshold && msg.args[3] <= threshold ) {
eulerRotation = [0, 0, 0];
console.log("EULER ROTATION RESET");
}
}
// LOGIC FOR MOMENTARY BUTTONS (0 - 3)
for (let i = 0; i < 4; i++) {
// toggle button 2 state between 0 and 1
if (msg.address == '/keys') {
if (msg.args[1] == 1) {
if (switchHeld == false) {
switchValue = !switchValue
switchHeld = true
if (msg.args[i] <= threshold ) {
buttonValue[i] = 1;
} else {
buttonValue[i] = 0;
}
msg.args.push(buttonValue[i] ? 1 : 0)
}
}
// LOGIC FOR TOGGLE SWITCHES (4-7)
for (let i = 4; i < 8; i++) {
// toggle button 2 state between 0 and 1
if (msg.address == '/keys') {
if (msg.args[i] <= threshold ) {
if (switchHeld[i-4] == false) {
switchValue[i-4] = !switchValue[i-4]
switchHeld[i-4] = true
}
} else {
if (switchHeld) {
switchHeld = false
if (switchHeld[i-4]) {
switchHeld[i-4] = false
}
}
msg.args.push(switchValue ? 1 : 0)
msg.args.push(switchValue[i-4] ? 1 : 0)
}
}
//------------------------------------------------
// Convert quaternion diff to euler angle diff
if (msg.address == '/quaternionDiff') {
const euler = eulerFromQuaternion(msg.args, 'XYZ');