Skip to content

Instantly share code, notes, and snippets.

@andrewcsmith
andrewcsmith / HETuner.sc
Created November 13, 2011 15:47
helmholtz-ellis string parsing for supercollider
/*
Basic idea of string parsing comes from Marc Sabat and Wolfgang Von Schweinitz's "Helmholtz-Ellis" set of accidentals. These accidentals take all uninflected ("normal") accidentals like naturals, sharps and flats as 3-limit Pythatgorean alterations. Further alterations include small arrows (for the 5-limit 81/80), Tartini-inspired 7s (for 7-limit 64/63), and quarter-tones for the unidecimal alteration 33/32.
I've found that while SuperCollider is great at creating scales and tunings, it's tough to really sequence a full pattern without cycling through a bunch of different tunings--it still seems conceptually tied to MIDI in that sense. So in order to sequence extended just intonation, it's important to have an easy, legible way of reading these pitches.
I've transported my Lilypond definitions to SuperCollider. "aflatUfDs" (the test String) is a Pythagorean a-flat, up a five-limit 81/80, down a seven-limit 63/64. This creates the interval 14/15, or a perfect fourth above the septimal tri-tone against
@andrewcsmith
andrewcsmith / olm search excerpt
Created August 9, 2012 01:08
Search algorithm that slows way, way down after around 40,000 iterations
max_iterations.times do |iter|
begin
# puts "Iteration #{iter}"
# puts "Now #{current_cost} away at #{current_point.to_a}"
print "\rIteration #{iter}: #{current_cost} away at #{current_point.to_a}"
cost = NMath.sqrt(((tuneable_data[true,1,true,true] - goal_vector) ** 2).sum(0))
# If this is the first run-through, keep the interval index the same
if initial_run
interval_index = 0
x = {|gate=1| Out.ar([0,1], EnvGen.ar(Env.asr(0.1, 1, 0.1), gate, doneAction: 2) * Splay.ar({[SinOsc.ar(80, 0, 0.05)] ++ Resonz.ar(WhiteNoise.ar(1), ExpRand(310,330), 0.01)}.dup(20) ++ {SinOsc.ar(ExpRand(200,280), 0, 0.01)}.dup(20) ++ [SinOsc.ar(84, 0, 0.1)] ));}.play;
@andrewcsmith
andrewcsmith / sinatrauthentication.rb
Last active December 20, 2015 04:59
A quick and dirty way to authenticate users in a Sinatra app. Probably not secure.
require 'sinatra'
require 'sinatra/reloader' if development?
require 'digest/md5'
require 'haml'
# enable :sessions
use Rack::Session::Cookie, :key => 'rack.session', :path => '/', :secret => 'change_me'
auth_dir = "./auth"
@andrewcsmith
andrewcsmith / Random Envelope Selection
Created August 18, 2013 17:46
Random envelope selection
(
SynthDef(\cloudin, {
arg freq = 440, env_input = 0;
var signal, envs;
// env_input is the number of the control-rate channel with the env signal
signal = Saw.ar(400 * 1) * In.kr(env_input);
Out.ar(0, signal);
}).add;
)
@andrewcsmith
andrewcsmith / UnitTest.sc
Last active January 4, 2016 05:19
UnitTest class and usage that I'm working on
UnitTest {
var <assertionCount = 0, <successCount = 0, <failureCount = 0;
test {
arg name, func;
("Testing: " ++ name).postln;
func.value(this);
("Assertions: " ++ assertionCount ++ "\t Successes: " ++ successCount ++ "\t Failures: " ++ failureCount).postln;
}
@andrewcsmith
andrewcsmith / gist:10342529
Created April 10, 2014 04:27
#rank, :reference assignment
[331] pry(main)> out
=>
{ layers:
[
[0, 1]
[0, 0]
]
[
[1, 0]
@andrewcsmith
andrewcsmith / main.cpp
Last active August 29, 2015 14:06
xgetrf results and proper specs
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <Accelerate/Accelerate.h>
void print_matrix(const int row_count, const int col_count, __CLPK_real* matrix) {
for(int i = 0; i < row_count; i++) {
for(int j = 0; j < col_count; j++) {
printf("% 7.3f", matrix[i*row_count + j]);
@andrewcsmith
andrewcsmith / .vimrc
Created December 30, 2014 03:11
Command to send whatever line you're on to the right tmux pane. Great for complicated ipython/pry work.
function! g:SendRight(...) range
if a:0 > 0
let start = a:1
let end = a:1
else
let start = a:firstline
let end = a:lastline
endif
for line in getline(start, end)
extern crate piston;
extern crate piston_window;
extern crate graphics;
extern crate gfx_graphics;
use piston::input::*;
use piston::window::{Window as Win, AdvancedWindow, WindowSettings};
use piston_window::{PistonWindow as Window};
fn main() {