[CM] snd-rt <slider> naming problem

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



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

(define oscilbank (oscillatorbank '((57.20 0.1 "freq1" "amp1")
                                     (175.63 0.1 "freq2" "amp2")
                                     (343.89 0.1 "freq3" "amp3"))))



Note that I had to turn off :log in the amp slider. There's a bug
with that one as well.


Thanks for reporting these problems. The gui stuff is only a few
weeks old, so this is very useful feedback.




More information about the Cmdist mailing list