initial music with hopes
This commit is contained in:
commit
aee2e57677
|
@ -0,0 +1,10 @@
|
|||
#+title: Programming Music Journal
|
||||
* [2022-08-19 Fri]
|
||||
** past friday I've done some basic setup (painfully) and had simplest examples running
|
||||
[[file:supercollider-example.lisp::;; to use cl-patterns with its SuperCollider backend, you'll first need to load the cl-patterns/supercollider system with quicklisp:][setting up supercollider]] package - so this doesn't work for some reason
|
||||
** here simplest things seem to work
|
||||
[[file:setting-up-cl-collider.lisp::;; https://defaultxr.github.io/cl-collider-tutorial/02-getting-started.html][cl-collider-tutorial-getting-started]]
|
||||
** so, let's just go the site?
|
||||
nope, continue with the file that had some promise
|
||||
the one about cl-collider turorial
|
||||
** also, let's make this a separate repo?
|
|
@ -0,0 +1,28 @@
|
|||
;; 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
|
||||
|
||||
|
||||
;;; https://defaultxr.github.io/cl-collider-tutorial/03-make-a-sound.html
|
||||
(proxy :foo (sin-osc.ar 440 0 0.2)) ; no error, but hear no sound
|
||||
;; opened QjackCtl, connected Graph SuperCollider to Air by Aftershokz left
|
||||
(proxy :foo (sin-osc.ar 300 0 0.2))
|
||||
(proxy :foo (saw.ar 300 0.2))
|
||||
|
||||
(proxy :foo (saw.ar (sin-osc.kr 0.5 0 150 300) 0.2))
|
||||
|
||||
(proxy :foo (saw.ar (mouse-y.kr 20 10000 :exponential) 0.2))
|
||||
|
||||
(proxy :foo ())
|
||||
|
||||
|
||||
(defsynth drum ((freq 3000))
|
||||
(let* ((env (env-gen.ar (perc 0.001 0.1) :act :free))
|
||||
(sig (lpf.ar (white-noise.ar) (* freq env))))
|
||||
(out.ar 0 (pan2.ar sig 0 0.2))))
|
||||
|
||||
(synth 'drum :freq 3000)
|
|
@ -0,0 +1,80 @@
|
|||
;; to use cl-patterns with its SuperCollider backend, you'll first need to load the cl-patterns/supercollider system with quicklisp:
|
||||
|
||||
(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)
|
||||
|
||||
;; ...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:
|
||||
|
||||
(play :foo)
|
||||
|
||||
(play :bar)
|
||||
|
||||
;; pdefs will loop by default when played. so even though the above patterns have finite durations (as set with the :pfin and :pfindur keys), triggering them via their containing pdefs will cause them to continue to play until you specifically stop them.
|
||||
;; while they're playing you can modify them by editing the code and re-evaluating it. the changes you make will be reflected the next time the patterns loops.
|
||||
|
||||
;; when you're done with them, you can stop playing the patterns like so:
|
||||
|
||||
(end :foo)
|
||||
|
||||
(end :bar)
|
||||
|
||||
;; the #'end function is used to make patterns stop at the end of their current loop, which is usually more musically desirable than stopping in the middle of the phrase.
|
||||
;; however, if you do want a pattern to stop immediately (or if you need it to because you defined it with an infinite length), you can use #'stop instead.
|
||||
|
||||
;; to continue learning cl-patterns, you can use the documentation in the doc/ directory.
|
||||
;; in particular, tutorial.org is a tutorial meant for people new to cl-patterns.
|
||||
;; sc-differences.org may be useful if you're used to SuperCollider's patterns system.
|
||||
;; you can also introspect the library, for example to get a list of all defined pattern types:
|
||||
|
||||
(all-patterns)
|
||||
|
||||
;; then you can use Lisp's standard #'describe function to get information about any patterns defined.
|
|
@ -0,0 +1,126 @@
|
|||
;; 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]
|
Loading…
Reference in New Issue