This keeps me annoyed for some time now, because I don’t seem to be able to work out the problem.
It would really help if there was some kind of ‘switch’ control like in C, C++, Swift, etc in the CSound language. It would make code like this a lot more readable.
I’ll add some sample code. Don’t bother about the contents, it’s about something I probably do wrong constructing this UDO. I also tried to use this construction inside an instrument, but I get the same error message for endin
I checked this code a million times, but as far as I can detect there is nothing wrong with it. All if/then/else conditions are closed, no typing errors, but I get the error message:
error: syntax error, unexpected UDOEND_TOKEN (token “endop”) from file
I work in CSoundQt, maybe it has something to do with that
opcode SetNewKey, 0, 0
iKeyDecision		random	0, 4.999
iKeyIntDec		=	int(iKeyDecision)
iProgDecision	random	0, 3.999	;Randomly decide what ChordProgression to play
iProgIntDec		=	int(iProgDecision)
;Decision structure to determine the giProgression chord order. Currently only 4 progressions are defined
if 	iProgIntDec == 0 then
giProgression = giMajMinMod1
elseif iProgIntDec == 1 then
giProgression = giMajMinMod2
else if iProgIntDec == 2 then
giProgression = giMajMinMod3
else
giProgression = giMajMinMod4
endif
if giCurrentKey[1] == 0 then	;Major key modulation if CurrentKey is major (currently 6 possibilities are defined)
if 	iKeyIntDec == 0 	then
giGoalKey[0] = giCurrentKey[0] + giMajorScale[2]	
giGoalKey[1]	= 1
elseif 	iKeyIntDec == 1	then
giGoalKey[0]	= giCurrentKey[0] + giMajorScale[4]
giGoalKey[1]	= 0
elseif 	iKeyIntDec == 2	then
giGoalKey[0]	= giCurrentKey[0] + giMajorScale[4]
giGoalKey[1]	= 1
elseif 	iKeyIntDec == 3	then
giGoalKey[0]	= giCurrentKey[0] + giMajorScale[6]
giGoalKey[1]	= 0
elseif 	iKeyIntDec == 4	then
giGoalKey[0]	= giCurrentKey[0] + giMajorScale[4]
giGoalKey[1]	= 0
else	;if 	iKeyIntDec == 5	then
giGoalKey[0]	= giCurrentKey[0] + giMajorScale[7]
giGoalKey[1]	= 1
endif
endif	
if giCurrentKey[1] == 1 then				; In second case the CurrentKey Scale is minor
if	 iKeyIntDec == 0	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[1]
giGoalKey[1] = 0
elseif	 iKeyIntDec == 1	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[2]
giGoalKey[1] = 1
elseif	 iKeyIntDec == 2	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[3]
giGoalKey[1] = 0
elseif	 iKeyIntDec == 3	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[4]
giGoalKey[1] = 1
elseif	 iKeyIntDec == 4	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[6]
giGoalKey[1] = 0
else	;if	 iKeyIntDec == 5	then
giGoalKey[0] = giCurrentKey[0] + giMinorScale[7]
giGoalKey[1] = 1
endif
endif
endop
 Those if/else blocks are hard enough to read with indentation, but are a complete nightmare without it.
  Those if/else blocks are hard enough to read with indentation, but are a complete nightmare without it.