From b4655bd4d86c9c8cc1845a8cbae2a4f670d2620a Mon Sep 17 00:00:00 2001 From: Gerard Date: Thu, 12 Sep 2019 15:27:12 +0200 Subject: [PATCH] refactor stubs for NRT objects --- release-packaging/Classes/FluidBufAmpSlice.sc | 32 ++-------- release-packaging/Classes/FluidBufCompose.sc | 36 ++---------- release-packaging/Classes/FluidBufHPSS.sc | 53 +++-------------- release-packaging/Classes/FluidBufLoudness.sc | 38 ++---------- release-packaging/Classes/FluidBufMFCC.sc | 37 ++---------- release-packaging/Classes/FluidBufMelBands.sc | 36 ++---------- release-packaging/Classes/FluidBufNMF.sc | 58 ++----------------- .../Classes/FluidBufNoveltySlice.sc | 39 ++----------- .../Classes/FluidBufOnsetSlice.sc | 39 ++----------- release-packaging/Classes/FluidBufPitch.sc | 37 ++---------- release-packaging/Classes/FluidBufSines.sc | 44 +++----------- .../Classes/FluidBufSpectralShape.sc | 37 ++---------- release-packaging/Classes/FluidBufStats.sc | 34 ++--------- .../Classes/FluidBufThreadDemo.sc | 46 +++------------ .../Classes/FluidBufTransients.sc | 47 +++------------ release-packaging/Classes/FluidNRTProcess.sc | 45 ++++++++++++++ 16 files changed, 132 insertions(+), 526 deletions(-) create mode 100644 release-packaging/Classes/FluidNRTProcess.sc diff --git a/release-packaging/Classes/FluidBufAmpSlice.sc b/release-packaging/Classes/FluidBufAmpSlice.sc index 6c8f901..d740433 100644 --- a/release-packaging/Classes/FluidBufAmpSlice.sc +++ b/release-packaging/Classes/FluidBufAmpSlice.sc @@ -1,9 +1,6 @@ FluidBufAmpSlice : UGen { - var <>server, <>synth; - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, absRampUp = 10, absRampDown = 10, absThreshOn = -90, absThreshOff = -90, minSliceLength = 1, minSilenceLength = 1, minLengthAbove = 1, minLengthBelow = 1, lookBack = 0, lookAhead = 0, relRampUp = 1, relRampDown = 1, relThreshOn = 144, relThreshOff = -144, highPassFreq = 85, doneAction = 0| - var maxSize = max(minLengthAbove + lookBack, max(minLengthBelow,lookAhead)); source = source.asUGenInput; @@ -25,29 +22,10 @@ FluidBufAmpSlice : UGen { source.isNil.if {"FluidBufAmpSlice: Invalid source buffer".throw}; indices.isNil.if {"FluidBufAmpSlice: Invalid features buffer".throw}; - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = {instance = FluidBufAmpSlice.kr(source, startFrame, numFrames, startChan, numChans, indices, absRampUp, absRampDown, absThreshOn, absThreshOff, minSliceLength, minSilenceLength, minLengthAbove, minLengthBelow, lookBack, lookAhead, relRampUp, relRampDown, relThreshOn, relThreshOff, highPassFreq, doneAction: Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - indices = server.cachedBufferAt(indices); - indices.updateInfo; - server.sync; - action.value(indices); - }; - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [indices] + ).process( + source, startFrame, numFrames, startChan, numChans, indices, absRampUp, absRampDown, absThreshOn, absThreshOff, minSliceLength, minSilenceLength, minLengthAbove, minLengthBelow, lookBack, lookAhead, relRampUp, relRampDown, relThreshOn, relThreshOff, highPassFreq + ); } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } - } diff --git a/release-packaging/Classes/FluidBufCompose.sc b/release-packaging/Classes/FluidBufCompose.sc index 0ae3502..5639e16 100644 --- a/release-packaging/Classes/FluidBufCompose.sc +++ b/release-packaging/Classes/FluidBufCompose.sc @@ -1,7 +1,5 @@ FluidBufCompose : UGen { - var <>server, <>synth; - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, gain = 1, destination, destStartFrame = 0, destStartChan = 0, destGain = 0, doneAction = 0| source = source.asUGenInput; @@ -10,46 +8,24 @@ FluidBufCompose : UGen { source.isNil.if {"FluidBufCompose: Invalid source buffer".throw}; destination.isNil.if {"FluidBufCompose: Invalid destination buffer".throw}; - ^this.multiNew('control', source, startFrame, numFrames, startChan, numChans, gain, destination, destStartFrame, destStartChan, destGain, doneAction); - } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, gain = 1, destination, destStartFrame = 0, destStartChan = 0, destGain = 0, action| - var synth, instance; source = source.asUGenInput; destination = destination.asUGenInput; source.isNil.if {"FluidBufCompose: Invalid source buffer".throw}; destination.isNil.if {"FluidBufCompose: Invalid destination buffer".throw}; - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = {instance = FluidBufCompose.kr(source, startFrame, numFrames, startChan, numChans, gain, destination, destStartFrame, destStartChan, destGain, doneAction: Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - destination = server.cachedBufferAt(destination); - destination.updateInfo; - server.sync; - action.value(destination); - }; - - instance.server = server; - instance.synth = synth; - ^instance; - } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } + ^FluidNRTProcess.new( + server, this, action, [destination] + ).process( + source, startFrame, numFrames, startChan, numChans, gain, destination, destStartFrame, destStartChan, destGain + ); + } } diff --git a/release-packaging/Classes/FluidBufHPSS.sc b/release-packaging/Classes/FluidBufHPSS.sc index c5804e6..d4ec59f 100644 --- a/release-packaging/Classes/FluidBufHPSS.sc +++ b/release-packaging/Classes/FluidBufHPSS.sc @@ -1,8 +1,6 @@ FluidBufHPSS : UGen { - var <>server, <>synth; - - *kr {|source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, harmonic, percussive, residual, harmFilterSize = 17, percFilterSize = 31, maskingMode = 0, harmThreshFreq1 = 0.1, harmThreshAmp1 = 0, harmThreshFreq2 = 0.5, harmThreshAmp2 = 0, percThreshFreq1 = 0.1, percThreshAmp1 = 0, percThreshFreq2 = 0.5, percThreshAmp2 = 0, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| + *kr {|source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, harmonic = -1, percussive = -1, residual = -1, harmFilterSize = 17, percFilterSize = 31, maskingMode = 0, harmThreshFreq1 = 0.1, harmThreshAmp1 = 0, harmThreshFreq2 = 0.5, harmThreshAmp2 = 0, percThreshFreq1 = 0.1, percThreshAmp1 = 0, percThreshFreq2 = 0.5, percThreshAmp2 = 0, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -10,10 +8,7 @@ FluidBufHPSS : UGen { harmonic = harmonic.asUGenInput; percussive = percussive.asUGenInput; residual = residual.asUGenInput; - - harmonic = harmonic ? -1; - percussive = percussive ? -1; - residual = residual ? -1; + source.isNil.if {"FluidBufHPSS: Invalid source buffer".throw}; //NB For wrapped versions of NRT classes, we set the params for maxima to //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) @@ -21,45 +16,13 @@ FluidBufHPSS : UGen { ^this.multiNew('control', source, startFrame, numFrames, startChan, numChans, harmonic, percussive, residual, harmFilterSize, percFilterSize, maskingMode, harmThreshFreq1, harmThreshAmp1, harmThreshFreq2, harmThreshAmp2, percThreshFreq1, percThreshAmp1, percThreshFreq2, percThreshAmp2, windowSize, hopSize, fftSize, maxFFTSize, harmFilterSize, percFilterSize, doneAction); } - *process {|server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, harmonic, percussive, residual, harmFilterSize = 17, percFilterSize = 31, maskingMode = 0, harmThreshFreq1 = 0.1, harmThreshAmp1 = 0, harmThreshFreq2 = 0.5, harmThreshAmp2 = 0, percThreshFreq1 = 0.1, percThreshAmp1 = 0, percThreshFreq2 = 0.5, percThreshAmp2 = 0, windowSize = 1024, hopSize = -1, fftSize = -1, action| - - var synth, instance; + *process {|server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, harmonic = -1, percussive = -1, residual = -1, harmFilterSize = 17, percFilterSize = 31, maskingMode = 0, harmThreshFreq1 = 0.1, harmThreshAmp1 = 0, harmThreshFreq2 = 0.5, harmThreshAmp2 = 0, percThreshFreq1 = 0.1, percThreshAmp1 = 0, percThreshFreq2 = 0.5, percThreshAmp2 = 0, windowSize = 1024, hopSize = -1, fftSize = -1, action| - source = source.asUGenInput; - harmonic = harmonic.asUGenInput; - percussive = percussive.asUGenInput; - residual = residual.asUGenInput; + ^FluidNRTProcess.new( + server, this, action, [harmonic, percussive, residual].select{|x| x!= -1} + ).process( + source, startFrame, numFrames, startChan, numChans, harmonic, percussive, residual, harmFilterSize, percFilterSize, maskingMode, harmThreshFreq1, harmThreshAmp1, harmThreshFreq2, harmThreshAmp2, percThreshFreq1, percThreshAmp1, percThreshFreq2, percThreshAmp2, windowSize, hopSize, fftSize + ); - source.isNil.if {"FluidBufHPSS: Invalid source buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - harmonic = harmonic ? -1; - percussive = percussive ? -1; - residual = residual ? -1; - - synth = { instance = FluidBufHPSS.kr(source, startFrame, numFrames, startChan, numChans, harmonic, percussive, residual, harmFilterSize, percFilterSize, maskingMode, harmThreshFreq1, harmThreshAmp1, harmThreshFreq2, harmThreshAmp2, percThreshFreq1, percThreshAmp1, percThreshFreq2, percThreshAmp2, windowSize, hopSize, fftSize, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - if (harmonic != -1) {harmonic = server.cachedBufferAt(harmonic); harmonic.updateInfo; server.sync;} {harmonic = nil}; - if (percussive != -1) {percussive = server.cachedBufferAt(percussive); percussive.updateInfo; server.sync;} {percussive = nil}; - if (residual != -1) {residual = server.cachedBufferAt(residual); residual.updateInfo; server.sync;} {residual = nil}; - action.value(harmonic, percussive, residual); - }; - - instance.server = server; - instance.synth = synth; - ^instance; } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } - } diff --git a/release-packaging/Classes/FluidBufLoudness.sc b/release-packaging/Classes/FluidBufLoudness.sc index e46ee09..ff02b2f 100644 --- a/release-packaging/Classes/FluidBufLoudness.sc +++ b/release-packaging/Classes/FluidBufLoudness.sc @@ -1,7 +1,5 @@ FluidBufLoudness : UGen{ - var <>server, <>synth; - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, kWeighting = 1, truePeak = 1, windowSize = 1024, hopSize = 512, doneAction = 0| var maxwindowSize = windowSize.nextPowerOfTwo; @@ -16,36 +14,10 @@ FluidBufLoudness : UGen{ } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, kWeighting = 1, truePeak = 1, windowSize = 1024, hopSize = 512, action| - - var synth, instance; - source = source.asUGenInput; - features = features.asUGenInput; - - source.isNil.if {"FluidBufPitch: Invalid source buffer".throw}; - features.isNil.if {"FluidBufPitch: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = {instance = FluidBufLoudness.kr(source, startFrame, numFrames, startChan, numChans, features, kWeighting, truePeak, windowSize, hopSize, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - features = server.cachedBufferAt(features); features.updateInfo; server.sync; - action.value(features); - }; - - instance.server = server; - instance.synth = synth; - ^instance; - } - - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; + ^FluidNRTProcess.new( + server, this, action, [features] + ).process( + source, startFrame, numFrames, startChan, numChans, features, kWeighting, truePeak, windowSize, hopSize + ); } } diff --git a/release-packaging/Classes/FluidBufMFCC.sc b/release-packaging/Classes/FluidBufMFCC.sc index 4132af2..cc6d5c8 100644 --- a/release-packaging/Classes/FluidBufMFCC.sc +++ b/release-packaging/Classes/FluidBufMFCC.sc @@ -1,5 +1,5 @@ FluidBufMFCC : UGen{ - var <>server, <>synth; + *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, numCoeffs = 13, numBands = 40, minFreq = 20, maxFreq = 20000, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -17,35 +17,10 @@ FluidBufMFCC : UGen{ } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, numCoeffs = 13, numBands = 40, minFreq = 20, maxFreq = 20000, windowSize = 1024, hopSize = -1, fftSize = -1, action| - var synth, instance; - - source = source.asUGenInput; - features = features.asUGenInput; - - source.isNil.if {"FluidBufMFCC: Invalid source buffer".throw}; - features.isNil.if {"FluidBufMFCC: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = { instance = FluidBufMFCC.kr(source, startFrame, numFrames, startChan, numChans, features, numCoeffs, numBands, minFreq, maxFreq, windowSize, hopSize, fftSize, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - features = server.cachedBufferAt(features); features.updateInfo; server.sync; - action.value(features); - }; - - instance.synth = synth; - instance.server = server; - ^instance; - } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; + ^FluidNRTProcess.new( + server, this, action, [features] + ).process( + source, startFrame, numFrames, startChan, numChans, features, numCoeffs, numBands, minFreq, maxFreq, windowSize, hopSize, fftSize + ); } } diff --git a/release-packaging/Classes/FluidBufMelBands.sc b/release-packaging/Classes/FluidBufMelBands.sc index 282130c..cbe5365 100644 --- a/release-packaging/Classes/FluidBufMelBands.sc +++ b/release-packaging/Classes/FluidBufMelBands.sc @@ -1,5 +1,4 @@ FluidBufMelBands : UGen { - var <>server, <>synth; *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, numBands = 40, minFreq = 20, maxFreq = 20000, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0 | @@ -19,36 +18,9 @@ FluidBufMelBands : UGen { } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, numBands = 40, minFreq = 20, maxFreq = 20000, windowSize = 1024, hopSize = -1, fftSize = -1, action| - - var synth, instance; - source = source.asUGenInput; - features = features.asUGenInput; - - source.isNil.if {"FluidBufMelBands: Invalid source buffer".throw}; - features.isNil.if {"FluidBufMelBands: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = { instance = FluidBufMelBands.kr(source, startFrame, numFrames, startChan, numChans, features, numBands, minFreq, maxFreq, windowSize, hopSize, fftSize, doneAction: Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - features = server.cachedBufferAt(features); features.updateInfo; server.sync; - action.value(features); - }; - - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [features] + ).process( + source, startFrame, numFrames, startChan, numChans, features, numBands, minFreq, maxFreq, windowSize, hopSize, fftSize); } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } - } diff --git a/release-packaging/Classes/FluidBufNMF.sc b/release-packaging/Classes/FluidBufNMF.sc index 97adaee..6b9c859 100644 --- a/release-packaging/Classes/FluidBufNMF.sc +++ b/release-packaging/Classes/FluidBufNMF.sc @@ -1,7 +1,5 @@ FluidBufNMF : UGen { - var <>server, <>synth; - *kr {|source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, bases, basesMode = 0, activations, actMode = 0, components = 1, iterations = 100, windowSize = 1024, hopSize = -1, fftSize = -1, windowType = 0, randomSeed = -1, doneAction = 0| @@ -21,56 +19,12 @@ FluidBufNMF : UGen { } - *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination, bases, basesMode = 0, activations, actMode = 0, components = 1, iterations = 100, windowSize = 1024, hopSize = -1, fftSize = -1, windowType = 0, randomSeed = -1, action| - - var instance,synth; - - source = source.asUGenInput; - destination = destination.asUGenInput; - bases = bases.asUGenInput; - activations = activations.asUGenInput; - - source.isNil.if {"FluidBufNMF: Invalid source buffer".throw}; - - destination = destination ? -1; - bases = bases ? -1; - activations = activations ? -1; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = {instance = FluidBufNMF.kr(source, startFrame, numFrames, startChan, numChans, destination, bases, basesMode, activations, actMode, components,iterations, windowSize, hopSize, fftSize, doneAction: Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - if (destination != -1) { - destination = server.cachedBufferAt(destination); - destination.updateInfo; - server.sync; - } {destination = nil}; - if (bases != -1) { - bases = server.cachedBufferAt(bases); - bases.updateInfo; - server.sync; - } {bases = nil}; - if (activations != -1) { - activations = server.cachedBufferAt(activations); - activations.updateInfo; - server.sync; - } {activations = nil}; - action.value(destination, bases, activations); - }; - - instance.synth = synth; - instance.server = server; - ^instance; - } + *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, destination = -1, bases = -1, basesMode = 0, activations = -1, actMode = 0, components = 1, iterations = 100, windowSize = 1024, hopSize = -1, fftSize = -1, windowType = 0, randomSeed = -1, action| - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; + ^FluidNRTProcess.new( + server, this, action, [destination, bases, activations].select{|x| x!= -1} + ).process( + source, startFrame, numFrames, startChan, numChans, destination, bases, basesMode, activations, actMode, components,iterations, windowSize, hopSize, fftSize, windowType, randomSeed + ); } } diff --git a/release-packaging/Classes/FluidBufNoveltySlice.sc b/release-packaging/Classes/FluidBufNoveltySlice.sc index f86d9b2..567cb54 100644 --- a/release-packaging/Classes/FluidBufNoveltySlice.sc +++ b/release-packaging/Classes/FluidBufNoveltySlice.sc @@ -1,7 +1,5 @@ FluidBufNoveltySlice : UGen { - var <>synth, <>server; - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, feature = 0, kernelSize = 3, threshold = 0.5, filterSize = 1, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0 | var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -17,38 +15,11 @@ FluidBufNoveltySlice : UGen { } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, feature = 0, kernelSize = 3, threshold = 0.5, filterSize = 1, windowSize = 1024, hopSize = -1, fftSize = -1, action| - - var synth, instance; - var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; - - source = source.asUGenInput; - indices = indices.asUGenInput; - - source.isNil.if {"FluidBufNoveltySlice: Invalid source buffer".throw}; - indices.isNil.if {"FluidBufNoveltySlice: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - - synth = { instance = FluidBufNoveltySlice.kr(source, startFrame, numFrames, startChan, numChans, indices, feature, kernelSize, threshold, filterSize, windowSize, hopSize, fftSize, maxFFTSize, kernelSize, filterSize, doneAction: Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - indices = server.cachedBufferAt(indices); indices.updateInfo; server.sync; - action.value(indices); - }; - - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [indices] + ).process( + source, startFrame, numFrames, startChan, numChans, indices, feature, kernelSize, threshold, filterSize, windowSize, hopSize, fftSize + ); } - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufOnsetSlice.sc b/release-packaging/Classes/FluidBufOnsetSlice.sc index 4579cb7..cf4bf6f 100644 --- a/release-packaging/Classes/FluidBufOnsetSlice.sc +++ b/release-packaging/Classes/FluidBufOnsetSlice.sc @@ -1,7 +1,5 @@ FluidBufOnsetSlice : UGen { - var <>synth, <>server; - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, metric = 0, threshold = 0.5, minSliceLength = 2, filterSize = 5, frameDelta = 0, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -15,41 +13,14 @@ FluidBufOnsetSlice : UGen { //NB For wrapped versions of NRT classes, we set the params for maxima to //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) - ^this.multiNew(\control, source, startFrame, numFrames, startChan, numChans, indices, metric, threshold, minSliceLength, filterSize, frameDelta, windowSize, hopSize, fftSize, maxFFTSize, doneAction); - } - *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, indices, metric = 0, threshold = 0.5, minSliceLength = 2, filterSize = 5, frameDelta = 0, windowSize = 1024, hopSize = -1, fftSize = -1, action| - var synth, instance; - source = source.asUGenInput; - indices = indices.asUGenInput; - - source.isNil.if {"FluidBufOnsetSlice: Invalid source buffer".throw}; - indices.isNil.if {"FluidBufOnsetSlice: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - //NB For wrapped versions of NRT classes, we set the params for maxima to - //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) - synth = { instance = FluidBufOnsetSlice.kr(source, startFrame, numFrames, startChan, numChans, indices, metric, threshold, minSliceLength, filterSize, frameDelta, windowSize, hopSize, fftSize, doneAction: Done.freeSelf)}.play(server); - forkIfNeeded{ - synth.waitForFree; - server.sync; - indices = server.cachedBufferAt(indices); indices.updateInfo; server.sync; - action.value(indices); - }; - instance.server = server; - instance.synth = synth; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [indices] + ).process( + source, startFrame, numFrames, startChan, numChans, indices, metric, threshold, minSliceLength, filterSize, frameDelta, windowSize, hopSize, fftSize + ); } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufPitch.sc b/release-packaging/Classes/FluidBufPitch.sc index fc97710..47419d8 100644 --- a/release-packaging/Classes/FluidBufPitch.sc +++ b/release-packaging/Classes/FluidBufPitch.sc @@ -1,5 +1,4 @@ FluidBufPitch : UGen{ - var <>synth, <>server; *kr {|source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, algorithm = 2, minFreq = 20, maxFreq = 10000, unit = 0, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| @@ -18,36 +17,10 @@ FluidBufPitch : UGen{ } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, algorithm = 2, minFreq = 20, maxFreq = 10000, unit = 0, windowSize = 1024, hopSize = -1, fftSize = -1, action| - - var synth,instance; - - source = source.asUGenInput; - features = features.asUGenInput; - - source.isNil.if {"FluidBufPitch: Invalid source buffer".throw}; - features.isNil.if {"FluidBufPitch: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - - synth = { instance = FluidBufPitch.kr(source, startFrame, numFrames, startChan, numChans, features, algorithm, minFreq, maxFreq, unit, windowSize, hopSize, fftSize, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - features = server.cachedBufferAt(features); features.updateInfo; server.sync; - action.value(features); - }; - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [features] + ).process( + source, startFrame, numFrames, startChan, numChans, features, algorithm, minFreq, maxFreq, unit, windowSize, hopSize, fftSize + ); } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufSines.sc b/release-packaging/Classes/FluidBufSines.sc index 70985d2..2fd2cd3 100644 --- a/release-packaging/Classes/FluidBufSines.sc +++ b/release-packaging/Classes/FluidBufSines.sc @@ -1,8 +1,6 @@ FluidBufSines : UGen{ - var <>synth, <>server; - - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, sines, residual, bandwidth = 76, threshold = 0.7, minTrackLen = 15, magWeight = 0.1, freqWeight = 1, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| + *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, sines = -1, residual = -1, bandwidth = 76, threshold = 0.7, minTrackLen = 15, magWeight = 0.1, freqWeight = 1, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -12,46 +10,18 @@ FluidBufSines : UGen{ source.isNil.if {"FluidBufSines: Invalid source buffer".throw}; - sines = sines ? -1; - residual = residual ? -1; - //NB For wrapped versions of NRT classes, we set the params for maxima to //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) ^this.multiNew(\control, source, startFrame, numFrames, startChan, numChans, sines, residual, bandwidth, threshold, minTrackLen, magWeight, freqWeight, windowSize, hopSize, fftSize, maxFFTSize, doneAction); } - - *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, sines, residual, bandwidth = 76, threshold = 0.7, minTrackLen = 15, magWeight = 0.1, freqWeight = 1, windowSize = 1024, hopSize = -1, fftSize = -1, action| - var synth, instance; - source = source.asUGenInput; - sines = sines.asUGenInput; - residual = residual.asUGenInput; - - source.isNil.if {"FluidBufSines: Invalid source buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - sines = sines ? -1; - residual = residual ? -1; - synth = { instance = FluidBufSines.kr(source, startFrame, numFrames, startChan, numChans, sines, residual, bandwidth, threshold, minTrackLen, magWeight, freqWeight, windowSize, hopSize, fftSize, doneAction:Done.freeSelf)}.play(server); - forkIfNeeded{ - synth.waitForFree; - server.sync; - if (sines != -1) {sines = server.cachedBufferAt(sines); sines.updateInfo; server.sync;} {sines = nil}; - if (residual != -1) {residual = server.cachedBufferAt(residual); residual.updateInfo; server.sync;} {residual = nil}; - action.value(sines, residual); - }; - instance.synth = synth; - instance.server = server; - ^instance; + *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, sines = -1, residual = -1, bandwidth = 76, threshold = 0.7, minTrackLen = 15, magWeight = 0.1, freqWeight = 1, windowSize = 1024, hopSize = -1, fftSize = -1, action| + ^FluidNRTProcess.new( + server, this, action, [sines, residual].select{|x| x!= -1} + ).process( + source, startFrame, numFrames, startChan, numChans, sines, residual, bandwidth, threshold, minTrackLen, magWeight, freqWeight, windowSize, hopSize, fftSize + ); } - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufSpectralShape.sc b/release-packaging/Classes/FluidBufSpectralShape.sc index 342d912..b3a1129 100644 --- a/release-packaging/Classes/FluidBufSpectralShape.sc +++ b/release-packaging/Classes/FluidBufSpectralShape.sc @@ -1,7 +1,5 @@ FluidBufSpectralShape : UGen { - var <>synth, <>server; - *kr{ |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, windowSize = 1024, hopSize = -1, fftSize = -1, doneAction = 0| var maxFFTSize = if (fftSize == -1) {windowSize.nextPowerOfTwo} {fftSize}; @@ -20,36 +18,11 @@ FluidBufSpectralShape : UGen { } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, features, windowSize = 1024, hopSize = -1, fftSize = -1, action| - - var synth, instance; - source = source.asUGenInput; - features = features.asUGenInput; - - source.isNil.if {"FluidBufSpectralShape: Invalid source buffer".throw}; - features.isNil.if {"FluidBufSpectralShape: Invalid features buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - synth = { instance = FluidBufSpectralShape.kr(source, startFrame, numFrames, startChan, numChans, features, windowSize, hopSize, fftSize, doneAction:Done.freeSelf)}.play(server); - - //NB For wrapped versions of NRT classes, we set the params for maxima to - //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) - forkIfNeeded{ - synth.waitForFree; - server.sync; - features = server.cachedBufferAt(features); features.updateInfo; server.sync; - action.value(features); - }; - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [features] + ).process( + source, startFrame, numFrames, startChan, numChans, features, windowSize, hopSize, fftSize + ); } - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufStats.sc b/release-packaging/Classes/FluidBufStats.sc index 409507b..833ddc6 100644 --- a/release-packaging/Classes/FluidBufStats.sc +++ b/release-packaging/Classes/FluidBufStats.sc @@ -1,5 +1,4 @@ FluidBufStats : UGen{ - var <>synth, <>server; *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, stats, numDerivs = 0, low = 0, middle = 50, high = 100, doneAction=0| @@ -13,34 +12,11 @@ FluidBufStats : UGen{ } *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, stats, numDerivs = 0, low = 0, middle = 50, high = 100, action| - - var synth, instance; - source = source.asUGenInput; - stats = stats.asUGenInput; - - source.isNil.if {"FluidBufStats: Invalid source buffer".throw}; - stats.isNil.if {"FluidBufStats: Invalid stats buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - - synth = { instance = FluidBufStats.kr(source, startFrame, numFrames, startChan, numChans, stats, numDerivs, low, middle, high, doneAction:Done.freeSelf)}.play(server); - forkIfNeeded{ - synth.waitForFree; - server.sync; - stats = server.cachedBufferAt(stats); stats.updateInfo; server.sync; - action.value(stats); - }; - instance.synth = synth; - instance.server = server; - ^instance; + ^FluidNRTProcess.new( + server, this, action, [stats] + ).process( + source, startFrame, numFrames, startChan, numChans, stats,numDerivs, low, middle, high + ); } - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidBufThreadDemo.sc b/release-packaging/Classes/FluidBufThreadDemo.sc index bbf9f61..d4e2425 100644 --- a/release-packaging/Classes/FluidBufThreadDemo.sc +++ b/release-packaging/Classes/FluidBufThreadDemo.sc @@ -1,46 +1,16 @@ FluidBufThreadDemo : UGen{ - var <>synth, <>server; - - *kr {|result, time, doneAction = 0| + *kr {|result, time, doneAction = 0| result = result.asUGenInput; - - result.isNil.if {"FluidBufThreadDemo: Invalid output buffer".throw}; - - //NB For wrapped versions of NRT classes, we set the params for maxima to - //whatever has been passed in language-side (e.g maxFFTSize still exists as a parameter for the server plugin, but makes less sense here: it just needs to be set to a legal value) + result.isNil.if {this.class.name+": Invalid output buffer".throw}; ^this.multiNew(\control, result, time, doneAction); - } + } *process { |server, result, time = 1000, action| - - var synth,instance; - - result = result.asUGenInput; - - result.isNil.if {"FluidBufThreadDemo: Invalid output buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - - synth = { instance = FluidBufThreadDemo.kr(result, time, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - result = server.cachedBufferAt(result); result.updateInfo; server.sync; - action.value(result); - }; - instance.synth = synth; - instance.server = server; - ^instance; - } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; + ^FluidNRTProcess.new( + server, this, action, [result] + ).process( + result, time + ); } } diff --git a/release-packaging/Classes/FluidBufTransients.sc b/release-packaging/Classes/FluidBufTransients.sc index 2d1c63b..eb0f832 100644 --- a/release-packaging/Classes/FluidBufTransients.sc +++ b/release-packaging/Classes/FluidBufTransients.sc @@ -1,8 +1,6 @@ FluidBufTransients : UGen { - var <>synth, <>server; - - *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, transients, residual, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, doneAction = 0 | + *kr { |source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, transients = -1, residual = -1, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, doneAction = 0 | source = source.asUGenInput; transients = transients.asUGenInput; @@ -10,46 +8,15 @@ FluidBufTransients : UGen { source.isNil.if {"FluidBufTransients: Invalid source buffer".throw}; - transients = transients ? -1; - residual = residual ? -1; - ^this.multiNew(\control, source, startFrame, numFrames, startChan, numChans, transients, residual, order, blockSize, padSize, skew, threshFwd, threshBack, windowSize, clumpLength, doneAction); } - *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, transients, residual, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, action| - - var synth, instance; - source = source.asUGenInput; - transients = transients.asUGenInput; - residual = residual.asUGenInput; - - source.isNil.if {"FluidBufTransients: Invalid source buffer".throw}; - - server = server ? Server.default; - server.ifNotRunning({ - "WARNING: Server not running".postln; - ^nil; - }); - transients = transients ? -1; - residual = residual ? -1; - - synth = {instance = FluidBufTransients.kr(source, startFrame, numFrames, startChan, numChans, transients, residual, order, blockSize, padSize, skew, threshFwd, threshBack, windowSize, clumpLength, doneAction:Done.freeSelf)}.play(server); - - forkIfNeeded{ - synth.waitForFree; - server.sync; - if (transients != -1) {transients = server.cachedBufferAt(transients); transients.updateInfo; server.sync;} {transients = nil}; - if (residual != -1) {residual = server.cachedBufferAt(residual); residual.updateInfo; server.sync;} {residual = nil}; - action.value(transients, residual); - }; - instance.synth = synth; - instance.server = server; - ^instance; + *process { |server, source, startFrame = 0, numFrames = -1, startChan = 0, numChans = -1, transients = -1, residual = -1, order = 20, blockSize = 256, padSize = 128, skew = 0, threshFwd = 2, threshBack = 1.1, windowSize = 14, clumpLength = 25, action| + ^FluidNRTProcess.new( + server, this, action,[transients, residual].select{|x| x!= -1} + ).process( + source, startFrame, numFrames, startChan, numChans, transients, residual, order, blockSize, padSize, skew, threshFwd, threshBack, windowSize, clumpLength + ); } - - cancel{ - if(this.server.notNil) - {this.server.sendMsg("/u_cmd", this.synth.nodeID, this.synthIndex, "cancel")}; - } } diff --git a/release-packaging/Classes/FluidNRTProcess.sc b/release-packaging/Classes/FluidNRTProcess.sc new file mode 100644 index 0000000..b47e0ad --- /dev/null +++ b/release-packaging/Classes/FluidNRTProcess.sc @@ -0,0 +1,45 @@ +FluidNRTProcess : Object{ + var