Sonic Pi activity

Yeah, yeah, I read the New York Times article (“Lesson of the Day: ‘That Music You’re Dancing To? It’s Code’”), and I was aware of Sonic Pi, but I’d never downloaded it and tried it out until yesterday, and I dug it right out of the box, so to speak. I was wondering what if anything folks here on Lines are doing with Sonic Pi, and a search suggested that there hasn’t been a dedicated thread to it, like there are for Lua and for Pure Data. So I started this one.

9 Likes

@samaaron great to see your name!

6 Likes

I started playing around with it a few months ago and was quite surprised with how much fun it was. Despite never having worked with Ruby I found it really easy to learn (and dead simple to install) and the results were definitely pleasing.

Here’s a relaxing little script that was still in one of my buffers. It only uses the included samples and synths so it should be usable anywhere:

set_mixer_control! amp: 0.95, limiter_bypass: 1

with_fx :reverb, room: 1.0, mix: 0.7 do
  live_loop :hello do
    play (scale :F3, :minor_pentatonic).choose, attack: 2.0, release: 0.9, amp: 0.5, pan: -0.3
    play (scale choose([:C4, :C5]), :minor_pentatonic).choose, attack: 2.0, release: 0.9, amp: 0.4 , pan: -0.4 if one_in(3)
    
    if one_in(4)
      sample :ambi_glass_rub, rate: choose([0.7, -0.7, 0.85])
    end
    
    if one_in(5)
      play (scale choose([:F4, :F5]), :minor_pentatonic).tick, amp: 0.3
    end
    
    in_thread do
      with_fx :echo, decay: 6.0, phase: 1.5, amp: 0.4 do
        use_synth :prophet
        if one_in(7)
          play_pattern_timed (scale choose([:F4, :F5, :C3]), :minor_pentatonic, num_octaves: choose([2,3])), choose([0.0625, 0.125]), amp: 0.5, cutoff: rrand_i(65, 85), cutoff_slide: 7.0
          sleep 0.25
        end
      end
    end
    
    sleep choose([0.5, 1.0, 3.0, 5.0])
    
  end
end

I don’t use Sonic Pi much lately…it piqued my curiosity in Tidal Cycles, and once I became comfortable with sending MIDI out from Tidal Cycles that was pretty much the end of my time with Sonic Pi.

That being said, if anyone were to express an interest in live coding to me, Sonic Pi is definitely the first thing I’d recommend they check out.

2 Likes

Sonic Pi is great, and that article has a couple of familiar names…and Hydra screenshots!

However - the bit that I’ve always really liked about SonicPi was its emphasis on curriculum. It made me think of logo the first time I saw it…sound turtles all the way down. The intersection of education and “generating art through code” makes a ton of sense imo - simple on ramp, near instant feedback, REPL like iterative coding…but then you can go deep…then you can go deeeeeper because it’s open source.

Seems like the perfect slippery slope to nerdsville.

If SonicPi ran on Glitch:mage::fish:

Oh! Don’t forget @samaaron made Overtone too! Hello!

3 Likes

That is exactly how I felt about it as well. So much so that the first person I showed it to was my 12 year old nephew who is interested in learning how to code.

2 Likes

That’s lovely. Thanks for having shared the script.

1 Like

shall we have a Pi Fight?

edit: I found the original tidal fights thread non-combative and inspiring, a little structure/prompting/deadline helps me a lot in giving time to things I might not otherwise, and given that @disquiet hosts the Junto I’m sure this isn’t an unfamiliar notion :upside_down_face:

4 Likes

Hi,

I am working with Sonic Pi on a regular basis since quite a while.

  • Amongst other things I offer a course at Leuphana University (Germany/Lüneburg).
  • Here is a presentation at Sonoj 2018 (a small Open Source Audio conference at Germany/Cologne) with some live coding and and a talk in very bad English.
  • Finally I am trying to integrate my Grid with Sonic Pi and have started to code an application similar to mlr (I have never been able to try mlr out so I actually don’t know in detail what functions it offers). The code is alpha but I will release it as soon I’ll consider it beta.
6 Likes

I love Sonic Pi, and frequently recommend it as an introduction to livecoding or to programming. I also, as a Rubyist, really appreciate that it’s mainly Ruby.

Here, have some break slicing:

load_sample :loop_amen

live_loop :drums do |count|
  if (count+1) % 4 == 0
    # put a break in every four bars where you chop the break randomly
    # slices = (1..8).to_a.sort_by { rand }
    slices = []
    slices << 0 # always start with slice 1, for a nice kick
    7.times do
      slices << rand_i(1..7)
    end
  else
    slices = (1..8).to_a
  end
  
  slices.each do |slice_int|
    sample :loop_amen, num_slices:8, slice: slice_int, amp: 5
    sleep sample_duration(:loop_amen) / 8
  end
  
  count += 1
end
5 Likes

Yes, sample slicing is a thing which is very easily done with Sonic Pi. You can make it even shorter (accepting a slight variation):

live_loop :drums2 do
  3.times do
    sample :loop_amen, beat_stretch: 2
    sleep 2
  end
  8.times do
    sample :loop_amen, beat_stretch: 2, num_slices: 8, slice: pick
    sleep 0.25
  end
end
3 Likes

Yes, that code is shorter… but I’m quite attached to not entirely randomly slicing things; forcing downbeats is useful. Anyhow, I like the expressiveness of slicing in it, and how easy it is to play with algorithms for making breaks dynamically.

I also like the use of blocks for wrapping effects processing.

4 Likes

Exactly! Sonic-Pi was my gate of entry in electronic music making and computer music. I spent countless hours improvising with this piece of software and fell in love both with sound design and live-coding on the way. Nowadays, I have more mixed feelings towards this piece of software, something that feels like nostalgia of the golden-age of my encounter with live-coding. I’m supporting Sam Aaron on his Patreon, and I check very frequently, as a routine, if there is an hint at the release of the long awaited 3.2. I’m still unable to contribute technically to the project, even If I would like to.

I would like to give an highlight to some members of the community, who created very interesting sub-languages for Sonic-Pi :

— Amiika with Ziffers. A sub-language that is nowadays pretty much an alternative language living on the top of Sonic-Pi. Melodic generation / algorithmic music / short-hand notation of melodic patterns.
Petal by SiafLab, a defunct early-attempt at implementing a Tidal Cycles like rhythmic language in Sonic-Pi. Lots of fun, sometimes a bit impredictable. It is really sad to see that no update will ever be published, and that I don’t have a single clue about Ruby.
— The incoming Thor Magnusson - Sam Aaaron collaboration about implementing an Ixi Lang sub-language in Sonic Pi.

I would definitely recommend Sonic Pi as a gate of entry into electronic music or live-coding, but I would not advise it for the sole purpose of learning programming. This might be an unpopular opinion, but I feel like making music / time-related programming and designing / extending programs is a completely different thing. When I first began using Sonic-Pi, I was highly confident that it would help me to learn programming but I pretty much crashed into a wall as soon as I was confronted with the real thing (now feeling better…).

The pedagogical aspect of Sonic Pi is excellent, and the in-built tutorial is covering almost everything you have to know to start live-coding and have fun. My dream for Sonic Pi would be to consolidate this pedagogical aspect (I wrote a very long french tutorial about Sonic Pi) and to focus on end-users (skilled users, computer scientists and musicians) to offer them the capacity to extend and contribute to the project as soon as they have mastered the language.

Many thanks to Sam Aaron for keeping this project alive and for dedicating so many attention and hard work to the project.

7 Likes