All pastes #421036 Raw Edit

update-dur

public text v1 · immutable
·published 2007-04-02 15:42 UTC
rendered paste body
0 [if]

   Any thoughts? I'm not so happy about the "rot rot"

[then]

\ needs NAB's struct words:

: struct{ 0 ;

: field: ( n "fieldname" -- )
   over create , +
   does> ( o -- o+n ) @ + ;

: }struct constant ;


struct{
   1 cells field: dur-inc
   1 cells field: dur-max
   1 cells field: dur-min
}struct wav-params

: tri-wav  ( -- )  create
   does>  ( dur1 -- dur2 )
   2dup dur-min @ > not rot rot
   2dup dur-max @ < not rot rot
   2swap or if
      dup dur-inc @ negate over dur-inc !
   then
   dur-inc @ +
;

tri-wav update-dur 1 , 4 , 1 ,

\ generates a series: 1 2 3 4 3 2 1 2 3...
\ with repeated calls to update-dur

2 update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .
update-dur dup .