Skip to content

Instantly share code, notes, and snippets.

@ctford
Created April 12, 2015 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ctford/b61f513483717e07411d to your computer and use it in GitHub Desktop.
Save ctford/b61f513483717e07411d to your computer and use it in GitHub Desktop.
An unhygienic macro for generating the standard template I use for instruments.
(defmacro deftrack
"Defines an instrument with frequency, duration, volume, position and wet pre-defined.
NB: these variables will shadow any instances in a wider scope.
(deftrack simple [vibrato 3]
(* (saw frequency) (sin-osc vibrato)) ; Signal
(adsr)) ; Envelope
(simple :frequency 440 :position -1 :wet 1)
(simple :frequency 220 :position 1 :duration 5.0 :vibrato 5.0)"
[instrument extra-params oscillator envelope]
`(definst ~instrument
[~'frequency 440 ~'duration 1.0 ~'volume 1.0 ~'position 0.0 ~'wet 0.3 ~@extra-params]
(-> ~oscillator ; Signal
(~'* (env-gen ~envelope (line:kr 1 0 ~'duration) :action FREE)) ; Envelope
(free-verb :mix (~'* 1/3 ~'wet) :room 0.1) ; Early reflections.
(free-verb :mix ~'wet :room 0.7) ; Proper reverb
(~'* ~'volume) ; Volume
(pan2 ~'position)))) ; Panning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment