[Impromptu] problem using two metres

Andrew Sorensen andrew at moso.com.au
Fri Mar 13 00:11:02 GMT 2009


Hi Michele,

You should avoid fmod, it is evil, and it will be removed in v1.4

If modulo isn't available then you must be using an out of date  
version of impromptu?

If you do have modulo but the previous example doesn't work then your  
beat is probably a real number and not a rational number.  Basically  
the rule of thumb is this - make sure that you always use integers or  
rationals whenever you create or touch a beat.  This goes for when you  
create the beat with metro such as (*metro* 'get-beat 4/1) (*metro*  
'get-beat 1/2) (*metro* 'get-beat 4) or modify a beat (+ beat 1/3) (+  
beat 3/2) (+ beat 3) (* beat 1/2) etc..  To check just print beat and  
if it is a real number then you're in trouble.

Rational numbers are really very helpful.  In particular for rhythmic  
work.  This ensures that things like triplets, quintuplets etc.. are  
always accurate.  fmod and modulo with real numbers basically will  
never work accurately.  Below is a similar example as before but uses  
rationals more explicitly.  You can't do this kind of thing reliably  
with real numbers (and therefore with fmod).

Hope this all makes sense :)

(define loop
    (lambda (beat)
       (case (modulo beat 4)
             ((0)
              (play piano 36 110 4))
             ((1/3 2/3 1)
              (play piano (random '(87 72 74 75 82)) (cosr 70 20 4)  
3/2))
             ((3/2)
              (for-each (lambda (p)
                           (play piano p (random 40 60) 2))
                        (pc:make-chord 50 70 3 (random '((0 3 7 10) (2  
5 8 10))))))
             ((10/4 11/4 12/4 13/4)
              (play piano (random '(60 65 63 62 58)) (cosr 70 30 3)  
3/2))
             ((15/4)
              (play piano 48 80 1/2)))
       (callback (*metro* (+ beat (* .5 1/12))) 'loop (+ beat 1/12))))

(loop (*metro* 'get-beat 4))

Cheers,
Andrew.

On 13/03/2009, at 9:11 AM, Michele Pasin wrote:

> btw the function below doesn't work like that, you need to use 'fmod'
> instead of 'modulo'.
> (mind that I haven't applied Glen's patches yet - nor had a chance to
> try to understand the various floating point related issues - so
> again, I might have left out something important here!)
>
> thanks, impromptu rocks!
>
> m
>
>
> On 12 Mar 2009, at 00:29, Andrew Sorensen wrote:
>
>> ;; using modulo directly
>> (define loop
>>   (lambda (beat)
>>      (case (modulo beat 8)
>>            ((0)
>>             (play piano 60 120 1)
>>             (play piano 36 120 1))
>>            ((1 2 3)
>>             (play piano 36 120 1))
>>            ((4 5 6 7)
>>             (play piano 40 120 1)))
>>      (callback (*metro* (+ beat (* .5 1/2))) 'loop (+ beat 1/2))))
>>
>> (loop (*metro* 'get-beat 4))
>
>
>
>
>
>
>
>
>
> ____________________________
> Dr. Michele Pasin
> Centre for Computing in the Humanities
> King's College, London
> http://staff.cch.kcl.ac.uk/~mpasin/
>
>
>
>
>
>
> _______________________________________________
> Impromptu mailing list
> Impromptu at lists.moso.com.au
> http://lists.moso.com.au/mailman/listinfo/impromptu



More information about the Impromptu mailing list