Creating more of a song

How would you go about creating a song as if you were writing it Verse, Chorus, Verse Bridge, Chorus, End without repeating yourself? Would it be cue or thread using variables? I’m trying to understand this is a bit better. Thanks so much for any tips given.


Hi @azdunek01 :slightly_smiling_face:
Here’s a topic that might provide some inspiration:


Hey @ethancrawford,

Thanks for that! Seems like it might be conditional but more so focused on switch/case/when

No problem. There’s probably several ways to do it - it’s as much about personal preference really :slightly_smiling_face:

1 Like

I’d likely store patterns in lists and then play them from the lists, selecting the lists based on the selection

1 Like

That worked! Thanks @Loopiloop

1 Like

Since I tend to like using live_loop, what I do is put if-else-statements within the live_loop and then have them react to a variable I set at the top of my code.

The variable may be something like:
song_section = 0 (For intro)
song_section = 1 (For verse)
song_section = 2 (For chorus)

I can then simply change that variable to whatever song section I’m wanting to change to, then execute the code so all the live_loops update to the new song section.

So if you prefer live_loops over a linear structure, that’s a way you could try doing it.

1 Like

Looking forward to seeing the finished thing

I have a small code sample here that helps with parts and structure, it might help you.


Oh nice, I didn’t know you could set bar length like that. I was just halving the BPM all the time haha.

1 Like

Hi Doffu! I’m new to sonic pi and also trying to figure out how to structure my first tune. Do you have a sample code I could look at to better understand your structure?


1 Like

If you look at the links in posts #2 and #7, you can see that one technique involves storing data in variables. To make up a minimal example, consider a snippet of code like

A = [ (chord :ab3, :major), (chord :f3, :minor), (chord :db3, :major), (chord :eb3, '7') ]
B = [ (chord :eb3,  '6'), (chord :c3, :major), (chord :bb2,  :minor), (chord :eb3, :major)]

live_loop :chord_player do
  CHORDS.each do |c|
    play_chord c
    sleep 4

If you start it playing then you can change to CHORDS = B without interrupting anything. For a song composed of sections, you can imagine storing chords, melodies, even entire functions that way, as well as including conditional code in your loop.


I like @nlb’s method of capturing your musical sequences inside function definitions, and then arranging those function calls so they trigger your sequences in the order you want them to play… Simple and to the point!

Hi @minetestist

Pour rendre à César ce qui appartient à César, the solution i use is due to @Martin in this post (How to code this)
@robin.newman gave another solution.

So thanks to them !


1 Like

Well, thanks to all of you then! Because that was exactly what I was looking for! ^^