cl-patterns-study/attempt-at-setup.lisp

80 lines
2.5 KiB
Common Lisp

;; https://defaultxr.github.io/cl-collider-tutorial/02-getting-started.html
(ql:quickload :cl-collider)
(in-package :sc-user)
(setf *s* (make-external-server "localhost" :port 4444))
(server-boot *s*) ; already in use
(ql:quickload :cl-patterns/supercollider)
;; ...this will take care of loading cl-collider for you if it's not already loaded.
;; once that is done, start the SuperCollider server if you haven't already:
(cl-patterns:backend-start 'supercollider)
;; (Note: if you get an error, make sure that sc:*sc-synth-program* is the same as the output of "which scsynth" from your command line. You may also need to set sc:*sc-plugin-paths* if you get errors about UGens not being installed.)
;; then define a few synths...
(in-package #:cl-collider)
(defsynth kik ((freq 440) (out 0))
(let* ((env (env-gen.kr (env (list 0 1 0) (list 0.001 1)) :act :free))
(fenv (env-gen.kr (env (list 1 0) (list 0.25)) :level-scale freq))
(sig (sin-osc.ar fenv 0 0.2)))
(out.ar out (pan2.ar sig 0 env))))
(defsynth default ((gate 1) (freq 440) (out 0))
(let* ((env (env-gen.kr (asr 0.01 1 0.1) :gate gate :act :free))
(sig (sin-osc.ar freq 0 0.2)))
(out.ar out (pan2.ar sig 0 env))))
;; then, enable cl-patterns's supercollider backend:
(in-package #:cl-patterns)
;; start the clock that patterns will be played on:
;; the clock keeps tempo in beats per second; thus 110/60 = 110 beats per minute
(start-clock-loop :tempo 110/60)
*clock*
;; ...and then go ahead and write some patterns!
(pb :foo ;; define a new pattern named :foo
:instrument :kik ;; use the :kik synth we defined above
:play-quant 4 ;; make sure the pattern will only start on a beat that is divisible by 4, to stay in sync
:dur 1 ;; give each event a duration of 1 beat
:pfin 4 ;; limit the length of the pattern to 4 events (the default is infinite events)
)
(pb :bar
:instrument :default
:play-quant 4
:dur 1/2
:scale :major ;; select the major scale
:degree (pwhite 0 7) ;; pick a random note from the first 7 notes in the selected scale
:pfindur 4 ;; limit the length of the pattern to 4 beats. pfindur causes the pattern to be limited based on its duration in beats, rather than the number of events.
)
;; start playing the defined patterns:
;;; testing
;; (in-package #:cl-collider)
;; (proxy :foo (sin-osc.ar 440 0 0.2))
;; (proxy :foo ())
;; (in-package #:cl-patterns)
;; (play :foo)
;; (play :bar)
;; (end :foo)
;; (end :bar)