Skip to content

Instantly share code, notes, and snippets.

@ctford
ctford / song.clj
Created May 27, 2017 23:47
Whilst you were
(ns whilst.song
(:require [overtone.live :refer :all]
[leipzig.melody :refer :all]
[leipzig.scale :as scale]
[leipzig.live :as live]
[leipzig.chord :as chord]
[leipzig.temperament :as temperament]))
; Instruments
(definst bass [freq 110 dur 1 volume 1.0]
@ctford
ctford / when.idr
Created February 17, 2017 21:23
A safe test that returns different types in the if and the else branches.
when : (test : Bool) -> a -> b -> if test then a else b
when True x _ = x
when False _ y = y
@ctford
ctford / locate.idr
Created February 12, 2017 16:50
A function that uses a membership proof to safely locate a tuple in a list.
locate : Eq a => (key : a) -> (entries : List (a, b)) -> {auto membership : Elem key (map Prelude.Basics.fst entries)} -> b
locate {membership} _ [] = absurd membership
locate {membership = Here} key ((key, value) :: _) = value
locate {membership = (There later)} key (_ :: entries) = locate key entries {membership = later}
@ctford
ctford / lydia.cljs
Last active September 22, 2016 13:34
A livecoded piece for Klangmeister
(defn synth [note]
(connect->
(add (sawtooth (:pitch note)))
;(low-pass (connect-> (sine 4.5) (gain 660)))
(adsr 2.7 0.3 0.5 0.01)
(gain 0.15)))
(defn shorten [section]
(->> section (take-while #(-> % :time (< 8)))))
@ctford
ctford / demo.cljs
Last active February 27, 2016 20:31
A demonstration of Klangmeister, designed to be loaded through the URL http://ctford.github.io/klangmeister/?gist=4b04fd7f2d361c6604c4
; A synthesiser we can play our piece on.
(defn synth [note]
(connect->
(add (square (* 1.01 (:pitch note))) (sawtooth (:pitch note)))
(low-pass 600)
(adsr 0.001 0.4 0.5 0.1)
(gain 0.15)))
(def melody
; The durations and pitches of the notes. Try changing them.
@ctford
ctford / intro.clj
Last active February 4, 2016 15:19
Clojure introduction
; Why Clojure?
;
; * Interactive
; * Succinct
; * Consistent
; * Java interoperability
; Try Clojure is an online "repl", where you can try out Clojure expressions.
; http://tryclj.com/
@ctford
ctford / processing.clj
Created December 24, 2015 23:29
Evaluating CLJS in the context of music fns.
(ns leipzig-live.processing
(:require
[leipzig-live.music :as music]
[leipzig-live.instruments :as instrument]
[leipzig-live.actions :as action]
[leipzig-live.framework :as framework]
[cljs.js :as cljs]))
(defn add-namespace [expr-str]
(str
(defn takes [dish minutes]
(-> dish (update-in [:time] #(+ % minutes))))
(defn sit [minutes]
(fn [dish] (-> dish (takes minutes))))
(defn add [ingredient attributes]
(fn [dish] (-> dish (assoc ingredient attributes) (takes 1))))
(defn water-for [ingredient]
@ctford
ctford / tail-position-problems.clj
Created December 22, 2015 02:47
A refactoring that breaks the tail call.
(defn factorial [n]
(letfn [(factorial' [n tally]
(if (zero? n)
tally
(factorial' (dec n) (* n tally))))]
(factorial' n 1)))
(defn factorial [n]
(letfn [(factorial' [n tally]
(if (zero? n)
@ctford
ctford / space_lab.clj
Last active December 20, 2015 07:49
Space lab, by Kraftwerk
(ns kraftwerk.die-mensch-machine.space-lab
(:use
[leipzig.melody]
[leipzig.live]
[leipzig.chord]
[leipzig.canon]
[overtone.inst.sampled-piano]
[leipzig.scale])
(:require
[overtone.live :as overtone]))