flucoma / flucoma-sc

Fluid Corpus Manipulation plugins for Supercollider
BSD 3-Clause "New" or "Revised" License
70 stars 16 forks source link

sclang: refactoring processSelect and validateBuffer #141

Open elgiano opened 2 years ago

elgiano commented 2 years ago

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 :)

weefuzzy commented 1 year ago

This looks grand. I'll give it an experimental merge and test when I can.

A general sclang question: is there any naming convention for denoting classes as being for internal use, in the absence of namespaces or such like? We've got quite a few little helpers like this that aren't part of the user interface, and I guess it would be useful noise reduction if we could mark them clearly.

tremblap commented 1 year ago

I just read in the "Writing Classes" tutorial that there is a prefix 'pr' for private methods... but that is a good question, maybe for the sc forum if @elgiano doesn't have the answer - which I doubt :)

elgiano commented 1 year ago

I'm sorry but I'm not aware of any convention for namespacing classes. I guess a note in the helpfile is the most we can do about it

On Thu, Sep 29, 2022, 12:02 tremblap @.***> wrote:

I just read in the "Writing Classes" tutorial that there is a prefix 'pr' for private methods... but that is a good question, maybe for the sc forum if @elgiano https://github.com/elgiano doesn't have the answer - which I doubt :)

— Reply to this email directly, view it on GitHub https://github.com/flucoma/flucoma-sc/pull/141#issuecomment-1262055656, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACNMWU4CL2GWQ3HUASEGFTWAVSMTANCNFSM6AAAAAAQE67AME . You are receiving this because you were mentioned.Message ID: @.***>