cl-patterns-study/trying-includine-sound.lisp

127 lines
4.0 KiB
Common Lisp

;; https://github.com/defaultxr/cl-patterns
(ql:quickload 'cl-patterns)
(use-package 'cl-patterns)
(defparameter *pat* (pbind :foo (pseq '(1 2 3))
:bar (prand '(9 8 7) 5)))
(defparameter *pstream* (as-pstream *pat*))
(next-n *pstream* 3)
;;; ugh
(ql:quickload :cl-collider)
(in-package :sc-user)
(named-readtables:in-readtable :sc)
(setf *sc-plugin-paths* nil)
(setf *sc-synthdefs-path* nil)
(setf *s* (make-external-server "localhost" :port 48800))
(server-boot *s*)
;; Server failed to boot.
;; could not initialize audio.
(jack-connect)
(defvar *synth*)
(setf *synth* (play (sin-osc.ar [320 321] 0 .2)))
(free *synth*)
;; jack server is not running or cannot be started
;; JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
;; JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
;; could not initialize audio.
;; terminate called without an active exception
;; Aborted (core dumped)
;;
;; so, i need to install jack server to fedora, so that it would run, or can I just start it from shell?
;;
;; let's try that
;; https://fedoraproject.org/wiki/JACK_Audio_Connection_Kit
;;
;; looks like QjackCtl starts something,
;; servers still not starts
;; reddit advices to kill and restart alsa, but my installation has something else
;; https://askubuntu.com/questions/557906/problem-starting-jack-server-jack-server-is-not-running-or-cannot-be-started
;; let's reboot?
;;
;; this has similar problem : https://github.com/byulparan/cl-collider/issues/2
;; this too and command to check scsynth directly https://github.com/byulparan/cl-collider/issues/66
;; scsynth -u 40555 -c 16384 -a 1024 -i 2 -o 2 -z 64 -S 0 -b 1024 -n 1024 -d 1024 -m 8192 -w 64 -r 64 -D 1 -R 1 -l 1 -V 0
;;
;; what if I install scsynth through fedora package manager?
;; welp. installing supercollider via package manager.
;; https://supercollider.github.io/
;; maybe that will help?
;; https://github.com/defaultxr/cl-patterns
(ql:quickload 'cl-patterns)
(use-package 'cl-patterns)
(defparameter *pat* (pbind :foo (pseq '(1 2 3))
:bar (prand '(9 8 7) 5)))
(defparameter *pstream* (as-pstream *pat*))
(next-n *pstream* 3)
(ql:quickload :cl-patterns/supercollider)
;; https://github.com/defaultxr/cl-patterns/blob/master/doc/supercollider-example.lisp
(cl-patterns:backend-start 'supercollider) ;;; that worked after I installed supercollider with Fedora dnf package manager
(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))))
(in-package #:cl-patterns)
(start-clock-loop :tempo 110/60)
(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.
)
(play :foo)
(play :bar)
(end :foo)
(end :bar)
(all-patterns)
(describe 'foo)
;; new problems and errors
;; There is no applicable method for the generic function
;; #<STANDARD-GENERIC-FUNCTION CL-COLLIDER::ID (2)>
;; when called with arguments
;; (NIL).
;; [Condition of type SB-PCL::NO-APPLICABLE-METHOD-ERROR]