Skip to content

Instantly share code, notes, and snippets.

@wilmermurillo
Forked from xavriley/README.md
Created August 1, 2016 22:33
Show Gist options
  • Save wilmermurillo/66b77468749d9b324d79967e79f0bb76 to your computer and use it in GitHub Desktop.
Save wilmermurillo/66b77468749d9b324d79967e79f0bb76 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment