system.log

clean-up: #39

since long i had this idea of sonifying what my laptop is doing. before, when laptops had spinning harddrives, one could at least hear the faint little noises when there was disk activity. but today with the sd disks, this insight is gone.

below is a draft of how it could work. it tracks activity in the system.log file. to try it start supercollider and run the code. then launch some apps, save files, disconnect network etc etc. it's quite fun to have it running in the background for a while.

one day i plan to do a more thorough sonification, tracking many more things. here is a good reference for what to tap into in the future.

/*
sudo iosnoop
sudo execsnoop -v
sudo opensnoop -ve
sudo dtruss -n SuperCollider
sudo errinfo -c
sudo iotop -CP 1
man -k dtrace
*/

//osx only
(
s.latency= 0.05;
s.waitForBoot{
var num= 10;
var delta= 0.1;
var maxlen= 256;
var rate= 0.5;
var curr= List.new;
var mySplit= {|str|
        var res= "";
        var arr= [];
        var separator= Char.nl.ascii;
        var tab= Char.tab.ascii;
        str.do{|chr, i|
                if(chr.ascii!=separator or:{str.clipAt(i+1).ascii==tab}, {
                        res= res++chr;
                }, {
                        arr= arr.add(res);
                        res= "";
                });
        };
        arr.add(res);
};
var read= Routine({
        var res, arr, last, new;
        inf.do{
                res= ("tail -n"+num+"/var/log/system.log").unixCmdGetStdOut;
                if(res!=last, {
                        last= res;
                        arr= mySplit.value(res);
                        new= arr.select{|x| curr.indexOfEqual(x).isNil};
                        new.do{|x|
                                curr.addFirst(x);
                        };
                });
                delta.wait;     //time between checking system log
        };
});
var play= Routine({
        var data;
        inf.do{
                if(curr.size>0, {
                        data= curr.pop;
                        ("buf"++curr.size++": ").post;
                        data.postln;
                        s.bind{
                                Synth(\log, [\data, data.ascii.extend(maxlen, 0)]);
                        };
                        (data.size/maxlen*rate).wait;
                }, {
                        delta.wait;
                });
        };
});
SynthDef(\log, {|out= 0, amp= 0.5, minFreq= 300, maxFreq= 14400|
        var data= Control.names([\data]).ir(Array.fill(maxlen, 0));
        var freq= Duty.ar(1/maxlen*rate, 0, Dseq(data), 2);
        var src= SinOsc.ar(freq.linexp(0, 255, minFreq, maxFreq), 0, (freq>0).lag(0.02));
        OffsetOut.ar(out, Pan2.ar(src, 0, amp));
}).add;
s.sync;
read.play(AppClock);
play.play;
};
)