|
From: Martin R. <ru...@us...> - 2005-02-03 15:31:06
|
Update of /cvsroot/foo/foo/elkfoo/examples/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21752 Modified Files: sine.foo Log Message: adopted sine example to new cmdline: stuff in order to show how to use it... Index: sine.foo =================================================================== RCS file: /cvsroot/foo/foo/elkfoo/examples/scripts/sine.foo,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** sine.foo 16 Aug 2004 19:50:05 -0000 1.2 --- sine.foo 3 Feb 2005 15:30:55 -0000 1.3 *************** *** 1,31 **** ! #!/usr/local/bin/foo ;; foo scripting example ! ;; (c) 2004 rumori ;; checking command line ! (if (< (length (command-line-args)) 3) ! (begin ! (format #t "usage: ~a <duration> <frequency>\n" ! (car (command-line-args))) ! (quit))) ! (format #t "~a script example~%" (car (command-line-args))) ! (format #t "creating, playing and removing a test-file.~%") ! ;; extract parameters from command line ! (define duration (string->number (list-ref (command-line-args) 1))) ! (define freq (string->number (list-ref (command-line-args) 2))) ! (format #t "duration: ~a frequency: ~a~%" duration freq) ! (format #t "synthesizing...~%") ! ;; here we do the major work ! (syn 1 duration (output~ 1 (sine~ (~ freq)))) ! (format #t "~%playing using '~a'~%" foo-default-play-command) ! (format #t "exiting (will remove temporary file as well)~%") ;; done --- 1,63 ---- ! #!/usr/local/bin/foo -- ;; foo scripting example ! ;; (c) 2004-2005 rumori ! ! (require 'cmdline) ;; checking command line ! (let* ! ;; single-opt or equiv-opts-list | mandatory? | with-params? | help-string ! ((option-list '(("--help" #f #f "this help screen") ! (("--freq" "-f") #t #t "frequency (hz)") ! (("--amp" "-a") #t #t "amplitude (0...1)") ! (("--dur" "-d") #t #t "duration (s)"))) ! (help ! (lambda () ! (format #t "usage: ~a [options]\noptions understood:\n" (car (foo:script-args))) ! (format #t "~a\n" (cmdline:help-message option-list)) ! (exit))) ! (number-check ! (lambda (arg description) ! (if (not (number? arg)) ! (begin ! (format #t "~a has to be number!\n" description) ! (help))))) ! (freq) ! (amp) ! (dur)) ! ;; help needed? ! (if (cmdline:option-given? (foo:script-args) option-list "--help") ! (help)) ! ;; validate cmdline ! (if (not (cmdline:cmdline-valid? (cdr (foo:script-args)) option-list #t)) ! (help)) ! ;; get parameters (take in account just 1st param of each option) ! (set! freq (string->number (car (cmdline:get-option-param (foo:script-args) option-list "--freq")))) ! (set! amp (string->number (car (cmdline:get-option-param (foo:script-args) option-list "--amp")))) ! (set! dur (string->number (car (cmdline:get-option-param (foo:script-args) option-list "--dur")))) ! ;; check parameters ! (number-check freq "frequency") ! (number-check amp "amplitude") ! (number-check dur "duration") ! (format #t "~a script example~%" (car (foo:script-args))) ! (format #t "creating, playing and removing a test-file.~%") ! (format #t "frequency: ~a amplitude: ~a duration: ~a~%" freq amp dur) ! (format #t "synthesizing...~%") ! ;; here we do the major work ! (syn 1 dur (output~ 1 (mul~ (~ amp) (sine~ (~ freq))))) ! (format #t "~%playing using '~a'~%" foo-default-play-command) ! (play) ! ! (format #t "exiting (will remove temporary file as well)~%")) ! ! (quit) ;; done |