moved button logic to supercollider

master
Rob Canning 2022-09-01 14:53:31 +02:00
parent bc49ed0c6c
commit a0879a876a
3 changed files with 139 additions and 72 deletions

View File

@ -19,8 +19,23 @@ the nodejs glue
## GPIO / PINS
LEDS
32 (ADC1_4 / TOUCH9)
GND
// OR 33
### ACCELEROMETER/GYRO
#### MPU6050
GPIO:
21 - SDA
22 - SCL
GND - GND
VCC - 3.3V
### CAPACATIVE TOUCH
@ -28,8 +43,8 @@ GPIO:
momentary switchs
4 TOUCH0 - record to buffer 0
0 TOUCH1
4 TOUCH0 - SHIFT KEY
0 TOUCH1 - record to buffer 0
2 TOUCH2
15 TOUCH3
@ -54,4 +69,22 @@ args: [
## BUTTON MAPPING
BUTTON 0 ----- SHIFT
BUTTON 1 ----- TRIGGER ONESHOT BUFFER RECORD
BUTTON X ----- GRANULAR POSITION MODE
BUTTON X ----- GRANULAR PITCH MODE
BUTTON X ----- GRANULAR IMPULSE MODE
BUTTON X ----> LOOP RECORDING MODE ON/OFF
BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
BUTTON X ----- LIVE SIGNAL / PROCESSED / MIX
BUTTON 0 && X RESET/ZERO SENSORS [in firmware]

113
gtr.scd
View File

@ -165,6 +165,7 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
~granulator1.set(\sensorimpulse, msg[2].linlin(-1, 1, 5, 50));
~granulator1.set(\impulsemodeindex, ~impulsemode );
//msg.postln;
}; , '/euler');
);
@ -173,70 +174,94 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
// ----------------------------------------------------
p = OSCdef(\keys, { arg msg, time, addr, recvPort;
//msg.postln;
// BUTTON 0 + 3 ----> ZERO EULER / MPU6050
// ==============================
// BUTTON MAPPING
// ==============================
// BUTTON X && X RESET/ZERO SENSORS [in firmware]
if (msg[9] == 1 && msg[10] == 1,
{ " ===== EULER ZEROED! =====".postln },
{});
if (msg[9] == 1,
{ r.set( \in, 0, \l, 0, \t_trig, 1);
" /////////// SAMPLING!".postln },
{});
// TRIGGER BUTTONS (3) ------------------------------
if (msg[10] == 1,
// BUTTON X ----- TRIGGER ONESHOT BUFFER RECORD
if (msg[10] == 1, { r.set( \in, 0, \l, 0, \t_trig, 1);
" /////////// SAMPLING!".postln }, {});
~btn2val;
// BUTTON X ----- GRANULAR POSITION MODE
if (msg[11]==1,
{
" /////////// SOOOOOOMMMEEETHIIIINNGGGG!".postln },
{});
( ~btn2val = (~btn2val + 1) % 3 ) ;
if (msg[11] == 1,
switch(~btn2val,
0, { ~granulator1.set(\positionmodeindex, 0 ); "POSITION MODE FIXED".postln; },
1, { ~granulator1.set(\positionmodeindex, 1 ); "POSITION MODE RANDOM".postln; },
2, { ~granulator1.set(\positionmodeindex, 2 ); "POSITION MODE SENSOR".postln; },
)
});
// BUTTON X ----- GRANULAR PITCH MODE
if (msg[12]==1,
{
" /////////// ////////////////////////////!".postln },
{});
( ~btn2val = (~btn2val + 1) % 3 ) ;
if (msg[12] == 1,
switch(~btn2val,
0, { ~granulator1.set(\pitchmodeindex, 0 ); "PITCH MODE FIXED".postln; },
1, { ~granulator1.set(\pitchmodeindex, 1 ); "PITCH MODE RANDOM".postln; },
2, { ~granulator1.set(\pitchmodeindex, 2 ); "PITCH MODE SENSOR".postln; },
)
});
// BUTTON X ----- GRANULAR IMPULSE MODE
if (msg[12]==1,
{
"=========================================".postln },
{});
( ~btn2val = (~btn2val + 1) % 3 ) ;
// TOGGLE 1 ----> LOOP RECORDING MODE ON/OFF
switch( msg[12].asInteger,
0, { ~granulator1.set(\impulsemodeindex, 0 ); "IMPULSE MODE FIXED".postln; },
1, { ~granulator1.set(\impulsemodeindex, 1 ); "IMPULSE MODE DUST".postln; },
2, { ~granulator1.set(\impulsemodeindex, 2 ); "IMPULSE MODE SENSOR".postln; },
);
};
/* if (msg[13] == 1,
{ r.set(\l, 1); "LOOPING ON".postln; },
{ r.set(\l, 0); "LOOPING OFF".postln; });
);
// TOGGLE 2 ----> OVERDUB RECORDING MODE ON/OFF
// BUTTON X ----> LOOP RECORDING MODE ON/OFF
if (msg[14] == 1,
{ r.set(\overdub, 1); "OVERDUB ON".postln; },
{ r.set(\overdub, 0); "OVERDUB OFF".postln; },
if (msg[13]==1,
{
( ~btn2val = (~btn2val + 1) % 2 ) ;
);*/
switch( msg[13].asInteger,
0, { r.set(\l, 1); "RECORD LOOPING ON".postln; },
1, { r.set(\l, 0); "RECORD LOOPING OFF".postln; }
);
};
);
/* case
//{ msg[14] == 0} {"result".postln; msg.postln}
// BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
// BUTTON 0 && 3 RESET/ZERO SENSORS [in firmware]
// BUTTON 0 ----> RECORD TO BUFFER 0
{ msg[9] == 1 } { r.set( \in, 0, \l, 0, \t_trig, 1);
msg.postln; msg[9].postln; "SAMPLING!".postln }
if (msg[14]==1,
{
( ~btn2val = (~btn2val + 1) % 2 ) ;
switch( msg[14].asInteger,
0, { r.set(\overdub, 1); "SAMPLE OVERDUB ON".postln; },
1, { r.set(\overdub, 0); "SAMPLE OVERDUB OFF".postln; },
);
};
);
// BUTTON 0 + 3 ----> ZERO EULER / MPU6050
// TOGGLE O ----> OVERDUB MODE ON/OFF
{ msg[14] == 0 } { r.set(\overdub, 0); "OVERDUB OFF".postln; }
{ msg[14] == 1 } { r.set(\overdub, 1); "OVERDUB ON".postln; }
// TOGGLE 2
//{ msg[13] == 0 } { ~granulator1.set(\positionmodeindex, 1 ); }
//{ msg[13] == 1 } { ~granulator1.set(\positionmodeindex, 2 ); }
// TOGGLE 3 ----> LOOP RECORDING MODE ON/OFF
{ msg[13] == 0 } { "LOOPING OFF".postln; r.set(\l, 0); msg[13].postln;}
{ msg[13] == 1 } { "LOOPING ON! SAMPLING".postln; r.set(\l, 1); msg[13].postln; };*/
} , '/keys');
} , '/keys');
);
);

View File

@ -70,7 +70,7 @@ function openSerial() {
scon.on('message', msg => {
// Debug incoming osc
if (DEBUG) {
console.log('osc msg', msg)
//console.log('osc msg', msg)
}
sendAll(msg, null, null, osclients)
@ -207,49 +207,58 @@ const sendAll = (msg, info, oscWS, osclients) => {
setTimeout(waitFalse, 1000);
}
// LOGIC FOR MOMENTARY BUTTONS (0 - 3)
for (let i = 0; i < 4; i++) {
// momentary state between 0 and 1 console
// LOGIC FOR SHIFT BUTTON 0
for (let i = 0; i < 1; i++) {
// momentary state between 0 and 1
if (msg.address == '/keys') {
if (msg.args[i] <= threshold ) {
buttonValue[i] = 1;
} else {
buttonValue[i] = 0;
}
msg.args.push(buttonValue[i] ? 1 : 0)
}
}
// LOGIC FOR MOMENTARY BUTTONS (1 - 3)
for (let i = 1; i < 8; i++) {
// momentary state between 0 and 1
if (msg.address == '/keys') {
buttonValue[i] = 0;
//if (waiting == false){
if (msg.args[i] <= threshold ) {
if (buttonHeld[i] == false) {
buttonHeld[i] = true
buttonValue[i] = 1;
}
//wait4Second();
} else if (msg.args[i] >= threshold+5) {
buttonHeld[i] = false;
}
msg.args.push(buttonValue[i] ? 1 : 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 {
// 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[i-4]) {
switchHeld[i-4] = false
}
}
msg.args.push(switchValue[i-4] ? 1 : 0)
}
}
// if (switchHeld[i-4]) {
// switchHeld[i-4] = false
// }
// }
// msg.args.push(switchValue[i-4] ? 1 : 0)
// }
// }
//------------------------------------------------
// Convert quaternion diff to euler angle diff