At first I defined HALF
, QUARTER
and EIGHT
to their values with define
and with it the quoted symbols would get introduced as arguments in the note
function thus making an error. Then I used let
and now I get the error
stream-rec->C: argument is not non-null `stream-rec' pointer
argument: #f
My theory is that stream still processes HALF
as 'HALF
instead of 30000
. I tried putting it into an eval
list in note
, in random-length
in let
bindings and in random-note
and neither worked. What can I do?
#lang racket
(require rsound
rsound/piano-tones)
;Where notes are made.
(define stream (make-pstream))
(define count 10000)
(define (note y x)
(pstream-queue stream (clip (piano-tone y) 0 20000) count)
(set! count (+ count x)))
;Defining length of notes.
(let ([HALF 30000]) 30000)
(let ([QUARTER 15000]) 15000)
(let ([EIGHT 7500]) 7500)
(define (random-element list)
(list-ref list (random (length list))))
;Getting a random note length.
(define (random-length)
(random-element '(HALF QUARTER QUARTER EIGHT)))
;Getting a random note and note length.
(define (random-note)
(note (random-element '(40 42 43 45 47 48 50 52 54 55 57 59 60 62 64)) (random-length)))
;Main loop for creating the notes.
(for ([i (in-range 32)])
(random-note))
;For the program not to close itself before runing loop, only after pstream- queue is emptied.
(define ok-to-exit? #f)
(pstream-queue-callback stream (lambda () (set! ok-to-exit? #t)) count)
(let loop ()
(sleep 0.1)
(unless ok-to-exit?
(loop)))