[Csnd] if statement and turnoff/turnon
Date | 2009-10-31 14:36 |
From | J |
Subject | [Csnd] if statement and turnoff/turnon |
Hello. I am using an if statement to turn on and off an instrument. It doesn't seem to be working however - what happens is that if I compile with the control set to "on", it stays on - if I turn it "off", it turns the instrument off, but then I can't turned it on again without recompiling. Also, I am having trouble in instrument 2 with initialisation - could that be the problem? everything works fine if I set the table numbers for tablewkt in my controls beforehand, and compiles without error but if I don't set my controls, I get this - "PERF ERROR in instr 2: Table write k rate function table no. 0.000000 < 1" - I thought my INITs were taking care of that, but apparently not.
I have a feeling I am just not conceiving of something correctly, but if someone could have a look, that would be very helpful. The code to turn on and off the instrument is here - the instrument being turned on and off is to record into tables - I have activated it in the score section for the same length as the first instrument
: instr 1 a1, a2, a3, a4, a5, a6, a7, a8 ino gkRecord chnget "k_rec" gkRecord init 0 if (gkRecord == 0) then
turnoff2 2, 0, 2 elseif (gkRecord == 1) then turnon 2 endif <code fragment> Here is the instrument: instr 2 ; Recording instrument ktabrec1 init 1 ktabrec2 init 2 ktabrec1 chnget "k_rec1" ktabrec2 chnget "k_rec2" kBuflength chnget "k_g_buflength" kFileLength tableng giFile kFileMasterlength = kBuflength/kFileLength
kRecMode chnget "k_rec_Mode" a7 inch 7 a8 inch 8 ;Record phasor inputs afilrec phasor sr/kBuflength afilrec = afilrec * kFileMasterlength; * kBuflength
tablewkt a7, afilrec, ktabrec1, 1 tablewkt a8, afilrec, ktabrec2, 1 printk2 kBuflength printk2 kFileMasterlength
endin |
Date | 2009-10-31 15:30 |
From | Victor Lazzarini |
Subject | [Csnd] Re: if statement and turnoff/turnon |
I guess the problem with your instr 1 is that 'turnon' is i-time only.
It won't work at performance time. Try using schedule or any of the
other instrument control opcodes that works at performance time.
In the second instrument, initialising the k-variables does not help
because the opcode chnget is setting them to another value (0)
straight after.
Victor
On 31 Oct 2009, at 14:36, J wrote:
> Hello. I am using an if statement to turn on and off an instrument.
> It doesn't seem to be working however - what happens is that if I
> compile with the control set to "on", it stays on - if I turn it
> "off", it turns the instrument off, but then I can't turned it on
> again without recompiling.
>
> Also, I am having trouble in instrument 2 with initialisation -
> could that be the problem? everything works fine if I set the table
> numbers for tablewkt in my controls beforehand, and compiles without
> error but if I don't set my controls, I get this - "PERF ERROR in
> instr 2: Table write k rate function table no. 0.000000 < 1" - I
> thought my INITs were taking care of that, but apparently not.
>
> I have a feeling I am just not conceiving of something correctly,
> but if someone could have a look, that would be very helpful. The
> code to turn on and off the instrument is here - the instrument
> being turned on and off is to record into tables - I have activated
> it in the score section for the same length as the first instrument
>
> :
>
> instr 1
>
> a1, a2, a3, a4, a5, a6, a7, a8 ino
> gkRecord chnget "k_rec"
> gkRecord init 0
>
> if (gkRecord == 0) then
>
> turnoff2 2, 0, 2
>
> elseif (gkRecord == 1) then
>
> turnon 2
>
> endif
>
> |
Date | 2009-10-31 15:36 |
From | J |
Subject | [Csnd] Re: Re: if statement and turnoff/turnon |
Thank you for your response! That makes perfect sense in the case of Turnon - I will look into using schedule instead. In the case of the second instrument, is there a way around this? So that a setting can be initialised to a value which can be changed by a chnget after it has been initialised?
Jeremy
On Sat, Oct 31, 2009 at 3:30 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote: I guess the problem with your instr 1 is that 'turnon' is i-time only. It won't work at performance time. Try using schedule or any of the other instrument control opcodes that works at performance time. |
Date | 2009-10-31 15:42 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: if statement and turnoff/turnon |
You can try using if - then etc perhaps? Victor On 31 Oct 2009, at 15:36, J wrote: Thank you for your response! That makes perfect sense in the case of Turnon - I will look into using schedule instead. |
Date | 2009-10-31 16:30 |
From | J |
Subject | [Csnd] Re: Re: Re: Re: if statement and turnoff/turnon |
Hmm - a combination of lack of experience and a paucity of imagination are perhaps preventing me from seeing how to achieve this using if/then - do you mean: if (chnget = 0) { do Init} else {use chnget} ? Jeremy
On Sat, Oct 31, 2009 at 3:42 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
|
Date | 2009-10-31 16:32 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: Re: Re: if statement and turnoff/turnon |
if kvar == 0 then kvar = 1 endif ? On 31 Oct 2009, at 16:30, J wrote: Hmm - a combination of lack of experience and a paucity of imagination are perhaps preventing me from seeing how to achieve this using if/then - do you mean: |
Date | 2009-10-31 16:39 |
From | J |
Subject | [Csnd] Re: Re: Re: Re: Re: Re: if statement and turnoff/turnon |
Yes! That works perfectly. Thank you for the help, I'm still struggling with the basics! Jeremy
On Sat, Oct 31, 2009 at 4:32 PM, Victor Lazzarini <Victor.Lazzarini@nuim.ie> wrote:
|
Date | 2009-10-31 16:41 |
From | Victor Lazzarini |
Subject | [Csnd] Re: Re: Re: Re: Re: Re: Re: if statement and turnoff/turnon |
Aren't we all? Glad to be of service. On 31 Oct 2009, at 16:39, J wrote: Yes! That works perfectly. Thank you for the help, I'm still struggling with the basics! |