Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
8 note polyphonic gated synths for Sonic Pi 3. Allows keyboard input with notes of any length. Requires SP3, and powerful computer at present: not Raspberry Pi. Article at https://rbnrpi.wordpress.com/2017/08/06/8-note-polyphonic-gated-synth-for-sonic-pi-3/ video at https://youtu.be/gD-50-_dgxg
#8 note polyphony gated synth setup program
#by Robin Newman, August 2017
#Set initial states for polyphonic synth
set :vm1,0
set :vm2,0
set :vm3,0
set :vm4,0
set :vm5,0
set :vm6,0
set :vm7,0
set :vm8,0
set :cnt1,60
set :cnt2,60
set :cnt3,60
set :cnt4,60
set :cnt5,60
set :cnt6,60
set :cnt7,60
set :cnt8,60
set :on1,0
set :on2,0
set :on3,0
set :on4,0
set :on5,0
set :on6,0
set :on7,0
set :on8,0
set :use1,0
set :use2,0
set :use3,0
set :use4,0
set :use5,0
set :use6,0
set :use7,0
set :use8,0
set :lk1,0
set :lk2,0
set :lk3,0
set :lk4,0
set :lk5,0
set :lk6,0
set :lk7,0
set :lk8,0
#8 note polyphony gated synth for Sonic Pi 3
#by Robin Newman, August 2017
TouchOSC_IP="192.168.1.50"
use_osc TouchOSC_IP,9000
use_debug false
use_cue_logging false
use_osc_logging false
set :vol,0.75
set :co,100
set :syn,:tri
set :trset,0
define :setLed do |n,i|
use_real_time
osc "/nc/"+n,i
end
osc "/nc/synthmaster/2/1",1
osc "/nc/vol",0.75
osc "/nc/cutoff",0.5
osc "/nc/transpose/1/8",1 # equiv 0 transpose
osc "/nc/reverb",0.5
define :getsyn do |address|
return get_event(address).to_s.split(",")[6][address.length-2..-4].to_i
end
live_loop :get_synthmaster do
use_real_time
b= sync "/osc/nc/synthmaster/**/1"
if b[0]==1
slist=[:chipbass, :chiplead,:dsaw, :fm,:mod_fm,:mod_pulse, :mod_saw,:prophet, :pulse, :saw, :square, :supersaw, :tb303, :tech_saws, :tri, :zawa]
p= 16-getsyn("/osc/nc/synthmaster/**/1")
set :syn,slist[p]
puts "synth",get(:syn)
end
end
define :book_synth do
s=0
if get(:use1)==0
set :use1,1
s=1
elsif get(:use2)==0
set :use2,1
s=2
elsif get(:use3)==0
set :use3,1
s=3
elsif get(:use4)==0
set :use4,1
s=4
elsif get(:use5)==0
set :use5,1
s=5
elsif get(:use6)==0
set :use6,1
s=6
elsif get(:use7)==0
set :use7,1
s=7
elsif get(:use8)==0
set :use8,1
s=8
end
puts get(:use1),get(:use2),get(:use3),get(:use4),get(:use5),get(:use6),get(:use7),get(:use8)
return s
end
live_loop :resetnotes do
b= sync "/osc/nc/resetnotes"
if b[0]>0
set :use1,0
set :use2,0
set :use3,0
set :use4,0
set :use5,0
set :use6,0
set :use7,0
set :use8,0
set :on1,0
set :on2,0
set :on3,0
set :on4,0
set :on5,0
set :on6,0
set :on7,0
set :on8,0
end
end
define :getTranspose do |address|
return get_event(address).to_s.split(",")[6][address.length+1..-2].to_i
end
live_loop :setTranspose do
use_real_time
b= sync "/osc/nc/transpose/1/*"
if b[0]==1
tr= getTranspose("/osc/nc/transpose/1/*")-1
puts "tr is",tr
set(:trset,[-12,-10,-8,-7,-5,-3,-1,0,2,4,5,7,9,11,12][tr])
puts "Transpose",get(:trset)
end
end
define :pdec2 do |n|
return (n.to_f*100).round.to_f/100
end
live_loop :get_cutoff do
use_real_time
b= sync "/osc/nc/cutoff"
set :co,b[0]*40+80
puts "Cutoff:",pdec2(get(:co))
end
live_loop :getvol do
use_real_time
b= sync "/osc/nc/vol"
set :vol,b[0]
puts "vol:",pdec2(get(:vol))
end
### PLAYING SECTION BELOW ###
with_fx :reverb,room: 0.8,mix: 0.5 do |rv|
in_thread do
loop do
b=sync "/osc/nc/reverb"
control rv,mix: b[0],mix_slide: 0.05
puts"Reverb mix",pdec2(b[0])
end
end
live_loop :c_synth1 do
use_real_time
while get(:on1)==0
sleep 0.02
end
setLed("led1",1)
use_synth get(:syn)
n = play get(:cnt1)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on1)==1
sleep 0.02
control n,note: get(:cnt1)+get(:trset),amp: get(:vol)*get(:vm1),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led1",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth2 do
use_real_time
while get(:on2)==0
sleep 0.02
end
setLed("led2",1)
use_synth get(:syn)
n= play get(:cnt2)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on2)==1
sleep 0.02
control n,note: get(:cnt2)+get(:trset),amp: get(:vol)*get(:vm2),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led2",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth3 do
use_real_time
while get(:on3)==0
sleep 0.02
end
setLed("led3",1)
use_synth get(:syn)
n= play get(:cnt3)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on3)==1
sleep 0.02
control n,note: get(:cnt3)+get(:trset),amp: get(:vol)*get(:vm3),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led3",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth4 do
use_real_time
while get(:on4)==0
sleep 0.02
end
setLed("led4",1)
use_synth get(:syn)
n= play get(:cnt4)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on4)==1
sleep 0.02
control n,note: get(:cnt4)+get(:trset),amp: get(:vol)*get(:vm4),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led4",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth5 do
use_real_time
while get(:on5)==0
sleep 0.02
end
setLed("led5",1)
use_synth get(:syn)
n= play get(:cnt5)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on5)==1
sleep 0.02
control n,note: get(:cnt5)+get(:trset),amp: get(:vol)*get(:vm5),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led5",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth6 do
use_real_time
while get(:on6)==0
sleep 0.02
end
setLed("led6",1)
use_synth get(:syn)
n= play get(:cnt6)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on6)==1
sleep 0.02
control n,note: get(:cnt6)+get(:trset),amp: get(:vol)*get(:vm6),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led6",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth7 do
use_real_time
while get(:on7)==0
sleep 0.02
end
setLed("led7",1)
use_synth get(:syn)
n= play get(:cnt7)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on7)==1
sleep 0.02
control n,note: get(:cnt7)+get(:trset),amp: get(:vol)*get(:vm7),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led7",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
live_loop :c_synth8 do
use_real_time
while get(:on8)==0
sleep 0.02
end
setLed("led8",1)
use_synth get(:syn)
n= play get(:cnt8)+get(:trset),sustain: 6000,cutoff: get(:co),amp: 0,release: 0
while get(:on8)==1
sleep 0.02
control n,note: get(:cnt8)+get(:trset),amp: get(:vol)*get(:vm8),amp_slide: 0.01,cutoff: get(:co),cutoff_slide: 0.01
end
sleep 0.02
setLed("led8",0)
control n, amp: 0,amp_slide: 0.01
sleep 0.02
n.kill
#sleep 0.01
end
end #fx
live_loop :midi_on do
use_real_time
b=sync "/midi/**/*/*/note_on"
if b[1]>0
msyn=book_synth
puts "SYNTH",msyn
if !(msyn == 0)
if msyn==1
set :lk1,b[0]
set :cnt1 ,b[0]
set :vm1,b[1].to_f/127
set :on1,1
elsif msyn==2
set :lk2,b[0]
set :cnt2 ,b[0]
set :vm2,b[1].to_f/127
set :on2,1
elsif msyn==3
set :lk3,b[0]
set :cnt3 ,b[0]
set :vm3,b[1].to_f/127
set :on3,1
elsif msyn==4
set :lk4,b[0]
set :cnt4 ,b[0]
set :vm4,b[1].to_f/127
set :on4,1
elsif msyn==5
set :lk5,b[0]
set :cnt5 ,b[0]
set :vm5,b[1].to_f/127
set :on5,1
elsif msyn==6
set :lk6,b[0]
set :cnt6 ,b[0]
set :vm6,b[1].to_f/127
set :on6,1
elsif msyn==7
set :lk7,b[0]
set :cnt7 ,b[0]
set :vm7,b[1].to_f/127
set :on7,1
elsif msyn==8
set :lk8,b[0]
set :cnt8 ,b[0]
set :vm8,b[1].to_f/127
set :on8,1
end
end
else
if b[0]== get(:lk1)
set :on1,0
set :use1,0
elsif b[0]==get(:lk2)
set :on2,0
set :use2,0
elsif b[0]==get(:lk3)
set :on3,0
set :use3,0
elsif b[0]==get(:lk4)
set :on4,0
set :use4,0
elsif b[0]==get(:lk5)
set :on5,0
set :use5,0
elsif b[0]==get(:lk6)
set :on6,0
set :use6,0
elsif b[0]==get(:lk7)
set :on7,0
set :use7,0
elsif b[0]==get(:lk8)
set :on8,0
set :use8,0
end
puts "In use",get(:use1),get(:use2),get(:use3),get(:use4),get(:use5),get(:use6),get(:use7),get(:use8)
end
end
<?xml version="1.0" encoding="UTF-8"?><layout version="15" mode="1" orientation="vertical"><tabpage name="bmM=" scalef="0.0" scalet="1.0" ><control name="bGFiZWwyMQ==" x="193" y="97" w="33" h="246" color="yellow" type="labelv" text="U29uaWMgUGkgMyBHYXRlZCBTeW50aHM=" size="22" background="true" outline="false" ></control><control name="bGFiZWwyMg==" x="181" y="676" w="33" h="205" color="yellow" type="labelv" text="YnkgUm9iaW4gTmV3bWFu" size="22" background="true" outline="false" ></control><control name="dHJhbnNwb3Nl" x="171" y="364" w="50" h="300" color="pink" scalef="0.0" scalet="1.0" type="multitoggle" number_x="1" number_y="15" ex_mode="true" local_off="false" ></control><control name="bGFiZWwyNg==" x="256" y="467" w="25" h="84" color="purple" type="labelv" text="VHJhbnNwb3Nl" size="14" background="true" outline="false" ></control><control name="bGFiZWwzMA==" x="226" y="364" w="25" h="25" color="purple" type="labelv" text="LTEy" size="14" background="true" outline="false" ></control><control name="bGFiZWwzNA==" x="143" y="384" w="25" h="25" color="purple" type="labelv" text="LTEw" size="14" background="true" outline="false" ></control><control name="bGFiZWwzNQ==" x="226" y="403" w="25" h="25" color="purple" type="labelv" text="LTg=" size="14" background="true" outline="false" ></control><control name="bGFiZWwzNg==" x="143" y="423" w="25" h="25" color="purple" type="labelv" text="LTc=" size="14" background="true" outline="false" ></control><control name="bGFiZWwzNw==" x="226" y="442" w="25" h="25" color="purple" type="labelv" text="LTU=" size="14" background="true" outline="false" ></control><control name="bGFiZWwzOA==" x="143" y="462" w="25" h="25" color="purple" type="labelv" text="LTM=" size="14" background="true" outline="false" ></control><control name="bGFiZWwzOQ==" x="226" y="481" w="25" h="25" color="purple" type="labelv" text="LTE=" size="14" background="true" outline="false" ></control><control name="bGFiZWw0MA==" x="143" y="501" w="25" h="25" color="purple" type="labelv" text="MA==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0MQ==" x="226" y="520" w="25" h="25" color="purple" type="labelv" text="Mg==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0Mg==" x="143" y="540" w="25" h="25" color="purple" type="labelv" text="NA==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0Mw==" x="226" y="559" w="25" h="25" color="purple" type="labelv" text="NQ==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0NA==" x="143" y="579" w="25" h="25" color="purple" type="labelv" text="Nw==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0NQ==" x="226" y="598" w="25" h="25" color="purple" type="labelv" text="OQ==" size="14" background="true" outline="false" ></control><control name="bGFiZWw0Ng==" x="143" y="618" w="25" h="25" color="purple" type="labelv" text="MTE=" size="14" background="true" outline="false" ></control><control name="bGFiZWw0Nw==" x="225" y="637" w="25" h="25" color="purple" type="labelv" text="MTI=" size="14" background="true" outline="false" ></control><control name="cmV2ZXJi" x="596" y="398" w="36" h="200" color="pink" scalef="0.0" scalet="1.0" type="faderv" response="absolute" inverted="false" centered="false" ></control><control name="bGFiZWw0OA==" x="643" y="466" w="25" h="66" color="pink" type="labelv" text="UmV2ZXJi" size="14" background="true" outline="false" ></control><control name="dm9s" x="354" y="153" w="200" h="50" color="yellow" scalef="0.0" scalet="1.0" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="bGJsdm9s" x="554" y="157" w="24" h="44" color="yellow" type="labelv" text="Vm9s" size="14" background="true" outline="false" ></control><control name="bGFiZWw2OQ==" x="477" y="302" w="25" h="45" color="green" type="labelv" text="c3ludGgx" size="14" background="true" outline="false" ></control><control name="bGVkMQ==" x="449" y="312" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="Y3V0b2Zm" x="354" y="216" w="200" h="50" color="green" scalef="0.0" scalet="1.0" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="bGJsY3V0b2ZmMQ==" x="554" y="214" w="25" h="51" color="green" type="labelv" text="Q3V0b2Zm" size="14" background="true" outline="false" ></control><control name="bGFiZWw4MQ==" x="477" y="363" w="25" h="45" color="green" type="labelv" text="c3ludGgy" size="14" background="true" outline="false" ></control><control name="bGVkMg==" x="449" y="373" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWw5Mw==" x="477" y="418" w="25" h="45" color="green" type="labelv" text="c3ludGgz" size="14" background="true" outline="false" ></control><control name="bGVkMw==" x="449" y="428" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMDQ=" x="477" y="468" w="25" h="45" color="green" type="labelv" text="c3ludGg0" size="14" background="true" outline="false" ></control><control name="bGVkNA==" x="449" y="478" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMTU=" x="477" y="519" w="25" h="45" color="green" type="labelv" text="c3ludGg1" size="14" background="true" outline="false" ></control><control name="bGVkNQ==" x="449" y="529" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMjY=" x="477" y="572" w="25" h="45" color="green" type="labelv" text="c3ludGg2" size="14" background="true" outline="false" ></control><control name="bGVkNg==" x="449" y="582" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="cmVzZXRub3Rlcw==" x="326" y="479" w="45" h="45" color="red" scalef="0.0" scalet="1.0" type="push" local_off="false" ></control><control name="bGFiZWwxMjk=" x="374" y="461" w="23" h="82" color="red" type="labelv" text="UmVzZXROb3Rlcw==" size="14" background="true" outline="false" ></control><control name="bGFiZWwxMzE=" x="478" y="623" w="24" h="45" color="green" type="labelv" text="c3ludGg3" size="14" background="true" outline="false" ></control><control name="bGVkNw==" x="450" y="633" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMzM=" x="477" y="676" w="25" h="45" color="green" type="labelv" text="c3ludGg4" size="14" background="true" outline="false" ></control><control name="bGVkOA==" x="450" y="686" w="20" h="20" color="red" scalef="0.0" scalet="1.0" type="led" ></control><control name="bGFiZWwxMzU=" x="509" y="351" w="25" h="146" color="yellow" type="labelv" text="UG9seXBob255IHN5bnRocw==" size="14" background="true" outline="false" ></control><control name="bGFiZWwxMzY=" x="508" y="496" w="25" h="146" color="yellow" type="labelv" text="UnVubmluZyBJbmRpY2F0b3Jz" size="14" background="true" outline="false" ></control><control name="bGFiZWwxMzc=" x="161" y="97" w="33" h="246" color="yellow" type="labelv" text="Z2l2aW5nIDggbm90ZSBwb2x5cGhvbnk=" size="22" background="true" outline="false" ></control><control name="c3ludGhtYXN0ZXI=" x="237" y="748" w="406" h="50" color="purple" scalef="0.0" scalet="1.0" type="multitoggle" number_x="16" number_y="1" ex_mode="true" local_off="false" ></control><control name="c3ludGhM" x="643" y="729" w="25" h="92" color="purple" type="labelv" text="TWFzdGVyIFN5bnRo" size="14" background="true" outline="false" ></control><control name="bGFiZWw2MQ==" x="389" y="802" w="24" h="34" color="purple" type="labelv" text="U2F3" size="14" background="true" outline="false" ></control><control name="bGFiZWw2Mg==" x="438" y="802" w="24" h="51" color="purple" type="labelv" text="UHJvcGhldA==" size="14" background="true" outline="false" ></control><control name="bGFiZWw2Mw==" x="314" y="802" w="25" h="42" color="purple" type="labelv" text="VEIzMDM=" size="14" background="true" outline="false" ></control><control name="bGFiZWw2NA==" x="538" y="802" w="23" h="26" color="purple" type="labelv" text="Rk0=" size="14" background="true" outline="false" ></control><control name="bGFiZWw2NQ==" x="512" y="802" w="25" h="60" color="purple" type="labelv" text="TW9kIEZN" size="14" background="true" outline="false" ></control><control name="bGFiZWw2Ng==" x="265" y="802" w="25" h="20" color="purple" type="labelv" text="VHJp" size="14" background="true" outline="false" ></control><control name="bGFiZWwxMzg=" x="364" y="802" w="24" h="50" color="purple" type="labelv" text="U3F1YXJl" size="14" background="true" outline="false" ></control><control name="bGFiZWwxMzk=" x="488" y="802" w="24" h="65" color="purple" type="labelv" text="TW9kUHVsc2U=" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDA=" x="339" y="802" w="24" h="72" color="purple" type="labelv" text="U3VwZXJTYXc=" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDE=" x="290" y="802" w="24" h="75" color="purple" type="labelv" text="VGVjaF9TYXdz" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDI=" x="241" y="802" w="24" h="41" color="purple" type="labelv" text="WmF3YQ==" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDM=" x="414" y="802" w="24" h="42" color="purple" type="labelv" text="UHVsc2U=" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDU=" x="587" y="802" w="24" h="59" color="purple" type="labelv" text="Q2hpcGxlYWQ=" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDY=" x="612" y="802" w="24" h="60" color="purple" type="labelv" text="Q2hpcGJhc3M=" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDc=" x="463" y="802" w="25" h="62" color="purple" type="labelv" text="TW9kIFNhdw==" size="14" background="true" outline="false" ></control><control name="bGFiZWwxNDg=" x="562" y="802" w="24" h="40" color="purple" type="labelv" text="RHNhdw==" size="14" background="true" outline="false" ></control></tabpage></layout>
Owner

rbnpi commented Aug 6, 2017

The index.html file contains the information for the TouchOSC file named PolyphonicSynths.touchosc
To create the file from this index follow the procedure described below.
The file index.xml needs to be converted to a format which is used by TouchOSC. To do this, download the raw file and save it as index.html Then turn it into a zip file. On the Mac do this by right clicking the index.xml file in Finder, and choosing the compress option. This will produce a file named index.xml.zip Now rename this file to PolyphonicSynths.touchosc (NB touchosc is the file extension). This file can then be loaded into the TouchOSC editor which comes with TouchOSC and downloaded to the TouchOSC app running on an iPad in the usual way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment