Skip to content

Instantly share code, notes, and snippets.

View rbnpi's full-sized avatar

Robin Newman rbnpi

  • Near Peterborough
View GitHub Profile
@rbnpi
rbnpi / broadcastOSC.py
Created October 26, 2018 20:33
OSC broadcast repeater for use with Sonic Pi. A video showing use is at https://youtu.be/5oIRqA6DLt4 and an article is being written (will post details here)
#!/usr/bin/env python3
#broadcast received OSC message
#written by Robin Newman, October 2018
#designed for use with Sonic Pi 3
#requires python-osc
#install with sudo pip3 install python-osc
import argparse
from pythonosc import osc_message_builder
from pythonosc import udp_client
from pythonosc import dispatcher
@rbnpi
rbnpi / BachFugues2-RF.rb
Last active February 4, 2024 20:04
Two small Bach Fugues (see source in code comments) Use run_file <filenamepath> to execute. Hear it on https://soundcloud.com/sp-rbn/twobachfugues
#BachFugues2-RF.rb
#Two small bach Fugues arranged for String Trio by Alexandre Evstyugov-Babaev
#from https://musescore.com/user/27897310/scores/14176597 copyright Attribution, Share Alike
#converted for Sonic Pi by Robin Newman, Feb 2024
use_synth :blade
use_synth_defaults amp: 0.6
s=0.95;r=0.05
with_fx :reverb, room: 0.6,mix: 0.6 do
a1=[]
b1=[]
@rbnpi
rbnpi / Blue_Danube-RF.rb
Last active January 2, 2024 17:43
Blue Danube waltz played by Sonic Pi hear it on https://soundcloud.com/sp-rbn/blue-danube
#Blue_Danube-RF.rb
#coded for sonic pi by Robin Newman, January 2024
#from https://musescore.com/user/29230024/scores/5161782 by andreamotas4
#Creative Commons Copyright Waiver
use_synth :blade
use_synth_defaults amp: 0.3
s=0.9;r=0.15
with_fx :reverb, room: 0.8,mix: 0.6 do
with_fx :level,amp: 1.2 do
a1=[]
@rbnpi
rbnpi / SonifyE.rb
Last active December 30, 2023 17:39
Sonify Euler's number e using Sonic Pi. Hear it on https://soundcloud.com/sp-rbn/sonifye
#sonification generated by the number E with steadily increasing precision
#from 1 to 60, written by Robin Newman, Dec 2023
#The number is generated by BigMath.E(precision)
#I use each digit as a lookup index into a minor pentatonic scale
#I read the digits from each end of the current number, and play
#one of the two resulting notes, selected by a density funtion and a spread function
#which gives a bit of rhythm.
#These notes are underpinned by a base drone, which is layered as it has a longer
#release time and is generated increasingly as the base E string gets longer
@rbnpi
rbnpi / SP4.5PipewireUtilities.rb
Created December 26, 2023 10:30
Program which can be run in a buffer or in init.rb to allow control of Audio connections
#functions to aid connecting and disconnectiog SuperCollider under pipewire
define :getCurrentData do
#first input ports
inputs = `pw-link -iI`.lines
set :hdmiL,inputs.grep(/hdmi.*playback_FL$/).first.to_i
set :hdmiR,inputs.grep(/hdmi.*playback_FR$/).first.to_i
set :usbL,inputs.grep(/usb.*playback_FL$/).first.to_i
set :usbR,inputs.grep(/usb.*playback_FR$/).first.to_i
set :bluezL,inputs.grep(/bluez.*playback_FL$/).first.to_i
@rbnpi
rbnpi / ReadMe.md
Last active November 9, 2023 09:30
Sonic Pi Midifile Player accompanying article at https://rbnrpi.wordpress.com/a-midi-file-player-program-for-sonic-pi/

These files comprise two versions of a midifileplayer for Sonic Pi version 3.0.1 or later. There are two versions.

File SPbasicMidiFilePlayer.rb is the basic version, where the synths used to play each channel in the midifile have to be specified in teh code before running the program in the form of a sonic pi ring. If this contains just a single synth e.g. (ring :saw) then each channel will use this synth. If two synths are specified eg (ring :rri) then midi channel 1 will use :saw, channel 2 :tri and then any further channel will use index into this ring and use in turn :saw, :tri,:saw,:tri This is set in line 38. Also specified at run time in the code is the attenuation level set by the fx :level wrapper in teh variable attenAmp set to 0.5 by default in line 40.

In the second more complicated vbesion, support is provided for an external TouchOSC interface which can be used to specify synth allocation on the fly as the program is running. and also to adjust the attenAmp setting in teh range 0.1 to 1 again

@rbnpi
rbnpi / ReadMe.md
Last active October 17, 2023 04:12
Beethoven Moonlight Sonata played by Sonic Pi. Uses Sonatina Symphonic Orchestra samples. See readme for availablilty. Video at https://youtu.be/8rdJ9wxGw5Y

The Sonic Pi file moonlightSonata-RF.rb which plays Beethoven's Moonlight Sonata 1st Movement requires the use of the Grand Piano samples from the Sonatina Symphonic Orchestra produced by Matthias Westlund.

Unfortunately this is no longer available from his website https://sso.mattiaswestlund.net/ However there is an alternative available at https://github.com/peastman/sso from where you can download the library. It is coverd by a https://creativecommons.org/licenses/sampling+/1.0/ Download and expand on your Desktop, or other suitable location and then set the link in the program at line 9 appropraitely for your installation.

The file should be run using the run_file "/path/to/file/location" command as it is too long to run from a Sonic Pi buffer.

An alternative version using the built in piano synth in Sonic Pi is included for comparison.

@rbnpi
rbnpi / bach-allabreve2-bwv589-RF.rb
Created July 27, 2023 15:50
Sonic Pi version of Bach's Allabreve. You need to use run_file "path/to/bach-allabreve2-bwv589-RF.rb" to run it. Listen to it on https://soundcloud.com/rbnsonicpi/bach-allabreve-bwv589
#bach-allabreve2-bwv589-RF.rb
#coded for Sonic Pi by Robin Newman, July 2023
use_debug false
use_synth_defaults amp: 0.5
s=0.96;r=0.04;st=0 #s,r,st = sustain factor,release factor, start tempo section
Last = 4 #pause on last note
with_fx :reverb , room: 0.9,mix: 0.7 do
use_synth :pulse
with_fx :compressor,amp: 0.7 do
@rbnpi
rbnpi / ReadMe.md
Last active August 4, 2023 14:35
Sonic Pi Record / Player version 1.2 (not Pi3 friendly) See REadMe file.

Sonic Pi Record / Player version 1.3

This version is updated to work on SP 3.2 or greater. This involves a change which is detailed in teh comments at the beginning of the program. The TouchOSC template is unchanged. I have left it as a MkI TouchOSC file , but you can load it into the latest TouchOSC and it will automatically concert from a .touchosc file to the new .tosc format which will only work in the new version of TouchOSC.

The two other files enable a TouchOSC interface to be used with Sonic Pi 3 and above to allow notes to be played on Sonic Pi, and also recorded in real time for subsequent replay. Recordings can also be stored in files on your computer.

The Sonic Pi program is too long to run in a buffer, and should be run using the run_file command eg

run_file "/path/to/file/recordplayercombined-RF.rb"
@rbnpi
rbnpi / SonicPiHiHats.rb
Last active May 10, 2023 21:45
Program illustrates HiHat samples added to Sonic Pi source around May9th 2023. Hear the result on https://soundcloud.com/sp-rbn/hihats
#Sonic Pi HiHats by Robin Newman May 2023
#demo of new hi-hat samples in action
#program prints sample names, then fades in
#and runs for about 1 minute before fading out and stopping
use_debug false
sample_names(:hat).each do |name|
puts name
end
set :kill,false
at 65 do