Cabbage Logo
Back to Cabbage Site

Pan knob

So i wanted to create a pan knob for all of my synth to be effected by, so i created the knob, and along with it, two variables; kRight, and kLeft.i multiply the output by those in their respected channels, and used my theory, of the right being just a plain knob, and the left being chnget (“masterpan”)*-1+1 to make it go in the opposite direction, but still be in the range of zero to one, but when i run the synth i get the compiler error: unexpected NEWLINE, expecting ‘,’ or ‘)’ (token “”).

instr 1
iFreq = p4/2
iAmp = p5

kRight = chnget ("masterpan")
kLeft = chnget ("masterpan")*-1+1

kGain chnget ("mastergain")
kEnv madsr chnget:i("attack"), chnget:i("decay"), chnget:i("sustain"), chnget:i("release")
kMod1Env madsr chnget:i("mod1attack"), chnget:i("mod1decay"), chnget:i("mod1sustain"), chnget:i("mod1release")
iOsc1Semitone = (2^(1/12)*p4)-p4
aOut vco2 iAmp, iFreq+iOsc1Semitone*chnget:k("osc1fine")
aLp moogladder aOut, chnget:k("filcutoff")*kMod1Env, chnget:k("filreso") 
outs aLp*kEnv*kGain*kRight, aLp*kEnv*kGain*kLeft

this is the code im using.
here is a picture of my theory if it makes more sense that way.

Firstly - there is a pan2 opcode, so no need to pan sound manually (pan2 is actually more clever than naive panning).

Also - the syntax error is because of = before chnget, right syntax would be:

kRight chnget "masterpan"
kLeft = ( kRight * -1 ) + 1

In my multitrack recorder I use pan2 this way:

  • I have balance knob with values from -0.5 to +0.5 (value is set to kBal variable)
  • then I do aL, aR pan2 aL+aR, kBal+0.5

Note the downmixing input to mono (aL+aR) because of uses only one input.

In fact, you can use chnget or any opcode this way, but you can’t put a space between the opcode name and the opening brackets.

kRight = chnget("masterpan")

will work fine.

1 Like