Mercurial > hg > jslab
view src/scheme/midi.scm @ 5:b67a33c44de7
Remove some crap, etc
author | samer |
---|---|
date | Fri, 05 Apr 2019 21:34:25 +0100 |
parents | 5df24c91468d |
children |
line wrap: on
line source
(import "samer.midi.*") (import "javax.sound.midi.*") (define (tomidi in) (letrec ( (nout 49) ; room for 4 octaves (patch (Matrix. "Synth" nout (.size in))) (out (VVector. "sout" nout)) (trigger (Trigger. out 1.0)) ; could use Latch instead (events (.output trigger)) (synth (MidiSynth. events))) (addtasks (MatrixTimesVector. out patch in) trigger synth) (matexec patch "load") (exec synth "open") (expose synth) synth ) ) ; (import "javax.sound.midi.*") ; (define _synth null) ; (define (synth) (set! _synth (javax.sound.midi.MidiSystem.getSynthesizer))) ; (define (c0) (vector-ref (.getChannels _synth) 0)) ; (define (open) (.open _synth)) ; (define (close) (.close _synth)) ; (define (on pitch) (.noteOn (c0) pitch 80)) ; (define (off pitch) (.noteOff (c0) pitch 0)) ;; trigger midi events from a signal using an 2 sample window and ;; an onset map. (define (midirec L) (define sigwin (SignalWindow. L 2)) (define onset-map (OnsetMap. (.output sigwin))) (define rec (MidiRecorderBase.)) (define imap (LinearMap. 128)) (define vel-map (samer.core.util.VMap. imap (Node. "velmap"))) (matexec (.getBinMatrix onset-map) "load") (Shell.exposeCommands rec) (compound-task sigwin (.flushTask sigwin) onset-map (task (if (.isOnset onset-map) (.noteOn rec 0 (.clipInt imap (.get L)) 80) ; (.noteOff rec 0 64) ) (.tick rec) ) ) )