Sonic Pi 3.2.2 and Scratch 3 project

Project to interface Scratch3 on a Pi4 to Sonic Pi. A scratch3 keyboard drives Sonic Pi. Associated article and links to all the software below the video.

Software link here too

Hey @robin.newman.

Sorry for bothering you again with this. I just been out for more then a few weeks.
And I want to start my osc loop project again.

Is it possible to dumb the example down to just a number of osc loops and how to connect them in a real time live loop?

Or did I miss some documentation on how the script works?

Hope I don’t come over as lazy but it’s hard to figure some stuff out if sonic pi is not the main aspect of my project but a tool to generate sound. Especially when it’s combined with osc…

Thanks again!!!

Did you read the article? That gives some explanation of the software.

I’m going thru it as we speak. But I’m getting confused with the scratch involvement.

As I am pretty sure I don’t need it. I just need a loop (in python) to send 1 - 7 and sonic pi to interpret this as sample 1 to 7.

So I pulled out groove1 and groove2 of your code.

The part for the button board is unnecessary for me but seems to be intertwined with the code? Could be mistaken here?

when 18 & 19 is important for the :flag correct?

#Sonic Pi Scratch3 interface by Robin Newman, May 2020
#two programs. Uncomment one section OR the other at a time
#first section sets Sonic PI as a keyboard instrument with dsaw synth
#second section has selectors to play sample groups, chords and two sample sub programs
use_osc "localhost",8000
#osc "/testprint","hello there"
osc "/start",0
set :flag,true


live_loop :waitReset do
  use_real_time
  r = sync "/osc*/reset"
  set :flag,false
  osc "/start",1
end

  
    live_loop :test2 do
      use_real_time
      k= sync "/osc*/playOn"
      if get(:flag) == true
        p=k[0]
        puts p
        case p
        when 0
          z=sample (sample_names sample_groups[0]).choose
        when 1
          z=sample (sample_names sample_groups[1]).choose
        when 2
          z=sample (sample_names sample_groups[2]).choose
        when 3
          z=sample (sample_names sample_groups[3]).choose
        when 4
          z=sample (sample_names sample_groups[4]).choose
        when 5
          z=sample (sample_names sample_groups[5]).choose
        when 6
          z=sample (sample_names sample_groups[6]).choose

        when 18
          set :kill,false #flag used for killing groove1
          groove1
        when 19
          set :kill2,false #flag ued for killinggroove2
          groove2
        else
          puts p
        end
        k=sync "/osc*/playOff"
        if k[0]<18 #keys that handle stamples
          control z,amp: 0,amp_slide: 0.05
          sleep 0.05
          kill z #kill smple after quick fade
        end
        if k[0]==18 #keys that start live loop functions
          set :kill,true #kill groove1
        end
        if k[0]==19 #keys that start live loop functions
          set :kill2,true #kill groove2
        end
      end
    end
  end
end

I’ll take a look at it and then post a cut down version below…

EDITED here is a cut down sonic pi progarm which will work with the other two files (scratch and python scripts) and will work with the first 7 keys. (You can adapt for more or less. You can delete the key “blobs” you don’t need/want from the scratch script).
I suggest you leave the python script as is, although it could be modified for fewer keys.

Change the samples in the Sonic Pi program for whatever samples you want.

#Sonic Pi Scratch3 interface by Robin Newman, May 2020 amended Aug 2020
#plays one of 7 samples using the first 7 key "blobs" on the scratch interface.
use_osc "localhost",8000
#osc "/testprint","hello there"
osc "/start",0
set :flag,true

live_loop :waitReset do
  use_real_time
  r = sync "/osc*/reset"
  set :flag,false
  osc "/start",1
end

with_fx :reverb,room: 0.8,mix: 0.7 do
  
  live_loop :test2 do
    use_real_time
    k= sync "/osc*/playOn"
    if get(:flag) == true
      p=k[0]
      puts p
      if p<7
        z = sample [:bd_haus,:loop_amen,:loop_garzul, :loop_mika, :loop_tabla,:loop_electric,:loop_perc1][p]
        k=sync "/osc*/playOff"
        control z,amp: 0,amp_slide: 0.05
        sleep 0.05
        kill z #kill sample after quick fade
      end
    end
  end
end