Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created October 19, 2015 12:19
Show Gist options
  • Save xavriley/22a3827726b90130ec0b to your computer and use it in GitHub Desktop.
Save xavriley/22a3827726b90130ec0b to your computer and use it in GitHub Desktop.
MIDI with Sonic Pi on OSX

Warning

These instructions are mainly for my own personal reference and should not be considered a supported feature of Sonic Pi. For experimentation only. Assumes OSX 10.10

  1. Setup a virtual midi channel on OSX

This is sometimes referred to as a "loopback" device and it should allow the various software applications to communicate.

  • Open /Applications/Utilities/Audio\ MIDI\ Setup.app/ and go to "Window > Show MIDI studio".
  • Double click IAC Driver
  • In the new window, click Device is online
  • Close Audio MIDI Setup
  1. Download MIDI Monitor

This is just to watch the messages fly around the system. Not essential for this.

  1. Download Virtual MIDI Piano Keyboard (VMPK)
  • Copy to the Applications folder
  • Open and go to "Edit > MIDI Connections"
  • Enable MIDI input, select CoreMIDI as the driver and IAC Driver Bus 1 as the "Input MIDI Connection". The outputs should both be FluidSynth.
  1. Open Sonic Pi and run the following:
require 'unimidi'

output = UniMIDI::Output.open(:first)
notes = [36, 40, 43, 48, 52, 55, 60, 64, 67] # C E G arpeggios
duration = 0.2

output.open do |output|

  8.times do
    note = (scale :a1, :minor_pentatonic).choose
    output.puts(0x90, note, 100) # note on message
    sleep(duration)  # wait
    output.puts(0x80, note, 100) # note off message
  end

end
@Sharp6
Copy link

Sharp6 commented Dec 23, 2015

Are you getting good results with this? MIDI in Sonic Pi would be awesome :-)

@juliancheal
Copy link

Oh neat, didn't realise you had a gist to do what I was trying to do!

Only problem is I'm getting this error.
screen shot 2016-03-13 at 23 22 54

Any idea. I'm running OS X 10.11.3 and latest version of Sonic Pi.

@pandax54
Copy link

pandax54 commented Dec 1, 2019

Oh neat, didn't realise you had a gist to do what I was trying to do!

Only problem is I'm getting this error.
screen shot 2016-03-13 at 23 22 54

Any idea. I'm running OS X 10.11.3 and latest version of Sonic Pi.

I got the same error, but this code works:

live_loop :midi_out do
  n=scale(:c4,:major).choose
  midi n,sustain: 0.2
  sleep 0.2
end

@xavriley
Copy link
Author

xavriley commented Mar 4, 2021

For anyone who stumbles on this, it's now outdated. Sonic Pi has had native midi support for a while now! Best place to look is in the documentation for the latest commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment