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 - 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
]

47
gtr.scd
View File

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

View File

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