Changing Synth parameters with Midi controller

I am trying to change some parameters of a Synth from my midi-controller. I have set some global variables used in the Synth, and change those variables outside the synth with the controller, but there is no changes inside the synth although values are being changed. Here is the part of my code (on GNU/Linux):

(
b = Buffer.readChannel(s, "/xxx/xxx/Untitled-2024-09-24-08-33-33/export/bass.wav", channels:[0]);
)
(
​~atkTime = 0.003;
~bufDur = b.duration;
~winenv = Env.perc(attackTime: ~atkTime, releaseTime: 1);
z = Buffer.sendCollection(s, ~winenv.discretize, 1);
// THE 2 GLOBAL VARIABLES
~pos_1 = 0;
~pos_2 = 0.1;
)
// THE SYNTH
(
x = {
    var gate=1, trigFreq, trig, rateSeq, freq, grainSize, envbuf, env,
	dseqYFact, drandXFact
	;
	// dseqYFact = MouseY.kr(0.3, 0.4, 1).round(0.001);
	// drandXFact = MouseX.kr(0.1, 0.2, 1).round(0.001);
	dseqYFact = Rand(0.29, 0.3).round(0.001);
	drandXFact = Rand(0.19, 0.2).round(0.001);
	// dseqYFact = 0.3;
	// drandXFact = 0.3;
	// trigFreq = 24;
	trigFreq = LFNoise1.kr(1).range(4, 24);
	trig = Impulse.ar(trigFreq);
    rateSeq = Drand([
		Dseq((1..5).mirror1 * LFNoise2.kr(0.5).range(0.3, 0.32), 2),
		Drand((4..10) * LFNoise2.kr(1).range(0.19, 0.2), 11)
	], inf);
	// grainSize = b.duration * FSinOsc.kr(ExpRand(0.1, 8)).exprange(0.01, 0.5);
	grainSize = b.duration * FSinOsc.kr(2).exprange(0.1, 0.5);
	// grainSize = 0.1;
	GrainBuf.ar(
		numChannels: 2,
		trigger: trig,
		dur: grainSize,
		sndbuf: b,
		rate: Demand.ar(trig, 0, rateSeq),
		// Nach unten wird langsamer zurückspringen zum Anfang
		// pos: LFNoise1.kr(trigFreq).range(0, 1),
		pos: LFNoise2.kr(trigFreq).range(~pos_1, ~pos_2),
		interp: 4,
		pan: LFNoise0.kr(trigFreq),
		envbufnum: z
	)
}.play;
)
//AND CONTROLLING THE GLOBAL VARIABLES POS_1 AND POS_2
(
~midfunc1 = MIDIFunc.cc({arg ...args; (~pos_1.postln;~pos_1 = (args.at(0)/127))}, 1); // match cc 1
~midfunc2 = MIDIFunc.cc({arg ...args; (~pos_2.postln;~pos_2 = (args.at(0)/127))}, 2); // match cc 1
)

You need to transmit the changes to ~pos_1 and ~pos_2 with x.set(…) messages.

1 Like

I was reading this on the phone and I missed another thing - you also need to give yourself synth inputs to be able to change the synth:

(
~pos_1 = 0;
~pos_2 = 0.1;
x = {
    var gate=1, trigFreq, trig, rateSeq, freq, grainSize, envbuf, env,
	dseqYFact, drandXFact
	;
	// dseqYFact = MouseY.kr(0.3, 0.4, 1).round(0.001);
	// drandXFact = MouseX.kr(0.1, 0.2, 1).round(0.001);
	dseqYFact = Rand(0.29, 0.3).round(0.001);
	drandXFact = Rand(0.19, 0.2).round(0.001);
	// dseqYFact = 0.3;
	// drandXFact = 0.3;
	// trigFreq = 24;
	trigFreq = LFNoise1.kr(1).range(4, 24);
	trig = Impulse.ar(trigFreq);
    rateSeq = Drand([
		Dseq((1..5).mirror1 * LFNoise2.kr(0.5).range(0.3, 0.32), 2),
		Drand((4..10) * LFNoise2.kr(1).range(0.19, 0.2), 11)
	], inf);
	// grainSize = b.duration * FSinOsc.kr(ExpRand(0.1, 8)).exprange(0.01, 0.5);
	grainSize = b.duration * FSinOsc.kr(2).exprange(0.1, 0.5);
	// grainSize = 0.1;
	GrainBuf.ar(
		numChannels: 2,
		trigger: trig,
		dur: grainSize,
		sndbuf: b,
		rate: Demand.ar(trig, 0, rateSeq),
		// Nach unten wird langsamer zurückspringen zum Anfang
		// pos: LFNoise1.kr(trigFreq).range(0, 1),
		pos: LFNoise2.kr(trigFreq).range(\pos_1.kr(0), \pos_2.kr(0.1)),
		interp: 4,
		pan: LFNoise0.kr(trigFreq),
		envbufnum: z
	)
}.play(args: [\pos_1, ~pos_1, \pos_2, ~pos_2]);
)

(
~pos_1 = 10;
~pos_2 = 20;
x.set(\pos_1, ~pos_1, \pos_2, ~pos_2)
)
1 Like