Compare commits

...

2 Commits

Author SHA1 Message Date
Rob Canning 69fc075715 fixed spatialisation and tuned pitch transpositions Dseq 2022-09-13 13:00:57 +02:00
Rob Canning 199c07c246 broken quadraphonic granular 2022-09-12 14:36:54 +02:00
1 changed files with 102 additions and 89 deletions

191
gtr.scd
View File

@ -1,28 +1,5 @@
////////////////////////////////////////////////////
/* GRANULATING SAMPLER INSTRUMENT //////////////////
////////////////////////////////////rc@kiben.net////
////////////////////////////////////////////////////
| .-.
| / \ .-.
| / \ / \ .-. .-. _
+--/-------\-----/-----\-----/---\---/---\---/-\-
| / \ / \ / '-' '-'
|/ '-' '-'
Ljudmila OTF Hackathon, Maribor 1-6 March 2022 */
// GTR MAC address: 10:97:BD:36:D6:4E
// DUMP ALL OSC MESSAGES (for debugging) ////////
OSCFunc.trace(true);
OSCFunc.trace(false);
thisProcess.openPorts;
(
s.reboot{
s.options.numBuffers = 1024 * 256; // increase this if you need to load more samples
@ -36,12 +13,16 @@ s.reboot{
} )
// RUNME 0 =========================================
s.boot();
// RUNME 1 =========================================
// -------------------------------------------------
( // SETUP ----------------------------------------- -
// ---------------------------------------------------
// Allocate a 4 second mono buffer
@ -56,6 +37,7 @@ thisProcess.openUDPPort(57121);
// RUNME 2 ==========================================
// -------------------------------------------------
( // DEFINE SYNTHS --------------------------------- <--
// -------------------------------------------------
( // direct signal + reverb -------------------------
@ -69,7 +51,6 @@ SynthDef("dryIn", { arg in=0, instrPanModeIndex=0, out=0, sensorInstrPan=0;
instrPanMode4 = LFSaw.kr(0.33).bipolar.range(-1,1);
instrPanMode5 = LFNoise1.kr(10).range(-1, 1);
instrPan = Select.kr(instrPanModeIndex,
[instrPanMode0, instrPanMode1, instrPanMode2, instrPanMode3, instrPanMode4, instrPanMode5, sensorInstrPan]);
@ -115,16 +96,16 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
pitchmodeindex=0, sensorpitch=1, sensorgdur=0.1, sensorgpan=0,
positionmodeindex=0, gdurmodeindex=0, gpanmodeindex=0,
sensorposition=0, impulsemodeindex=0, sensorimpulse=0,
signalChannelIndex=1,
signalChannelIndex=1, dseqarrayIndex=1,
rlow= -1, rhigh=10 |
var signal, env, freqdev, pos,
pitchmode0, pitchmode1, pitchmode2, pitch,
pitchmode0, pitchmode1, pitchmode2,pitchmode3,pitchmode4,pitchmode5, pitchmode6, pitch,
gdurmode0, gdurmode1, gdurmode2, gdurmode3, gdurmode4, gdurmode5, gdurmode6, gdur,
gpanmode0, gpanmode1, gpanmode2, gpan,
positionmode0, positionmode1, positionmode2, positionmode3, position,
impulsemode0, impulsemode1, impulse,
stereosignal, quadsignalL, quadsignalR, quadsignal, signalchannels;
impulsemode0, impulsemode1, impulse, xdseq, dseq_array1, dseq_array2, dseq_array3, dseq_array4, dseq_array5, dseq_array6, stereosignal, quadsignalL, quadsignalR, quadsignal, signalchannels;
// grain duration mode -untransposed, random, or sensor controlled
gdurmode0 = 0.2;
@ -145,16 +126,33 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
gpan = Select.kr(gpanmodeindex,
[gpanmode0, gpanmode1, gpanmode2, sensorgpan]);
// grain pitch mode -untransposed, random, or sensor controlled
// grain pitch mode -untransposed, random, or sensor controlled
~dseq = Dseq([1,-1, 2, 1, -1.5, 1, 1.75, 1, -0.5, 1, 3, 1, 2.25, 1 -0.125, 1], inf);
Scale.minor.degrees.midiratio;
dseq_array1 = Dseq([1,-1, 2, 1, -1.5, 1, 1.33, 1, -0.5, 1, 3, 1, 2.37, 1, -0.33, 1], inf);
dseq_array2 = Dseq([1,-1, -0.5, 1, 1.33, 1], inf);
dseq_array3 = Drand([(1..5).mirror.midiratio], inf);
dseq_array4 = Drand(Scale.minor.degrees.midiratio, inf);
dseq_array5 = Dseq([1,-1, -0.5, 1, 1.33, 1], inf);
//
//
// xdseq = [dseq_array1, dseq_array2,dseq_array3, dseq_array4, dseq_array5];
dseqarrayIndex =1;
pitchmode0 = 1;
pitchmode1 = Demand.kr(Impulse.kr(imp), 0, ~dseq);
pitchmode2 = LFNoise1.kr(imp).range(rlow, rhigh);
pitchmode1 = Demand.kr(Impulse.kr(imp), 0, Dseq([1,-1, 2, 1, -1.5, 1, 1.33, 1, -0.5, 1, 3, 1, 2.37, 1, -0.33, 1], inf));
pitchmode2 = Demand.kr(Impulse.kr(imp), 0, Drand(Scale.minor.degrees.midiratio, inf) * Drand([0.5, 0.25,1,2], inf));
pitchmode3 = Demand.kr(Impulse.kr(imp), 0, Dseq([1,-1, -0.5, 1, 1.33, 1], inf));
pitchmode4 = Demand.kr(Impulse.kr(imp), 0, Drand([0.5, 0.25,1,2], inf));
pitchmode5 = Demand.kr(Impulse.kr(imp), 0, Drand(Scale.diminished.degrees.midiratio, inf));
pitchmode6 = LFNoise1.kr(imp).range(rlow, rhigh);
pitch = Select.kr(pitchmodeindex,
[pitchmode0, sensorpitch, pitchmode1, pitchmode2 ]);
[pitchmode0, sensorpitch, pitchmode1, pitchmode2 ,pitchmode3, pitchmode4, pitchmode5, pitchmode6]);
// granular playhead mode - fixed random or sensor controlled
@ -176,20 +174,14 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
signal = TGrains.ar(4, impulse, b, pitch, position, gdur, gpan, amp, 4) * env;
stereosignal = signal;
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);
Out.ar(0, signal);
}).add;
);
)
// RUNME 3 ==========================================
// ----------------------------------------------------
(( // START SYNTHS ---------------------------------
@ -197,7 +189,7 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
// TODO NO EPRAND IN INSTR!
r = Synth(\recBuf, [\in, 0, \out, 0, \bufnum, b, \t_trig, 0]); // recorder
~g1 = Synth(\buf_grain, [\sndbuf, b, \amp, exprand(0.4, 0.9), \envbuf, -1, \gate, 1, doneAction: 2]); // granulate
~g1 = Synth(\buf_grain, [\sndbuf, b, \amp, 0.5, \envbuf, -1, \gate, 1, doneAction: 2]); // granulate
~gtrIn = Synth(\dryIn); // dry audio signaL
));
@ -205,20 +197,28 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
// RUNME 4 ==========================================
// ----------------------------------------------------
(( // OSC Receivers // ENABLE SENSOR AND SWITCH VALUES <--
// ----------------------------------------------------
~pitchmode = 0; ~positionmode = 0; ~impulsemode = 1;
~gdurmode=0; ~gpanmode=0; ~channelmode=0;
~instrPanMode =0;
~gdurmode=0; ~gpanmode=0; ~channelmode=0;
~instrPanMode=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
~btn0val = -1; ~btn1val = -1; ~btn2val = -1; ~btn3val = -1;
~btn4val = -1; ~btn5val = -1; ~btn6val = -1; ~btn7val = -1;
~btn8val = -1; // shift buttons
~btn9val = -1; ~btn10val = -1; ~btn11val = -1; ~btn12val = -1;
~btn13val = -1; ~btn14val = -1; ~btn15val = -1; ~btn16val = -1;
( // accel gyro quaternion mapping ///////////////////
// msg[1] msg[2] msg[3] X Y Z ==> ROLL, PITCH, YAW
@ -247,10 +247,10 @@ SynthDef(\buf_grain, { | out, gate = 1, amp = 0.5,
~g1.set(\sensorgpan, msg[2]);
~g1.set(\gpanmodeindex, ~gpanmode );
~g1.set(\sensorgpan, msg[2].linlin(-1, 1, -1, 1));
~g1.set(\signalChannelIndex, ~channelmode );
//~g1.set(\sensorgpan, msg[2].linlin(-1, 1, -1, 1));
//~g1.set(\signalChannelIndex, ~channelmode );
~gtrIn.set(\instrPan, msg[2].linlin(-1, 1, -1, 1));
~gtrIn.set(\sensorInstrPan, msg[2].wrap(0, 5).linlin(0, 5, -1, 1));
~gtrIn.set(\instrPanModeIndex, ~instrPanMode);
//msg.postln;
@ -295,8 +295,8 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----> LOOP RECORDING MODE ON/OFF
if (msg[11]==1,
{
( ~btn4val = (~btn4val + 1) % 3 ) ;
switch( ~btn4val,
( ~btn2val = (~btn2val + 1) % 3 ) ;
switch( ~btn2val,
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
@ -306,13 +306,13 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----> OVERDUB RECORDING MODE ON/OFF
if (msg[12]==1,
{
( ~btn2val = (~btn2val + 1) % 5 ) ;
switch( ~btn2val,
0, { r.set(\overdub, 0); "SAMPLE OVERDUB OFF".postln; },
1, { r.set(\overdub, 0.5); "SAMPLE OVERDUB ON 50%".postln; },
( ~btn3val = (~btn3val + 1) % 5 ) ;
switch( ~btn3val,
0, { r.set(\overdub, 0); "SAMPLE OVERDUB OFF".postln; },
1, { r.set(\overdub, 0.5); "SAMPLE OVERDUB ON 50%".postln; },
2, { r.set(\overdub, 0.75); "SAMPLE OVERDUB ON 75%".postln; },
3, { r.set(\overdub, 0.90); "SAMPLE OVERDUB ON 90%".postln; },
4, { r.set(\overdub, 1); "SAMPLE OVERDUB ON 100%".postln; },
4, { r.set(\overdub, 1); "SAMPLE OVERDUB ON 100%".postln; },
)
});
@ -322,23 +322,22 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
/////////////////// RESET RANDOM PITCH TO FIXED PITCH IN ONE TAP
if (msg[14]==1,
{
( ~btn6val = (~btn6val + 1) % 2 ) ;
( ~btn5val = (~btn5val + 1) % 2 ) ;
switch( ~btn6val,
switch( ~btn5val,
0, { ~pitchmode = 0; "PITCH RESET TO UNTRANSPOSED MODE".postln; },
1, { ~pitchmode = 1; "PITCH IN SENSOR MODE".postln; }
);
});
// INCREASE IMPULSE RATE ---------------------------------------
if (msg[15]==1,
{
( ~btn7val = (~btn7val + 1) % 8 ) ;
switch(~btn7val,
0, { ~g1.set(\imp, 0); "IMPULSE = 0".postln; },
( ~btn6val = (~btn6val + 1) % 8 ) ;
switch(~btn6val,
0, { ~g1.set(\imp, 1); "IMPULSE = 1".postln; },
1, { ~g1.set(\imp, 2); "IMPULSE = 2".postln; },
2, { ~g1.set(\imp, 4); "IMPULSE = 4".postln; },
3, { ~g1.set(\imp, 8); "IMPULSE = 8".postln; },
@ -352,16 +351,15 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----- G PANNING MODE
if (msg[16]==1,
{
( ~btn8val = (~btn8val + 1) % 3 ) ;
switch( ~btn8val,
0, { ~gpanmode = 0 ;"PAN STEREO".postln; },
( ~btn7val = (~btn7val + 1) % 3 ) ;
switch( ~btn7val,
0, { ~gpanmode = 0 ; "PAN STEREO".postln; },
1, { ~gpanmode = 1 ; "PAN QUAD ROTATIONS".postln; },
2, { ~gpanmode = 2 ; "PAN RANDOM QUAD".postln; },
)
});
}, /// SHIFT 0 LOGIC ENDS HERE --------------------------------------------
{
@ -371,8 +369,10 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// GTR INPUT =======================
if (msg[11]==1,
{
( ~btn2val = (~btn2val + 1) % 7 ) ;
switch(~btn2val,
( ~btn10val = (~btn10val + 1) % 9 ) ;
switch(~btn10val,
0, { ~gtrIn.set(\in, 1 ); "DRY SIGNAL OFF".postln; },
1, { ~gtrIn.set(\in, 0 ); ~instrPanMode=0; "DRY FRONT {STERE0}".postln; },
2, { ~gtrIn.set(\in, 0 ); ~instrPanMode=1; "DRY BACK {STERE0}".postln; },
@ -380,6 +380,9 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
4, { ~gtrIn.set(\in, 0 ); ~instrPanMode=3; "DRY L/R PAN {STEREO}".postln; },
5, { ~gtrIn.set(\in, 0 ); ~instrPanMode=4; "DRY ROTATE {QUAD}".postln; },
6, { ~gtrIn.set(\in, 0 ); ~instrPanMode=5; "DRY RaND {QUAD}".postln; },
7, { ~gtrIn.set(\in, 0 ); ~instrPanMode=6; "DRY SENSOR {QUAD}".postln; },
8, { ~gtrIn.set(\in, 0 ); ~instrPanMode=7; "DRY SENSOR {QUAD}".postln; },
)
});
@ -391,8 +394,8 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----- GRANULAR POSITION MODE
if (msg[13]==1,
{
( ~btn3val = (~btn3val + 1) % 5 ) ;
switch(~btn3val,
( ~btn12val = (~btn12val + 1) % 5 ) ;
switch(~btn12val,
0, { ~positionmode = 0; "POSITION MODE FIXED".postln; },
1, { ~positionmode = 1; "POSITION MODE LOOPING".postln; },
2, { ~positionmode = 2; "POSITION MODE RANDOM".postln; },
@ -404,26 +407,26 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----- GRANULAR PITCH MODE
if (msg[14]==1,
{
( ~btn6val = (~btn6val + 1) % 7 ) ;
switch(~btn6val,
0, { ~pitchmode = 2; "mode 2".postln; },
1, { ~pitchmode = 2; "mode 2 reserve".postln; },
2, { ~pitchmode = 3; ~g1.set(\rlow, 0.8); ~g1.set(\rhigh, 1.2); "PITCH RANDOM 1".postln; },
3, { ~pitchmode = 3; ~g1.set(\rlow, 0.01); ~g1.set(\rhigh, 1.5); "PITCH MODE RANDOM 2".postln; },
4, { ~pitchmode = 3; ~g1.set(\rlow, -1.5 ); ~g1.set(\rhigh, 1.5); "PITCH MODE RANDOM 3".postln; },
5, { ~pitchmode = 3; ~g1.set(\rlow, -5 ); ~g1.set(\rhigh, 5); "PITCH MODE RANDOM 4".postln; },
6, { ~pitchmode = 3; ~g1.set(\rlow, -10 ); ~g1.set(\rhigh, 10); "PITCH MODE RANDOM 5".postln; },
7, { ~pitchmode = 3; ~g1.set(\rlow, -30 ); ~g1.set(\rhigh, 30); "PITCH MODE RANDOM 6".postln; },
( ~btn13val = (~btn13val + 1) % 8 ) ;
switch(~btn13val,
0, { ~pitchmode = 2; "pitch array 0".postln; },
1, { ~pitchmode = 3; "pitch array 1".postln; },
2, { ~pitchmode = 4; "pitch array 2".postln; },
3, { ~pitchmode = 5; "pitch array 3".postln; },
4, { ~pitchmode = 6; "pitch array 4".postln; },
5, { ~pitchmode = 7; ~g1.set(\rlow, -0.8 ); ~g1.set(\rhigh, 1.5); "PITCH MODE RANDOM 4".postln; },
6, { ~pitchmode = 7; ~g1.set(\rlow, -3 ); ~g1.set(\rhigh, 3); "PITCH MODE RANDOM 5".postln; },
7, { ~pitchmode = 7; ~g1.set(\rlow, -8 ); ~g1.set(\rhigh, 8); "PITCH MODE RANDOM 6".postln; },
)
});
// BUTTON X ----- GRAIN DURATION MODE
if (msg[15]==1,
{
( ~btn8val = (~btn8val + 1) % 7 ) ;
switch(~btn8val,
0, { ~gdurmode = 0; ~g1.set(\imp, 40); "DURATION MODE 0".postln; },
1, { ~gdurmode = 1; ~g1.set(\imp, 30); "DURATION MODE 1".postln; },
( ~btn14val = (~btn14val + 1) % 7 ) ;
switch(~btn14val,
0, { ~gdurmode = 0; ~g1.set(\imp, 64); "DURATION MODE 0".postln; },
1, { ~gdurmode = 1; ~g1.set(\imp, 30); "DURATION MODE 1".postln; },
2, { ~gdurmode = 2; ~g1.set(\imp, 20); "DURATION MODE 2".postln; },
3, { ~gdurmode = 3; ~g1.set(\imp, 15); "DURATION MODE 3".postln; },
4, { ~gdurmode = 4; ~g1.set(\imp, 10); "DURATION MODE 4".postln; },
@ -435,8 +438,8 @@ p = OSCdef(\keys, { arg msg, time, addr, recvPort;
// BUTTON X ----- GRANULAR IMPULSE MODE
if (msg[16]==1,
{
( ~btn7val = (~btn7val + 1) % 3 ) ;
switch( ~btn7val,
( ~btn15val = (~btn15val + 1) % 3 ) ;
switch( ~btn15val,
0, { ~g1.set(\impulsemodeindex, 0 ); "IMPULSE MODE FIXED".postln; },
1, { ~g1.set(\impulsemodeindex, 1 ); "IMPULSE MODE DUST".postln; },
2, { ~g1.set(\impulsemodeindex, 2 ); "IMPULSE MODE SENSOR".postln; },
@ -502,6 +505,12 @@ r.set(\overdub, 0); // off
~gpanmode = 2 ; // random position
~gpanmode = 3 ; // random position
~dseqarrayIndex=0;
~g1.set(\dseqarrayIndex, 0);
~g1.set(\gpan, -1 );
~channelmode = 1;
@ -514,6 +523,9 @@ r.set(\overdub, 0); // off
~g1.set(\gate, 1); // granulator on
~g1.set(\gate, 0); // granulator off
~g1.set(\amp, 0.5); // granulator off
a = Scale.major;
@ -535,3 +547,4 @@ a = Scale.major;
//n = NetAddr.new("224.0.1.9", 6696);