Csound Csound-dev Csound-tekno Search About

Global variables in conditional statements

Date1999-09-16 16:51
FromLars Luthman
SubjectGlobal variables in conditional statements
I think I have found a bug... I'm using the PPC 3.56 version.

I have a global k-rate variable that should have different values depending
on the value of another global k-rate variable. I tried using ( ? : ), but
got two strange error messages:

error:  input arg '' used before defined, line 21:
    gkSpeed    = (gkIsChanging == 0 ? kSldToNorm : gkSpeed)
error:  input arg '' of type ? not allowed, line 21:
    gkSpeed    = (gkIsChanging == 0 ? kSldToNorm : gkSpeed)

I tried using an if ... goto statement, but I got the same errors. Then I
copied the value of the global variable into a "normal" k-rate variable.
And now it worked!

Doesn't any global variables work in conditional statements? Maybe it's not
a bug, but I didn't find anything about it in the manual.

Here is the code if you want to see it:

This one doesn't work...

instr 1

	iNorm	= p4
	iSlide	init 5/kr

	; Slide to normal speed if gkIsChanging != 1
	kSldToNorm = (abs(gkSpeed-iNorm) < iSlide ? iNorm :
gkSpeed-iSlide*(gkSpeed-iNorm)/abs(gkSpeed-iNorm))
	gkSpeed    = (gkIsChanging == 0 ? kSldToNorm : gkSpeed)
	; Get the data from the file...
	aOut	diskin "vivaldi.aiff", gkSpeed, 0, 1, 4
	; ...and reset gkIsChanging
	gkIsChanging = 0

			out aOut
endin


...but this one does.

instr 1

	iNorm	= p4
	iSlide	init 5/kr

	kIsChanging = gkIsChanging

	; Slide to normal speed if gkIsChanging != 1
	kSldToNorm = (abs(gkSpeed-iNorm) < iSlide ? iNorm :
gkSpeed-iSlide*(gkSpeed-iNorm)/abs(gkSpeed-iNorm))
	gkSpeed    = (kIsChanging == 0 ? kSldToNorm : gkSpeed)
	; Get the data from the file...
	aOut	diskin "vivaldi.aiff", gkSpeed, 0, 1, 4
	; ...and reset gkIsChanging
	gkIsChanging = 0

			out aOut
endin




--ll