Opcode to init once at beginning of performace
Date | 2016-01-04 12:04 |
From | Peter Burgess |
Subject | Opcode to init once at beginning of performace |
Hi again. Is there an opcode similar to init that initialised a value only at the very start of the performance, ie, not every time the instrument is called. I know this can be done with global variables outside of the instrument definitions, but in some situations it would be much neater to just include certain global variable definitions within an instrument definition. Pete Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here |
Date | 2016-01-04 12:22 |
From | Rory Walsh |
Subject | Re: Opcode to init once at beginning of performace |
No. Afaik using globals init-ed in instr0 is the only way to achieve this. On 4 January 2016 at 12:04, Peter Burgess <pete.soundtechnician@gmail.com> wrote: Hi again. Is there an opcode similar to init that initialised a value |
Date | 2016-01-04 12:33 |
From | Peter Burgess |
Subject | Re: Opcode to init once at beginning of performace |
Fair play, I'll stick with that then, cheers man! On Mon, Jan 4, 2016 at 12:22 PM, Rory Walsh |
Date | 2016-01-04 13:13 |
From | Michael Gogins |
Subject | Re: Opcode to init once at beginning of performace |
You can, at least, put your global variable initializations directly above the instrument definition that will use them. What I do is preface each variable with the name of the instrument, this creates a kind of namespace and prevents clashes of variables. This includes ftables and variables used as control channels as well. For example: gk_Harpsichord_level init 0 gk_HarpsichordPan init .5 gi_Harptable ftgen 0, 0, 65536, 7, -1, 1024, 1, 1024, -1 instr Harpsichord ////////////////////////////////////////////// // Original by James Kelley. // Adapted by Michael Gogins. ////////////////////////////////////////////// insno = p1 itime = p2 iduration = p3 ikey = p4 ivelocity = p5 iphase = p7 ipan = p6 idepth = p8 iheight = p9 ipcs = p10 ihomogeneity = p11 iattack = .005 isustain = p3 irelease = .3 p3 = iattack + isustain + irelease iHz = cpsmidinn(ikey) kHz = k(iHz) iamplitude = ampdb(ivelocity) aenvelope transeg 1.0, 20.0, -10.0, 0.05 apluck pluck 1, kHz, iHz, 0, 1 aharp poscil 1, kHz, gi_Harptable aharp2 balance apluck, aharp asignal = (apluck + aharp2) * iamplitude * aenvelope * 10 adeclick linsegr 0, iattack, 1, isustain, 1, irelease, 0 kgain = ampdb(gk_Harpsichord_level) asignal = asignal * adeclick * kgain aoutleft, aoutright pan2 asignal, ipan chnmix aoutleft, "out_left" chnmix aoutright, "out_right" prints "instr %4d t %9.4f d %9.4f k %9.4f v %9.4f p %9.4f\n", p1, p2, p3, p4, p5, p7 endin ----------------------------------------------------- Michael Gogins Irreducible Productions http://michaelgogins.tumblr.com Michael dot Gogins at gmail dot com On Mon, Jan 4, 2016 at 7:33 AM, Peter Burgess |
Date | 2016-01-04 13:25 |
From | Peter Burgess |
Subject | Re: Opcode to init once at beginning of performace |
that's a good point, that will definitely help tidy it up On Mon, Jan 4, 2016 at 1:13 PM, Michael Gogins |
Date | 2016-01-04 21:58 |
From | Steven Yi |
Subject | Re: Opcode to init once at beginning of performace |
I use chnset and chnget to do once per performance initialization in my instruments. It looks something like: If chnget:i(someval) == 0 then I have an article about writing encapsulated instruments that has some example code in the Csound journal. (Sorry, typing on a cellphone and hard to lookup) Hope that helps! Steven On Mon, Jan 4, 2016, 5:25 AM Peter Burgess <pete.soundtechnician@gmail.com> wrote: that's a good point, that will definitely help tidy it up |
Date | 2016-01-05 18:07 |
From | Peter Burgess |
Subject | Re: Opcode to init once at beginning of performace |
Ah, that is another good idea. Is there much of a difference in performance between using chnget/chnset as opposed to init? Would it be noticeable, say, if it had to be done 20,000 times? On Mon, Jan 4, 2016 at 9:58 PM, Steven Yi |
Date | 2016-01-08 16:04 |
From | Peter Burgess |
Subject | Re: Opcode to init once at beginning of performace |
I thought I'd found a new solution to this. I was hoping that a UDO would allow me to init a global variable once at the beginning of a performance within it's definition, but it seems not, lol. I take it that means that a UDO is only active when called, rather than being active throughout the performance? On Tue, Jan 5, 2016 at 6:07 PM, Peter Burgess |