Cabbage Logo
Back to Cabbage Site

Gk variables

Hi all,

I’m trying to figure out how global k-rate variables work for a larger project. For the purposes of clarity, I’ve isolated the technique over here. I want to try and use gk variables to control ADSR data across multiple instruments. A global linseg doesn’t seem to work.

I’m trying this approach, but it doesn’t seem very intuitive to me. Can anyone correct/suggest something?

<CsoundSynthesizer>
<CsOptions>
-odac
</CsOptions>
<CsInstruments>

sr = 44100
ksmps = 64
nchnls = 2
0dbfs = 1

gklinseg init 0

;gklinseg linseg 0, 30, 440

instr 1

gklinseg = gklinseg+0.1
aoscil oscil 1.0, gklinseg
outs aoscil, aoscil

endin 

</CsInstruments>
<CsScore>
f   1         0       4096	10	 1
i1  0   5
i1  8   5
i1  0   5
i1  16   5

</CsScore>
</CsoundSynthesizer>

Disclaimer: I’m not a fan of global variables :slight_smile:

But, there are a few issues here. One, you can’t call a k or a rate opcode outside an instrument. Each instrument will increment gklinseg by 0.1 for as long as it’s running. I assume this is not what you want?

Why not just put the ADSR inside the instrument? You can update the ADSR at any time, which will in turn will affect all instances of the instrument.

Hi Rory,

Thanks for your reply. Actually the large project I’m working on has a convoluted design, but you mentioning that I cannot change g-variables outside the instrument helped me solve the issue. I will certainly share the project here once it’s done. Thanks for your help.

No problem. There are so many ways of writing Csound code. The good news is that it’s not that easy to write extremely inefficient code, so at the end of the day the use of global variables, named channels, score events, etc, is all a matter of personal choice. There isn’t really a right or wrong approach. Good luck with the project :smiley: