flucoma-sc icon indicating copy to clipboard operation
flucoma-sc copied to clipboard

sclang: refactoring processSelect and validateBuffer

Open elgiano opened this issue 2 years ago • 3 comments

to remove duplicate code scattered over many classes, prProcessSelect becomes FluidProcessSelect, and buffer validation for BufProcessors is now a method inherited from FluidBufProcessor.

FluidProcessSelect usage:

// FluidSpectralShape
const <features=#[\centroid,\spread,\skewness,\kurtosis,\rolloff,\flatness,\crest];
classvar <featuresLookup;
*initClass {
	featuresLookup = FluidProcessSelect(this, this.features);
}
*kr { 
   [...]
   var selectbits = this.featuresLookup.encode(select);
   [...]
}

validateBuffer: converts with .asUGenInput, checks for nil, and throws on error

// e.g FluidBufPitch
*kr {
    [...]
    source = this.validateBuffer(source, "source");
    [...]
}
// example error: the class name and the second argument are used in the error message
// FluidBufPitch:  Invalid source buffer

Let me know if you like it :)

elgiano avatar Sep 05 '22 12:09 elgiano