‹ More SC Workshop MaterialHarmonicism ›

Keystroke Recorder

2014-10-15 23:55:37 supercollider

clean-up: #51

Today a very simple piece of code that takes whatever you're typing in a document and posts it back 2 seconds later. See it as a demonstration. The list is treated as a FIFO buffer.

Note: only works in SuperCollider versions with Document support (not 3.6, but 3.4, 3.5, 3.7...)

(
var delay= 2;  //post 2 seconds later
var l= List.new;

//--record in list l
Document.current.keyDownAction= {|doc, key|
    l.addFirst(
        (key: key, time: Main.elapsedTime)
    );
};

//--playback of list l
Routine({
    inf.do{
        var now= Main.elapsedTime;
        if(l.size>0 and:{now-delay>l.last.time}, {
            l.pop.postln;
        });
        0.01.wait;
    };
}).play;
)
‹ More SC Workshop MaterialHarmonicism ›