Hi there
Sorry more of a conceptual Csound query really, rather than Cabbage specifically. I’m sure this have been done to death, but I’m trying to come up with a standard way of creating re-usable modular code for my patches. For example, below is an instr
definition for a reverb that I can #include
, that takes either p-fields or if supplied with a string, creates a k-rate chnget
so that it can be controlled externally:
#define SET_CTL_TYPE(VAR'CHNID'PARAM) #
ilen strlen $CHNID
if ilen > 0 then
$VAR chnget $CHNID
else
$VAR = $PARAM
endif
#
#define REVERBSC_ALT(NUM ' B_IN ' B_OUT ' K_SIZE ' K_DAMP ' K_MIX) #
instr $NUM
prints {{
REVERBSC_ALT =>
B_IN: %s
B_OUT: %s
SIZE: %s, {float} [0..1]
DAMP: %s, {float} [0.. israte/2]
MIX: %s, {float} [0..1]
PTCHMOD: %f, {float} [0..10]
}}, $B_IN, $B_OUT, $K_SIZE, $K_DAMP, $K_MIX, p7
ainl chnget strcat($B_IN, "L")
ainr chnget strcat($B_IN, "R")
$SET_CTL_TYPE(ksize'$K_SIZE'p4)
$SET_CTL_TYPE(kdamp'$K_DAMP'p5)
$SET_CTL_TYPE(kmix'$K_MIX'p6)
iptchmod = p7
aRevL, aRevR reverbsc ainl, ainr, ksize, kdamp, sr, iptchmod, 0
aMixL ntrpol ainl, aRevL, kmix
aMixR ntrpol ainr, aRevR, kmix
outs aMixL, aMixR
chnclear strcat($B_IN, "L"), strcat($B_IN, "R")
endin
#
and it’s called in the main orchestra as:
$REVERBSC_ALT(VerbAlt ' "Verb" ' "" ' "Size" ' "Damp" ' "Mix")
schedule("VerbAlt", 0, -1, .95, 5000, 0.5, .2)
The empty string denotes whether a channel needs to be used, or can be skipped to use a p-field instead (SET_CTL_TYPE
macro handles all this). The prints
stuff is to document inputs/outputs so I don’t have to open the src file, as I’m a bit lazy!
I did try a udo for the $SET_CTL_TYPE
bit to use inline, but I wasn’t having much success with it. I think a macro was the way to go anyhow.
So, what are your thoughts, is this way over engineered? - am I overlooking something obvious, like a better way to achieve my aim of drop in re-usability? (sidenote, I’m inspired by Pd’s abstraction system when I say reusability).
cheers