0

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)))
Alexis King
  • 43,109
  • 15
  • 131
  • 205
Theodor Berza
  • 573
  • 3
  • 12
  • 1
    You want `(list HALF QUARTER QUARTER EIGHT)`, not `'(HALF QUARTER QUARTER EIGHT)`. The latter produces a list of symbols because quoting completely disables any evaluation (it is not a shorthand for `list`). – Alexis King Jan 23 '16 at 22:02
  • Thank you, thank you, thank you! – Theodor Berza Jan 23 '16 at 22:49
  • Also, you probably want to use `(define HALF 30000)` instead of `(let ([HALF 30000]) 30000)`. Let creates a definition that's only available within the body of the let, but define creates a definition that's available anywhere in that scope (in this case anywhere in the module). – Alex Knauth Jan 24 '16 at 00:18
  • I already changed that. Now it works perfect. – Theodor Berza Jan 24 '16 at 16:24
  • Possible duplicate of [What is the difference between quote and list?](http://stackoverflow.com/questions/34984552/what-is-the-difference-between-quote-and-list) – Alexis King Jan 25 '16 at 03:27
  • My question was first even if it's less general. – Theodor Berza Jan 25 '16 at 12:46
  • @TheodorBerza [On the SE network, it is perfectly okay for older questions to be closed as duplicates of newer ones](http://meta.stackoverflow.com/q/251938/465378), and [the idea of canonical duplicates is common and useful](http://meta.stackoverflow.com/tags/canonical/info). – Alexis King Jan 25 '16 at 16:35

0 Answers0