touch interface improvements in sc

master
Rob Canning 2022-09-07 12:04:52 +02:00
parent d2ec85ba95
commit a32fef059f
2 changed files with 164 additions and 55 deletions

189
gtr.scd
View File

@ -13,11 +13,25 @@
Ljudmila OTF Hackathon, Maribor 1-6 March 2022 */
// GTR MAC address: 10:97:BD:36:D6:4E
(
s.reboot{
s.options.numBuffers = 1024 * 256; // increase this if you need to load more samples
s.options.sampleRate = 44100; // also tried with 44000 value
s.options.memSize = 8192 * 32; // increase this if you get "alloc failed" messages
s.options.numWireBufs = 64; // increase this if you get "exceeded number of interconnect buffers" messages
s.options.maxNodes = 1024 * 32; // increase this if you are getting drop outs and the message "too many nodes"
s.options.numInputBusChannels = 4;
s.options.numOutputBusChannels = 4;
} )
// RUNME 0 =========================================
s.boot();
// RUNME 1 =========================================
// -------------------------------------------------
( // SETUP ----------------------------------------- -
// ---------------------------------------------------
// Allocate a 4 second mono buffer
@ -33,6 +47,7 @@ thisProcess.openUDPPort(57121);
// RUNME 2 ==========================================
// -------------------------------------------------
( // DEFINE SYNTHS --------------------------------- <--
// -------------------------------------------------
@ -67,6 +82,7 @@ SynthDef("recBuf",{
);
// ---------~positionmode = 1; -------------------------------------------
( // Granulator --------------------------------------
// ----------------------------------------------------
@ -76,32 +92,39 @@ SynthDef("recBuf",{
//z = Buffer.sendCollection(s, winenv.discretize, 1);
// ~rndpos = LFNoise2.kr(0.1).range(0, 1);
SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
sndbuf, envbuf, pan=0, imp=50,
pitchmodeindex=0, sensorpitch=1, sensorgdur=0.1, sensorgpan=0,
positionmodeindex=0, gdurmodeindex=0, gpanmodeindex=0,
positionmodeindex=1, gdurmodeindex=0, gpanmodeindex=0,
sensorposition=0, impulsemodeindex=0, sensorimpulse=0,
rlow= -1, rhigh=1 |
signalChannelIndex=1,
rlow= -1, rhigh=10 |
var signal, env, freqdev, pos,
pitchmode0, pitchmode1, pitch,
gdurmode0, gdurmode1, gdurmode2, gdur,
gdurmode0, gdurmode1, gdurmode2, gdurmode3, gdurmode4, gdurmode5, gdurmode6, gdur,
gpanmode0, gpanmode1, gpan,
positionmode0, positionmode1, position,
impulsemode0, impulsemode1, impulse;
positionmode0, positionmode1, positionmode2, position,
impulsemode0, impulsemode1, impulse,
stereosignal, quadsignalL, quadsignalR, quadsignal, signalchannels;
// grain duration mode -untransposed, random, or sensor controlled
gdurmode0 = 0.1;
gdurmode1 = LFNoise1.kr.range(0.2, 3.3);
gdurmode2 = LFNoise1.kr.range(0.2, 3.3);
gdurmode0 = 0.05;
gdurmode1 = 0.1;
gdurmode2 = LFNoise1.kr.range(0.1, 0.3);
gdurmode3 = LFNoise1.kr.range(0.1, 0.6);
gdurmode4 = LFNoise1.kr.range(0.6, 0.6);
gdurmode5 = LFNoise1.kr.range(0.1, 2.6);
gdurmode6 = LFNoise1.kr.range(1, 2);
gdur = Select.kr(gdurmodeindex,
[gdurmode0, gdurmode1, gdurmode2, sensorgdur]);
[gdurmode0, gdurmode1, gdurmode2, gdurmode3, gdurmode4, gdurmode5, gdurmode6, sensorgdur]);
// grain pan mode -untransposed, random, or sensor controlled
gpanmode0 = 0.1;
gpanmode1 = LFNoise1.kr.range(0.1, 10.3);
gpanmode0 = 0;
gpanmode1 = LFNoise1.kr(100).range(-1, 1);
gpan = Select.kr(gpanmodeindex,
[gpanmode0, gpanmode1, sensorgpan]);
@ -109,13 +132,16 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
pitchmode0 = 1;
pitchmode1 = LFNoise1.kr.range(rlow, rhigh);
pitch = Select.kr(pitchmodeindex,
[pitchmode0, pitchmode1, sensorpitch]);
[pitchmode0, sensorpitch, pitchmode1 ]);
// granular playhead mode - fixed random or sensor controlled
positionmode0 = 1;
positionmode1 = LFNoise1.kr.range(0, 1);
positionmode0 = 0.1;
positionmode0 = (Phasor.ar(0, 1 * BufRateScale.ir(b), 0, BufSamples.ir(b)-1) + LFNoise1.ar(100).bipolar(0.1 * SampleRate.ir) ) / BufSamples.ir(b);
positionmode1 = LFNoise1.kr.range(0.05, 0.98);
positionmode2 = LFNoise1.kr.range(0.1, 0.2);
position = Select.kr(positionmodeindex,
[positionmode0, positionmode1, sensorposition]);
[positionmode0, positionmode1, positionmode2, sensorposition]);
// grain impulse frequency mode - random, metric or sensor based impulse modes
impulsemode0 = Impulse.kr(imp);
@ -123,18 +149,30 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
impulse = Select.kr(impulsemodeindex,
[impulsemode0, impulsemode1, sensorimpulse]);
env = EnvGen.kr(
env = EnvGen.kr(~gpanmode=1;
Env([0, 1, 0], [1, 1], \sin, 1), gate, levelScale: amp, doneAction: 2);
signal = GrainBuf.ar(2,
impulse, // selectable between impulse.kr and dust.kr
gdur, sndbuf, pitch, position, 2, gpan, envbuf);
signal = FreeVerb2.ar(signal[0], signal[1],
mix:0.4, room:0.5, damp:0
);
//signal = FreeVerb2.ar(signal[0], signal[1], mix:0.4, room:0.5, damp:0);
signal = signal* env;
Out.ar(0,signal);
stereosignal = signal* env;
quadsignalL = PanAz.ar(4, signal[0], MouseX.kr(0,2));
quadsignalR = PanAz.ar(4, signal[1], MouseX.kr(0,2).range(2,0));
quadsignal = signal; //Mix.ar([quadsignalL, quadsignalR]);
signalchannels = Select.ar(signalChannelIndex, [stereosignal, quadsignal]);
//signal = signalchannels;
Out.ar(0, signalchannels);
}).add;
);
)
@ -143,6 +181,7 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
// ----------------------------------------------------
(( // START SYNTHS ---------------------------------
// ----------------------------------------------------
@ -157,7 +196,19 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
// ----------------------------------------------------
(( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <--
// ----------------------------------------------------
~pitchmode = 0; ~positionmode = 0; ~impulsemode = 0; ~gdurmode=0; ~gpanmode=0;
~pitchmode = 0; ~positionmode = 0; ~impulsemode = 0; ~gdurmode=0; ~gpanmode=1; ~channelmode=0;
~btnstate = [];
~btnsA = [];
~btnsB = [];
~btnsC = [];
~btn0val = 0; ~btn1val = 0; ~btn2val = 0; ~btn3val = 0;
~btn4val = 0; ~btn5val = 0; ~btn6val = 0; ~btn7val = 0;
~btn8val = 0; // shift buttons
( // accel gyro quaternion mapping ///////////////////
// msg[1] msg[2] msg[3] X Y Z ==> ROLL, PITCH, YAW
@ -173,7 +224,7 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
~granulator1.set(\pitchmodeindex, ~pitchmode );
// POSITION ------- Z Yaw
~granulator1.set(\sensorposition, msg[2].linlin(-1, 1, 0, 4));
~granulator1.set(\sensorposition, msg[2].linlin(-1, 1, 0.05, 3.99));
~granulator1.set(\positionmodeindex, ~positionmode );
// RATE ------- X (roll [with PAN])
@ -186,6 +237,10 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
~granulator1.set(\sensorgpan, msg[2].linlin(-1, 1, -1, 1));
~granulator1.set(\gpanmodeindex, ~gpanmode );
~granulator1.set(\sensorgpan, msg[2].linlin(-1, 1, -1, 1));
~granulator1.set(\signalChannelIndex, ~channelmode );
//msg.postln;
}; , '/euler');
@ -195,16 +250,25 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
// button press mapping ///////////////////////////////
// ----------------------------------------------------
~btn0val = 0; ~btn1val = 0; ~btn2val = 0; ~btn3val = 0;
~btn4val = 0; ~btn5val = 0; ~btn6val = 0; ~btn7val = 0;
~btn8val = 0; // shift buttons
m = NetAddr("127.0.0.1", 57120); // loopback
m.sendMsg("/chat", "Hello App 1");
// send message back to nodejs
m = NetAddr("127.0.0.1", 57100);
m.sendMsg("/xyzc", 1);
m.sendMsg("/xyzc", 0);
p = OSCdef(\keys, { arg msg, time, addr, recvPort;
~btnsA[~btn2val, ~btn3val];
~btnsB[~btn4val, ~btn5val, ~btn6val, ~btn7val];
~btnsC[~btn5val];
~btnstate = [~btnsA, ~btnsB, ~btnsC];
if (msg[9] == 1 && msg[10] == 1, {~btnstate.postln;});
//msg.println;
// ==============================
// BUTTON MAPPING
@ -227,7 +291,7 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
0, { r.set(\l, 0); "RECORD LOOPING OFF".postln; },
1, { r.set(\l, 1); "RECORD LOOPING ON".postln; },
2, { r.set(\l, 1); "RECORDING ONSET DETECTION ON".postln; }, //todo
)
);
});
// BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
@ -242,17 +306,24 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
}, /// SHIFT 0 LOGIC ENDS HERE
{ // SHIFT IN STATE 1 =======================
{
// SHIFT IN STATE 1 =======================
// BUTTON X ----- GRAIN DURATION MODE
if (msg[15]==1,
{
( ~btn8val = (~btn8val + 1) % 4 ) ;
( ~btn8val = (~btn8val + 1) % 7 ) ;
switch(~btn8val,
0, { ~gdurmode = 0; "DURATION MODE 0".postln; },
1, { ~gdurmode = 1; "DURATION MODE 1".postln; },
2, { ~gdurmode = 2; "DURATION MODE 2".postln; },
3, { ~gdurmode = 3; "DURATION MODE 3".postln; },
0, { ~gdurmode = 0; ~granulator1.set(\imp, 40); "DURATION MODE 0".postln; },
1, { ~gdurmode = 1; ~granulator1.set(\imp, 0); "DURATION MODE 1".postln; },
2, { ~gdurmode = 2; ~granulator1.set(\imp, 20); "DURATION MODE 2".postln; },
3, { ~gdurmode = 3; ~granulator1.set(\imp, 15); "DURATION MODE 3".postln; },
4, { ~gdurmode = 4; ~granulator1.set(\imp, 10); "DURATION MODE 4".postln; },
5, { ~gdurmode = 5; ~granulator1.set(\imp, 5); "DURATION MODE 5".postln; },
6, { ~gdurmode = 6; ~granulator1.set(\imp, 3); "DURATION MODE 6".postln; },
)
});
@ -270,11 +341,21 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----- GRANULAR PITCH MODE
if (msg[14]==1,
{
( ~btn6val = (~btn6val + 1) % 3 ) ;
( ~btn6val = (~btn6val + 1) % 7 ) ;
switch(~btn6val,
0, { ~pitchmode = 0; "PITCH MODE FIXED".postln; },
1, { ~pitchmode = 1; "PITCH MODE RANDOM".postln; },
2, { ~pitchmode = 2; "PITCH MODE SENSOR".postln; },
1, { ~pitchmode = 1; "PITCH MODE SENSOR".postln; },
2, { ~pitchmode = 2; ~granulator1.set(\rlow, 0.8); ~granulator1.set(\rhigh, 1.2); "PITCH RANDOM 1".postln; },
3, { ~pitchmode = 2; ~granulator1.set(\rlow, 0); ~granulator1.set(\rhigh, 1.5); "PITCH MODE RANDOM 2".postln; },
4, { ~pitchmode = 2; ~granulator1.set(\rlow, -1.5 ); ~granulator1.set(\rhigh, 0); "PITCH MODE RANDOM 3".postln; },
5, { ~pitchmode = 2; ~granulator1.set(\rlow, -5 ); ~granulator1.set(\rhigh, 5); "PITCH MODE RANDOM 4".postln; },
6, { ~pitchmode = 2; ~granulator1.set(\rlow, -30 ); ~granulator1.set(\rhigh, 30); "PITCH MODE RANDOM 5".postln; },
7, { ~pitchmode = 2; ~granulator1.set(\rlow, -100 ); ~granulator1.set(\rhigh, 100); "PITCH MODE RANDOM 6".postln; },
~granulator1.set(\rhigh, 2);
2, { },
)
});
@ -293,6 +374,7 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X && X RESET/ZERO SENSORS [in firmware just here for notificaton]
if (msg[12] == 1, { " ===== EULER ZEROED! =====".postln }, {});
// GTR INPUT =======================
if (msg[11]==1,
{
@ -303,16 +385,13 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
2, { ~gtrIn.set(\in, 1 ); "DRY + REVERB ON".postln; },
)
});
} // SHIFT ONE LOGIC ENDS HERE ================
); /// closes SHIFT 1
} , '/keys');
);
);
GUI
// ----------------------------------------------------
// ----------------------------------------------------
// PERFORMABLE PARAMETERS /////////////////////////////
@ -330,18 +409,22 @@ r.set(\overdub, 1); // overdub mode on - MAPPED TO SWITCH 4
r.set(\overdub, 0); // off
/// random pitch/rate low and high values
~granulator1.set(\rlow, 0);
~granulator1.set(\rlow, -1);
~granulator1.set(\rhigh, 1);
~granulator1.set(\rlow, 0.2);
~granulator1.set(\rhigh, 2);
~granulator1.set(\rhigh, 1.2);
~impulsemode = 0; // impulse
~impulsemode = 1; // dust
~impulsemode = 2; // sensor
~pitchmode = 0; // no transpose
~pitchmode = 1; // random
~pitchmode = 2; // sensor (pitch) input
~pitchmode = 1; // sensor (pitch) input
~pitchmode = 2; // random2
~pitchmode = 3; // random3
~pitchmode = 4; // random4
~pitchmode = 5; // random5
~pitchmode = 6; //
~positionmode = 0; // middle of sample
~positionmode = 1; // random position
@ -350,13 +433,21 @@ r.set(\overdub, 0); // off
~gdurmode = 0 ; // random position
~gdurmode = 1 ; // random position
~gdurmode = 2 ; // random position
~gdurmode = 3 ; // random position
~gdurmode = 4 ; // random position
~gdurmode = 5 ; // random position
~gdurmode = 6 ; // random position
~gpanmode = 0 ; // random position
~gpanmode = 1 ; // random position
~gpanmode = 2 ; // random position
~channelmode = 1;
// set grain impulse rate
~granulator1.set(\imp, 50);
~granulator1.set(\imp, 10);
// fix doneaction
~granulator1.set(\gate, 1); // granulator on

View File

@ -133,9 +133,21 @@ const scudp = new osc.UDPPort({
scudp.on('open', () => {
console.log("UDP to OSC open")
})
});
// turn on and off osc messages sent to UDP / Supercollider
scudp.on('message', (msg) => {
if (msg.address == "/xyzc"){
if ( msg.args[0] == '1' )
{ console.log("XYZ ON ---- ", msg.args[0]); osconoff = 1; }
else { console.log("XYZ OFF ---- "); console.log("ddddd", msg.args[0]); osconoff = 0 }
}
});
scudp.on('message', (msg) => {
console.log('got UDP msg', msg);
osclients.forEach( client => {
if (client) {
@ -144,6 +156,7 @@ scudp.on('message', (msg) => {
}
})
})
scudp.on('error', (e) => {
console.log('UDP OSC error!', e)
})
@ -190,11 +203,15 @@ var threshdiff = 4;
var touchvalue = [40,40,40,40,40,40,40,40];
var touchcount = [0,0,0,0,0,0,0,0];
var osconoff = 0;
const sendAll = (msg, info, oscWS, osclients) => {
//if (msg.address == '/XYZcontrols') console.log("XYZ ON ------------------------------------ ", msg[1]);
if (msg.address == '/keys') {
console.log("TOUCH MSG",msg.args);
//console.log("TOUCH MSG",msg.args);
for (let i = 1; i < 8; i++) {
touchvalue[i]=msg.args[i];
@ -213,8 +230,8 @@ const sendAll = (msg, info, oscWS, osclients) => {
thresholds[i]=Math.round(floatthresholds[i]);
}
}
console.log("TOUCH FLTHR ",floatthresholds);
console.log("TOUCH THR ",thresholds);
//console.log("TOUCH FLTHR ",floatthresholds);
//console.log("TOUCH THR ",thresholds);
/* // LOGIC FOR SHIFT BUTTON 0
@ -312,8 +329,9 @@ const sendAll = (msg, info, oscWS, osclients) => {
})
if (scudp) {
console.log("SENDING UDP", msg)
scudp.send(msg)
if (osconoff == 1)
console.log("SENDING UDP", msg); scudp.send(msg)
//msg.slice(7,15);
//scudp.send(msg.slice(7,15))
}