Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbutz/cbcc5d0f8aeed2b8fdb8160e5173ef20 to your computer and use it in GitHub Desktop.
Save mbutz/cbcc5d0f8aeed2b8fdb8160e5173ef20 to your computer and use it in GitHub Desktop.
Sonic Pi Live Looper with touchosc: Controller, Library and touchosc layout
# key: live looper touchosc
# filename: live_looper_touchosc.sps
# point_line: 1
# point_index: 2
# --
# Please configure connections between Sonic Pi and touchosc:
set :ip, "192.168.2.150"
set :port, 4000
# where can this script find the library?
set :libpath, "~/projects/sonicpi/playground/code/lib/lib-live-looper-touchosc.rb"
# Defaults: Adjust to your convenience:
set :metro_vol_master, 1
set :my_bpm, 120
set :playback_master, 10
set :rec_level, 3
set :track1_len, 8
set :track2_len, 8
set :track3_len, 8
set :track4_len, 8
# Initialization of looper and touchosc interface
use_osc get(:ip), get(:port)
osc "/looper/track1_vol", 0
osc "/looper/track2_vol", 0
osc "/looper/track3_vol", 0
osc "/looper/track4_vol", 0
osc "/looper/metro_vol", 0
osc "/looper/metro", 0
osc "/looper/track_arm/2/1", 0
osc "/looper/track_arm/2/2", 0
osc "/looper/track_arm/1/1", 0
osc "/looper/track_arm/1/2", 0
set :track1_vol, 0
set :track2_vol, 0
set :track3_vol, 0
set :track4_vol, 0
set :metro_vol, 0
set :metro_toggle, 0
set :track_len, 4
live_loop :go do
use_real_time
p = sync "/osc/looper/go"
if p[0] > 0 then
run_file get(:libpath) # live_looper_touchosc
end
end
# Live Looper Library with TouchOSC Control (beta-1)
# filename: lib-live-looper-touchosc.rb
use_osc get(:ip), get(:port)
use_bpm get(:my_bpm)
t1 = buffer[:track1, get(:track1_len)]
t2 = buffer[:track2, get(:track2_len)]
t3 = buffer[:track3, get(:track3_len)]
t4 = buffer[:track4, get(:track4_len)]
# Get/set track to be armed
live_loop :t1 do
use_real_time
c = sync "/osc/looper/track_arm/2/1"
set :track1, c[0]
set :track_len, get(:track1_len)
end
live_loop :t2 do
use_real_time
c = sync "/osc/looper/track_arm/2/2"
set :track2, c[0]
set :track_len, get(:track2_len)
end
live_loop :t3 do
use_real_time
c = sync "/osc/looper/track_arm/1/1"
set :track3, c[0]
set :track_len, get(:track3_len)
end
live_loop :t4 do
use_real_time
c = sync "/osc/looper/track_arm/1/2"
set :track4, c[0]
set :track_len, get(:track4_len)
end
# metronom volume
live_loop :m_vol do
use_real_time
c = sync "/osc/looper/metro_vol"
set :metro_vol, c[0]
end
live_loop :m do
use_real_time
c = sync "/osc/looper/metro"
set :metro_toggle, c[0]
end
# set metronom according to track currently armed
live_loop :metro do
f = get(:track_len) - 1
sample :elec_tick, amp: get(:metro_vol) * get(:metro_vol_master), rate: 1.25 if get(:metro_toggle) == 1
sleep 1
f.times do
sample :elec_tick, amp: get(:metro_vol) * get(:metro_vol_master), rate: 1 if get(:metro_toggle) == 1
sleep 1
end
end
# Get/set playback volume
live_loop :t1_vol do
use_real_time
c = sync "/osc/looper/track1_vol"
set :track1_vol, c[0]
end
live_loop :t2_vol do
use_real_time
c = sync "/osc/looper/track2_vol"
set :track2_vol, c[0]
end
live_loop :t3_vol do
use_real_time
c = sync "/osc/looper/track3_vol"
set :track3_vol, c[0]
end
live_loop :t4_vol do
use_real_time
c = sync "/osc/looper/track4_vol"
set :track4_vol, c[0]
end
# Record track 1
if get(:track1) == 1.0
in_thread sync: :metro do
with_fx :record, buffer: t1 do
osc "/looper/track1_rec", 1
live_audio :audio_in1, stereo: true
end
sleep get(:track1_len)
live_audio :audio_in1, :stop
osc "/looper/track_arm/2/1", 0
osc "/looper/track1_rec", 0
set :track1, 0
end
end
# Record track 2
if get(:track2) == 1.0
in_thread sync: :metro do
with_fx :record, buffer: t2 do
osc "/looper/track2_rec", 1
live_audio :audio_in2, stereo: true
end
sleep get(:track2_len)
live_audio :audio_in2, :stop
osc "/looper/track_arm/2/2", 0
osc "/looper/track2_rec", 0
set :track2, 0
end
end
# Record track 3
if get(:track3) == 1.0
in_thread sync: :metro do
with_fx :record, buffer: t3 do
osc "/looper/track3_rec", 1
live_audio :audio_in3, stereo: true
end
sleep get(:track3_len)
live_audio :audio_in3, :stop
osc "/looper/track_arm/1/1", 0
osc "/looper/track3_rec", 0
set :track3, 0
end
end
# Record track 4
if get(:track4) == 1.0
in_thread sync: :metro do
with_fx :record, buffer: t4 do
osc "/looper/track4_rec", 1
live_audio :audio_in4, stereo: true
end
sleep get(:track4_len)
live_audio :audio_in4, :stop
osc "/looper/track_arm/1/2", 0
osc "/looper/track4_rec", 0
set :track4, 0
end
end
# (Re)Play Tracks
live_loop :play_t1, sync: :metro do
sample t1, amp: get(:track1_vol)
sleep get(:track1_len)
end
live_loop :play_t2, sync: :metro do
sample t2, amp: get(:track2_vol)
sleep get(:track2_len)
end
live_loop :play_t3, sync: :metro do
sample t3, amp: get(:track3_vol)
sleep get(:track3_len)
end
live_loop :play_t4, sync: :metro do
sample t4, amp: get(:track4_vol)
sleep get(:track4_len)
end
<?xml version="1.0" encoding="UTF-8"?><layout version="16" mode="3" w="320" h="580" orientation="vertical"><tabpage name="dHJhY2sxX3ZvbA==" scalef="0.0" scalet="1.0" li_t="" li_c="gray" li_s="14" li_o="false" li_b="false" la_t="" la_c="gray" la_s="14" la_o="false" la_b="false" ><control name="VHJhY2tfU2VsZWN0" x="68" y="67" w="200" h="200" color="red" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci90cmFja19hcm0=" type="multitoggle" number_x="2" number_y="2" ex_mode="true" local_off="false" ></control><control name="bGVkMQ==" x="230" y="75" w="30" h="30" color="green" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci90cmFjazFfcmVj" type="led" ></control><control name="bGVkMg==" x="228" y="172" w="30" h="30" color="green" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci90cmFjazJfcmVj" type="led" ></control><control name="bGVkMw==" x="133" y="171" w="30" h="30" color="green" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci90cmFjazRfcmVj" type="led" ></control><control name="bGVkNA==" x="133" y="76" w="30" h="30" color="green" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci90cmFjazNfcmVj" type="led" ></control><control name="ZmFkZXJfdHJhY2sxX3ZvbA==" x="11" y="294" w="257" h="50" color="green" scalef="0.0" scalet="5.0" osc_cs="L2xvb3Blci90cmFjazFfdm9s" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="ZmFkZXJfdHJhY2syX3ZvbA==" x="11" y="364" w="257" h="50" color="green" scalef="0.0" scalet="5.0" osc_cs="L2xvb3Blci90cmFjazJfdm9s" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="ZmFkZXJfdHJhY2szX3ZvbA==" x="11" y="434" w="257" h="50" color="green" scalef="0.0" scalet="5.0" osc_cs="L2xvb3Blci90cmFjazNfdm9s" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="ZmFkZXJfdHJhY2s0X3ZvbA==" x="11" y="504" w="257" h="50" color="green" scalef="0.0" scalet="5.0" osc_cs="L2xvb3Blci90cmFjazRfdm9s" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="bGFiZWwxNw==" x="232" y="80" w="27" h="20" color="yellow" type="labelv" text="MQ==" size="14" background="false" outline="false" ></control><control name="bGFiZWwxOA==" x="231" y="176" w="27" h="20" color="yellow" type="labelv" text="Mg==" size="14" background="false" outline="false" ></control><control name="bGFiZWwxOQ==" x="135" y="175" w="27" h="20" color="yellow" type="labelv" text="NA==" size="14" background="false" outline="false" ></control><control name="bGFiZWwyMA==" x="135" y="80" w="27" h="20" color="yellow" type="labelv" text="Mw==" size="14" background="false" outline="false" ></control><control name="R28=" x="11" y="67" w="45" h="200" color="red" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci9nbw==" type="push" local_off="false" sp="true" sr="true" ></control><control name="bWV0cm9fdm9s" x="68" y="18" w="200" h="30" color="orange" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci9tZXRyb192b2w=" type="faderh" response="absolute" inverted="false" centered="false" ></control><control name="bWV0cm8=" x="11" y="18" w="45" h="30" color="orange" scalef="0.0" scalet="1.0" osc_cs="L2xvb3Blci9tZXRybw==" type="toggle" local_off="false" ></control></tabpage></layout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment