[CM] snd-rt <slider> naming problem

Kjetil S. Matheussen k.s.matheussen at notam02.no
Wed Apr 2 17:29:05 PDT 2008



On Thu, 3 Apr 2008, Kjetil S. Matheussen wrote:

>
>
> On Thu, 3 Apr 2008, border wrote:
>
>> hi,
>>
>> I'm working on a model of a tibetan singing bowl with additive synthesis
>> and I'm trying to write a few functions assisting me with it.
>> The following function is supposed to take a list of arbitrary length as
>> argument and is creating a sinus with a few sliders from each element in
>> the list. The list is as follows:
>>
>> ((frequency amplitude frequency_slider_name amp_slider_name) ...)
>>
>> so for each list of four elements it should create a sinus with the
>> given frequency, amplitude and names of the slider.
>> But the problem is that the <slider> object only accepts strings, not
>> expressions which evaluate to a string (or so it would seem to me) and
>> also no variables containing a string.
>> How am I going to get past that problem?
>>
>> the error I get is thus:
>>
>> string-append: wrong-type-arg: Wrong type (expecting "string"): freqname
>> (freqname)
>>
>> but if I use string-append like this:
>>
>> (let ((freq "freq")
>>      (amp "amp"))
>>  (print (string-append freq amp)))
>>
>> it works?!?!  prints --> "freqamp"
>>
>>
>> My code is the following:
>>
>> (definstrument (oscillatorbank oscillators)
>>    (define-multi-instrument-rt-dialog)
>>    (define* (oscillator-rec oscillators)
>>      (if (null? oscillators)
>>  #t
>>  (let*
>>      ((oscillator1 (car oscillators))
>>       (freq (car oscillator1))
>>       (amp (car (cdr oscillator1)))
>>       (freqname (car (cdr (cdr oscillator1))))
>>       (ampname (car (cdr (cdr (cdr oscillator1))))))
>>    (begin (<rt-out> (* (oscil* (<slider> freqname (- freq 1) freq (+
>> freq 1)))
>> (<slider> ampname 0 amp 1 :log #t)))
>>   (oscillator-rec (cdr oscillators))))))
>>    (oscillator-rec oscillators))
>>
>> (define oscilbank (oscillatorbank '((57.20 0.1 "freq1" "amp1") (175.63
>> 0.1 "freq2" "amp2") (343.89 0.1 "freq3" "amp3"))))
>>
>> anyone any hints?
>>
>
> Good question. What you are trying to do is currently
> not possible, unfortunately. The slider problem can be
> solved by replacing the <rt-out> block with:
>
> (<rt-out> (* (oscil* ,`(<slider> ,(local-eval freqname *rt-local-code-environment*)
>                                  (- freq 1) freq (+ freq 1)))
>              ,`(<slider> ,(local-eval ampname *rt-local-code-environment*)
>                          0.0001 amp 2 :log #t)
>              ))
>
> (Yes, I know thats pretty horrible. :-) )
>
> However, this problem is luckily trivial to fix in the <slider> macro
> itself, and I will do that shortly.
>
>
> The bigger problem, though, is that after doing this
> replacement, only two sliders  are shown, and not
> six. And I don't know how to fix that.
> I have to think about this. Hopefully its possible to fix
> without having to expand macros before caching the function.
>
>
> But luckily, I have a workaround _hack_ for this problem as well:
>
> (definstrument (oscillatorbank oscillators)
>   (<rt-out> ,`(+ ,@(map (lambda (osc)
>                           (define freq (nth 0 osc))
>                           (define amp (nth 1 osc))
>                           (define freqname (nth 2 osc))
>                           (define ampname (nth 3 osc))
>                           `(* (oscil* (<slider> ,freqname
>                                                 (- ,freq 1) ,freq (+ ,freq 1)))
>                               (<slider> ,ampname
>                                         0 ,amp 1 :log #f)))
>                         oscillators))))
>

This one is better:

(definstrument (oscillatorbank oscillators)
   (rt-clear-cache!)
   (<rt-out> ,`(+ ,@(map (lambda (osc)
                           (define freq (nth 0 osc))
                           (define amp (nth 1 osc))
                           (define freqname (nth 2 osc))
                           (define ampname (nth 3 osc))
                           `(* (oscil* (<slider> ,freqname
                                                 (- ,freq 1) ,freq (+ ,freq 1)))
                               (<slider> ,ampname
                                         0 ,amp 1 :log #f)))
                         oscillators))))


Since functions are cached before macros are expanded (there
are good reasons for doing that if I remember correctly),
the cache must manually be cleared with (rt-clear-cache!)
before calling <rt-out> to avoid getting the exact
same instrument as last time even when the parameters
for the instrument have been changed.




More information about the Cmdist mailing list