// title: [beginner question] how to transmit parameter value to a function inside a SynthDef // author: pictosonic // description: // In this code, I have a list of frequencies. // When I am calling \synthexample, I provide some parameters, the usual ones (amp, etc) and other like bb and threshold. // The bb parameter is taken into account and works. // And the threshold parameter is passed to a function which goal is to pick a frequency on a list of frequencies that is greater or equal to the threshold value. // The problem is that the threshold value is not taken into account. It works only if I pass to the function a litteral value, such as 200. // Also passing \threshold.ir(100) raises an exception at Command+Enter time. // // So how to pass a parameter to a function called inside a SynthDef ? // // Thank you ! // code: ~freqgold = List[ 29.034441847481, 58.068883694963, 116.13776738993, 232.27553477985, 464.5510695597, 929.1021391194, 1858.2042782388, 3716.4085564776, 7432.8171129552, 14865.63422591, 29731.268451821 ]; ~getFirstFreq = { | array = #[0], seuil = 0 | var rfreq=0; var i=0; while({ (rfreq==0) && (i < array.size()) }, { if( array[i] >= seuil , { rfreq=array[i]; }, { } ); i = i+1 }); rfreq.postln; if( rfreq == 0, { rfreq=array[array.size()-1] }, { rfreq } ) }; SynthDef(\synthexample, { |out, sustain = 1, amp = 0.5, bb = 5, threshold = 500| var env = Env.adsr(\atk.ir(0.05), \dec.ir(0.5), \slev.ir(0.4), \rel.ir (1) ).ar(Done.freeSelf, \gate.kr (1)); var modHz = XLine.kr(1, bb, 10); var mod = SinOsc.ar(modHz, mul: 3); var f = ~getFirstFreq.value(~freqgold, \threshold); var sig = SinOsc.ar([f, f+mod], mul: 0.2 ) * amp * env; Out.ar(out, sig ); }).add; (instrument: \synthexample, atk: 0.01, rel: 40, amp: 0.5, bb: 2, threshold: 500).play;