Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // midi controll
- MIDIClient.init
- MIDIIn.connectAll
- ~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
- // I think you want:
- // ~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
- ~instrumentList = [\sound,\tone,\mySound];
- (
- MIDIdef.noteOn(\noteOnTest,
- {
- arg vel, nn,chan,src;
- [vel,nn,chan].postln;
- // so far ~notes is nil, so ~notes[nn] will give an error. initialize with ~notes = Array.new(128)
- ~notes[nn] = ~instrumentList.collect{
- arg instName;
- Synth.new(instName, [\freq,nn.midicps/2,\amp,vel.linexp(1,127,0.01,1), \gate, 1,])
- }
- });
- )
- (
- MIDIdef.bend(\bendTest, {
- arg vel,chan,src;
- [vel,chan,src].postln;
- });
- )
- (MIDIdef.noteOff(\noteOffTest, {
- arg vel, nn;
- [vel,nn].postln;
- ~notes[nn].do{
- arg nn;
- nn.do{arg x; x.set(\gate, 0)};
- };
- ~notes[nn] == nil;
- };
- ))
- (
- MIDIdef.cc(\breathTest, {
- arg vel, nn;
- vel.postln;
- ~breath = vel;
- ~notes[nn].do{
- arg nn;
- nn.do{arg synth;
- if (synth.class == Synth, {synth.set(\amp,vel.linexp(1,127,0.01,1))})
- };
- };
- }))
- (
- SynthDef.new(\tone, {
- arg freq=440,amp=0.3,gate=1,bend=0,vibRate=0,vibDepth=0; // no sound until I changed gate to 1
- var sig, env,vib;
- vib = SinOsc.kr(vibRate,mul:5);
- sig=SinOsc.ar((freq*bend.midiratio)+vib)!2;
- env=EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate,doneAction:2);
- sig=sig*env*amp;
- Out.ar(~buses[1],sig); // just for clarity, I suggest using ~buses[0], [1], and [2] for your 3 sounds
- }
- ).add;)
- (SynthDef(\mySound, {arg freq=440, amp=0.5,gate=1, pan=0,resFreq=0,numharm=3;
- var sound, env,vib,env1,pan1;
- env = EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate:gate, doneAction:2);
- vib = SinOsc.kr(7.5,mul:6,add:6);
- sound = Blip.ar(freq: [freq-20+vib,freq-20+3+vib]+(env*20),numharm:numharm) * amp * env;
- sound = RLPF.ar(in: sound, freq: 1000);
- sound = Pan2.ar(in:sound, pos:pan);
- Out.ar(~buses[2], sound)
- }).add)
- (
- SynthDef.new(\sound,
- {
- 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
- var sig, env;
- env=EnvGen.kr(Env.adsr(0.4,releaseTime:0.1),gate,doneAction:2);
- sig=Blip.ar([freq,freq-2]*LFNoise1.kr(0.2!16).bipolar(detune.neg,detune).midiratio,nharm);
- sig=sig*LFNoise1.kr(0.5!16).exprange(0.1,1);
- // sig = Resonz.ar(sig,resFreq,resBand);
- sig=Splay.ar(sig);
- sig=Balance2.ar(sig[0],sig[1],pan);
- sig=sig*env*amp;
- Out.ar( ~buses[0],sig);
- }).add)
- //
- (SynthDef.new(\soundChooser, {arg synthPos=0;
- var soundIn;
- 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
- soundIn= PanAz.ar(~instrumentList.size,soundIn,synthPos,1,0.1);
- Out.ar(0,soundIn);
- }).add)
- // elliot edit:
- // 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)
- (SynthDef.new(\soundChooser, {arg synthPos=0;
- var soundIn, soundOut;
- soundIn = In.ar(~buses[0],6).poll(0.5); // get 6 channels starting with bus 0
- soundOut = Pan2.ar(SelectX.ar(synthPos, soundIn)); // added Pan to get stereo
- Out.ar(0,soundOut);
- }).add)
- // TEST IT:
- (
- x = Synth(\tone);
- y = Synth(\mySound);
- z = Synth(\sound);
- )
- a = Synth(\soundChooser, addAction:\addToTail); // \addToTail is necessary (signal flows down node tree: command-T)
- a.set(\synthPos, 0)
- a.set(\synthPos, 1)
- a.set(\synthPos, 1.5)
- a.set(\synthPos, 2.5)
- a.set(\synthPos, 3.5)
- a.set(\synthPos, 6)
- a.free
- NetAddr.langPort
- (
- // OSCdef.new(
- // \toggle,
- // {
- // arg msg,time,addr,port;
- // msg[1].postln;
- // x.set(\gate,msg[1])
- // },
- // '/1/toggle1'
- // );
- // OSCdef.new(
- // \fader3,
- // {
- // arg msg,time,addr,port;
- // msg[1].postln;
- // x.set(\freq,msg[1].linexp(0,1,20,500));
- // },
- // '/1/fader3'
- // );
- OSCdef.new(
- \fader4,
- {
- arg msg,time,addr,port;
- msg[1].postln;
- ~notes.do {arg x; x.set(\nharm,msg[1].linlin(0,1,1,50));}
- },
- '/1/fader4'
- );
- // OSCdef.new(
- // \fader5,
- // {
- // arg msg,time,addr,port;
- // msg[1].postln;
- // x.set(\amp,msg[1].linexp(0,1,0.0001,1));
- // },
- // '/1/fader5'
- // );
- OSCdef.new(
- \rotary1,
- {
- arg msg,time,addr,port;
- msg[1].postln;
- y.set(\synthPos,msg[1].linexp(1,127,-1,1)); /// !!! y is nil. put y = Synth(\soundChooser, addAction:\addToTail) somewhere earlier
- },
- '/1/rotary1'
- );
- OSCdef.new(
- \rotary2,
- {
- arg msg,time,addr,port;
- msg[1].postln;
- ~notes.do{
- arg nn;
- nn.do{arg synth;
- 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