Cabbage Logo
Back to Cabbage Site

Cabbage macros (resolved)

Would it be possible to enhance Cabbage macros so that they behave more in line with Csound macros? Here are a few illustrations of some quirks I have encountered.

Cabbage seems to insist on the inclusion of a space at the beginning of the macro text. The following snippet creates the keyboard widget but ignores the bounds identifier.

#define MacroName #bounds( 5,160,240,80)#
keyboard $MacroName

If a space is added, as in the following, all works fine.

#define MacroName # bounds( 5,160,240,80)#
keyboard $MacroName

It doesn’t seem possible to include the widget name in the macro code. The following won’t create the keyboard widget.

#define MacroName # keyboard bounds( 5,160,240,80) #
$MacroName

Ultimately I would be like to be able to replace a channel name (or part of a channel name) with a macro but this doesn’t seem possible yet (with or without a space) as in the following snippet. The channel “ctrl” can’t be read in Csound:

#define MacroName #ctrl#
rslider bounds(  5,  5, 70, 70), channel("$MacroName")

In the future it would be great to be able to use macros with arguments… but I’m prepared to wait for that :wink:

Thanks Iain. I’ll take a look!

So it turns out that defines work like defines in languages like C, that is to say they don’t need other ‘#’ symbols than the one at the very start. It should just be:

#define MacroName bounds( 5,160,240,80)
keyboard $MacroName

I was able to use a macro for the channel name by doing it like this:

#define MacroName "hello"
rslider bounds(0,0, 100, 100), channel($MacroName)

As for macros with arguments. That would be nice but I don’t think the current parser could handle it. What would be great is if I could somehow convince Steven Yi to write a new bison based parser for Cabbage and completely replace the piecemeal effort I have in place. I’m afraid that no amount of beers will ever make this happen!

Thanks, that’s all clear. I think the Csound use of bounding ‘#’ characters is to permit multi-line macros.

I see. I guess you’re next question is, can we have multi-line macros?! :wink:

I wouldn’t dream of asking that…