download bess1.scm
Language: Scheme
LOC: 464
Project Info
Snd
Server: SourceForge
Type: cvs
SourceForge\s\snd\snd\cvs‑snd\
   _new_snd-test.rb
   _sndlib.h
   aclocal.m4
   analog-filter.scm
   audinfo.c
   audio.c
   autosave.scm
   bess.rb
   bess.scm
   bess1.rb
   bess1.scm
   bird.rb
   bird.scm
   clm-ins.rb
   clm-ins.scm
   clm-strings.h
   clm.c
   clm.h
   clm23.scm
   clm2xen.c
   clm2xen.h
   cmn-glyphs.lisp
   config.guess
   config.h.in
   config.rpath
   config.sub
   configure.ac
   debug.scm
   dlocsig.rb
   draw.rb
   draw.scm
   dsp.rb
   dsp.scm
   edit-menu.scm
   edit123.scm
   effects-utils.scm
   effects.rb
   env.rb
   env.scm
   enved.scm
   eval-c.scm
   event.scm
   examp.rb
   examp.scm
   extensions.rb
   extensions.scm
   fade.scm
   fft-menu.scm
   fix-optargs.scm
   fmv.scm
   freeverb.rb
   freeverb.scm
   gettext.h
   gl.c
   grani.scm
   gtk-effects.scm
   gtk-popup.scm
   gui.scm
   headers.c
   help-snd-fm.pd
   help-snd.pd
   HISTORY.Snd
   hooks.rb
   hooks.scm
   index.rb
   index.scm
   inf-snd.el
   io.c
   jcrev.scm
   ladspa-help.scm
   ladspa.scm
   makefile.in
   makefile.no-gettext
   maraca.rb
   maraca.scm
   marks-menu.scm
   marks.rb
   marks.scm
   maxf.rb
   maxf.scm
   midi.c
   misc.scm
   mix-menu.scm
   mix.rb
   mix.scm
   mixer.scm
   moog.scm
   musglyphs.rb
   musglyphs.scm
   nb.rb
   nb.scm
   new-backgrounds.scm
   new-buttons.scm
   new-effects.scm
   new-icons.scm
   noise.rb
   noise.scm
   old-mac-audio.c
   old-snd.spec
   oo.scm
   oscope.scm
   panic.scm
   pd-add.scm
   pd-any.scm
   pd-fm.scm
   pd-global.scm
   pd-inout.scm
   pd-local.scm
   pd-mozilla.scm
   pd-send_receive.scm
   peak-env.scm
   piano.rb
   piano.scm
   play.rb
   play.scm
   poly.rb
   poly.scm
   popup.rb
   popup.scm
   prc95.rb
   prc95.scm
   pvoc.rb
   pvoc.scm
   README.Snd
   rgb.rb
   rgb.scm
   rmsgain.scm
   rt-compiler.scm
   rt-engine.scm
   rt-examples.scm
   rt.tex
   rtio.rb
   rtio.scm
   rubber.rb
   rubber.scm
   saw.c
   singer.rb
   singer.scm
   snd-0.h
   snd-1.h
   snd-axis.c
   snd-chn.c
   snd-completion.c
   snd-dac.c
   snd-data.c
   snd-draw.c
   snd-edits.c
   snd-env.c
   snd-error.c
   snd-fft.c
   snd-file.c
   snd-file.h
   snd-find.c
   snd-g0.h
   snd-g1.h
   snd-gchn.c
   snd-gdraw.c
   snd-gdrop.c
   snd-genv.c
   snd-gfft.c
   snd-gfile.c
   snd-gfind.c
   snd-ghelp.c
   snd-gl.scm
   snd-glistener.c
   snd-gmain.c
   snd-gmenu.c
   snd-gmix.c
   snd-gprefs.c
   snd-gprint.c
   snd-grec.c
   snd-gregion.c
   snd-gsnd.c
   snd-gtk.scm
   snd-gutils.c
   snd-gxbitmaps.c
   snd-gxcolormaps.c
   snd-gxen.c
   snd-gxutils.c
   snd-help.c
   snd-hobbit.scm
   snd-io.c
   snd-kbd.c
   snd-ladspa.c
   snd-listener.c
   snd-main.c
   snd-marks.c
   snd-menu.c
   snd-menu.h
   snd-mix.c
   snd-motif.scm
   snd-nogui.c
   snd-nogui0.h
   snd-nogui1.h
   snd-prefs.c
   snd-print.c
   snd-rec.c
   snd-rec.h
   snd-region.c
   snd-run.c
   snd-select.c
   snd-sig.c
   snd-snd.c
   snd-strings.h
   snd-trans.c
   snd-utils.c
   snd-x0.h
   snd-x1.h
   snd-xchn.c
   snd-xdraw.c
   snd-xdrop.c
   snd-xen.c
   snd-xenv.c
   snd-xfft.c
   snd-xfile.c
   snd-xfind.c
   snd-xhelp.c
   snd-xlistener.c
   snd-xm.rb
   snd-xmain.c
   snd-xmenu.c
   snd-xmix.c
   snd-xprefs.c
   snd-xprint.c
   snd-xrec.c
   snd-xref.c
   snd-xregion.c
   snd-xsnd.c
   snd-xutils.c
   snd-xxen.c
   snd.1
   Snd.ad
   snd.c
   Snd.gtkrc
   snd.h
   snd.spec
   snd_conffile.scm
   snd_pd_external.c
   snd_pd_external.h
   snd4.scm
   snd5.scm
   snd6.scm
   snd7.scm
   sndctrl.c
   sndinfo.c
   sndlib-strings.h
   sndlib.h.in
   sndlib2xen.c
   sndlib2xen.h
   sndplay.c
   sndrecord.c
   sndwarp.scm
   sound.c
   special-menu.scm
   spectr.rb
   spectr.scm
   strad.rb
   strad.scm
   TODO.Snd
   track-colors.scm
   v.rb
   v.scm
   vct.c
   vct.h
   ws.rb
   ws.scm
   xen.c
   xen.h
   xg-x11.h
   xm-enved.rb
   xm-enved.scm
   zip.rb
   zip.scm

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
#!/usr/bin/env guile \
-e main -s
!#
;;; bess1.scm -- some examples from clm-2/rt.lisp and clm-2/bess5.cl

;; Author: Michael Scholz <scholz-micha@gmx.de>
;; Created: Thu May 29 04:14:35 CEST 2003
;; Last: Sun Jun 15 03:50:21 CEST 2003

;;; Commentary:

;; Requires libsndlib.so and libxm.so!

;; This file provides simple mono real time output to DAC.  Tempo,
;; frequency, amplitude, and FM index can be controlled via sliders.
;; The music algorithms are taken from clm-2/rt.lisp and
;; clm-2/bess5.cl.

;; (main) calls (rt-motif) which starts a Motif widget with two DAC
;; tests.
;;
;; (rt-motif #:srate       *clm-srate*        ;; 22050
;;           #:bufsize     *clm-rt-bufsize*   ;; 128
;;           #:data-format *clm-data-format*) ;; mus-lshort

;;; Code:

(use-modules (ice-9 optargs) (ice-9 format))

;; You may correct next two lines to fit your needs.
(load-extension "libsndlib" "Init_sndlib")
(load-extension "libxm" "Init_libxm")

(define* (main #:rest args) (rt-motif))
;;(define* (main #:rest args) (rt-motif #:srate 11025 #:bufsize 1024))

(define *clm-srate* 22050)
(define *clm-data-format* mus-lshort)
(define *clm-rt-bufsize* 128)
(define *output* #f)			;holds fd from (mus-audio-open-output)

(define ctempo 0.25)
(define camp 1.0)
(define cfreq 1.0)
(define cindex 1.0)
(define cplay #f)
  
(define sliderback "lightsteelblue")
(define background "lightsteelblue1")

(if (not (defined? 'definstrument)) (define definstrument define*))
;(define (seconds->samples secs) (inexact->exact (round (* secs (mus-srate)))))

;; called by XtAppAddWorkProc
(define (rt-send->dac func)
  (if cplay
      (begin
	(mus-audio-write *output* (vct->sound-data (vct-map! (make-vct *clm-rt-bufsize*) (func))
						   (make-sound-data 1 *clm-rt-bufsize*) 0)
			 *clm-rt-bufsize*)
	#f)
      (begin
	(mus-audio-close *output*)
	#t)))

(definstrument (make-rt-violin dur freq amp #:key
			       (fm-index 1.0)
			       (amp-env '(0 0 25 1 75 1 100 0)))
  "(make-rt-violin dur freq amp (fm-index 1.0) (amp-env '(0 0 25 1 75 1
100 0))) real time simple violin (see snd-7/fm.html)"
  (let* ((frq-scl (hz->radians freq))
         (maxdev (* frq-scl fm-index))
         (index1 (* maxdev (/ 5.0 (log freq))))
         (index2 (* maxdev 3.0 (/ (- 8.5 (log freq)) (+ 3.0 (/ freq 1000)))))
         (index3 (* maxdev (/ 4.0 (sqrt freq))))
         (carrier (make-oscil #:frequency freq))
         (fmosc1 (make-oscil #:frequency freq))
         (fmosc2 (make-oscil #:frequency (* 3 freq)))
         (fmosc3 (make-oscil #:frequency (* 4 freq)))
         (ampf  (make-env #:envelope amp-env #:scaler amp #:duration dur))
         (indf1 (make-env #:envelope '(0 1 25 0.4 75 0.6 100 0) #:scaler index1 #:duration dur))
         (indf2 (make-env #:envelope '(0 1 25 0.4 75 0.6 100 0) #:scaler index2 #:duration dur))
         (indf3 (make-env #:envelope '(0 1 25 0.4 75 0.6 100 0) #:scaler index3 #:duration dur))
         (pervib (make-triangle-wave #:frequency 5 #:amplitude (* 0.0025 frq-scl)))
         (ranvib (make-rand-interp #:frequency 16 #:amplitude (* 0.005 frq-scl))))
    (lambda ()
      (let ((vib (+ (triangle-wave pervib) (rand-interp ranvib))))
	(* (env ampf)
	   (oscil carrier
		  (+ vib 
		     (* (env indf1) (oscil fmosc1 vib))
		     (* (env indf2) (oscil fmosc2 (* 3.0 vib)))
		     (* (env indf3) (oscil fmosc3 (* 4.0 vib))))))))))

;; from clm-2/rt.lisp
(define* (make-vct-test #:key
			(srate *clm-srate*)
			(bufsize *clm-rt-bufsize*)
			(data-format *clm-data-format*))
  (let ((vmode (list->array 1 '(0 12 2 4 14 4 5 5 0 7 7 11 11)))
	(vpits (make-array 0 (1+ lim)))
	(vbegs (make-array 0 (1+ lim)))
	(cellbeg 0)
	(cellsiz 6)
	(cellctr 0)
	(func #f)
	(len 0)
	(dur 0.0))
    (do ((i 0 (1+ i)))
	((= i lim))
      (array-set! vpits (inexact->exact (floor (random 12.0))) i)
      (array-set! vbegs (+ 1 (inexact->exact (floor (random 3.0)))) i))
    (set! *clm-srate* srate)
    (set! *clm-rt-bufsize* bufsize)
    (set! (mus-srate) srate)
    (set! *output* (mus-audio-open-output mus-audio-default srate 1 data-format (* bufsize 2)))
    (lambda ()
      (if (> len 1)
	  (set! len (- len 1))
	  (begin
	    (set! dur (* ctempo (array-ref vbegs (1+ cellctr))))
	    (set! cellctr (1+ cellctr))
	    (if (> cellctr (+ cellsiz cellbeg))
		(begin
		  (if (> (random 1.0) 0.5) (set! cellbeg (1+ cellbeg)))
		  (if (> (random 1.0) 0.5) (set! cellsiz (1+ cellsiz)))
		  (set! cellctr cellbeg)))
	    (set! func (make-rt-violin dur
				       (* cfreq 16.351 16
					  (expt 2 (/ (array-ref vmode (array-ref vpits cellctr))
						     12.0)))
				       (* camp 0.3) #:fm-index cindex))
	    (set! len (inexact->exact (ceiling (/ (seconds->samples dur) bufsize))))))
      func)))

;; from clm-2/bess5.cl and clm-2/clm-example.lisp
(define lim 256)
(define time 60)
(define mode (list->array 1 '(0 0 2 4 11 11 5 6 7 9 2 0 0)))
(define rats (list->array 1 '(1.0 256/243 9/8 32/27 81/64 4/3 1024/729
				  3/2 128/81 27/16 16/9 243/128 2.0)))

(define bell '(0 0 10 0.25 90 1.0 100 1.0))

(define pits (make-array 0 (1+ lim)))
(define octs (make-array 0 (1+ lim)))
(define rhys (make-array 0 (1+ lim)))
(define begs (make-array 0 (1+ lim)))
(define amps (make-array 0 (1+ lim)))

(define (tune x)
  (let* ((pit (modulo x 12))
	 (oct (inexact->exact (floor (/ x 12))))
	 (base (array-ref rats pit)))
    (* base (expt 2 oct))))

(define (rbell x)
  (envelope-interp (* x 100) bell))

(define* (make-agn #:key
		   (srate *clm-srate*)
		   (bufsize *clm-rt-bufsize*)
		   (data-format *clm-data-format*))
  (let ((wins (list->array 1 '((0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
			       (0 0 60 0.1 80 0.2 90 0.4 95 1 100 0)
			       (0 0 10 1 16 0 32 0.1 50 1 56 0 60 0 90 0.3 100 0)
			       (0 0 30 1 56 0 60 0 90 0.3 100 0)
			       (0 0 50 1 80 0.3 100 0)
			       (0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
			       (0 0 40 0.1 60 0.2 75 0.4 82 1 90 1 100 0)
			       (0 0 10 1 32 0.1 50 1 90 0.3 100 0)
			       (0 0 60 0.1 80 0.3 95 1 100 0)
			       (0 0 80 0.1 90 1 100 0))))
	(nextbeg 0.0)
	(beg 0.0)
	(dur 0.0)
	(freq 0.0)
	(ampl 0.0)
	(ind 0.0)
	(cellctr 0)
	(cellsiz 4)
	(cellbeg 0)
	(whichway 1)
	(func #f)
	(len 0))
    (do ((i 0 (1+ i)))
	((= i lim))
      (array-set! octs (inexact->exact (floor (+ 4 (* 2 (rbell (random 1.0)))))) i)
      (array-set! pits (array-ref mode (inexact->exact (floor (* 12 (random 1.0))))) i)
      (array-set! rhys (inexact->exact (floor (+ 4 (* 6 (random 1.0))))) i)
      (array-set! begs (inexact->exact (if (< (random 1.0) 0.9) 
					   (floor (+ 4 (* 2 (random 1.0))))
					   (* 6 (floor (random 4.0)))))
		  i)
      (array-set! amps (inexact->exact (floor (+ 1 (* 8 (rbell (random 1.0)))))) i))
    (set! *clm-srate* srate)
    (set! *clm-rt-bufsize* bufsize)
    (set! (mus-srate) srate)
    (set! *output* (mus-audio-open-output mus-audio-default srate 1 data-format (* bufsize 2)))
    (lambda ()
      (if (> len 1)
	  (set! len (- len 1))
	  (begin
	    (set! beg (+ beg nextbeg))
	    (set! nextbeg (+ nextbeg (max 0.025 (* ctempo (+ 0.95 (random 0.1))
						   (array-ref begs cellctr)))))
	    (set! dur (max 0.025 (* ctempo (+ 0.85 (random 0.1)) (array-ref rhys cellctr))))
	    (set! freq (* cfreq 16.351 (tune (array-ref pits cellctr))
			  (expt 2 (array-ref octs cellctr))))
	    (set! ampl (* camp 10 (max 0.003 (* (array-ref amps cellctr) 0.01))))
	    (set! ind (* cindex (random 1.0) 3.0))
	    (set! cellctr (1+ cellctr))
	    (if (> cellctr (+ cellsiz cellbeg))
		(begin
		  (set! cellbeg (1+ cellbeg))
		  (if (> (random 1.0) 0.5) (set! cellsiz (+ cellsiz whichway)))
		  (if (and (> cellsiz 10) (> (random 1.0) 0.99))
		      (set! whichway -2)
		      (if (and (> cellsiz 6) (> (random 1.0) 0.999))
			  (set! whichway -1)
			  (if (< cellsiz 4)
			      (set! whichway 1))))
		  (set! nextbeg (+ nextbeg (random 1.0)))
		  (set! cellctr cellbeg)))
	    (set! func (make-rt-violin dur freq ampl
				       #:fm-index ind
				       #:amp-env (array-ref wins
							    (inexact->exact
							     (floor (* 10 (- beg (floor beg))))))))
	    (set! len (ceiling (/ (seconds->samples dur) bufsize)))))
      func)))

;; from env.scm
(define* (envelope-interp #:rest args)
  (let ((x (car args))
	(env (cadr args))
	(base (if (null? (cddr args)) #f (caddr args))))
    (cond ((null? env) 0.0)
	  ((or (<= x (car env))
	       (null? (cddr env)))
	   (cadr env))
	  ((> (caddr env) x)
	   (if (or (= (cadr env) (cadddr env))
		   (and base (= base 0.0)))
	       (cadr env)
	       (if (or (not base) (= base 1.0))
		   (+ (cadr env)
		      (* (- x (car env))
			 (/ (- (cadddr env) (cadr env))
			    (- (caddr env) (car env)))))
		   (+ (cadr env)
		      (* (/ (- (cadddr env) (cadr env))
			    (- base 1.0))
			 (- (expt base (/ (- x (car env))
					  (- (caddr env) (car env))))
			    1.0))))))
	  (else (envelope-interp x (cddr env))))))

(define* (rt-motif #:rest args)
  (let* ((shell-app (XtVaOpenApplication 
		     "FM" 0 '() applicationShellWidgetClass
		     (list XmNallowShellResize #t)))
	 (app (cadr shell-app))
	 (shell (car shell-app))
	 (dpy (XtDisplay shell))
	 (screen (DefaultScreenOfDisplay dpy))
	 (cmap (DefaultColormap dpy (DefaultScreen dpy)))
	 (black (BlackPixelOfScreen screen))
	 (white (WhitePixelOfScreen screen)))
    (define (get-color color)
      (let ((col (XColor)))
	(if (= (XAllocNamedColor dpy cmap color col col) 0)
	    (error (format #f "can't allocate ~A" color))
	    (.pixel col))))
    (define (set-flabel label value)
      (let ((s1 (XmStringCreate (format #f "~5,3F" value) XmFONTLIST_DEFAULT_TAG)))
	(XtVaSetValues label (list XmNlabelString s1))
	(XmStringFree s1)))
    (XtSetValues shell (list XmNtitle "FM Forever!"))
    (let* ((light-blue (get-color sliderback))
	   (form (XtCreateManagedWidget "form" xmFormWidgetClass shell 
					(list XmNbackground (get-color background)
					      XmNforeground black
					      XmNresizePolicy XmRESIZE_GROW)))
	   ;; play
	   (play-button (XtCreateManagedWidget "play" xmToggleButtonWidgetClass form
					       (list XmNleftAttachment   XmATTACH_FORM
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_FORM
						     XmNrightAttachment  XmATTACH_NONE
						     XmNbackground       (get-color background))))
	   ;; radio
	   (radio (XmCreateRadioBox form "radio"
				    (list XmNorientation XmHORIZONTAL
					  XmNleftAttachment   XmATTACH_WIDGET
					  XmNleftWidget       play-button
					  XmNbottomAttachment XmATTACH_NONE
					  XmNtopAttachment    XmATTACH_FORM
					  XmNrightAttachment  XmATTACH_NONE
					  XmNbackground       (get-color background))))
	   ;; play agn
	   (agn-button (XtCreateManagedWidget "agn" xmToggleButtonWidgetClass radio
					      (list XmNleftAttachment   XmATTACH_FORM
						    XmNbottomAttachment XmATTACH_NONE
						    XmNtopAttachment    XmATTACH_FORM
						    XmNrightAttachment  XmATTACH_NONE
						    XmNbackground       (get-color background))))
	   ;; play test
	   (test-button (XtCreateManagedWidget "test" xmToggleButtonWidgetClass radio
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       agn-button
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_FORM
						     XmNrightAttachment  XmATTACH_NONE
						     XmNbackground       (get-color background))))
	   ;; quit
	   (quit-button (XtCreateManagedWidget " quit " xmPushButtonWidgetClass form
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       radio
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_FORM
						     XmNrightAttachment  XmATTACH_FORM
						     XmNbackground       (get-color background))))
	   (sep (XtCreateManagedWidget "sep" xmSeparatorWidgetClass form
				       (list XmNleftAttachment   XmATTACH_FORM
					     XmNbottomAttachment XmATTACH_NONE
					     XmNtopAttachment    XmATTACH_WIDGET
					     XmNtopWidget        radio
					     XmNrightAttachment  XmATTACH_FORM
					     XmNheight 4
					     XmNorientation XmHORIZONTAL)))
	   ;; tempo
	   (tempo (XtCreateManagedWidget " tempo:" xmLabelWidgetClass form
					 (list XmNleftAttachment   XmATTACH_FORM
					       XmNbottomAttachment XmATTACH_NONE
					       XmNtopAttachment    XmATTACH_WIDGET
					       XmNtopWidget        sep
					       XmNrightAttachment  XmATTACH_NONE
					       XmNrecomputeSize    #f
					       XmNbackground       (get-color background))))
	   (tempo-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       tempo
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						     XmNtopWidget        tempo
						     XmNrightAttachment  XmATTACH_NONE
						     XmNbackground       (get-color background))))
	   (tempo-scale (XtCreateManagedWidget "tempo" xmScaleWidgetClass form
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       tempo-label
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						     XmNtopWidget        tempo-label
						     XmNrightAttachment  XmATTACH_FORM
						     XmNshowValue        #f
						     XmNorientation      XmHORIZONTAL
						     XmNheight           20
						     XmNbackground       light-blue)))
	   ;; freq
	   (freq (XtCreateManagedWidget "  freq:" xmLabelWidgetClass form
					(list XmNleftAttachment   XmATTACH_FORM
					      XmNbottomAttachment XmATTACH_NONE
					      XmNtopAttachment    XmATTACH_WIDGET
					      XmNtopWidget        tempo
					      XmNrightAttachment  XmATTACH_NONE
					      XmNrecomputeSize    #f
					      XmNbackground       (get-color background))))
	   (freq-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
					      (list XmNleftAttachment   XmATTACH_WIDGET
						    XmNleftWidget       freq
						    XmNbottomAttachment XmATTACH_NONE
						    XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						    XmNtopWidget        freq
						    XmNrightAttachment  XmATTACH_NONE
						    XmNbackground       (get-color background))))
	   (freq-scale (XtCreateManagedWidget "freq" xmScaleWidgetClass form
					      (list XmNleftAttachment   XmATTACH_WIDGET
						    XmNleftWidget       freq-label
						    XmNbottomAttachment XmATTACH_NONE
						    XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						    XmNtopWidget        freq-label
						    XmNrightAttachment  XmATTACH_FORM
						    XmNshowValue        #f
						    XmNorientation      XmHORIZONTAL
						    XmNheight           20
						    XmNbackground       light-blue)))
	   ;; amp
	   (amp (XtCreateManagedWidget "   amp:" xmLabelWidgetClass form
				       (list XmNleftAttachment   XmATTACH_FORM
					     XmNbottomAttachment XmATTACH_NONE
					     XmNtopAttachment    XmATTACH_WIDGET
					     XmNtopWidget        freq
					     XmNrightAttachment  XmATTACH_NONE
					     XmNrecomputeSize    #f
					     XmNbackground       (get-color background))))
	   (amp-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
					     (list XmNleftAttachment   XmATTACH_WIDGET
						   XmNleftWidget       amp
						   XmNbottomAttachment XmATTACH_NONE
						   XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						   XmNtopWidget        amp
						   XmNrightAttachment  XmATTACH_NONE
						   XmNbackground       (get-color background))))
	   (amp-scale (XtCreateManagedWidget "amp" xmScaleWidgetClass form
					     (list XmNleftAttachment   XmATTACH_WIDGET
						   XmNleftWidget       amp-label
						   XmNbottomAttachment XmATTACH_NONE
						   XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						   XmNtopWidget        amp-label
						   XmNrightAttachment  XmATTACH_FORM
						   XmNshowValue        #f
						   XmNorientation      XmHORIZONTAL
						   XmNheight           20
						   XmNbackground       light-blue)))
	   ;; index
	   (index (XtCreateManagedWidget " index:" xmLabelWidgetClass form
					 (list XmNleftAttachment   XmATTACH_FORM
					       XmNbottomAttachment XmATTACH_NONE
					       XmNtopAttachment    XmATTACH_WIDGET
					       XmNtopWidget        amp
					       XmNrightAttachment  XmATTACH_NONE
					       XmNrecomputeSize    #f
					       XmNbackground       (get-color background))))
	   (index-label (XtCreateManagedWidget "label" xmLabelWidgetClass form
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       index
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						     XmNtopWidget        index
						     XmNrightAttachment  XmATTACH_NONE
						     XmNbackground       (get-color background))))
	   (index-scale (XtCreateManagedWidget "index" xmScaleWidgetClass form
					       (list XmNleftAttachment   XmATTACH_WIDGET
						     XmNleftWidget       index-label
						     XmNbottomAttachment XmATTACH_NONE
						     XmNtopAttachment    XmATTACH_OPPOSITE_WIDGET
						     XmNtopWidget        index-label
						     XmNrightAttachment  XmATTACH_FORM
						     XmNshowValue        #f
						     XmNorientation      XmHORIZONTAL
						     XmNheight           20
						     XmNbackground       light-blue)))
	   (low-tempo 0.05)
	   (high-tempo 0.5)
	   (high-amp 1.0)
	   (low-freq 0.1)
	   (high-freq 4.0)
	   (high-index 2.0)
	   (which-play 0)
	   (proc #f)
	   (func #f))
      (define (tempo-callback w c i)
	(set! ctempo (+ low-tempo (* (.value i) (/ (- high-tempo low-tempo) 100.0))))
	(set-flabel tempo-label ctempo))
      (define (amp-callback w c i)
	(set! camp (* (.value i) (/ high-amp 100.0)))
	(set-flabel amp-label camp))
      (define (freq-callback w c i)
	(set! cfreq (+ low-freq (* (.value i) (/ (- high-freq low-freq) 100.0))))
	(set-flabel freq-label cfreq))
      (define (index-callback w c i)
	(set! cindex (* (.value i) (/ high-index 100.0)))
	(set-flabel index-label cindex))
      (define (set-defaults)
	(set! ctempo 0.25)
	(set! camp 1.0)
	(set! cfreq 1.0)
	(set! cindex 1.0)
	(set-flabel tempo-label ctempo)
	(set-flabel amp-label camp)
	(set-flabel freq-label cfreq)
	(set-flabel index-label cindex)
	(XmScaleSetValue tempo-scale (inexact->exact (floor (* 100 (/ (- ctempo low-tempo)
								      (- high-tempo low-tempo))))))
	(XmScaleSetValue freq-scale (inexact->exact (floor (* 100 (/ (- cfreq low-freq)
								     (- high-freq low-freq))))))
	(XmScaleSetValue amp-scale (inexact->exact (* 100 camp)))
	(XmScaleSetValue index-scale (inexact->exact (floor (* 100 (/ cindex high-index))))))

      (XtManageChild radio)
      ;; add scale-change (drag and value-changed) callbacks
      (XtAddCallback tempo-scale XmNdragCallback tempo-callback)
      (XtAddCallback tempo-scale XmNvalueChangedCallback tempo-callback)

      (XtAddCallback amp-scale XmNdragCallback amp-callback)
      (XtAddCallback amp-scale XmNvalueChangedCallback amp-callback)

      (XtAddCallback freq-scale XmNdragCallback freq-callback)
      (XtAddCallback freq-scale XmNvalueChangedCallback freq-callback)

      (XtAddCallback index-scale XmNdragCallback index-callback)
      (XtAddCallback index-scale XmNvalueChangedCallback index-callback)

      (XtAddCallback agn-button XmNvalueChangedCallback
		     (lambda (w c i)
		       (if (.set i)
			   (set! which-play 0))
		       (set! cplay #f)
		       (XmToggleButtonSetState play-button cplay #f)))

      (XmToggleButtonSetState agn-button #t #f)
      (XtAddCallback test-button XmNvalueChangedCallback
		     (lambda (w c i)
		       (if (.set i)
			   (set! which-play 1))
		       (set! cplay #f)
		       (XmToggleButtonSetState play-button cplay #f)))
		     
      (XtAddCallback quit-button XmNactivateCallback
		     (lambda (w c i)
		       (set! cplay #f)
		       (if proc (XtRemoveWorkProc proc))
		       (exit 0)))
      
      (XtAddCallback play-button XmNvalueChangedCallback
		     (lambda (w c i)
		       (set! cplay (.set i))
		       (if cplay
			   (begin
			     (set-defaults)
			     (if (= which-play 0)
				 (set! func (apply make-agn args))
				 (set! func (apply make-vct-test args)))
			     (set! proc (XtAppAddWorkProc app (lambda (c) (rt-send->dac func)))))
			   (if proc (XtRemoveWorkProc proc)))))
      (XmToggleButtonSetState play-button cplay #f)
      (set-defaults)
      (XtRealizeWidget shell))
    (XtAppMainLoop app)))

;; bess1.scm ends here

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us