new button logic in supercollider

master
Rob Canning 2022-09-05 10:02:57 +02:00
parent 3f595e5750
commit d2ec85ba95
2 changed files with 101 additions and 104 deletions

155
gtr.scd
View File

@ -11,10 +11,7 @@
|/ '-' '-' |/ '-' '-'
Ljudmila OTF Hackathon, Maribor 1-6 March 2022 */ Ljudmila OTF Hackathon, Maribor 1-6 March 2022 */
// GTR MAC address: 10:97:BD:36:D6:4E
////////////////////////////////////////////
// guitar MAC address 98:CD:AC:63:78:E2
// RUNME 0 ========================================= // RUNME 0 =========================================
s.boot(); s.boot();
@ -35,6 +32,7 @@ thisProcess.openUDPPort(57121);
// RUNME 2 ========================================== // RUNME 2 ==========================================
// ------------------------------------------------- // -------------------------------------------------
( // DEFINE SYNTHS --------------------------------- <-- ( // DEFINE SYNTHS --------------------------------- <--
// ------------------------------------------------- // -------------------------------------------------
@ -53,11 +51,11 @@ SynthDef("dryIn", { arg in=0, out=0;
( // mono buffer recorder ---------------------------- ( // mono buffer recorder ----------------------------
// with loop and overdub modes ///////////////////// // with loop and overdub modes /////////////////////
// make record togglable between looping, direct or onset detection trigger // make record togglable between looping, direct or onset detection trigger
SynthDef("recBuf",{ arg in=0, out=0, bufnum=0, t_trig=0, l=0, overdub=0;
SynthDef("recBuf",{
arg in=0, out=0, bufnum=0, t_trig=0, l=0, overdub=0;
var sig, chain, onsets; var sig, chain, onsets;
sig = SoundIn.ar(in); sig = SoundIn.ar(in);
// Onsets // Onsets
chain = FFT(LocalBuf(512), sig); chain = FFT(LocalBuf(512), sig);
onsets = Onsets.kr(chain, MouseX.kr(0,1), \rcomplex); onsets = Onsets.kr(chain, MouseX.kr(0,1), \rcomplex);
@ -88,7 +86,7 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
var signal, env, freqdev, pos, var signal, env, freqdev, pos,
pitchmode0, pitchmode1, pitch, pitchmode0, pitchmode1, pitch,
gdurmode0, gdurmode1, gdur, gdurmode0, gdurmode1, gdurmode2, gdur,
gpanmode0, gpanmode1, gpan, gpanmode0, gpanmode1, gpan,
positionmode0, positionmode1, position, positionmode0, positionmode1, position,
impulsemode0, impulsemode1, impulse; impulsemode0, impulsemode1, impulse;
@ -96,8 +94,10 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
// grain duration mode -untransposed, random, or sensor controlled // grain duration mode -untransposed, random, or sensor controlled
gdurmode0 = 0.1; gdurmode0 = 0.1;
gdurmode1 = LFNoise1.kr.range(0.2, 3.3); gdurmode1 = LFNoise1.kr.range(0.2, 3.3);
gdurmode2 = LFNoise1.kr.range(0.2, 3.3);
gdur = Select.kr(gdurmodeindex, gdur = Select.kr(gdurmodeindex,
[gdurmode0, gdurmode1, sensorgdur]); [gdurmode0, gdurmode1, gdurmode2, sensorgdur]);
// grain pan mode -untransposed, random, or sensor controlled // grain pan mode -untransposed, random, or sensor controlled
gpanmode0 = 0.1; gpanmode0 = 0.1;
@ -142,6 +142,7 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
// RUNME 3 ========================================== // RUNME 3 ==========================================
// ---------------------------------------------------- // ----------------------------------------------------
(( // START SYNTHS --------------------------------- (( // START SYNTHS ---------------------------------
// ---------------------------------------------------- // ----------------------------------------------------
@ -156,7 +157,7 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 1,
// ---------------------------------------------------- // ----------------------------------------------------
(( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <-- (( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <--
// ---------------------------------------------------- // ----------------------------------------------------
~pitchmode = 0; ~positionmode = 2; ~impulsemode = 0; ~gdurmode=0; ~gpanmode=0; ~pitchmode = 0; ~positionmode = 0; ~impulsemode = 0; ~gdurmode=0; ~gpanmode=0;
( // accel gyro quaternion mapping /////////////////// ( // accel gyro quaternion mapping ///////////////////
// msg[1] msg[2] msg[3] X Y Z ==> ROLL, PITCH, YAW // msg[1] msg[2] msg[3] X Y Z ==> ROLL, PITCH, YAW
@ -194,7 +195,14 @@ o = OSCdef(\test, { arg msg, time, addr, recvPort, rlow, rhigh;
// button press mapping /////////////////////////////// // button press mapping ///////////////////////////////
// ---------------------------------------------------- // ----------------------------------------------------
~btn2val = 0; ~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");
p = OSCdef(\keys, { arg msg, time, addr, recvPort; p = OSCdef(\keys, { arg msg, time, addr, recvPort;
//msg.println; //msg.println;
@ -211,26 +219,48 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
if (msg[10] == 1, { r.set( \in, 0, \l, 0, \t_trig, 1); if (msg[10] == 1, { r.set( \in, 0, \l, 0, \t_trig, 1);
" /////////// SAMPLING!".postln }, {}); " /////////// SAMPLING!".postln }, {});
// BUTTON X ----> LOOP RECORDING MODE ON/OFF
if (msg[11]==1,
if (msg[16]==1,
{ {
( ~btn2val = (~btn2val + 1) % 3 ) ; ( ~btn4val = (~btn4val + 1) % 3 ) ;
switch( ~btn4val,
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
)
});
switch(~btn2val, // BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
0, { ~positionmode = 0; "TEST MODE FIXED".postln; }, if (msg[12]==1,
1, { ~positionmode = 1; "POSITION MODE RANDOM".postln; }, {
2, { ~positionmode = 2; "POSITION MODE SENSOR".postln; }, ( ~btn2val = (~btn2val + 1) % 2 ) ;
switch( ~btn2val,
0, { r.set(\overdub, 0); "SAMPLE OVERDUB OFF".postln; },
1, { r.set(\overdub, 1); "SAMPLE OVERDUB ON".postln; },
)
});
}, /// SHIFT 0 LOGIC ENDS HERE
{ // SHIFT IN STATE 1 =======================
// BUTTON X ----- GRAIN DURATION MODE
if (msg[15]==1,
{
( ~btn8val = (~btn8val + 1) % 4 ) ;
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; },
) )
}); });
// BUTTON X ----- GRANULAR POSITION MODE // BUTTON X ----- GRANULAR POSITION MODE
if (msg[13]==1,
if (msg[11]==1,
{ {
( ~btn2val = (~btn2val + 1) % 3 ) ; ( ~btn3val = (~btn3val + 1) % 3 ) ;
switch(~btn3val,
switch(~btn2val,
0, { ~positionmode = 0; "POSITION MODE FIXED".postln; }, 0, { ~positionmode = 0; "POSITION MODE FIXED".postln; },
1, { ~positionmode = 1; "POSITION MODE RANDOM".postln; }, 1, { ~positionmode = 1; "POSITION MODE RANDOM".postln; },
2, { ~positionmode = 2; "POSITION MODE SENSOR".postln; }, 2, { ~positionmode = 2; "POSITION MODE SENSOR".postln; },
@ -238,70 +268,41 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
}); });
// BUTTON X ----- GRANULAR PITCH MODE // BUTTON X ----- GRANULAR PITCH MODE
if (msg[14]==1,
if (msg[15]==1,
{ {
( ~btn2val = (~btn2val + 1) % 3 ) ; ( ~btn6val = (~btn6val + 1) % 3 ) ;
switch(~btn6val,
switch(~btn2val, 0, { ~pitchmode = 0; "PITCH MODE FIXED".postln; },
0, { ~granulator1.set(\pitchmodeindex, 0 ); "PITCH MODE FIXED".postln; }, 1, { ~pitchmode = 1; "PITCH MODE RANDOM".postln; },
1, { ~granulator1.set(\pitchmodeindex, 1 ); "PITCH MODE RANDOM".postln; }, 2, { ~pitchmode = 2; "PITCH MODE SENSOR".postln; },
2, { ~granulator1.set(\pitchmodeindex, 2 ); "PITCH MODE SENSOR".postln; },
) )
}); });
// BUTTON X ----- GRANULAR IMPULSE MODE // BUTTON X ----- GRANULAR IMPULSE MODE
if (msg[16]==1,
if (msg[12]==1,
{ {
( ~btn2val = (~btn2val + 1) % 3 ) ; ( ~btn7val = (~btn7val + 1) % 3 ) ;
switch( ~btn7val,
switch( msg[12].asInteger,
0, { ~granulator1.set(\impulsemodeindex, 0 ); "IMPULSE MODE FIXED".postln; }, 0, { ~granulator1.set(\impulsemodeindex, 0 ); "IMPULSE MODE FIXED".postln; },
1, { ~granulator1.set(\impulsemodeindex, 1 ); "IMPULSE MODE DUST".postln; }, 1, { ~granulator1.set(\impulsemodeindex, 1 ); "IMPULSE MODE DUST".postln; },
2, { ~granulator1.set(\impulsemodeindex, 2 ); "IMPULSE MODE SENSOR".postln; }, 2, { ~granulator1.set(\impulsemodeindex, 2 ); "IMPULSE MODE SENSOR".postln; },
); )
}; });
);
// BUTTON X ----> LOOP RECORDING MODE ON/OFF
if (msg[13]==1, // 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,
{ {
( ~btn2val = (~btn2val + 1) % 2 ) ; ( ~btn2val = (~btn2val + 1) % 3 ) ;
switch(~btn2val,
switch( msg[13].asInteger, 0, { ~gtrIn.set(\in, 1 ); "DRY SIGNAL OFF".postln; },
0, { r.set(\l, 1); "RECORD LOOPING ON".postln; }, 1, { ~gtrIn.set(\in, 0 ); "DRY SIGNAL ON".postln; },
1, { r.set(\l, 0); "RECORD LOOPING OFF".postln; } 2, { ~gtrIn.set(\in, 1 ); "DRY + REVERB ON".postln; },
); )
}; });
);
// BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
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; },
);
};
);
}, /// SHIFT 0 LOGIC ENDS HERE
{ // SHIFT IN STATE 1 =======================
// BUTTON X && X RESET/ZERO SENSORS [in firmware]
if (msg[11] == 1,
{ " ===== EULER ZEROED! =====".postln },
{});
} // SHIFT ONE LOGIC ENDS HERE ================ } // SHIFT ONE LOGIC ENDS HERE ================
@ -311,7 +312,7 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
); );
); );
GUI
// ---------------------------------------------------- // ----------------------------------------------------
// ---------------------------------------------------- // ----------------------------------------------------
// PERFORMABLE PARAMETERS ///////////////////////////// // PERFORMABLE PARAMETERS /////////////////////////////
@ -332,7 +333,7 @@ r.set(\overdub, 0); // off
~granulator1.set(\rlow, 0); ~granulator1.set(\rlow, 0);
~granulator1.set(\rlow, -1); ~granulator1.set(\rlow, -1);
~granulator1.set(\rhigh, 1); ~granulator1.set(\rhigh, 1);
~granulator1.set(\rhigh, 3); ~granulator1.set(\rhigh, 2);
~impulsemode = 0; // impulse ~impulsemode = 0; // impulse
~impulsemode = 1; // dust ~impulsemode = 1; // dust

View File

@ -130,11 +130,7 @@ float GyX, GyY, GyZ;
// Keys // Keys
//byte keys[] = {16, 17, 5, 18}; //byte keys[] = {16, 17, 5, 18};
// noise on
byte keys[] = {4, 0, 2, 15, 13, 14, 12, 27}; // TOUCH0 - TOUCH7 byte keys[] = {4, 0, 2, 15, 13, 14, 12, 27}; // TOUCH0 - TOUCH7
//byte keys[] = {33, 0, 2, 15, 13, 14, 12, 27}; // TOUCH8, TOUCH1 - TOUCH7
byte pressed[] = {0, 0, 0, 0, 0, 0, 0, 0}; byte pressed[] = {0, 0, 0, 0, 0, 0, 0, 0};
byte KEYLEN = 8; byte KEYLEN = 8;
@ -188,6 +184,7 @@ int touchValue;
void setup() { void setup() {
pinMode(32, OUTPUT);
// Basic(debug) serial init // Basic(debug) serial init
Serial.begin(115200); // set this as high as you can reliably run on your platform Serial.begin(115200); // set this as high as you can reliably run on your platform
Serial.println("Starting up..."); Serial.println("Starting up...");
@ -301,6 +298,7 @@ void setup() {
} }
void loop() { void loop() {
// LED ON
// capacitive ------------------ // capacitive ------------------
@ -390,7 +388,7 @@ void loop() {
speed += speedGain; speed += speedGain;
bundle.add("/position/").add(position(0)).add(position(1)).add(position(2)); bundle.add("/position/").add(position(0)).add(position(1)).add(position(2));
bundle.add("/speed/").add(speed(0)).add(speed(1)).add(speed(2)); bundle.add("3/speed/").add(speed(0)).add(speed(1)).add(speed(2));
*/ */
// Accelerometer // Accelerometer
bundle.add("/accel").add(AcX).add(AcY).add(AcZ); ; // X Y Z bundle.add("/accel").add(AcX).add(AcY).add(AcZ); ; // X Y Z
@ -400,15 +398,13 @@ void loop() {
// Send keys // Send keys
for(int i = 0; i < KEYLEN; i++) { for(int i = 0; i < KEYLEN; i++) {
//pressed[i] = !digitalRead(keys[i]);
pressed[i] = touchRead(keys[i]); pressed[i] = touchRead(keys[i]);
bundle.getOSCMessage("/keys")->add(pressed[i]); bundle.getOSCMessage("/keys")->add(pressed[i]);
} }
if (pressed[0] != 0 ){ digitalWrite(32, HIGH);}
else { digitalWrite(32, LOW); };
// Reset calibration euler? // Reset calibration euler?
if (pressed[0] && pressed[1] && pressed[2] && pressed[3]) { if (pressed[0] && pressed[1] && pressed[2] && pressed[3]) {
if (!reset) { if (!reset) {