Skip to content

Instantly share code, notes, and snippets.

View emlyn's full-sized avatar

Emlyn Corrin emlyn

View GitHub Profile
use_bpm 94
live_loop :drums do
# 1 e & a 2 e & a 3 e & a 4 e & a
cymbal = bools(0,0,0,0, 0,1,0,1, 0,0,0,0, 0,1,0,0)
hard = bools(0,0,0,0, 1,0,0,0, 0,0,0,0, 1,0,0,0)
soft = bools(0,0,0,0, 0,0,0,1, 0,1,0,1, 0,0,0,1)
kick = bools(1,0,1,0, 0,0,0,0, 0,0,1,0, 0,1,0,0)
with_fx :reverb, room: 0.4, damp: 0.1, amp: 1.5 do
16.times do
@emlyn
emlyn / mml.rb
Last active December 15, 2015 09:58
Sonic Pi MML interpreter (inspired by https://gist.github.com/xavriley/87ef7548039d1ee301bb)
define :music do |txt, vol_scale=100|
octave = 5
length = 4
use_bpm 120
txt = txt.downcase.gsub(/^mml@| |;$/, '').gsub(/#/, '+').gsub(/w/, 'r')
while not txt.empty?
r = txt.scan(/^(.)([+-]?)(\d*)(\.?)(.*)$/)
cmd, opt, num, dot, txt = r[0]
#print cmd, opt, num
case cmd
{"+auto switch":{"color":"#99dd99","defaultProfileName":"direct","name":"auto switch","profileType":"SwitchProfile","revision":"155a03f540b","rules":[{"condition":{"conditionType":"HostWildcardCondition","pattern":"*internal.swiftkey.com"},"profileName":"AWS"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"ec2-*"},"profileName":"AWS"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"ip-10-*"},"profileName":"AWS"},{"condition":{"conditionType":"HostWildcardCondition","pattern":"10.*"},"profileName":"AWS"}]},"-confirmDeletion":true,"-downloadInterval":1440,"-enableQuickSwitch":false,"-exportLegacyRuleList":false,"-monitorWebRequests":false,"-quickSwitchProfiles":["system","auto switch"],"-refreshOnProfileChange":true,"-revertProxyChanges":true,"-showInspectMenu":true,"-startupProfileName":"","schemaVersion":2,"+AWS":{"bypassList":[{"conditionType":"BypassCondition","pattern":"<local>"}],"color":"#dd3333","fallbackProxy":{"host":"localhost","port":8157,"scheme":"socks5"},"name":
@emlyn
emlyn / primes.clj
Last active March 23, 2016 23:24
Generate unbounded lazy sequence of primes in Clojure (and unbounded iterator of primes in Python)
#!/usr/bin/env inlein
'{:dependencies [[org.clojure/clojure "1.8.0"]]
:jvm-opts []}
;; to run, use inlein: https://github.com/hyPiRion/inlein (or paste into a repl)
(defn primes
"Generate a lazy infinite sequence of primes, using method from (improved to skip even numbers):
https://web.archive.org/web/20150710134640/http://diditwith.net/2009/01/20/YAPESProblemSevenPart2.aspx"
@emlyn
emlyn / guitar.rb
Last active January 5, 2025 09:24
Strumming guitar chords in Sonic Pi
# Guitar Strumming - by Emlyn
# This tries to work out the guitar (or ukulele etc.) fingering for arbitrary chords (and tuning).
# It seems to work reasonably well for basic chords, but is quite naive and probably makes many mistakes.
# Ideas, bug reports, fixes etc. gratefully received, just comment below, or tweet @emlyn77.
# Feel free to make use of this code as you like (with attribution if you feel like it, but you don't have to).
# Thanks to @Project_Hell_CK for fixing the tuning, and spotting that it gets chord(:f, :major) not quite right.
# Next note higher or equal to base note n, that is in the chord c
define :next_note do |n, c|
# Make sure n is a number
@emlyn
emlyn / smoke.md
Last active March 14, 2023 23:40
Smoke on the Water
@emlyn
emlyn / soundboard.md
Last active April 30, 2021 21:11
Sonic Pi Soundboard controlled from your phone
  • Install Control on your phone (for Android, but it, or something similar, is probably available for iOS).
  • Run it, tap on "menu", then "Destinations", and then the "+" symbol. For the destination URL enter the IP address of your computer running Sonic Pi, and for the destination port enter 5005, then click "Add".
  • In your terminal, run the soundboard.sh script (or just copy and paste the last line). This listens on a public port and forwards any UDP packets to Sonic Pi (because Sonic Pi only listens on localhost).
  • Copy and paste the soundboard.rb code into a Sonic Pi buffer and run it.
  • In the Control app, tap on "Interfaces" and select "Monome Emulation".
  • Tap the grid, and you should hear sounds.
  • The sliders adjust volume and low-pass cutoff.
let tail_y = 0
let tail_x = 0
let head_y = 0
let head_x = 0
let eaten = false
let score = 0
let dir = 0
let food_y = 0
let food_x = 0
let alive = false
# The Secret Garden by Pauline Hall
use_synth :saw
use_bpm 100
use_midi_defaults channel: 1
# play note/chord
define :pl do |ns, t, p=0.8|
if not ns.respond_to?('each')
ns = [ns]
# I set myself a challenge to code a piece using only white noise.
# White noise contains equal amounts of energy at every (audible) frequency.
# It sounds like this:
#synth :noise
# Not very musical.
# But... it contains every frequency, so every possible sound or piece of music
# is hidden in there somewhere... you just have to filter out the parts you don't want.