#include #include #include #include "abuf.h" #include "guic.h" enum{ Gfreq, Gtype, Gvol, Gexit, }; char *keywords[] = { "freq", "type", "vol", "exit", 0, }; void threadmain(int argc, char *argv[]) { double ph, w, s, v; int type; Abuf ab; Event ev; if(argc < 2) sysfatal("usage: osc gui"); guistart(argv[1]); ainit(&ab, 1); w = miditophase(69); v = 1; type = 0; for(ph=0;;ph+=w){ while(nbrecv(guichan, &ev) == 1) switch(ev.k){ case Gfreq: w = miditophase(ev.n); break; case Gtype: type = ev.n; break; case Gvol: v = voltomul(ev.n); break; case Gexit: threadexitsall(0); } switch(type){ case 0: s = sin(ph * 2 * PI); break; case 1: s = (fmod(ph, 1) < 0.5) * 2 - 1; break; case 2: s = fmod(ph, 1) * 2 - 1; break; } aputd(&ab, s*v); } }