where myinst is whatever name the user wants the instrument to be bound too. 'blah' needs to map to valid note (blah_note) and fx (blah_fx) implementations. Significantly a user can now bind any number of unique instances of the instrument (which was not possible before)
etc..
(sys:load "libs/core/instruments.xtm")
;; a tivial sine instrument with no enveloping!
(bind-func simple_note
(lambda ()
(lambda (data:NoteData* nargs:i64 dargs:SAMPLE*)
(let (;; you'll probably want the note start time
(starttime (note_starttime data))
;; you'll probably want the note frequency (in hz)
(frq (note_frequency data))
;; you'll probably want the note amplitude (0.0-1.0)
(amp (note_amplitude data))
;; you'll probably need the duration (in samples)
(dur (note_duration data))
(osc (osc_mc_c 0.0)))
(lambda (time:i64 chan:i64)
;; you are responsible for stopping a note!
(if (> (- time starttime) dur) (note_active data #f))
(osc chan amp frq))))))
;; a stereo fx for trivial sine instrument
(bind-func simple_fx
(lambda ()
(let ((notekernel:NOTE_KERNEL null) ;; you must provide this line
(gain 1.0)
(dly (delay_st_c (ftoi64 (* SRf 0.333)) (ftoi64 (* SRf 0.25)))))
(lambda (in:SAMPLE time:i64 chan:i64 dat:SAMPLE*)
(if (< chan 2)
(* gain (dly chan in 0.7 0.5))
0.0)))))
(make-instrument myinst simple)
(bind-func dsp:DSP
(lambda (in time chan dat)
(myinst in time chan dat)))
(dsp:set! dsp)
;; 'clicking' because no envelope for simple instrument
(define test
(lambda (beat dur)
(playp 1 0 myinst 0 `(60 63 ,(random '(67 67 67 68))) 80 dur)
(playp 2 0 myinst 12 `(60 63 ,(random '(67 67 67 68 70 72))) 80 dur)
(playp 3 0 myinst -24 `(60 67 72) 80 dur)
(callback (*metro* (+ beat (* .5 dur))) 'test (+ beat dur) dur)))
(test (*metro* 'get-beat 4) 1/4)
Probably not quite the email you were hoping for but ...
Andrew.