2012/09/19

nanoK

/* GUI */

~col = [
 Color.clear,
 Color.new255(255,200,0),
 Color.new255(210,120,255),
 Color.new255(0,200,255)
];

~wd = JSCWindow("nanoK", Rect(200, 200, 500, 300) );
~wd.view.canFocus = true;
~wd.view.focus;

~s1 = JSCVLayoutView(~wd, Rect(10, 0, 500, 300));

~u0u = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
Array.fill(9, {|i|
 t = [
  "P",
  "",
  "FQ",
  "",
  "LP",
  "EV",
  "RM",
  "DS",
  "TR"
 ];
 c = [0,1,1,1,1,3,0,0,0];
 JSCStaticText(~u0u, Rect(0, 0, 50, 0))
 .string_(t[i])
 .font_(JFont("Arial",14,1))
 .align_(\center);
});

~u0 = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
Array.fill(9, {|i|
 t = [
  "port",
  "wave",
  "freq",
  "shape",
  "LPf",
  "env",
  "ring",
  "dist",
  "trem"
 ];
 c = [0,1,1,1,1,3,0,0,0];
 JSCStaticText(~u0, Rect(0, 0, 50, 0))
 .string_(t[i])
 .align_(\center)
 .background_(~col[c[i]]);w
});

~t0 = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
~tx0 = Array.fill(9, {|i|
 JSCStaticText(~t0, Rect(0, 0, 50, 0))
 .stringColor_(Color.green)
 .background_(Color.black)
 .align_(\center);
});

~u1 = JSCHLayoutView(~s1, Rect(0, 0, 400, 40));
~knb = Array.fill(9, {
 JKnob(~u1, Rect(0, 0, 50, 25));
});

~u2u = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
Array.fill(9, {|i|
 t = [
  "",
  "",
  "WD",
  "fR",
  "fD",
  "SH",
  "DL",
  "",
  ""
 ];
 c = [0,0,1,2,2,3,0,0,0];
 JSCStaticText(~u2u, Rect(0, 0, 50, 0))
 .string_(t[i])
 .font_(JFont("Arial",14,1))
 .align_(\center);
});

~u2 = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
Array.fill(9, {|i|
 t = [
  "oct/smp",
  "pitch",
  "width",
  "ratio",
  "depth",
  "s/h",
  "delay",
  "vol",
  "gate"
 ];
 c = [0,0,1,2,2,3,0,0,0];
 JSCStaticText(~u2, Rect(0, 0, 50, 0))
 .string_(t[i])
 .align_(\center)
 .background_(~col[c[i]]);
});

~t1 = JSCHLayoutView(~s1, Rect(0, 0, 400, 15));
~tx1 = Array.fill(9, {|i|
 JSCStaticText(~t1, Rect(0, 0, 50, 0))
 .stringColor_(Color.green)
 .background_(Color.black)
 .align_(\center);
});

~u3 = JSCHLayoutView(~s1, Rect(0, 0, 400, 115));
~vsl = Array.fill(9,{
 JSCSlider(~u3, Rect(0, 0, 50, 120));
});

~t2 = JSCStaticText(~s1, Rect(0, 0, 0, 20))
.string_("osc")
.background_(Color.green)
.align_(\center);

~wd.front;


/* Keystroke */

~key0 = ['1','2','3','4','5','6','7','8','9'];
~key1 = ['z','s','x','d','c','v','g','b','h','n','j','m',','];
~key2 = ['q','w','e'];
~semi = [0,2,4,6,8,10,12,14,16,18,20,22,24];
~name = ['C','C+','C#','D-','D','D+','Eb','E-','E','F-','F','F+',
 'F#','G-','G','G+','G#','A-','A','A+','Bb','B-','B','C-'];

~amp = 0;
~oct = 0;
~nn = 0;
~mode = 0;
~qt = 0;

~wd.view.keyDownAction = {
 |view, char, modifiers, unicode, keycode|
 
 b = 0;
 
 ~key0.size.do{|i|
  if(unicode == ~key0[i].ascii[0], {
   ~oct = i+1;
   ~tx1[0].string = ~oct;
  });
 };
 
 ~key1.size.do{|i|
  if(unicode == ~key1[i].ascii[0], {
   ~nn = ~semi[i] + ~qt;
   b = 1;
  });
 };
 
 ~key2.size.do{|i|
  if(unicode == ~key2[i].ascii[0], {
   ~qt = i-1;
  });
 };
 
 if(b==1, {
  s.sendMsg("/c_set", 0, ~oct/9);
  s.sendMsg("/c_set", 1, ~nn/24);
  ~qt = 0;
 });
 
 switch( unicode,
  27, {
   ~wd.close;
   s.sendMsg(\n_free, 999);
  }
 );
};


/* nanoK */

CCResponder.removeAll;
CCResponder({|src,ch,num,val| 
 //[src,ch,num,val].postln;
 
 if(num>=0 && num<=18, { s.sendMsg("/c_set", num, val/127) });
 
 case
 {num>=0 && num<=8}{~vsl[num].value_(val/127)}
 {num>=10 && num<=18}{~knb[num-10].value_(val/127)}
 {num>=20 && num<=38}{
  ~mode = ~mode+1%4;
  if(~mode<1, {
   s.sendMsg("/c_set", 80, 0);
   ~t2.string_("osc");
   ~t2.background_(Color.green);
   },{
    s.sendMsg("/c_set", 80, 1);
    ~t2.string_("smp");
    ~t2.background_(Color.red);
  });
 };
});


/* SendTrig */

OSCresponder(s.addr,'/tr',{ arg time,responder,msg;
 i = msg[2];
 v = msg[3];
 if(i<10, {
  switch(i,
   0, {~tx1[0].string = v-1},
   1, {~tx1[1].string = ~name[v]},
   {~tx1[i].string = (v*100).asInteger/100}
  )
  },{
   switch(i,
    11, {~tx0[1].string = ["pulse","saw","noise","noise"].at(v)},
    80, {~t2.string = (v*100).asInteger/100},
    {~tx0[i-10].string = (v*100).asInteger/100}
   )
 });
}).add;


/* functions*/

~send = { |i,x|
 y = abs(x-Delay1.kr(x));
 SendTrig.kr(y,i,x);
};

~pitch = {|cc|
 x = [0,1];
 a = floor(cc[x[0]]*8+2);
 b = floor(cc[x[1]]*24);
 c = a*24+b;
 ~send.(x[0],floor(c/24));
 ~send.(x[1],c%24);
 (c/2).midicps;
};

~port = {|fq,cc|
 x = 10;
 a = cc[x]**4*4;
 ~send.(x,a);
 fq.lag(a);
};

~mod = {|fq,cc|
 var pls, saw, wnz, mod, shr, sht;
 x = [12,13,14,11,2,5];
 
 a = cc[x[0]]*2-1**4*50;   // freq
 ~send.(x[0],a);
 
 pls = LFPulse.ar(a.abs,0,cc[x[1]]);
 
 d = LinExp.kr(cc[x[1]],0,1,0.05,50); // shape
 saw = LFSaw.ar(a,0,1/2,1/2)**d;
 
 b = LinExp.kr(cc[x[2]],0,1,100,6);  // LPF
 c = cc[x[2]]>0;
 ~send.(x[2],b*c);
 b = b.lag(1);
 pls = Select.ar(c,[pls,LPF.ar(pls,b)]);
 saw = Select.ar(c,[saw,LPF.ar(saw,b)]);
 
 wnz = WhiteNoise.ar(1);
 
 e = cc[x[3]]*3;    // type
 ~send.(x[3],e);
 mod = Select.ar(e,[pls,saw,wnz]);
 ~send.(x[1],Select.kr(e,[cc[x[1]],d]));
 
 f = cc[x[4]]**2*32;    // width
 ~send.(x[4],f);
 f = f*mod;
 
 g = LinExp.kr(cc[x[5]],0,1,1,100);  // s/h
 h = LinExp.kr(cc[x[5]],0,1,1,1e4);
 shr = Select.kr(cc[x[3]]*3,[g,g,h]);
 sht = Impulse.ar(shr);
 j = Latch.ar(f,sht);
 k = cc[x[5]]>0;
 ~send.(x[5],shr*k);
 z = Select.ar(k,[f,j]);
 
 Out.kr(90,shr);
 Out.ar(91,sht);
 fq*z+fq;
};

~fm = {|fq,cc|
 x = [3,4];
 a = cc[x[0]]*4;
 b = cc[x[1]]*10;
 ~send.(x[0],a);
 ~send.(x[1],b);
 a = a.lag(0.1);
 b = b.lag(0.1);
 SinOsc.ar(fq,SinOsc.ar(fq*a,0,b),1);
};

~env = {|oo,cc|
 x = [15,5];
 a = In.kr(90);
 b = In.ar(91);
 c = EnvGen.ar(Env.perc(0.005,1/a),b);
 d = cc[x[0]]**2*8;
 ~send.(x[0],d);
 e = (cc[x[0]]>0)*(cc[x[1]]>0);
 Select.ar(e, [oo, c**d*oo]);
};

~ring = {|oo,cc|
 x = 16;
 a = LinExp.kr(cc[x],0,1,50,2e4);
 b = cc[x]>0;
 ~send.(x,a*b);
 b = b.lag(0.1)*2-1;
 c = SinOsc.ar(a)*oo;
 XFade2.ar(oo,c,b);
};

~dist = {|oo,cc|
 x = 17;
 a = 1-cc[x];
 ~send.(x,a);
 oo**a;
};

~trem = {|oo,cc|
 x = 18;
 a = cc[x]**2*20;
 b = cc[x]>0;
 ~send.(x,a*b);
 b = b.lag(1)*2-1;
 c = SinOsc.ar(1,0,1e-9,1);
 d = SinOsc.ar(a);
 e = XFade2.ar(c,d,b);
 oo*e;
};

~amp = {|oo,cc|
 x = [7,8];
 a = cc[x[0]]**2;
 b = cc[x[1]]>0.2;
 ~send.(x[0],a);
 ~send.(x[1],b);
 c = a.lag(0.1)*b;
 oo*c;
};

~comb = {|oo,cc|
 x = 6;
 a = cc[x]/2;
 ~send.(x,a);
 b = Mix.fill(2, {|i|
  c = Impulse.ar(1,0.5*i);
  d = EnvGen.ar(Env.sine(1,1),c);
  e = Latch.ar(K2A.ar(a),c);
  Pan2.ar(CombN.ar(oo,0.5,e,e*3,d),i*2-1);
 });
 Select.ar(cc[x]>0, [oo, oo+b*0.7]);
};

~smp = {|cc|
 a = SoundIn.ar(0);
 b = cc[0]*2-1**2+1;
 ~send.(80,-1*b+1);
 c = Phasor.ar(b,b/44100,0,4);
 c = [c,c+2%4];
 d = sin(c/4*pi);
 e = DelayC.ar(a,8,c)*d;
 Mix(DelayN.ar(e,4,[2,0]));
};


/* SynthDef */

SynthDef("hoge", {
 var cc, fq, au, oo, pp;
 cc = In.kr(0,20);
 
 fq = ~pitch.(cc);
 fq = ~port.(fq,cc);
 fq = ~mod.(fq,cc);
 oo = ~fm.(fq,cc);
 oo = ~ring.(oo,cc);
 oo = ~dist.(oo,cc);
 oo = ~trem.(oo,cc);
 oo = ~env.(oo,cc);
 oo = ~amp.(oo,cc);
 oo = ~comb.(oo,cc);
 
 pp = ~smp.(cc);
 oo = Select.ar(In.kr(80),[oo,pp]);
 oo = Limiter.ar(HPF.ar(oo,30),0.9,0.01);
 
 Out.ar(0,oo);
}).store;


/* startup */

s.sendMsg(\s_new, \hoge, 999);
s.sendMsg("/c_set", 80, 0);

/*
s.options.device_("ASIO : UA-4FX");
*/

2012/09/06

Ellen C. Covitoの音楽

No Collective+実験音楽とシアターのためのアンサンブル(EEMT)
Ellen C. Covitoの音楽

2012年9月19日(水) 20:00開演
公園通りクラシックス
2000円+1D