Skip to content

Instantly share code, notes, and snippets.

@rbnpi
rbnpi / OSC_API_KeyboardInput.rb
Last active September 30, 2021 06:09
Experimental code to play with the new OSC-API in Sonic Pi2.11dev. Note this is highly experimental and will probably change. The two programs allow input from a Mac keyboard to Sonic Pi. You may need to change some of the keyboard mapping on other keyboards. You can here a recording of the system at https://soundcloud.com/scrbn/sonicpiexperimen…
#This program polls the keyboard and then maps the code for detected keys to midi note values
#which are tranmsitted to the new OSC-API in Sonic Pi
#Warning THIS API IS EXTREMEMLY EXPERIMENTAL AND MAY CHANGE (current version 2.11 dev 2d13e)
#This script runs in a terminal window. Once the SP script is running, type in the terminal window to send key presses.
require 'io/wait'
require 'socket'
require 'rubygems'
require 'osc-ruby'
client ||= OSC::Client.new('localhost', 4559) #set up OSC channel to port 4559