Cabbage Logo
Back to Cabbage Site

Passing macro a string argument causes compile error

#define PATTERN(name'pattern) #
prints "test %s %d\n", $name, lenarray($pattern)
instr $name
	iN = p4
	iTrans = p5
endin
#

gkArr[] fillarray 1,2,3,4
$PATTERN("Pattern1"'gkArr)

The prints logs $name fine…

Named instruments accept a string, so why is $name in the instr declaration throwing errors?

error: syntax error, unexpected STRING_TOKEN (token """)

When an instrument has a name instead of a number, that name should not be in double inverted commas. It is only in the score where double inverted commas need to be used. You will then need to add the double inverted commas when the macro argument is used by prints. See below:

#define PATTERN(name'pattern) #
prints "test %s %d\n", "$name", lenarray($pattern)
instr $name
	iN = p4
	iTrans = p5
endin
#

gkArr[] fillarray 1,2,3,4
$PATTERN(Pattern1'gkArr)

Oh so it was the prints that was error-ing. Hmm strange that it logged ok though :confused:

thanks Iain

No, prints was fine in your original. It was because I removed the " " in the macro argument, for the benefit of the instr name, that I had to add them back again when used with prints.

oh yes I see, cheers