Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // midi controll
  2.  
  3. MIDIClient.init
  4. MIDIIn.connectAll
  5.  
  6. ~buses = Array.fill(8,(Bus.audio(s,8)));  // this (without the second argument being a FUNCTION) creates a single 8 eight-channel bus and puts 8 copies of it into an array
  7.  
  8. // I think you want:
  9. // ~buses = Array.fill(8,{Bus.audio(s,2)});  // second argument is a FUNCTION, so Bus.audio runs 8 separate times, creating 8 distinct 2-channel busses
  10.  
  11.  
  12.  
  13. ~instrumentList = [\sound,\tone,\mySound];
  14.  
  15. (
  16. MIDIdef.noteOn(\noteOnTest,
  17.     {
  18.         arg vel, nn,chan,src;
  19.         [vel,nn,chan].postln;
  20.        
  21.         // so far ~notes is nil, so ~notes[nn] will give an error.  initialize with ~notes = Array.new(128)
  22.        
  23.         ~notes[nn] = ~instrumentList.collect{
  24.             arg instName;
  25.             Synth.new(instName, [\freq,nn.midicps/2,\amp,vel.linexp(1,127,0.01,1),  \gate, 1,])
  26.         }
  27. });
  28. )
  29. (
  30. MIDIdef.bend(\bendTest, {
  31.     arg vel,chan,src;
  32.     [vel,chan,src].postln;
  33. });
  34. )
  35.  
  36. (MIDIdef.noteOff(\noteOffTest, {
  37.     arg vel, nn;
  38.     [vel,nn].postln;
  39.     ~notes[nn].do{
  40.         arg nn;
  41.         nn.do{arg x; x.set(\gate, 0)};
  42.     };
  43.     ~notes[nn] == nil;
  44. };
  45. ))
  46.  
  47. (
  48. MIDIdef.cc(\breathTest, {
  49.     arg vel, nn;
  50.     vel.postln;
  51.     ~breath = vel;
  52.     ~notes[nn].do{
  53.         arg nn;
  54.         nn.do{arg synth;
  55.             if (synth.class == Synth, {synth.set(\amp,vel.linexp(1,127,0.01,1))})
  56.         };
  57.     };
  58. }))
  59.  
  60.  
  61. (
  62. SynthDef.new(\tone, {
  63.     arg freq=440,amp=0.3,gate=1,bend=0,vibRate=0,vibDepth=0; // no sound until I changed gate to 1
  64.     var  sig, env,vib;
  65.     vib = SinOsc.kr(vibRate,mul:5);
  66.     sig=SinOsc.ar((freq*bend.midiratio)+vib)!2;
  67.     env=EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate,doneAction:2);
  68.     sig=sig*env*amp;
  69.     Out.ar(~buses[1],sig); // just for clarity, I suggest using ~buses[0], [1], and [2] for your 3 sounds
  70. }
  71. ).add;)
  72.  
  73. (SynthDef(\mySound, {arg freq=440, amp=0.5,gate=1, pan=0,resFreq=0,numharm=3;
  74.     var sound, env,vib,env1,pan1;
  75.     env = EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate:gate, doneAction:2);
  76.     vib = SinOsc.kr(7.5,mul:6,add:6);
  77.     sound = Blip.ar(freq: [freq-20+vib,freq-20+3+vib]+(env*20),numharm:numharm) * amp * env;
  78.     sound = RLPF.ar(in: sound, freq: 1000);
  79.     sound = Pan2.ar(in:sound, pos:pan);
  80.     Out.ar(~buses[2], sound)
  81. }).add)
  82.  
  83.  
  84. (
  85. SynthDef.new(\sound,
  86.     {
  87.         arg freq=440,nharm=12,detune=0.2,gate=1,pan=0,amp=1,out=0,resFreq=0,resBand=0.0001; // no sound until I changed gate to 1
  88.         var sig, env;
  89.         env=EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate,doneAction:2);
  90.         sig=Blip.ar([freq,freq-2]*LFNoise1.kr(0.2!16).bipolar(detune.neg,detune).midiratio,nharm);
  91.         sig=sig*LFNoise1.kr(0.5!16).exprange(0.1,1);
  92.         // sig = Resonz.ar(sig,resFreq,resBand);
  93.         sig=Splay.ar(sig);
  94.         sig=Balance2.ar(sig[0],sig[1],pan);
  95.         sig=sig*env*amp;
  96.         Out.ar( ~buses[0],sig);
  97. }).add)
  98. //
  99.  
  100. (SynthDef.new(\soundChooser, {arg synthPos=0;
  101.     var soundIn;
  102.     soundIn = In.ar(~buses[0],2); // here you're only listening to TWO channels of bus, when you want all 3 of your sounds coming in
  103.     soundIn= PanAz.ar(~instrumentList.size,soundIn,synthPos,1,0.1);
  104.     Out.ar(0,soundIn);
  105. }).add)
  106.  
  107.  
  108.  
  109.  
  110. // elliot edit:
  111. // I WAS WRONG!  PanAz is not the right thing here.  SelectX is: (synthPos should be between 0 and n where n is the number of CHANNELS OF AUDIO: ie for 3 stereo instruments, 6)
  112.  
  113. (SynthDef.new(\soundChooser, {arg synthPos=0;
  114.     var soundIn, soundOut;
  115.     soundIn = In.ar(~buses[0],6).poll(0.5); // get 6 channels starting with bus 0
  116.  
  117.     soundOut = Pan2.ar(SelectX.ar(synthPos, soundIn)); // added Pan to get stereo
  118.    
  119.     Out.ar(0,soundOut);
  120. }).add)
  121.  
  122.  
  123. // TEST IT:
  124. (
  125. x = Synth(\tone);
  126. y = Synth(\mySound);
  127. z = Synth(\sound);
  128. )
  129.  
  130. a = Synth(\soundChooser, addAction:\addToTail); // \addToTail is necessary (signal flows down node tree: command-T)
  131. a.set(\synthPos, 0)
  132. a.set(\synthPos, 1)
  133. a.set(\synthPos, 1.5)
  134. a.set(\synthPos, 2.5)
  135. a.set(\synthPos, 3.5)
  136. a.set(\synthPos, 6)
  137. a.free
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144. NetAddr.langPort
  145.  
  146. (
  147. // OSCdef.new(
  148. // \toggle,
  149. // {
  150. // arg msg,time,addr,port;
  151. // msg[1].postln;
  152. // x.set(\gate,msg[1])
  153. // },
  154. // '/1/toggle1'
  155. // );
  156. // OSCdef.new(
  157. // \fader3,
  158. // {
  159. // arg msg,time,addr,port;
  160. // msg[1].postln;
  161. // x.set(\freq,msg[1].linexp(0,1,20,500));
  162. // },
  163. // '/1/fader3'
  164. // );
  165. OSCdef.new(
  166.     \fader4,
  167.     {
  168.         arg msg,time,addr,port;
  169.         msg[1].postln;
  170.         ~notes.do {arg x; x.set(\nharm,msg[1].linlin(0,1,1,50));}
  171.     },
  172.     '/1/fader4'
  173. );
  174. // OSCdef.new(
  175. // \fader5,
  176. // {
  177. // arg msg,time,addr,port;
  178. // msg[1].postln;
  179. // x.set(\amp,msg[1].linexp(0,1,0.0001,1));
  180. // },
  181. // '/1/fader5'
  182. // );
  183. OSCdef.new(
  184.     \rotary1,
  185.     {
  186.         arg msg,time,addr,port;
  187.         msg[1].postln;
  188.         y.set(\synthPos,msg[1].linexp(1,127,-1,1)); /// !!! y is nil.  put y = Synth(\soundChooser, addAction:\addToTail) somewhere earlier
  189.     },
  190.     '/1/rotary1'
  191. );
  192. OSCdef.new(
  193.     \rotary2,
  194.     {
  195.         arg msg,time,addr,port;
  196.         msg[1].postln;
  197.         ~notes.do{
  198.             arg nn;
  199.             nn.do{arg synth;
  200.                 if (synth.class == Synth, {synth.set(\detune,msg[1].linexp(0,1,0.01,12))})
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement