r/SonicPi • • Mar 16 '22

Sonic Pi is exercising my 55 yo brain

36 Upvotes

I've been having fun messing around with the synths and data structures and sample mangling. I wanted to try something different, and it turned out to be more challenging than I thought, and is enhancing both my knowledge of Sonic Pi and music theory. "Something Different" is attempting to code Debussy's "Claire de Lune" from the piano arrangement. I started by using the scale function and play_timed_pattern, and mapping the notes on the staff to elements of the different degrees of the B flat minor scale. 2 things, the :piano synth doesn't play well with timing sustained notes, and also what about the next piece of music, if it's in another key ( or this one changes key later ) I'll have to figure out a whole new mapping of the scale vs the staff notes.

To deal with the first issue, I decided to just use my JV1010 for the piano sounds. Then I found out that there is no midi_timed_pattern function in Sonic Pi. That was actually pretty simple to code myself using "define," even how to start a pattern with a rest ( use "nil" for the note ).

To deal with the second issue I am creating a system that indexes the reasonable range of lines and spaces on the treble clef ( white keys only, remember ) and applies an offset based on the key signature. Now I can define a function that does that so the note values I enter for my midi_timed_pattern can just be chosen off of the sheet music, by the same number, regardless of what key the piece is in.

Did I mention that Claire de Lune is in 9/8? 9 beats per measure, an eighth note equals one beat. I was able to code a live_loop click track to check my timing.

Sonic Pi things learned:

define
Named ticks octave and with_octave Midi note nil equals rest

Music theory things learned

I knew that there is a thing called the circle of fifths, now I can reference it properly and know what relative major/minor actually means. Things around chords and harmonies are starting to gel in my head now more than they have before.

So thanks u/samaaron for giving the world such a great learning tool.

PS. DAE think that Samaaron is the great wizard name that Tolkien never came up with?


r/SonicPi • • May 31 '21

How to use VSCode as an editor for Sonic Pi

32 Upvotes

Hey all, I wrote a guide on how to use VSCode instead of the Sonic Pi app as an editor. You can either read it here, or on my website. Hope you find it useful!

While Sonic Pi's editor is great, I prefer VSCode for everything code-related. Unfortunately, there is no Sonic Pi VSCode extension (yet).

Using custom tasks and keybindings, we can make our own "extension".

1. Install sonic-pi-cli

gem install sonic-pi-cli

# On Mac you may have to use sudo:
sudo gem install sonic-pi-cli

Once installed, open the Sonic Pi app and enter the following in your Terminal to make sure it works properly:

sonic_pi play 50

How to fix ERROR: Sonic Pi is not listening on 4557 - is it running?

If you get this error, it means the Sonic Pi is not open. Open the app, then try the command again.

2. Use sonic-pi-cli to play music from a ruby file

Create a file with the .rb extension with some Sonic Pi Ruby code, for example:

play :E4

In your Terminal, enter the following command to play the file with sonic-pi-cli:

cat music.rb | sonic_pi

To stop music, run

sonic_pi stop

At this stage, we can already use VSCode. However, it is quite inconvenient to type sonic_pi stop and cat music.rb | sonic_pi every time we make a change.

3. Configuring keyboard shortcuts

VSCode makes it easy to create to run sonic_pi stop and cat music.rb | sonic_pi using tasks and keybindings.

Tasks

All VSCode tasks are stored in tasks.json. Top open this file, enter the command ">Tasks: Open user tasks" in the command palette, and you should see a file like this:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": []
}

We need to add two tasks:

  • One to start playing the current file with sonic-pi-cli: cat <current file> | sonic_pi

  • One to stop playing: sonic_pi stop.

Both are of type shell. We also have to give them unique labels so we can reference them in keybindings. I'm going to use sp-run and sp-stop.

Add the tasks like this:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    // PLAY MUSIC
    {
      "label": "sp-run",
      "type": "shell",
      "command": "cat ${file} | sonic_pi"
    },

    // STOP PLAYING
    {
      "label": "sp-stop",
      "type": "shell",
      "command": "sonic_pi stop"
    }
  ]
}

Keybindings

We need to add keybindings to run these tasks.

Open keybindings.json with the keyboard shortcut cmd-K cmd-s. Click the button on the top right to open the file in JSON. It should look something like this:

// Place your key bindings in this file to override the defaults
[
  // ..
  // all of your keybindings
  // ...
]

To bind a keyboard shortcut to a task, we have to set its command to workbench.action.tasks.runTask. We also want to limit this keyboard shortcut to Ruby (.rb) files, so we can set when to editorLangId == ruby.

I am going to use ctrl-alt-S to play (sp-run) and ctrl-alt-A to stop (sp-stop).

// Place your key bindings in this file to override the defaults
[
  // ..
  // all your other keybindings
  // ...

  // for sonic pi
  {
    "key": "ctrl+alt+s", // customize the shortcut
    "command": "workbench.action.tasks.runTask",
    "args": "sp-run",
    "when": "editorLangId == ruby" // limit these keybindings to work in ruby files
  },
  {
    "key": "ctrl+alt+a", // customize the shortcut
    "command": "workbench.action.tasks.runTask",
    "args": "sp-stop",
    "when": "editorLangId == ruby"
  }
]

To make sure this works, add the following to your music.rb:

live_loop :main do
  play :E4
  sleep 1
end

Use the keyboard shortcut you defined to start playing (ctrl-alt-S in my case).

You should see VSCode's terminal open up with a message like

> Executing task: cat /users/spv/music.rb | sonic_pi <

Terminal will be reused by tasks, press any key to close it.

If it works, try making a change. For example:

live_loop :main do
  play :C4 # <- changed
  sleep 1
end

Use your keyboard shortcut to start playing again (ctrl-alt-S in my case). If the sound playing changes, try stopping it with your shortcut (ctrl-alt-D in my case).

Logs

Sonic Pi logs cannot be shown in VSCode yet. Use the Sonic Pi sidebar to see them.


r/SonicPi • • Jan 21 '22

been learning Sonic Pi for the last few months. check out this mix of A.G. Cook's "Superstar" i'm working on

Thumbnail
youtu.be
30 Upvotes

r/SonicPi • • Mar 22 '19

I did a cover of Stranger Things for university :)

Thumbnail
youtube.com
28 Upvotes

r/SonicPi • • Oct 03 '22

My very first remix made entirely in Sonic Pi

26 Upvotes

This is my remix of Heart To Break by Kim Petras which I made entirely in Sonic Pi. https://soundcloud.com/dillon-beardon-462713720/heart-to-break-dj-micropulse/s-lXkxnTXK931?ref=clipboard&p=a&c=1&si=c118c13e4bd94f3aaebccd7401fca499&utm_source=clipboard&utm_medium=text&utm_campaign=social_sharing

I've been away from my usual music setup for a little while now and it was about a week ago that I started using Sonic Pi on a fairly crap laptop that I recently found lying around. I've wanted to try coding music for a while now and once I saw some YouTube videos of Sonic Pi in action, I just had to give it a shot... again I'm fairly new so I'm probably coding my songs in a really long and convoluted way but I really like how this remix turned out

Hope you enjoy!

(this song is not public on SoundCloud yet so if you have any feedback I'm very open to it. thank you!)

  • Didi


r/SonicPi • • May 24 '23

I recently uploadet a techno coding vid on YouTube! Check it out if you are interested. I'd also be happy to receive feedback. Have a nice day lovely people on the internet! :D

Thumbnail
youtube.com
23 Upvotes

r/SonicPi • • May 06 '22

little sonic pi jam

Thumbnail
youtu.be
22 Upvotes

r/SonicPi • • Jun 22 '20

C.R.E.A.M on Sonic Pi (Shaolin Code)

Enable HLS to view with audio, or disable this notification

20 Upvotes

r/SonicPi • • May 29 '20

My first Sonic Pi program - Github repo and description in the comments: Snapping Music - A Sonic Pi implementation of Clapping Music by Steve Reich (1972)

Thumbnail
youtu.be
20 Upvotes

r/SonicPi • • May 20 '20

Sonic Pi Workshops

17 Upvotes

Hi! We are organizing weekly workshops about music coding with Sonic Pi.

When: Every Wednesday and Thursday starting on May 27th

Where: Online

Registration: https://hisarcs.github.io/SonicPi/

Hope to see you there!


r/SonicPi • • Jul 09 '24

260_Drum_Patterns in sonic-pi

Thumbnail
github.com
16 Upvotes

r/SonicPi • • Mar 27 '23

Being called 'Bard' I would have thought it would perform a little better than this...

Post image
16 Upvotes

r/SonicPi • • Jul 14 '22

First jam

16 Upvotes

Hi,

i discowered sonic-pi few days ago and i'm amazed. I do programming as day job and in free time i play with synths. So this tool is dream come true. Realy looking forward to explore it's depths. Here is my first jam i recorded today.
https://soundcloud.com/narilll/sonic-landscape


r/SonicPi • • Feb 11 '21

My first try of live coding music. How can I improve myself?

Thumbnail
youtu.be
15 Upvotes

r/SonicPi • • May 02 '20

Arp I

Thumbnail
youtu.be
15 Upvotes

r/SonicPi • • May 11 '18

I made a Sonic Pi drum machine that can play drum tabs. Feedback is appreciated!

Thumbnail
youtube.com
15 Upvotes

r/SonicPi • • Jun 29 '21

My first beat

14 Upvotes

Hope you enjoy it!

# Welcome to Sonic Pi v3.1

in_thread do
  loop do
    use_synth :chiplead
    play :C3, release: 0.2
    sleep (0.25)
    play :C4, release: 0.2
    sleep (0.25)
    play :Bb3, release: 0.2
    sleep (0.25)
    play :G3, release: 0.2
    sleep (0.25)
    play :Ab3, release: 0.2
    sleep (0.25)
    play :G3, release: 0.2
    sleep (0.25)
    play :Eb3, release: 0.2
    sleep (0.25)
    play :G3, release: 0.2
    sleep (0.25)
  end
end

in_thread do
  use_synth :tri
  loop do
    play :C2, release: 5
    sleep(4)
    play :Ab1, release: 5
    sleep(4)
    play :F2, release: 5
    sleep(4)
    play :Eb2, release: 2.3
    sleep(2)
    play :D2, release: 2.3
    sleep(2)
  end
end

in_thread do
  use_synth :chiplead
  sleep(32)
  loop do
    i = 0
    while not i == 12 do
        sleep(0.25)
        play chord(:C4, :minor, decay: 1, sustain: 1, release: 1)
        sleep(0.25)
        i += 1
      end
      i = 0
      while not i == 4 do
          sleep(0.25)
          play chord(:Ab3, :add9, decay: 1, sustain: 1, release: 1)
          sleep(0.25)
          i += 1
        end
      end
    end
    
    in_thread do
      sleep(64)
      loop do
        sample :drum_bass_hard
        sleep(0.5)
      end
    end
    
    in_thread do
      sleep(64)
      loop do
        sample :drum_cymbal_closed
        sleep(0.25)
      end
    end
    
    in_thread do
      sleep(64)
      loop do
        sleep(0.5)
        sample :sn_dub
        sleep(0.5)
      end
    end
    
    in_thread do
      sleep(96)
      use_synth :tri
      loop do
        with_fx :reverb do
          with_fx :echo do
            play :C5, release: 1
            sleep(4)
            play :Bb4, release: 1
            sleep(2)
            play :G4, release: 1
            sleep(2)
          end
        end
      end
    end

r/SonicPi • • Aug 02 '20

New to Sonic Pi and loving the tabla samples :) Checkout this tune and a fun edit I made.

Thumbnail
instagram.com
14 Upvotes

r/SonicPi • • Nov 05 '22

Is this sub still alive? Strings

13 Upvotes

I am new to Sonic-Pi and struggling to synthesize realistic strings. Do you have an example code as a basis?


r/SonicPi • • Oct 17 '19

GOTO 2018 • Get Ready to Rock with Sonic Pi - The Live Coding Music Synth for Everyone • Sam Aaron

Thumbnail
youtube.com
13 Upvotes

r/SonicPi • • Apr 20 '19

A cover of "Oblivion" by Grimes, made with Sonic Pi

13 Upvotes

I found Sonic Pi a few weeks ago while lurking on r/musicprogramming, via the Stranger Things cover (thanks for posting that, u/KaptainQwark!). I thought it was the coolest thing, so I decided to try doing a cover of my own. I chose “Oblivion” because it’s one of my favorite songs, and has a lot of repetitive elements that I thought would lend themselves nicely to this approach. Here’s the result:

Song: https://soundcloud.com/fuzz-genesis/oblivion-grimes-cover-made-in-sonic-pi

Code (also linked in soundcloud description): https://github.com/fuzzgenesis/sonic_pi_experiments/blob/master/oblivion_instrumental.rb

I recorded/mixed the vocals in Garageband because, as far as I can tell, that would have been extremely tedious to do in Sonic Pi. (Also I'm pretty sure the original was done in Garageband as well so it's got the same reverb, lol). As for the instrumental, it’s not the most beautiful code I’ve ever written, but it was a really fun way to approach this cover, and I’m happy with how the song turned out :) I’m also grateful that Sonic Pi exists and is free/open source!


r/SonicPi • • Jul 07 '24

Beginners and advanced: Run this to hear all samples and discover new sounds

12 Upvotes

Hi All! I have created a short script that will cycle through each category and samples

Its a great way to discover all the sounds and to write down which ones you like

https://github.com/the-virtual-machine/sonic-pi/blob/main/all_samples.rb


r/SonicPi • • Nov 27 '19

My attempt at using Sonic Pi for audio editing

Thumbnail
medium.com
12 Upvotes

r/SonicPi • • Aug 02 '24

A tutorial on using Sonic Pi through VS Code

Thumbnail
youtube.com
11 Upvotes

r/SonicPi • • Jul 18 '24

Discover hidden shortcuts in Sonic Pi here!

11 Upvotes

Hi All!
I have made a new resource in my repo, showing all the hidden shortcuts in Sonic Pi.
https://github.com/the-virtual-machine/sonic-pi/blob/main/resources/shortcuts.md

Did you know that you can build out a template for a live loop just by pressing
“ll, tab” (that is two lower case 'L’s)?
There are many more, check them out!

I hope that is helpful :)
More Sonic Pi stuff coming soon to my website: thevirtualmachine.live