//================================================================ // Joe Mariglio - 6.15.10 // MIDI synth for audio in! // //================================================================ s.boot; a = ~occam = NetAddr("127.0.0.1", 57117); "open -a occam".unixCmd; SynthDef(\analyze, {|in = 0, trate = 20, vol = 1, thresh = 0.2| var trig, pitch, has, amplitude, input, bend, delta_bend; input = SoundIn.ar(in); // input = Compander.ar(input, input, thresh, 10, 1, 0.01, 0.01); input = input*vol; trig = Impulse.kr(trate); amplitude = Amplitude.kr(input, 0.1, 0.2); #pitch, has = Tartini.kr(input); bend = pitch.cpsmidi / pitch.cpsmidi.round; delta_bend = abs(bend - LastValue.kr(bend, 0.01)); SendTrig.kr(trig, 0, pitch); SendTrig.kr(trig, 1, amplitude); SendTrig.kr(trig, 2, bend); }).store; ~pitch = 64; ~amp = 0; ~bend = 0; ~responder = OSCresponder(nil, '/tr', {|t,r,m,a| ~occam.sendMsg("/osc/midi/out/noteOff", 0, ~pitch.cpsmidi.asInteger, ~amp.linlin(0, 1, 0, 127).asInteger); switch ( m[2], 0, { ~pitch = m[3]; }, 1, { ~amp = m[3]; }, 2, { ~bend = m[3].linlin(0.94387431268169, 1.0594630943593, 0, 2**14).round; } ); //128.do{|x| ~occam.sendMsg("/osc/midi/out/noteOff", 0, x.asInteger, 127.asInteger) }; ~occam.sendMsg("/osc/midi/out/noteOn", 0, ~pitch.cpsmidi.asInteger, ~amp.linlin(0, 1, 0, 127).asInteger); ~occam.sendMsg("/osc/midi/out/bend", 0, ~bend.asInteger); }).add; Conductor.make{|con, trate, vol| trate.sp(10, 1, 60); vol.sp(1, 0, 32); con.synth_( ( \instrument: \analyze), [trate:trate, vol:vol] ); con.action_({}, {{128.do{|x| a.sendMsg("/osc/midi/out/noteOff", 0, x.asInteger, 127.asInteger) }}.play}); }.show("pitch -> midi", w:1040)