Arduino interface to sonic pi

Here’s a little something I threw together this evening.
Starts drum loop when you start playing midikeyboard. Continues until no notes have been played for a specified time adjusted by number in
set :pause,true if look>=12
line.

 live_loop :mreset do #sets reset to true whenever a note is pressed
  use_real_time
  n,v=sync "/midi*/note_on"
  set :reset,true if v>0
  play n,amp: v/127.0 #plays the note which is input
end
define :pat do #plays drum pattern loop until pause is true then stops loop
  set :pause,false
  live_loop :drums do
    use_real_time
    sample :bd_haus
    sleep 0.5
    sample :drum_cymbal_closed
    sleep 0.25
    sample :drum_cymbal_closed
    sleep 0.25
    if get(:pause)
      set :pause,false
      stop
    end
  end
end

live_loop :timer,delay: 0.1 do #sets pause true after given time with no notes played
  use_real_time
  tick
  sleep 0.25
  if get(:reset)
    set :pause,false
    set :reset,false
    tick_reset
    pat
  end
  puts look
  set :pause,true if look>=12 #sets pause if no notes played in 11 ticks
end
1 Like

Thanks so much guys can’t wait to test just traveling at the moment

Hi Guys
Getting back into the swing of things :slight_smile:
Thank you for the tremendous help so far.
Im full of puns today, so on a further note, I would like to ask how to possibly include a full song and have it play in the background or in sync with the the midi synth.
The 2 possibilities for the full song are a) a mp3 or wav file, or b) a decent sonic pi song ie: use the code from Simple Slow Techno and run that while playing the midi synths.

much appreciated
w