\ pulse_tracker+
\
\ a "smarter" pulse tracker class designed to works in conjunction with the
\ parser classes.
\
\ takes into account the variation in the parameters passed to it (pitch,
\ volume, etc). Also has the concept of 'expected' time of the next event.
\
\ code: Han-earl Park
\ copyright 2004 buster & friends' C-ALTO Labs
\ (Valencia, October 1999 -
\ (Southampton, October 2000 -
\
\ MOD: HeP 10/01/99 Started project.
\ MOD: HeP 03/17/00 Add PUT.NOTE.DIM: and PUT.VEL.DIM: methods.
\ Move iv-ptrk-vel-min from the pulse.tracker class.
\ MOD: HeP 04/05/00 Change behavior of NOTE.ON: and NOTE.OFF: methods from
\ ( note# vel time -- ) to ( note# vel -- ) since we
\ have the PUT.TIME: method.
\ Add velocity and note# filtering.
\ User on and off functions can override behavior of the
\ ELEMENT.ON: and ELEMENT.OFF: methods.
\ MOD: HeP 05/20/00 Trash filter stuff, since we now have a "general" purpose
\ filter class (see the file myt:filter).
\ MOD: HeP 10/20/00 Load mono.parser classes first.
\ MOD: HeP 11/03/00 Provision for tracking pulse from a polyphonic source.
\ MOD: HeP 11/05/00 Tested: Modesty prevents me from saying how well it works.
\ MOD: HeP 11/12/00 Check if opened in the ELEMENT.ON: method.
\ MOD: HeP 02-23-04 Fix PTRK.POLYPHONIC.CALC.PULSE which got broken somewhere
\ along the way.
\
\ ToDo: Have filter/subdivision dependent on current state/context
\ ToDo: Std methods DEFAULT: OPEN: CLOSE: UPDATE: RESET: and REFRESH:
include? task-mono_parser myt:mono_parser
include? task-pulse_tracker myt:pulse_tracker
anew task-pulse_tracker+
method PUT.NOTE.DIM: method PUT.VEL.DIM:
:class OB.PULSE.TRACKER+ iv-ptrk-dur-dim
parser_pitch_dim# iv=> iv-ptrk-note-dim
parser_vol_dim# iv=> iv-ptrk-vel-dim
\
$ 80000000 iv=> iv-ptrk-note-lo \ very small number
$ 7FFFFFFF iv=> iv-ptrk-note-hi \ very big number
\
50 iv=> iv-ptrk-resolution
0 iv=> iv-ptrk-vel-min
;m
\ pitch resolution
:m PUT.RESOLUTION: ( n -- )
dup 50 >
IF " put.resolution:"
" pitch sesolution has been set to greater than 50"
er_warning
ob.report.error
THEN
iv=> iv-ptrk-resolution
;m
\ parsing shape
:m PUT.NOTE.DIM: ( dim# -- )
iv=> iv-ptrk-note-dim
;m
:m PUT.VEL.DIM: ( dim# -- )
iv=> iv-ptrk-vel-dim
;m
\ pulse value
: PTRK.SAME.NOTE? ( -- flag )
iv-ptrk-prev-note iv-ptrk-cur-note -
ABS
iv-ptrk-resolution
>
;
: PTRK.POLYPHONIC? ( -- flag , true if event is from polyphic parser )
current-parser @ \ -- addr | 0
dup
IF get.chord: [] \ -- addr | 0
dup
IF many: [] \ -- many | 0
dup
IF drop
iv-ptrk-prev-note iv-ptrk-cur-note - ABS
iv-ptrk-resolution
> \ -- flag , true if different note
THEN
THEN
THEN
;
: PTRK.POLYPHONIC.CALC.PULSE { dtime -- }
iv-ptrk-error-factor
dup 1- 1 MAX iv=> iv-ptrk-error-factor \ reduce error margin!
\
dtime ptrk.calc.pulse
\
iv=> iv-ptrk-error-factor \ restore error factor
;
: PTRK.MONOPHONIC.CALC.PULSE ( dtime -- )
ptrk.calc.pulse
;
:m ON: ( -- )
iv-ptrk-cur-time iv=> iv-ptrk-prev-time
self TIME: [] iv=> iv-ptrk-cur-time
\
PTRK.DTIME@
\
?dup
IF dup iv-ptrk-pulse-max >
IF
drop
0 iv=> iv-ptrk-raw-pulse
ELSE
ptrk.polyphonic?
IF
ptrk.POLYphonic.calc.pulse
ELSE
ptrk.MONOphonic.calc.pulse
THEN
THEN
THEN
;m
\ for use with mp vector
: PTRK.VALID.NOTE? ( note# vel -- flag )
iv-ptrk-vel-min >=
swap iv-ptrk-note-lo iv-ptrk-note-hi within?
AND
;
:m NOTE.ON: ( note# vel -- )
2dup ptrk.valid.note?
IF
iv-ptrk-cur-vel iv=> iv-ptrk-prev-vel
iv-ptrk-cur-note iv=> iv-ptrk-prev-note
iv=> iv-ptrk-prev-vel
iv=> iv-ptrk-prev-note
\
ON: self
ELSE
2drop
THEN
;m
\ for use with parser object
: PTRK.GET.NOTE ( -- note# )
iv-ptrk-note-dim 0>
IF
iv-ptrk-elm# iv-ptrk-note-dim iv-ptrk-shape ed.at: []
ELSE
iv-ptrk-note-lo
THEN
;
: PTRK.GET.VEL ( -- vel )
iv-ptrk-vel-dim 0>
IF
iv-ptrk-elm# iv-ptrk-vel-dim iv-ptrk-shape ed.at: []
ELSE
iv-ptrk-vel-min
THEN
;
:m ELEMENT.ON: ( elm# sh -- )
iv-dev-#opened
IF
iv=> iv-ptrk-shape
iv=> iv-ptrk-elm#
\
iv-dev-on-cfa
IF
iv-ptrk-elm# iv-ptrk-shape self iv-dev-on-cfa -3 exec.stack?
ELSE
ptrk.get.note ptrk.get.vel note.on: self
THEN
ELSE
2drop
THEN
;m
:m PRINT: ( -- )
print: super
\
space ." NOTE dim# =" iv-ptrk-note-dim 4 .r cr
space ." VEL dim# =" iv-ptrk-vel-dim 4 .r cr
." Note:" cr
space ." Note range =" iv-ptrk-note-lo 4 .r space
iv-ptrk-note-hi 4 .r cr
space ." Minimum Vel =" iv-ptrk-vel-min 4 .r cr
space ." Current Note =" iv-ptrk-cur-note 4 .r cr
space ." Current Vel =" iv-ptrk-cur-vel 4 .r cr
space ." Prev Note =" iv-ptrk-prev-note 4 .r cr
space ." Prev Vel =" iv-ptrk-prev-vel 4 .r cr
;m
;class