id
int64 0
45.1k
| file_name
stringlengths 4
68
| file_path
stringlengths 14
193
| content
stringlengths 32
9.62M
| size
int64 32
9.62M
| language
stringclasses 1
value | extension
stringclasses 6
values | total_lines
int64 1
136k
| avg_line_length
float64 3
903k
| max_line_length
int64 3
4.51M
| alphanum_fraction
float64 0
1
| repo_name
stringclasses 779
values | repo_stars
int64 0
882
| repo_forks
int64 0
108
| repo_open_issues
int64 0
90
| repo_license
stringclasses 8
values | repo_extraction_date
stringclasses 146
values | sha
stringlengths 64
64
| __index_level_0__
int64 0
45.1k
| exdup_ids_cmlisp_stkv2
sequencelengths 1
47
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
9,122 | draw.lisp | azimut_shiny/examples/walls/draw.lisp | (in-package :shiny)
(defvar *light-factor* 1f0)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *lfbo* nil)
(defvar *sfbo* nil)
(defgeneric draw (actor camera))
(defmethod draw (actor camera))
(defmethod draw ((actor ground) camera)
(with-slots (buf) actor
(map-g #'ground-pipe buf
:time (mynow)
:light-tex *sfbo*
:cam-pos (pos camera)
:light-factor *light-factor*
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor lead) camera)
;; (with-slots (buf) actor
;; (map-g #'lead buf
;; :time (mynow)
;; :light-factor *light-factor*
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera)))
)
(defmethod draw ((actor voz) camera)
(with-slots (buf) actor
(with-instances 10
(map-g #'pipe buf
:time (mynow)
:lead-pos (pos *lead*)
:light-factor *light-factor*
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
(defmethod draw ((actor sphere) camera)
(with-setf:with-setf (cull-face) :front
(with-slots (buf) actor
(map-g #'white buf
:time (mynow)
:light-factor *light-factor*
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
(defmethod draw ((actor wall) camera)
(with-slots (buf) actor
(map-g #'white buf
:time (mynow)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor portal) camera)
(with-instances 10
(with-slots (buf) actor
(map-g #'portal-pipe buf
:time (mynow)
:portal-window *sam*
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
(defmethod draw ((actor planet) camera)
(with-slots (buf) actor
(map-g #'planet-pipe buf
:time (mynow)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
;;----------------------------------------
(defun render-all-the-things (actor camera)
(update actor)
(draw actor camera))
| 2,525 | Common Lisp | .lisp | 73 | 27.30137 | 48 | 0.569262 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4b8cdd56fa0e6211acac233a9223b84b5342d4368c097357dcc3492e4d643d59 | 9,122 | [
-1
] |
9,123 | actors.lisp | azimut_shiny/examples/walls/actors.lisp | (in-package :shiny)
(defvar *outsiders* nil)
(defvar *actors* nil)
(defvar *lead* nil)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if (lambda (x) (string= class-name (class-name (class-of x))))
*actors*)))
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
(defgeneric update (actor))
(defmethod update (actor))
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defclass actor ()
((pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (v! 0 0 0) :accessor rot)
(buf :initarg :buf :initform (box))))
(defclass lead (actor) ())
(defclass voz (actor) ())
(defclass sphere (actor) ())
(defclass wall (actor) ())
(defclass ground (actor) ())
(defclass portal (actor)
((buf :initform (box))))
(defclass planet (actor)
((buf :initform (sphere 5))
(pos :initform (v! 0 50 0))))
(defun make-planet ()
(let ((planet (make-instance 'planet)))
(push planet *actors*)
planet))
(defun make-portal ()
(let ((portal (make-instance 'portal)))
(push portal *outsiders*)
portal))
(defun make-ground ()
(let ((ground
(make-instance
'ground
:pos (v! 0 -50 0)
:buf (lattice))))
(push ground *actors*)
ground))
(defun make-lead ()
(let ((lead
(make-instance
'lead
:buf (cone 1f0 3f0) :pos (v! 0 30 -50)
:rot (q:from-axis-angle (v! 0 0 1) (radians 90)))))
(push lead *actors*)
lead))
(defun make-sphere ()
(push (make-instance 'sphere :buf (sphere 200))
*actors*))
(defun make-voz ()
(push (make-instance
'voz
:buf (cone 1f0 3f0)
:pos (v! 0 30 0)
:rot (q:from-axis-angle (v! 0 0 1)
(radians 90)))
*actors*))
(defun make-wall ()
(push (make-instance 'wall :buf (box 5 5 .2))
*actors*))
(defmethod update ((actor lead))
(setf (rot actor) (q:from-axis-angle (v! 1 0 0) (radians 90)))
(setf (pos actor) (v! 0 100 200))
;; (setf (pos actor) (v! (* 20 (sync (* 2 (mynow))))
;; (* 10 (cync (mynow)))
;; (* 100 (sync (* .5 (mynow))))))
)
(defmethod update ((actor voz))
;; (setf (pos actor) (v! 0 0 0))
;; (setf (rot actor) (q:from-axis-angle (v! 0 1 0)
;; (radians 90)))
)
(defmethod update ((actor sphere))
;; (setf (rot actor) (v! 0 0 0))
;; (setf (pos actor) (v! 0 0 0))
;;(setf (rot actor) (v! 0 0 0))
;; (setf (rot actor)
;; (q:from-axis-angle (v! 0 1 0)
;; (radians 90)))
)
(defmethod update ((actor wall))
;; (setf (pos actor) (v! 0 0 0))
;; (setf (rot actor) (v! 0 0 0))
;;(setf (pos actor) (v! 0 (* 2 (sin (mynow))) 0))
;; (setf (rot actor) (q:from-axis-angle
;; (v! 0 1 0)
;; (radians (* 360 (sync (mynow))))))
)
(defmethod update ((actor portal))
;;(setf (rot actor) (v! 0 0 0))
(setf (rot actor)
(q:from-axis-angle
(v! 1 1 1)
(radians (mod (* .01 (get-internal-real-time)) 360))))
;; (setf (rot actor)
;; (q:from-axis-angle (v! 1 1 0)
;; (radians (mod (* .01 (get-internal-real-time)) 360))))
)
| 3,523 | Common Lisp | .lisp | 111 | 27.162162 | 84 | 0.531388 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5fa0fb5db745975f06263383565acc104de6cc5e9c58440c24a1546e81ae6198 | 9,123 | [
-1
] |
9,124 | render.lisp | azimut_shiny/examples/walls/render.lisp | (in-package :shiny)
(defun-g g-rand ((x :float))
(fract (* (sin x)
10000f0)))
(defun-g cyn ((x :float))
(+ .5 (* .5 (cos x))))
(defun-g syn ((x :float))
(+ .5 (* .5 (sin x))))
(defun-g shadow-factor ((light-sampler :sampler-2d)
(pos-in-light-space :vec4))
(let* ((proj-coords (/ (s~ pos-in-light-space :xyz)
(w pos-in-light-space)))
(proj-coords (+ (* proj-coords 0.5) (vec3 0.5)))
(our-depth (z proj-coords))
(shadow 0f0)
(bias 0.005)
(texel-size (/ (vec2 1f0) (texture-size light-sampler 0)))
(uv (s~ proj-coords :xy)))
(for (x -1) (<= x 1) (++ x)
(for (y -1) (<= y 1) (++ y)
(let* ((uv+offset (+ uv (* (v! x y) texel-size)))
(pcf-depth (x (texture light-sampler uv+offset))))
(incf shadow (if (> (- our-depth bias) pcf-depth) 0f0 1f0)))))
(/ shadow 9f0)))
;; https://learnopengl.com/Advanced-OpenGL/Depth-testing
(defun-g linearize-depth ((depth :float) (near :float) (far :float))
(let ((z (- (* depth 2f0) 1f0))) ;; to NDC
(/ (* 2f0 near far)
(+ far near
(- (* z (- far near)))))))
(defun-g circle-g ((uv :vec2) (size :float))
(v3! (* size
(distance (v! .5 .5)
uv))))
;;--------------------------------------------------
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(time :float))
(let* ((pos (pos vert))
(time (+ time gl-instance-id))
;; (pos (+ pos (v! 0 (mod time 10) 0)
;; (* (* 100 (sin time))
;; (tan gl-instance-id))))
(norm (norm vert))
(tex (tex vert))
(norm (* (m4:to-mat3 model-world) (norm vert)))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
norm
(s~ world-pos :xyz))))
;;--------------------------------------------------
(defvar *stars* .9991)
(defun-g sphere-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float) (light-factor :float))
(let* (
;; (vec-to-light (- (v! 0 0 0)
;; frag-pos))
;; (dir-to-light (normalize vec-to-light))
(light-color (v! .2 .9 .09)) ;; .9 .1 0 ;; .2 .9 .1
(light-size (+ (/ 90 light-factor)
(syn time)))
(circle (circle-g uv light-size))
(sky (- 1 (* circle light-color)))
(noise (+ -3 (perlin-noise (* 40 (+ (v! (* .01 time) 0) uv)))))
(landmass (* (v! .2 .2 .2) ;; 0 .2 .9 ;; .2 .2 .2
(v3! noise)
(clamp (v3! (- (y frag-pos))) 0 1.2)))
(starry (let ((r (g-rand (* 100 (y uv)))))
(if (> r *stars*)
(v3! r)
(v3! 0))))
(starry (clamp (* starry (y frag-pos)) 0 1))
(final (+ (* .9 landmass)
(clamp sky 0 1)
(* 2 (+ .2 (* .05 (sin (* 10 time)))) starry)))
;; (final (+ (* 1 (dot dir-to-light frag-norm)) (s~ final :xyz)))
)
(v! (cos time) (sin time))))
;;--------------------------------------------------
(defun-g voz-vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(time :float) (lead-pos :vec3))
(let* ((pos (pos vert))
(time (+ time gl-instance-id))
(norm (norm vert))
(tex (tex vert))
(norm (* (m4:to-mat3 model-world) (norm vert)))
(world-pos (* model-world (v! pos 1)))
(vec-to-lead (- lead-pos (s~ world-pos :xyz)))
(dic-to-lead (normalize vec-to-lead))
(new-pos (+ lead-pos
(v! (* 70 (cos time) (sin time))
(* 20 (cos time))
(+ -50 (* 20 (cos time))))))
(world-pos (+ world-pos
(v! new-pos 0)))
;; (world-pos (* world-pos (m3:point-at (v! 1 1 1) new-pos lead-pos)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
norm
(s~ world-pos :xyz))))
(defun-g voz-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float) (light-factor :float) (cam-pos :vec3) (light-tex :sampler-2d))
(let* ((light-pos (v! 0 70 -150))
(obj-color (v! .2 .9 1));; .2 .9 1 ;; celeste
;; Ambient
(light-ambient .1)
;; Diffuse
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
(light-diffuse (saturate (dot frag-norm dir-to-light)))
(shadow (shadow-factor light-tex (v! light-pos 1)))
(lights (+ light-ambient (* shadow (+ light-diffuse))))
(result (* lights obj-color))
(depth (v3! (/ (linearize-depth (z gl-frag-coord) .1f0 100f0) 100f0)))
(result (* ;;depth
result)))
(v! result 0)))
;;--------------------------------------------------
(defun-g ground-vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(time :float) (tex-noise :sampler-2d))
(let* ((pos (pos vert))
(norm (norm vert))
(tex (tex vert))
(dis (* 20
(x
(texel-fetch
tex-noise
(ivec2 (v! (int (floor (* 200 (/ (+ 50 (x pos)) 100))))
(int (floor (* 200 (/ (+ 50 (z pos)) 100))))))
0))))
(pos (+ pos (v! 0 dis 0)))
;; (pos (- pos (v! 0 10 0)))
(pos (* pos (v! 3 3 3)))
(norm (* (m4:to-mat3 model-world) (norm vert)))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
norm
(s~ world-pos :xyz))))
(defun-g ground-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float))
(let* ((color (v3! 1)))
color))
;;--------------------------------------------------
(defun-g pass-vert ((pos :vec2))
(values (v! pos 0 1)
(+ .5 (* .5 pos))))
(defun-g pass-frag ((uv :vec2) &uniform (time :float))
(let ((color
(v3! (nineveh.noise:cellular-noise
(+ (- (v! 0 (+ (- (clamp (sin time) .1 .16)) time)))
(* 4 uv))))))
(v! color 0)))
(defpipeline-g pass-pipe ()
(pass-vert :vec2)
(pass-frag :vec2))
;;--------------------------------------------------
(defun-g planet-vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(time :float) (noise-tex :sampler-2d))
(let* ((pos (pos vert))
(norm (norm vert))
(tex (tex vert))
(dis (* 2
(x
(texel-fetch
noise-tex
(ivec2 (v! (int (floor (* 200 (/ (+ 5 (x pos)) 10))))
(int (floor (* 200 (/ (+ 5 (z pos)) 10))))))
0))))
(pos (+ pos (* norm dis)))
;; (pos (+ pos (v! 0 dis 0)))
;; (pos (- pos (v! 0 10 0)))
;; (pos (* pos (v! 3 3 3)))
(norm (* (m4:to-mat3 model-world) (norm vert)))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
norm
(s~ world-pos :xyz))))
(defun-g portal-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float) (portal-window :sampler-2d))
(let* ((uv (* -1 uv))
(final (texture portal-window uv)))
final))
;;--------------------------------------------------
(defun-g planet-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float))
(let* ((final (v! .2 .2 .3 0)))
.2))
(defun-g planet-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float))
(let* ((light-pos (v! 0 50 -100))
(obj-color (v! .2 .9 1));; .2 .9 1 ;; celeste
;; Ambient
(light-ambient .1)
;; Diffuse
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
(light-diffuse (saturate (dot frag-norm dir-to-light)))
(lights (+ light-ambient (+ light-diffuse)))
(result (* lights obj-color))
;; (depth (v3! (/ (linearize-depth (z gl-frag-coord) .1f0 10f0) 10f0)))
(result (* ;;depth
result)))
(v! result 0)))
(defpipeline-g planet-pipe ()
:vertex (planet-vert g-pnt)
:fragment (planet-frag :vec2 :vec3 :vec3))
(defpipeline-g portal-pipe ()
:vertex (vert g-pnt)
:fragment (portal-frag :vec2 :vec3 :vec3))
;; Deform vertex logic, voz-shading
(defpipeline-g ground-pipe ()
:vertex (ground-vert g-pnt)
:fragment (voz-frag :vec2 :vec3 :vec3))
;; No verted logic, voz shading
(defpipeline-g lead ()
:vertex (vert g-pnt)
:fragment (voz-frag :vec2 :vec3 :vec3))
;; Vertex movement, voz shading
(defpipeline-g pipe ()
:vertex (voz-vert g-pnt)
:fragment (voz-frag :vec2 :vec3 :vec3))
;; No vextex logic, sphere shading
(defpipeline-g white ()
:vertex (vert g-pnt)
:fragment (sphere-frag :vec2 :vec3 :vec3))
| 9,631 | Common Lisp | .lisp | 249 | 30.028112 | 81 | 0.458779 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 995854fe7a0325da2e1dd239d688ac7b85e3e7adbcae3a1e90774c8fe82b8a7b | 9,124 | [
-1
] |
9,125 | main.lisp | azimut_shiny/examples/iclc/main.lisp | (in-package :shiny)
(defparameter *step* (make-stepper (seconds .05) (seconds 1)))
(defparameter *trigger* (make-trigger))
(defvar *buf* (make-buffer 512 :channels 2))
(defvar *mar* nil)
(defvar *ubo* nil)
(defvar *actors* nil)
(dsp! monitor-master ((buf buffer))
(buffer-write
buf
(counter 0 511 :loop-p t)
(audio-out 0)))
;; (monitor-master *buf* :id 100)
;;--------------------------------------------------
;;(bbuffer-load "/home/sendai/music/Furi.wav")
;;(bbplay "Furi.wav" :id 10 :loop-p t)
;;(incudine:free (node 100))
;;(initialize)
(defun initialize ()
(setf (clear-color) (v! .2 .2 .2 0))
(setf *actors* nil)
(push (make-instance 'dolly)
*actors*)
(push (make-instance 'piso
:buf (sphere 100))
*actors*)
;; (push (make-instance 'piso
;; :buf (box 25 .1 25)
;; :pos (v! 0 -5 0))
;; *actors*)
(push (make-instance 'voz
:buf (box))
*actors*)
(unless *ubo*
(setf *mar* (make-c-array nil :dimensions 1 :element-type 'music))
(setf *ubo* (make-ubo *mar*))))
(defun draw! ()
(when (funcall *step*)
;; NOTE: ?
(with-gpu-array-as-c-array (m (ubo-data *ubo*) :access-type :write-only)
(foreign-copy-samples (c-array-pointer m)
(buffer-data *buf*)
1024)))
(let ((res (surface-resolution (current-surface))))
(setf (resolution (current-viewport))
res)
(as-frame
(update *currentcamera*)
(loop :for a :in *actors*
:do
(update a)
(draw a res)))))
(def-simple-main-loop runplay (:on-start #'initialize)
(draw!))
| 1,710 | Common Lisp | .lisp | 54 | 25.944444 | 76 | 0.540426 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 775d877c8a8c2afe1abd55426f57117a015b180dd7becf274ca9bd8f08cfc32f | 9,125 | [
-1
] |
9,126 | actors.lisp | azimut_shiny/examples/iclc/actors.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :initform (v! 0 0 0) :accessor rot)
(rot :initarg :rot :initform (q:identity) :accessor pos)
(near :initarg :near :initform .1 :accessor near)
(far :initarg :far :initform 400f0 :accessor far)))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initform 60f0 :accessor fov)))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *currentcamera* *camera*)
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera width height)
(:method ((camera pers) width height)
(rtg-math.projection:perspective
width
height
(near camera)
(far camera)
(fov camera)))
(:method ((camera orth) width height)
(rtg-math.projection:orthographic
(* .1 width)
(* .1 height)
(near camera)
(far camera))))
(defvar *actors* nil)
(defclass actor ()
((pos :initarg :pos :initform (v! 0 0 0))
(rot :initarg :rot :initform (v! 0 0 0))
(buf :initarg :buf :initform (box))))
;;--------------------------------------------------
(defclass voz (actor) ())
(defclass piso (actor) ())
(defclass dolly (actor) ())
(defparameter *trigger* (make-trigger 20))
(defgeneric update (actor))
;; y - altura
(defmethod update ((camera orth))
;; (setf (pos camera)
;; (v! 0 5 0))
;; (setf (rot camera)
;; (q:from-axis-angle (v! 1 0 0) (radians -90)))
)
(defmethod sync (x)
(+ .5 (* .5 (sin x))))
(defmethod cync (x)
(+ .5 (* .5 (cos x))))
(defmethod update ((camera pers))
(setf (pos camera) (v! 0 2 10))
(setf (rot camera) (v! 0 0 0))
;; (setf (rot camera) (q:from-axis-angle (v! 1 0 0)
;; (radians -35)))
(setf (rot camera)
(q:from-axis-angle
(v! 1 1 1)
(radians (mod (* (+ 20 (funcall *trigger* 'shoot))
(mynow))
360))))
)
(defmethod update ((actor dolly))
;; (let* ((time (* .001 (get-internal-real-time)))
;; (st (sync time))
;; (newpos (v! (+ -10 (* 20 (cync time)))
;; 2
;; (+ -10 (* 20 st)))))
;; (with-slots (pos) actor
;; (setf pos newpos)))
)
(defmethod update ((actor piso))
(with-slots (pos) actor
(setf pos (v! 0 -5 0))))
(defmethod update ((actor voz))
(with-slots (pos rot) actor
(setf pos (v! 0
(+ .5 (* .5 (sin (* .001 (get-internal-real-time)))))
0))
(setf rot (v! 0 0 0))
(setf rot (q:from-axis-angle
(v! -1 1 1)
(radians (* 360 (+ .5 (* .5 (cos (* .001 (get-internal-real-time)))))))))
))
(defgeneric draw (actor res))
(defmethod draw ((actor piso) res)
(with-setf:with-setf (cull-face) :front
(with-slots (buf) actor
(map-g #'white buf
:time (mynow)
:model-world (model->world actor)
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*
(x res)
(y res))))))
(defvar *instances* 185)
(defmethod draw ((actor dolly) res)
(with-slots (buf) actor
(with-instances *instances*
(map-g #'dollypipe buf
:time (mynow)
:sound *ubo*
:model-world (model->world actor)
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*
(x res)
(y res))))))
(defmethod draw ((actor voz) res)
(with-slots (buf) actor
(map-g #'pipe buf
:time (mynow)
:sound *ubo*
:model-world (model->world actor)
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*
(x res)
(y res)))))
| 4,197 | Common Lisp | .lisp | 122 | 27.131148 | 88 | 0.522329 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7a8834e9d2ec2c968dfce29963bf778b6f3c2382ebddb16258fabbac309e7574 | 9,126 | [
-1
] |
9,127 | render.lisp | azimut_shiny/examples/iclc/render.lisp | (in-package :shiny)
(defstruct-g (music :layout :std-140)
(samples (:double 512)))
(defun-g g-rand ((x :float))
(fract (* (sin x)
10000f0)))
(defun-g cyn ((x :float))
(+ .5 (* .5 (cos x))))
(defun-g syn ((x :float))
(+ .5 (* .5 (sin x))))
(defun-g white-frag
((uv :vec2) (color :vec3) &uniform
(time :float) (trigger :float))
(let* (;;(c2 (v4! (syn time)))
;;(c1 (v4! (cyn time)))
(c2 (v! 0 .3 0 1))
(c1 (v! .7 .7 .7 1))
(final (mix c1 c2 (* (tan time) (y uv))))
;;(final (smoothstep 0 1 (y uv)))
)
final))
(defun-g frag
((uv :vec2) (color :vec3) &uniform
(sound music :ubo) (time :float) (rms :float))
(with-slots (samples) sound
(let* ((wide 312)
(wave (float (aref samples (abs (int (ceil (* wide (x uv))))))))
(wave (- 1 (smoothstep 0f0 .05 (abs (- wave (- (y uv) .5))))))
(wave (v! 0 wave 0)))
wave)))
;; Este V shader pasa las cosas asi como las encuentra
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4))
(let* ((pos (pos vert))
(norm (norm vert))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
(v! (+ .5 (* .5 (s~ pos :xy))))
norm)))
;; Este shader modifica cosas en base a gl-instance-id
(defun-g dolly-frag
((uv :vec2) (frag-pos :vec3) (frag-norm :vec3) &uniform
(sound music :ubo) (time :float) (rms :float))
(with-slots (samples) sound
(let* ((wide 102)
(wave (float (aref samples (abs (int (ceil (* wide (x uv))))))))
(wave (- 1 (smoothstep 0f0 .05 (abs (- wave (- (y uv) .5))))))
(wave (v3! wave ))
(vec-to-light (- (v! 0 5 0)
frag-pos))
(dir-to-light (normalize vec-to-light))
(wave (+ wave (* .2 (dot dir-to-light frag-norm)))))
wave)))
(defun-g dolly-vert
((vert g-pnt) &uniform (time :float)
(model-world :mat4) (world-view :mat4) (view-clip :mat4))
(let* ((time (+ (* (* .01
(syn time)) time) gl-instance-id))
(myid gl-instance-id)
(p (pos vert))
(pos (cond ((< myid 50)
(+ (v! (+ -15 (* 30 (syn time)))
(* 10 (syn time))
(+ -15 (* 30 (cyn time))))
p))
((< myid 100)
(+ (v! (+ -13 (* 26 (cyn time)))
(* 10 (syn time))
(+ -13 (* 26 (syn time))))
p))
((< myid 145)
(+ (v! (* 10 (syn time))
(+ -20 (* 40 (syn time)))
(+ -15 (* 30 (cyn time))))
p))
(t
(+ (v! (* 10 (syn time))
(+ -10 (* 20 (cyn time)))
(+ -5 (* 10 (syn time))))
p))))
(pos (* pos (m3:rotation-z (radians (* 90 (syn time))))))
(norm (* (m4:to-mat3 model-world) (norm vert)))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
(v! (+ .5 (s~ p :xy)))
(s~ world-pos :xyz)
norm)))
;;--------------------------------------------------
(defpipeline-g pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3))
(defpipeline-g white ()
:vertex (vert g-pnt)
:fragment (white-frag :vec2 :vec3))
(defpipeline-g dollypipe ()
:vertex (dolly-vert g-pnt)
:fragment (dolly-frag :vec2 :vec3 :vec3))
| 3,976 | Common Lisp | .lisp | 102 | 27.372549 | 75 | 0.42213 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7f4699d5498f8fafeb14a42fc53c26a75127a906ea408a2b205b78bc7ab36021 | 9,127 | [
-1
] |
9,128 | camera.lisp | azimut_shiny/examples/particles-tfs/camera.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (q:identity) :accessor rot)
(near :initarg :near :initform .1 :accessor near)
(far :initarg :far :initform 400f0 :accessor far)
(frame-size
:initarg :frame-size :initform nil :accessor frame-size)
(buf :initform (box))))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initform 60f0 :accessor fov)))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *currentcamera* *camera*)
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera)
(:method ((camera pers))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:perspective
(x fs)
(y fs)
(near camera)
(far camera)
(fov camera))))
(:method ((camera orth))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:orthographic
(x fs)
(y fs)
(near camera)
(far camera)))))
(defmethod update ((camera orth))
(setf (pos camera) (v! 0 0 0))
(setf (frame-size camera) (v2! 5))
;; (setf (rot camera) (v! 0 0 0))
(setf (rot camera)
;; TOP
;; (q:from-axis-angle (v! 1 0 0)
;; (radians -90))
;; FRONT
(q:from-axis-angle (v! 1 0 0)
(radians -45))
))
(defparameter *crotate* nil)
(defparameter *head* nil)
(defparameter *wave* 1f0)
(defparameter *cam-vector* (v! 1 0 0))
(defmethod update ((camera pers))
(with-slots (pos rot) camera
;;(setf rot (q:from-axis-angle (v! 0 0 1) (radians 0)))
(setf pos (v! (* 1 (cos (* .5 (mynow))))
(* 1 (sin (* .5 (mynow))))
(+ 20 (* .1 (cos (* .5 (mynow)))))))
;;(setf rot (q:look-at (v! 0 1 0) pos (v! 0 -1 0)))
))
| 2,084 | Common Lisp | .lisp | 60 | 28.75 | 61 | 0.571429 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 32c5e5fa3e0d02b4ad6f2d231e03788af512418e143295097dc8426947177722 | 9,128 | [
-1
] |
9,129 | main.lisp | azimut_shiny/examples/particles-tfs/main.lisp | (in-package :shiny)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *bs* nil)
(defvar *blend* (make-blending-params))
(defvar *gar-src* nil)
(defvar *gar-dst* nil)
(defvar *tfs-src* nil)
(defvar *tfs-dst* nil)
(defvar *str-src* nil)
(defvar *str-dst* nil)
(defun initialize ()
;; Different type of streams over the SAME gpu-arrays...
;; This might be a CEPL limitation, but is not that bad...
(unless *gar-src*
(setf *gar-src* (make-gpu-array nil :dimensions 1000 :element-type 'pdata)
*gar-dst* (make-gpu-array nil :dimensions 1000 :element-type 'pdata)
*str-src* (make-buffer-stream *gar-src* :primitive :points)
*str-dst* (make-buffer-stream *gar-dst* :primitive :points)
*tfs-src* (make-transform-feedback-stream *gar-src*)
*tfs-dst* (make-transform-feedback-stream *gar-dst*)))
(with-transform-feedback (*tfs-src*)
(map-g #'pinit-pipe *bs*))
(with-transform-feedback (*tfs-dst*)
(map-g #'pinit-pipe *bs*))
;;--------------------------------------------------
;; Buffer stream for single stage pipelines
(unless *bs* (setf *bs* (make-buffer-stream nil :primitive :points)))
;;--------------------------------------------------
;; HDR fbo(s)
(when *fbo* (free *fbo*))
(setf *fbo* (make-fbo (list 0 :element-type :rgb16f)
:d))
(setf *sam* (cepl:sample (attachment-tex *fbo* 0)))
(setf (clear-color) (v! 0 0 0 1))
;;--------------------------------------------------
;; Actores
(setf *actors* nil)
(make-celestial-sphere)
;;(make-box)
;;(make-piso (v! 0 -2 0))
;;(make-piso (v! 0 2 0) (q:from-axis-angle (v! 1 0 0) (radians 180)))
;; (%gl::sampler-parameter-f
;; (%cepl.types::%sampler-id (get-tex "static/checker.dds"))
;; :texture-max-anisotropy-ext 1f0)
NIL)
(defun draw! ()
(let ((res (surface-resolution (current-surface))))
(setf (resolution (current-viewport)) res)
(update *currentcamera*)
(update-all-the-things *actors*)
(with-fbo-bound (*fbo*)
(clear-fbo *fbo*)
(loop :for actor :in *actors* :do
(draw actor *currentcamera*))
;; Update particles
(with-transform-feedback (*tfs-dst*)
(map-g #'pupdate-pipe *str-src*
:time (mynow)))
;; Draw particles
(map-g #'prender-pipe *str-src*
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*))
(rotatef *tfs-src* *tfs-dst*)
(rotatef *str-src* *str-dst*)
(rotatef *gar-src* *gar-dst*)
;; (with-blending *blend*
;; (map-g #'billboard-pipe *bs*
;; :camera-pos (pos *currentcamera*)
;; :tex (get-tex "static/float-alpha.png")
;; :time (mynow)
;; :world-view (world->view *currentcamera*)
;; :view-clip (projection *currentcamera*)))
)
(as-frame
(with-setf* ((depth-mask) nil
(cull-face) nil
(clear-color) (v! 0 0 0 1)
(depth-test-function) #'always)
(map-g #'generic-2d-pipe *bs*
:sam *sam*)))))
(def-simple-main-loop runplay
(:on-start #'initialize)
(draw!))
| 3,215 | Common Lisp | .lisp | 84 | 32.166667 | 78 | 0.55684 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f6fe560ee74ca817ac61274e80ccfacf964a43162a8651e3b52bb3b4674d4227 | 9,129 | [
-1
] |
9,130 | draw.lisp | azimut_shiny/examples/particles-tfs/draw.lisp | (in-package :shiny)
(defparameter *dirlight-pos* (v! 1000 1000 1000))
(defparameter *dirlight-mul* .5)
(defparameter *pointlight-pos* (v! 0 2 0))
(defun render-all-the-things (actor camera)
(update actor)
(draw actor camera))
(defgeneric draw (actor camera))
(defmethod draw (actor camera))
;; (defmethod draw ((actor camera) camera)
;; (with-slots (buf tex) actor
;; (map-g #'generic-tex-pipe buf
;; :time (mynow)
;; :scale 1f0
;; :tex tex
;; ;; :color (v! .1 .1 .8)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))))
(defmethod draw ((actor piso) camera)
(with-slots (buf scale tex) actor
(map-g #'tex-pipe buf
:scale 1f0
:albedo tex
:cam-pos (pos camera)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor box) camera)
(with-slots (buf scale) actor
(map-g #'generic-pipe buf
:scale scale
:color (v! .9 .9 .9)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
;; (defmethod draw ((actor sphere) camera)
;; (with-slots (buf scale) actor
;; (map-g #'generic-pipe buf
;; :time (mynow)
;; :scale scale
;; :color (v! 1 1 1)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))))
(defmethod draw ((actor celestial-sphere) camera)
(with-slots (buf scale) actor
(with-setf* ((cull-face) :front
;;(depth-test-function) #'always
;;(depth-mask) nil
)
(map-g #'light-pipe buf
:color (v! .5 .2 .5)
:scale 20f0
:time (mynow)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
| 2,099 | Common Lisp | .lisp | 58 | 30.258621 | 49 | 0.552386 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | df73d906e192a42013b472e84cf0f7179157e688aed77e46b73f106fe98c85aa | 9,130 | [
-1
] |
9,131 | actors.lisp | azimut_shiny/examples/particles-tfs/actors.lisp | (in-package :shiny)
(defvar *actors* nil)
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun delete-actor-name (actor-name)
(declare (keyword actor-name))
(setf *actors*
(delete-if
(lambda (x) (eq actor-name (slot-value x 'name)))
*actors*))
NIL)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*))
NIL)
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
(defclass actor ()
((name :initarg :name :initform (gensym))
(pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (v! 0 0 0) :accessor rot)
(buf :initarg :buf :initform (box))
(scale :initarg :scale :initform 1f0)))
(defclass celestial-sphere (actor)
((buf :initform (sphere 10 10 10))))
(defclass piso (actor)
((buf :initform (lattice 50 50 2 2))
(tex :initform (get-tex "static/checker.dds"))))
(defclass box (actor)
((buf :initform (box 2 2 2))))
(defclass sphere (actor)
((buf :initform (sphere 1))))
(defun make-celestial-sphere ()
(let ((obj (make-instance 'celestial-sphere)))
(push obj *actors*)
obj))
(defun make-box ()
(let ((obj (make-instance 'box)))
(push obj *actors*)
obj))
(defun make-sphere ()
(let ((obj (make-instance 'sphere)))
(push obj *actors*)
obj))
(defun make-piso (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj (make-instance 'piso :pos pos :rot rot)))
(push obj *actors*)
obj))
(defgeneric update (actor))
(defmethod update (actor))
(defmethod update ((actor celestial-sphere))
(setf (rot actor) (q:from-axis-angle (v! 0 1 0)
(radians 90))))
(defmethod update ((actor box))
(setf (pos actor) (v! 0 -.5 0))
;; (setf (slot-value actor 'scale) .5)
;; (setf (rot actor)
;; (q:from-axis-angle
;; (v! 1 1 1)
;; (radians (* 360 (sync (* .2 (mynow)))))))
)
| 2,238 | Common Lisp | .lisp | 70 | 27.742857 | 68 | 0.596752 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | dee66bc07cfed462b4fe54ab5b06e59d39c0cc92e1619d0d6e64e0983bf7c190 | 9,131 | [
-1
] |
9,132 | render.lisp | azimut_shiny/examples/particles-tfs/render.lisp | (in-package :shiny)
(defparameter *exposure* 2f0)
(defstruct-g pdata
(pos :vec3)
(dir :vec3)
(life :float))
(defun-g treat-uvs ((uv :vec2))
(v! (x uv) (- 1.0 (y uv))))
;;--------------------------------------------------
;; 3D - g-pnt with tangent info in tb-data AND textures
(defun-g vert-with-tbdata
((vert g-pnt) (tb tb-data)
&uniform
(model-world :mat4)
(world-view :mat4)
(view-clip :mat4)
(scale :float)
;; Parallax vars
(light-pos :vec3)
(cam-pos :vec3))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(uv (treat-uvs (tex vert)))
(norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(t0 (normalize
(s~ (* model-world
(v! (tb-data-tangent tb) 0))
:xyz)))
(n0 (normalize
(s~ (* model-world
(v! norm 0))
:xyz)))
(t0 (normalize (- t0 (* (dot t0 n0) n0))))
(b0 (cross n0 t0))
(tbn (mat3 t0 b0 n0)))
(values clip-pos
uv
norm
(s~ world-pos :xyz)
tbn
(* tbn light-pos)
(* tbn cam-pos) (* tbn (s~ world-pos :xyz)))))
(defun-g frag-tex-tbn ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d)
(normap :sampler-2d)
(height-map :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; Parallax
(tan-cam-dir (- tan-cam-pos tan-frag-pos))
(newuv (parallax-mapping uv tan-cam-dir height-map .1))
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo newuv) :xyz)
(vec3 2.2)))
;;(normal (normalize frag-norm))
(nfm (norm-from-map normap newuv))
(normal (* tbn nfm))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
)
(values
;; (v! final-color 1)
;; (v! 1 1 1 1)
;;frag-pos
(normalize frag-norm))))
(defpipeline-g generic-tex-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (frag-tex-tbn :vec2 :vec3 :vec3 :mat3
;; Parallax
:vec3 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - g-pnt mesh without tangents
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(scale :float))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(tex (tex vert))
(world-norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
world-norm
(s~ world-pos :xyz))))
;; http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
(defun-g frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float) (color :vec3) (cam-pos :vec3))
(let* ((light-pos *pointlight-pos*)
(light-color (v! 1 .7 .4))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(direc-light-strength
(* *dirlight-mul*
light-color
(saturate
(dot frag-norm
(normalize (- *dirlight-pos* frag-pos))))))
(point-light-strength
(* light-color
light-strength
;; saturate?
(saturate (dot frag-norm dir-to-light))
;; attenuation - constant, linear, cuadratic
(/ 1f0 (+ 1f0
(* .014 (length vec-to-light))
(* .07 (pow (length vec-to-light)
2))))))
(final-color (+ (* color point-light-strength)
(* color direc-light-strength))))
(v! final-color 1)
(v! color 0)))
;;--------------------------------------------------
;; 2D - Post Processing
(defun-g vert-2d ((vert :vec2))
(let* ((uv (+ .5 (* .5 vert))))
(values (v! vert 0 1)
uv)))
(defparameter *exposure* .09)
(defun-g frag-2d ((uv :vec2) &uniform (sam :sampler-2d))
(let* ((color (s~ (texture sam uv) :xyz))
;; (color
;; (s~ (nineveh.anti-aliasing:fxaa3 uv sam (v2! (/ 1 320f0))) :xyz))
(ldr (nineveh.tonemapping:tone-map-reinhard color *exposure*))
(luma (rgb->luma-bt601 ldr))
)
;;(v! (pow ldr (vec3 2.2)) 1)
(v! ldr luma)
;;(v! color 1)
;;(v! ldr 1)
))
(defpipeline-g generic-2d-pipe (:points)
:fragment (frag-2d :vec2))
;;--------------------------------------------------
;; 3D - g-pnt mesh with light shading
(defpipeline-g generic-pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - Lamp solid color
(defun-g light-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3)
&uniform (color :vec3) (time :float))
(nineveh.noise:perlin-noise
(+ (* .1 time) frag-pos))
)
(defpipeline-g light-pipe ()
:vertex (vert g-pnt)
:fragment (light-frag :vec2 :vec3 :vec3))
(defun-g frag-tex ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (* 10 (s~ (texture albedo (* 20 uv)) :xyz)))
;;(color (expt color (vec3 2.2)))
;;--------------------
;; Fog
;;(fog-color (v! 0 1 1))
(fog-color (* 1 (v! 0.14901961 0.3019608 0.69803923)))
;;(fog-factor (fog-linear frag-pos cam-pos .1 30))
(fog-factor (fog-exp2 frag-pos cam-pos .16))
;;(normal (normalize frag-norm))
;;(nfm (norm-from-map normap uv))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
)
;;(v! (mix fog-color color (vec3 (saturate fog-factor))) 1)
(v! 0 (fract (tan (* 100 (x uv)))) 1)
))
(defpipeline-g tex-pipe ()
:vertex (vert g-pnt)
:fragment (frag-tex :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; Billboard
;; https://www.youtube.com/watch?v=puOTwCrEm7Q
;; - basis vectors:
;; -- 3 vectors are true orthogonal
;; -- fill space (span)
;;
(defparameter *quad-3d*
(list '(-1 -1 0) '( 1 -1 0)
'( 1 1 0) '(-1 1 0)))
(defun-g billboard-vert ((pos :vec3)
&uniform
(time :float)
(world-view :mat4))
(* world-view (v! .5 0 18.5 1)))
(defun-g billboard-geom (&uniform (camera-pos :vec3)
(view-clip :mat4))
(declare (output-primitive :kind :triangle-strip :max-vertices 4))
(let* ((p (s~ (gl-position (aref gl-in 0)) :xyz))
(to-camera (normalize (- camera-pos p)))
;;(to-camera (v! (x to-camera) 0 (z to-camera)))
(up (v! 0 1 0))
(right (cross to-camera up)))
;;
(decf p (* .5 right))
(emit ()
(* view-clip (v! p 1))
(v! 0 0))
;;
(incf (y p) 1f0)
(emit ()
(* view-clip (v! p 1))
(v! 0 1))
;;
(decf (y p) 1f0)
(incf p right)
(emit ()
(* view-clip (v! p 1))
(v! 1 0))
;;
(incf (y p) 1f0)
(emit ()
(* view-clip (v! p 1))
(v! 1 1))
(end-primitive)
(values)))
(defun-g billboard-frag ((uv :vec2) &uniform (tex :sampler-2d) (time :float))
(let* ((color (expt (texture tex (treat-uvs (* (m2:rotation-from-euler (radians (+ 0 (sin (* 5 time))))) uv))) (vec4 2.2) )))
color))
(defpipeline-g billboard-pipe (:points)
:vertex (billboard-vert :vec3)
:geometry (billboard-geom)
:fragment (billboard-frag :vec2))
;;--------------------------------------------------
;; render points
(defun-g prender-vert ((pdata pdata)
&uniform
(world-view :mat4)
(view-clip :mat4))
(with-slots (pos) pdata
(let* ((world-pos (v! pos 1))
(clip-pos (* world-view world-pos))
(clip-pos (* view-clip clip-pos)))
(values clip-pos))))
(defun-g prender-frag ()
(v! 1 1 1 0))
(defpipeline-g prender-pipe (:points)
:vertex (prender-vert pdata)
:fragment (prender-frag))
;;--------------------------------------------------
;; Update particles
(defparameter *distance* 0f0)
(defparameter *offset* 1f0)
(gl:point-size 50)
(defun-g pupdate-vert ((pdata pdata)
&uniform
(time :float))
(with-slots (pos dir life) pdata
(let ((time (* time (* *offset* gl-vertex-id))))
(values (v! 0 0 0 0)
(:feedback (+ (* .9 pos)
(v! (cos time) (sin time) *distance*)))
(:feedback dir)
(:feedback life)))))
(defpipeline-g pupdate-pipe (:points)
:vertex (pupdate-vert pdata))
;;--------------------------------------------------
;; Init particles
(defun-g pinit-vert (&uniform (time :float))
(values (v! 0 0 0 0)
(:feedback (v! 1 0 0))
(:feedback (v! 0 0 0))
(:feedback 0f0)))
(defpipeline-g pinit-pipe (:points)
:vertex (pinit-vert))
| 11,801 | Common Lisp | .lisp | 333 | 26.363363 | 127 | 0.454402 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c5aa3aaf737c1cefae7df504c50a257d893cfa2f8dd02d2c6d47b385070865c8 | 9,132 | [
-1
] |
9,133 | camera.lisp | azimut_shiny/examples/planetes/camera.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (q:identity) :accessor rot)
(near :initarg :near :initform .1 :accessor near)
(far :initarg :far :initform 400f0 :accessor far)
(frame-size
:initarg :frame-size :initform nil :accessor frame-size)
(buf :initform (box))))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initform 60f0 :accessor fov)))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *currentcamera* *camera*)
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera)
(:method ((camera pers))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:perspective-v2
fs
(near camera)
(far camera)
(fov camera))))
(:method ((camera orth))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:orthographic
(x fs)
(y fs)
(near camera)
(far camera)))))
(defmethod update ((camera orth))
(setf (pos camera) (v! 0 0 0))
(setf (frame-size camera) (v2! 30))
;; (setf (rot camera) (v! 0 0 0))
(setf (rot camera)
;; TOP
(q:from-axis-angle (v! 1 0 0)
(radians -40))
;; FRONT
;; (q:from-axis-angle (v! 1 0 0)
;; (radians -45))
))
(defparameter *crotate* nil)
(defparameter *head* nil)
(defparameter *wave* 1f0)
(defparameter *cam-vector* (v! 1 0 0))
(defmethod update ((camera pers))
(let ((time (mynow))) (with-slots (pos rot) camera
;;(setf rot (q:identity))
(setf rot (q:*
(q:from-axis-angle (v! 1 0 0) (radians 10))
(q:from-axis-angle (v! 0 1 0)
(radians (* 20 (sin (* .2 time)))))))
;;(setf rot (q:from-axis-angle (v! 0 0 1) (radians 80)))
(setf pos (v! (+ -10 (* 0 (cos (* .5 time))))
(+ 22 (* .1 (sin (* .5 time))))
(+ 100 (* 1 (cos (* .5 time))))
))
;;(setf pos (v! 0 0 0))
;;(setf rot (q:look-at (v! 0 1 0) pos (v! 0 -1 0)))
)))
| 2,386 | Common Lisp | .lisp | 66 | 29.106061 | 72 | 0.54628 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d5319afb767a47ea8acb10106739471b5389f78c0c4669c893ce69fc118d3736 | 9,133 | [
-1
] |
9,134 | main.lisp | azimut_shiny/examples/planetes/main.lisp | (in-package :shiny)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *sam1* nil)
(defvar *bs* nil)
(defvar *res* nil)
(defvar *blend* (make-blending-params))
(defvar *god-fbo* nil)
(defvar *god-sam* nil)
(defun initialize ()
;;--------------------------------------------------
;; Buffer stream for single stage pipelines
(unless *bs* (setf *bs* (make-buffer-stream nil :primitive :points)))
;;--------------------------------------------------
;; HDR fbo(s)
(when *fbo* (free *fbo*))
(setf *fbo* (make-fbo (list 0 :element-type :rgb16f :dimensions '(600 450))
;; 1 - Used for godrays to know what is occluded and bright.
(list 1 :element-type :rgb16f :dimensions '(600 450))
(list :d :dimensions '(600 450))))
(setf *sam* (cepl:sample (attachment-tex *fbo* 0)
:wrap :clamp-to-edge))
(setf *sam1* (cepl:sample (attachment-tex *fbo* 1)
:wrap :clamp-to-edge))
;;--------------------------------------------------
(when *god-fbo* (free *god-fbo*))
(setf *god-fbo* (make-fbo (list 0 :element-type :rgb16f :dimensions '(600 450))))
(setf *god-sam* (cepl:sample (attachment-tex *god-fbo* 0)
:wrap :clamp-to-edge))
(setf *res* (dimensions (attachment-tex *fbo* 0)))
(setf (clear-color) (v! 0 0 0 1))
;;--------------------------------------------------
(setf *actors* nil)
;;(make-box (v! 0 0 -10))
;;(make-sphere *light-pos* 1f0)
;; (dotimes (i 20)
;; (make-box (v! (+ -10 (random 20f0))
;; (random 1f0)
;; (- (random 30f0)))
;; (random 1f0)))
(make-pbr (v! 0 -2 0))
(setf *radius-planet* 6371000f0)
;; (make-pbr (v! 20 30 0) (q:from-axis-angle (v! 0 0 1)
;; (radians 135)))
;; (make-pbr (v! -10 4 0) (q:from-axis-angle (v! 0 0 1)
;; (radians 225)))
;;(make-planet)
;;(make-clouds)
(make-celestial-sphere)
NIL)
(defun draw! ()
(let* ((res (surface-resolution (current-surface)))
(time (mynow))
)
(setf (resolution (current-viewport)) res)
(update *currentcamera*)
(update-all-the-things *actors*)
(with-fbo-bound (*fbo*)
(clear-fbo *fbo*)
(loop :for actor :in *actors* :do
(draw actor *currentcamera*)))
(with-fbo-bound (*god-fbo*)
(map-g #'god-rays-pipe *bs*
:res res
:time time
:sam *sam1*
:sun-pos (screen-coord res *light-pos*)))
(as-frame
(with-setf* ((depth-mask) nil
(cull-face) nil
(clear-color) (v! 0 0 0 1))
(map-g #'combine-god-pipe *bs*
:sam *sam*
:sam-god *god-sam*)))))
(def-simple-main-loop runplay
(:on-start #'initialize)
(draw!))
| 2,937 | Common Lisp | .lisp | 77 | 31.051948 | 84 | 0.483439 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a32dcab8691b6920c6d081d9afa38c76e315e7f7796fd85bbab3da3ffee4c66f | 9,134 | [
-1
] |
9,135 | draw.lisp | azimut_shiny/examples/planetes/draw.lisp | (in-package :shiny)
(defparameter *dirlight-pos* (v! 1000 1000 1000))
(defparameter *dirlight-mul* .5)
(defparameter *pointlight-pos* (v! 0 0 0))
(defun render-all-the-things (actor camera)
(update actor)
(draw actor camera))
(defgeneric draw (actor camera))
(defmethod draw ((actor piso) camera)
(with-slots (buf scale tex) actor
(map-g #'tex-pipe buf
:scale 1f0
:albedo tex
:cam-pos (pos camera)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor box) camera)
(with-slots (buf scale) actor
(map-g #'generic-pipe buf
:scale scale
:color (v! .001 .001 .001)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor sphere) camera)
(with-slots (buf scale) actor
(map-g #'circle-pipe buf
:scale scale
:color (v! 1 1 1)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor planet) camera)
(with-slots (buf albedo normal height roughness scale ao) actor
(map-g #'pbr-pipe buf
:scale scale
:uv-repeat 1f0
:uv-speed .01
:albedo albedo
:normal-map normal
:height-map height
:ao-map ao
:time (mynow)
:rough-map roughness
:oclussion-factor (v! 1 0 0 1)
:cam-pos (pos camera)
:light-pos (v! -60 90 -50)
:model-world (model->world actor)
:world-view (world->view camera)
:color-mult 100f0
:view-clip (projection camera))))
(defmethod draw ((actor pbr) camera)
(with-slots (buf albedo normal height roughness scale ao) actor
(map-g #'pbr-pipe buf
:uv-repeat 8f0
:uv-speed 1f0
:scale scale
:albedo albedo
:normal-map normal
:height-map height
:ao-map ao
:oclussion-factor (v! 0 1 0 1)
:time (mynow)
:rough-map roughness
:color-mult 1f0
:cam-pos (pos camera)
:light-pos *light-pos*
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor celestial-sphere) camera)
(with-slots (buf scale) actor
(with-setf* ((cull-face) :front
(depth-test-function) #'always
(depth-mask) nil)
(map-g #'light-pipe buf
:color (v! .5 .2 .5)
:scale 200f0
:light-pos (screen-coord (resolution (current-viewport)) *light-pos*)
:cam-pos (pos camera)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
| 3,011 | Common Lisp | .lisp | 84 | 26.404762 | 82 | 0.565307 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6ebd1680600daf30f37606e4b657c3d8d2b0ac4d3bb38b156b3fb709fceca31d | 9,135 | [
-1
] |
9,136 | actors.lisp | azimut_shiny/examples/planetes/actors.lisp | (in-package :shiny)
(defvar *actors* nil)
(defparameter *light-pos* (v! -60 100 -50)
;;(v! 0 10 -40)
)
(defparameter *light-color* (v! .9 .9 .9))
(defparameter *sun-intensity* 10f0)
(defparameter *exposure* .5f0)
(defparameter *radius-planet* 16000000f0)
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun delete-actor-name (actor-name)
(declare (symbol actor-name))
(setf *actors*
(delete-if
(lambda (x) (eq actor-name (slot-value x 'name)))
*actors*))
NIL)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*))
NIL)
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
(defclass actor ()
((name :initarg :name :initform (gensym))
(pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (v! 0 0 0) :accessor rot)
(buf :initarg :buf :initform (box))
(scale :initarg :scale :initform 1f0)))
(defclass pbr (actor)
((albedo :initarg :albedo)
(ao :initarg :ao)
(height :initarg :height)
(normal :initarg :normal)
(roughness :initarg :roughness)))
(defclass celestial-sphere (actor)
((buf :initform (sphere 20 20 20))))
(defclass piso (actor)
((buf :initform (lattice 50 50 2 2))
(tex :initform (get-tex "static/checker.dds"))))
(defclass box (actor)
((buf :initform (box 2 2 2))))
(defclass sphere (actor)
((buf :initform (sphere 1))))
(defun make-pbr (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj
(make-instance
'pbr
:buf (lattice 200 200 2 2 t)
:pos pos
:rot rot
:albedo (get-tex "static/32.Rock01-1k/rock01_albedo.jpg" nil t :rgb8)
:ao (get-tex "static/32.Rock01-1k/rock01_ao.jpg" nil t :r8)
:height (get-tex "static/32.Rock01-1k/rock01_height.jpg" nil t :r8)
:normal (get-tex "static/32.Rock01-1k/rock01_normal.jpg" nil t :rgb8)
:roughness (get-tex "static/32.Rock01-1k/rock01_roughness.jpg" nil t :r8))))
(push obj *actors*)
obj))
(defclass planet (actor)
((buf :initform (sphere))
(albedo :initform (get-tex "static/16.Plasterwall02-1k/plasterwall02_albedo.jpg" nil t :rgb8))
(ao :initform (get-tex "static/16.Plasterwall02-1k/plasterwall02_ao.jpg" nil t :r8))
(height :initform (get-tex "static/16.Plasterwall02-1k/plasterwall02_height.jpg" nil t :r8))
(normal :initform (get-tex "static/16.Plasterwall02-1k/plasterwall02_normal.jpg" nil t :rgb8))
(roughness :initform (get-tex "static/16.Plasterwall02-1k/plasterwall02_roughness.jpg" nil t :r8))))
(defun make-planet (&optional (pos (v! 0 0 0))
(scale 1f0)
(rot (q:identity)))
(let ((obj
(make-instance
'planet
:pos pos
:rot rot
:scale scale)))
(push obj *actors*)
obj))
(defun make-celestial-sphere ()
(let ((obj (make-instance 'celestial-sphere)))
(push obj *actors*)
obj))
(defun make-box (&optional (pos (v! 0 0 0)) (scale 1f0))
(let ((obj (make-instance 'box
:pos pos
:scale scale
:buf (box) ;;(box 3 10 1)
)))
(appendf *actors* (list obj))
obj))
(defun make-sphere (&optional
(pos (v! 0 0 0))
(scale 1f0))
(let ((obj (make-instance 'sphere
:pos pos
:scale scale)))
(push obj *actors*)
obj))
(defun make-piso (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj (make-instance 'piso :pos pos :rot rot)))
(push obj *actors*)
obj))
(defgeneric update (actor))
(defmethod update (actor))
(defmethod update ((actor pbr))
;;(setf (pos actor) (v! 0 -2 0))
)
(defmethod update ((actor sphere))
(with-slots (pos) actor
(let* ((old-pos pos)
(time (* 1f0 (mynow)))
(new-pos (v! (+ -4 (* 4 (sin time)))
0
(+ 60 (- (* 10 (cos time))))))
;;(new-pos (v! 0 0 0))
)
(setf pos new-pos)
(setf *light-pos* new-pos))))
(defmethod update ((actor celestial-sphere))
;;(setf (pos actor) (v! 0 0 0))
)
(defmethod update ((actor planet))
(with-slots (pos name) actor
(v3:incf pos (v! 0 0 .5))
(setf *light-pos* pos)
(if (or (> (z pos) 100)
(> (y pos) 30))
(progn
(v3:decf pos (v! 0 .5 0))
;;(delete-actor-name name)
)))
;; (with-slots (pos scale) actor
;; (setf pos (v! (* -60 (cos (mynow))) (* 100 (sin (mynow))) -100))
;; ;;(setf pos (v! 0 0 10))
;; (setf *light-pos* pos)
;; (setf scale 10f0))
)
(defmethod update ((actor box))
(with-slots (pos name) actor
(v3:incf pos (v! 0 0 .5))
(if (or (> (z pos) 100)
(> (y pos) 30))
(progn
(v3:decf pos (v! 0 .5 0))
;;(delete-actor-name name)
))))
| 5,308 | Common Lisp | .lisp | 154 | 27.636364 | 103 | 0.559587 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 23c277e776ab34cd026af9a93b15f7823f6c168ee10ed248719eb7fcaba3de8a | 9,136 | [
-1
] |
9,137 | render.lisp | azimut_shiny/examples/planetes/render.lisp | (in-package :shiny)
(defparameter *exposure* 1f0)
(defun-g treat-uvs ((uv :vec2))
(v! (x uv) (- 1.0 (y uv))))
;;--------------------------------------------------
;; 3D - g-pnt with tangent info in tb-data AND textures
(defun-g vert-with-tbdata
((vert g-pnt) (tb tb-data)
&uniform
(model-world :mat4)
(world-view :mat4)
(view-clip :mat4)
(scale :float)
;; Parallax vars
(light-pos :vec3)
(cam-pos :vec3))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(uv (treat-uvs (tex vert)))
(norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(t0 (normalize
(s~ (* model-world
(v! (tb-data-tangent tb) 0))
:xyz)))
(n0 (normalize
(s~ (* model-world
(v! norm 0))
:xyz)))
(t0 (normalize (- t0 (* (dot t0 n0) n0))))
(b0 (cross n0 t0))
(tbn (mat3 t0 b0 n0)))
(values clip-pos
uv
norm
(s~ world-pos :xyz)
tbn
(* tbn light-pos)
(* tbn cam-pos)
(* tbn (s~ world-pos :xyz)))))
(defun-g frag-tex-tbn ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d)
(normap :sampler-2d)
(height-map :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; Parallax
(tan-cam-dir (- tan-cam-pos tan-frag-pos))
(newuv (parallax-mapping uv tan-cam-dir height-map .1))
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo newuv) :xyz)
(vec3 2.2)))
;;(normal (normalize frag-norm))
(nfm (norm-from-map normap newuv))
(normal (* tbn nfm))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
)
(values
;; (v! final-color 1)
;; (v! 1 1 1 1)
;;frag-pos
(normalize frag-norm))))
(defpipeline-g generic-tex-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (frag-tex-tbn :vec2 :vec3 :vec3 :mat3
;; Parallax
:vec3 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - g-pnt mesh without tangents
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(scale :float))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(tex (tex vert))
(world-norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
world-norm
(s~ world-pos :xyz))))
;; http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
(defun-g frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(time :float)
(color :vec3)
(cam-pos :vec3))
(let* (
;;--------------------
(final-color color)
(final-color
(dir-light-apply final-color
(v! 20 20 20)
(v! 0 1000 1000)
frag-pos
frag-norm))
(final-color
(point-light-apply final-color
(v! 10 10 10)
*light-pos*
frag-pos
frag-norm
1f0
0.014 0.07))
;; (final-color (apply-fog final-color
;; (v! .5 .6 .7)
;; (length (- frag-pos cam-pos))
;; cam-pos
;; frag-pos))
;; AO FAKE
;; (final-color (mix final-color
;; (v! 0 0 0)
;; (* (vec3 (y (- frag-pos (v! 0 -2 0))))
;; (vec3 (y (- frag-pos (v! 0 0)))))))
;; (fog (get-exponential-height-fog
;; frag-pos
;; cam-pos
;; (let ((fog-density .05)
;; (fog-height-falloff .5)
;; (fog-height 3)
;; (cos-terminator-angle 10))
;; (v! (* fog-density (exp2 (* (- fog-height-falloff)
;; (- (z cam-pos) fog-height))))
;; fog-height-falloff
;; cos-terminator-angle))
;; (v! 200 0 0)))
;;(final-color (mix final-color (s~ fog :xyz) (z fog)))
;; (final-color
;; (fog-linear-apply
;; final-color
;; (v! .7 .6 .5)
;; frag-pos
;; cam-pos
;; 0 1000))
)
(values (v! final-color 1)
(v! 0 1 0 1))))
;;--------------------------------------------------
;; 2D - Post Processing
(defun-g vert-2d ((vert :vec2))
(let* ((uv (+ .5 (* .5 vert))))
(values (v! vert 0 1)
uv)))
(defun-g frag-2d ((uv :vec2) &uniform (sam :sampler-2d))
(let* ((color (s~ (texture sam uv) :xyz))
;; (color
;; (s~ (nineveh.anti-aliasing:fxaa3 uv sam (v2! (/ 1 320f0))) :xyz))
(ldr (nineveh.tonemapping:tone-map-reinhard color *exposure*))
(luma (rgb->luma-bt601 ldr))
)
;;(v! (pow ldr (vec3 2.2)) 1)
(v! ldr luma)
;;(v! (- 1 (x color)) 0 0 1)
;;(v! color 1)
;;(v! ldr 1)
))
(defpipeline-g generic-2d-pipe (:points)
:fragment (frag-2d :vec2))
;;--------------------------------------------------
;; 3D - g-pnt mesh with light shading
(defpipeline-g generic-pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - Lamp solid color
(defun-g light-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(light-pos :vec2)
(color :vec3))
(atmosphere (normalize frag-pos)
(v! 0 6372000 0)
(v! 0 0 -100)
*sun-intensity*
*radius-planet*
6471000f0
(v! .0000055 .000013 .0000224)
.000021
8000f0 ;; rayleigh scale height
1200 ;; mie scale height
.758))
(defpipeline-g light-pipe ()
:vertex (vert g-pnt)
:fragment (light-frag :vec2 :vec3 :vec3))
(defun-g frag-tex ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (* 10 (s~ (texture albedo (* 20 uv)) :xyz)))
;;(color (expt color (vec3 2.2)))
;;--------------------
;; Fog
;;(fog-color (v! 0 1 1))
(fog-color (* 1 (v! 0.14901961 0.3019608 0.69803923)))
;;(fog-factor (fog-linear frag-pos cam-pos .1 30))
;;(fog-factor (fog-exp2 frag-pos cam-pos .16))
;;(normal (normalize frag-norm))
;;(nfm (norm-from-map normap uv))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
;;(color (fog-exp2-apply color (v! .2 0 .2) frag-pos cam-pos .1))
(color (apply-fog color
(v! .5 .6 .7)
(length (- frag-pos cam-pos))
cam-pos
(normalize (- frag-pos cam-pos)))))
(v! color 1)))
(defpipeline-g tex-pipe ()
:vertex (vert g-pnt)
:fragment (frag-tex :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; (defun-g pbr-frag ((uv :vec2)
;; (frag-norm :vec3)
;; (frag-pos :vec3)
;; (tbn :mat3)
;; (tan-light-pos :vec3)
;; (tan-cam-pos :vec3)
;; (tan-frag-pos :vec3)
;; &uniform
;; (time :float)
;; (cam-pos :vec3)
;; (rough-map :sampler-2d)
;; (albedo :sampler-2d)
;; (normal-map :sampler-2d))
;; (let* (
;; ;;(uv (treat-uvs uv))
;; (color (expt (s~ (texture albedo uv) :xyz) (vec3 2.2)))
;; ;;(normal (normalize frag-norm))
;; (normal (normalize (norm-from-map normal-map uv)))
;; (normal (normalize (* tbn normal)))
;; (light-pos (v! (* 10 (cos time)) 0 (* 10 (sin time))))
;; (final-color color)
;; (final-color
;; (dir-light-apply final-color (v! 10 10 10) (v! 10 0 0)
;; frag-pos frag-norm))
;; (final-color
;; (point-light-apply final-color
;; (v! 1 1 1)
;; light-pos
;; frag-pos
;; normal
;; 1 .014 .07))
;; ;; (final-color
;; ;; (fog-exp2-apply final-color
;; ;; (v! .5 .6 .7) frag-pos cam-pos .1))
;; )
;; (v! final-color 1)))
(defun-g pbr-direct-lum ((light-pos :vec3)
(frag-pos :vec3)
(v :vec3)
(n :vec3)
(roughness :float)
(f0 :vec3)
(metallic :float)
(color :vec3))
(let* ((l (normalize (- light-pos frag-pos)))
(h (normalize (+ v l)))
(distance (length (- light-pos frag-pos)))
;;(attenuation (/ 1 (* distance distance)))
(attenuation 1f0)
(radiance (* (v! 5 5 5) attenuation))
;; pbr - cook-torrance brdf
(ndf (distribution-ggx n h roughness))
(g (geometry-smith n v l roughness))
(f (fresnel-schlick (max (dot h v) 0) f0))
;;
(ks f)
(kd (- 1 ks))
(kd (* kd (- 1 metallic)))
;;
(numerator (* ndf g f))
(denominator (+ .001
(* (max (dot n v) 0)
(max (dot n l) 0)
4)))
(specular (/ numerator denominator))
;; add to outgoing radiance lo
(n-dot-l (max (dot n l) 0))
(lo (* (+ specular (/ (* kd color) 3.14159265359))
radiance
n-dot-l)))
lo))
(defun-g pbr-point-lum ((light-pos :vec3)
(frag-pos :vec3)
(v :vec3)
(n :vec3)
(roughness :float)
(f0 :vec3)
(metallic :float)
(color :vec3))
(let* ((l (normalize (- light-pos frag-pos)))
(h (normalize (+ v l)))
(distance (length (- light-pos frag-pos)))
(attenuation (/ 1f0 (* distance distance)))
(radiance (* (v! 10 10 10) attenuation
))
;; pbr - cook-torrance brdf
(ndf (distribution-ggx n h roughness))
(g (geometry-smith n v l roughness))
(f (fresnel-schlick (max (dot h v) 0) f0))
;;
(ks f)
(kd (- 1 ks))
(kd (* kd (- 1 metallic)))
;;
(numerator (* ndf g f))
(denominator (+ .001
(* (max (dot n v) 0)
(max (dot n l) 0)
4)))
(specular (/ numerator denominator))
;; add to outgoing radiance lo
(n-dot-l (max (dot n l) 0))
(lo (* (+ specular (/ (* kd color) 3.141516))
radiance
n-dot-l)))
lo))
(defun-g pbr-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(oclussion-factor :vec4)
(light-pos :vec3)
(time :float)
(color-mult :float)
(cam-pos :vec3)
(ao-map :sampler-2d)
(rough-map :sampler-2d)
(albedo :sampler-2d)
(height-map :sampler-2d)
(normal-map :sampler-2d)
(uv-repeat :float)
(uv-speed :float))
(let* (;;(uv (treat-uvs uv))
(uv (+ (* uv uv-repeat)
(v! 0 (* uv-speed time))))
(roughness (x (texture rough-map uv)))
(ao (x (texture ao-map uv)))
(color (* color-mult (expt (s~ (texture albedo uv) :xyz)
(vec3 2.2))))
(color (* color (v! .4 .1 .9)))
(normal (normalize (norm-from-map normal-map uv)))
(normal (normalize (* tbn normal)))
;; (light-pos (v! (+ -10 (* 20 (+ .5 (* .5 (sin time)))))
;; 1
;; (+ -10 (* 20 (+ .5 (* .5 (cos time)))))))
;; metallic
(metallic .1)
(f0 (vec3 .04))
;;(f0 color)
(f0 (mix f0 color metallic))
;; pbr - reflectance equation
(lo (vec3 0f0))
(n normal)
(v (normalize (- cam-pos frag-pos)))
;; ---------- START
;; (l (normalize (- light-pos frag-pos)))
;; (h (normalize (+ v l)))
;; (distance (length (- light-pos frag-pos)))
;; ;;(attenuation (/ 1 (* distance distance)))
;; (attenuation 1f0)
;; (radiance (* (v! 5 5 5) attenuation))
;; ;; pbr - cook-torrance brdf
;; (ndf (distribution-ggx n h roughness))
;; (g (geometry-smith n v l roughness))
;; (f (fresnel-schlick (max (dot h v) 0) f0))
;; ;;
;; (ks f)
;; (kd (- 1 ks))
;; (kd (* kd (- 1 metallic)))
;; ;;
;; (numerator (* ndf g f))
;; (denominator (+ .001
;; (* (max (dot n v) 0)
;; (max (dot n l) 0)
;; 4)))
;; (specular (/ numerator denominator))
;; ;; add to outgoing radiance lo
;; (n-dot-l (max (dot n l) 0))
;; (lo (* (+ specular (/ (* kd color) 3.141516))
;; radiance
;; n-dot-l))
;; (lo (pbr-direct-lum
;; light-pos
;; frag-pos
;; v
;; n
;; roughness
;; f0
;; metallic
;; color))
(lo (+ lo (pbr-point-lum light-pos
frag-pos
v
n
roughness
f0
metallic
color)))
(lo (+ lo (pbr-direct-lum (v! 0 1000 1000)
frag-pos
v
n
roughness
f0
metallic
color)))
;; ---------- END
(ambient (* color ao (vec3 .03)))
(final-color (+ ambient lo))
;; AO trickery
;;(final-color (vec3 (fract (length (- frag-pos (v! 0 0 -10))))))
;; (pos (- frag-pos (v! 0 0 -10)))
;; (size (/ (v! 3 10 1) 2))
;; (d (- (abs pos) size))
;; (final-color (mix final-color
;; (v! .001 .001 .001)
;; (- 1 (saturate (vec3 (length (max d 0)))))))
(final-color
(fog-exp2-apply
final-color
;;(v! .4 .9 .9)
;;(v! .1 .01 .01)
(v! 0 0 0)
frag-pos
cam-pos .003
;;50 3000
)))
(values (v! final-color 1)
oclussion-factor)))
(defpipeline-g pbr-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (pbr-frag :vec2 :vec3 :vec3
:mat3 :vec3 :vec3 :vec3))
;;--------------------------------------------------
(defun-g get-height-fxp ((in-position :vec3)
(in-cloud-min-max :vec2))
(let ((height-fraction (/ (- (z in-position)
(x in-cloud-min-max))
(- (y in-cloud-min-max)
(x in-cloud-min-max)))))
(saturate height-fraction)))
;;--------------------------------------------------
;; God
(defpipeline-g god-rays-pipe (:points)
:fragment (god-rays-frag :vec2))
(defun-g circle-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(time :float)
(color :vec3)
(cam-pos :vec3))
(let* ((final-color color))
(values final-color
(v! 1 0 0 1))))
(defpipeline-g circle-pipe ()
:vertex (vert g-pnt)
:fragment (circle-frag :vec2 :vec3 :vec3))
| 19,894 | Common Lisp | .lisp | 530 | 25.681132 | 78 | 0.388662 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | ffdeb3317f990bae5049d0ed7844b5378e72730948f225174d6493e44f7c7e39 | 9,137 | [
-1
] |
9,138 | main.lisp | azimut_shiny/examples/cv/main.lisp | (in-package :shiny)
;; CV> (query-video "/home/sendai/videos/sally.mp4")
;; size:7600 n-size:144 w:50 h:50
(defun show-video (filename &optional (sec 30))
(with-captured-file (capture filename)
(skip-to capture sec)
(let ((frame (cv:query-frame capture)))
(cv:with-ipl-images ((img (cv:size 50 50) cv:+ipl-depth-8u+ 3))
(cv:resize frame img)
(cepl.types::%memcpy
(cepl:pointer *car*)
(cffi:foreign-slot-value
img
'(:struct cv::ipl-image)
'cv::image-data)
1800)))))
(defparameter *step*
(make-stepper (seconds .5) (seconds 1)))
(defvar *car* nil) (defvar *tex* nil) (defvar *sam* nil)
(defun initialize ()
;;(setf (clear-color) (v! .2 .2 .2 0))
(unless *car*
(setf *car* (make-c-array nil
:dimensions '(30 30)
:element-type :short))
(setf *tex* (make-texture *car* :element-type :rgb))
(setf *sam* (cepl:sample *tex*))))
(defun-g vert ((vert g-pnt))
(let ((pos (pos vert)))
(values (v! pos 1)
(+ .5 (* .5 pos)))))
(defun-g frag ((uv :vec3) &uniform (tarr :sampler-2d) (resolution :vec2))
(let ((color (texture tarr (s~ uv :xy))))
color))
(defun-g frag ((uv :vec3) &uniform (tarr :sampler-2d) (resolution :vec2))
(v! 1 1 1 0))
(defpipeline-g pipe ()
(vert g-pnt)
(frag :vec3))
(defun draw! ()
;; (when (funcall *step*)
;; (push-g *car* (texref *tex*))
;; ;; (show-video "/home/sendai/videos/sally.mp4" 20)
;; )
(let ((res (surface-resolution (current-surface))))
(setf (resolution (current-viewport))
res)
(as-frame
(map-g #'pipe (get-quad-stream-v2)
:tarr *sam*
:resolution res))))
(def-simple-main-loop runplay (:on-start #'initialize)
(draw!))
| 1,824 | Common Lisp | .lisp | 53 | 28.396226 | 73 | 0.569397 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b59fabfc6bd677771cdf0b9b0faa3b080ad956422d4e65dc244f94baeec83f99 | 9,138 | [
-1
] |
9,139 | camera.lisp | azimut_shiny/examples/dof/camera.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (q:identity) :accessor rot)
(near :initarg :near :initform .1 :accessor near)
(far :initarg :far :initform 400f0 :accessor far)
(frame-size
:initarg :frame-size :initform nil :accessor frame-size)
(buf :initform (box))))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initform 60f0 :accessor fov)))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *currentcamera* *camera*)
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera)
(:method ((camera pers))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:perspective
(x fs)
(y fs)
(near camera)
(far camera)
(fov camera))))
(:method ((camera orth))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:orthographic
(x fs)
(y fs)
(near camera)
(far camera)))))
(defmethod update ((camera orth))
(setf (pos camera) (v! 0 0 0))
(setf (frame-size camera) (v2! 5))
;; (setf (rot camera) (v! 0 0 0))
(setf (rot camera)
;; TOP
;; (q:from-axis-angle (v! 1 0 0)
;; (radians -90))
;; FRONT
(q:from-axis-angle (v! 1 0 0)
(radians -45))
))
(defparameter *crotate* nil)
(defparameter *head* nil)
(defparameter *wave* 1f0)
(defparameter *cam-vector* (v! 1 0 0))
(defmethod update ((camera pers))
(with-slots (pos rot) camera
;;(setf rot (q:identity))
;;(setf rot (q:from-axis-angle (v! 0 1 0) (radians 90)))
;;(setf rot (q:from-axis-angle (v! 0 0 1) (radians 80)))
;;(setf pos (v! 0 0 (mod (mynow) 40)))
(setf pos (v! 0 0 25))
;; (setf pos (v! (* 1 (cos (* .5 (mynow))))
;; (* 1 (sin (* .5 (mynow))))
;; (+ 20 (* .1 (cos (* .5 (mynow)))))))
(setf rot (q:from-axis-angle (v! 0 1 0) (radians 15)))
;;(setf rot (q:look-at (v! 0 1 0) pos (v! 0 -1 0)))
))
| 2,314 | Common Lisp | .lisp | 65 | 30.123077 | 61 | 0.566265 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6f4e2fdbeb8a46c88b971422143943cdaed79525455623e0932721c4f01e428b | 9,139 | [
-1
] |
9,140 | main.lisp | azimut_shiny/examples/dof/main.lisp | (in-package :shiny)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *bs* nil)
(defvar *sam-depth* nil)
(defvar *coc-fbo* nil)
(defvar *coc-sam* nil)
(defvar *dimensions* nil)
(defvar *texel-size* nil)
(defun initialize ()
(when *coc-fbo*
(free *coc-fbo*))
;;(setf *coc-fbo* (make-fbo '(0 :element-type :float)))
(setf *coc-fbo* (make-fbo '(0 :element-type :r8)))
(setf *coc-sam* (cepl:sample (attachment-tex *coc-fbo* 0)))
;;--------------------------------------------------
;; Buffer stream for single stage pipelines
(unless *bs*
(setf *bs* (make-buffer-stream nil :primitive :points)))
;;--------------------------------------------------
;; HDR fbo(s)
(when *fbo*
(free *fbo*))
(setf *fbo* (make-fbo (list 0 :element-type :rgb16f)
:d))
(setf *sam*
(cepl:sample (attachment-tex *fbo* 0) :wrap :clamp-to-edge))
(setf *sam-depth*
(cepl:sample (attachment-tex *fbo* :d)))
(setf (clear-color) (v! 0 0 0 1))
(setf *dimensions* (dimensions (attachment-tex *fbo* 0)))
;; https://docs.unity3d.com/Manual/SL-PropertiesInPrograms.html
(setf *texel-size* (v! (/ 1 (car *dimensions*))
(/ 1 (lastcar *dimensions*))))
;;--------------------------------------------------
(setf *actors* nil)
(make-celestial-sphere)
(dotimes (i 20)
(make-box (v! (+ -5 (random 10f0)) (+ -5 (random 10f0)) i)))
(make-piso (v! 0 -2 0) (q:from-axis-angle (v! 1 0 0) (radians 30)))
NIL)
(defun draw! ()
(let ((res (surface-resolution (current-surface))))
(setf (resolution (current-viewport)) res)
(update *currentcamera*)
(update-all-the-things *actors*)
(with-fbo-bound (*fbo*)
(clear-fbo *fbo*)
(loop :for actor :in *actors* :do
(draw actor *currentcamera*)))
(with-setf* ((depth-mask) nil
(cull-face) nil
(depth-test-function) #'always)
(with-fbo-bound (*coc-fbo*)
(map-g #'dof-pipe *bs*
:tex *sam-depth*))
(as-frame
(map-g #'bokeh-pass *bs*
:texel-size *texel-size*
:scene *sam*)))
;; (as-frame
;; ;; (with-setf* ((depth-mask) nil
;; ;; (cull-face) nil
;; ;; (clear-color) (v! 0 0 0 1)
;; ;; (depth-test-function) #'always)
;; (map-g #'generic-2d-pipe *bs*
;; :sam *sam*)
;; ;; )
;; )
))
(def-simple-main-loop runplay (:on-start #'initialize)
(draw!))
| 2,539 | Common Lisp | .lisp | 72 | 29.736111 | 69 | 0.516461 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | ce4d308b98163f8823716927732a8d0014ccbd3ed97410cbe22af42631b211dc | 9,140 | [
-1
] |
9,141 | draw.lisp | azimut_shiny/examples/dof/draw.lisp | (in-package :shiny)
(defparameter *dirlight-pos* (v! 1000 1000 1000))
(defparameter *dirlight-mul* 1f0)
(defparameter *pointlight-pos* (v! 0 2 0))
(defun render-all-the-things (actor camera)
(update actor)
(draw actor camera))
(defgeneric draw (actor camera))
(defmethod draw (actor camera))
;; (defmethod draw ((actor camera) camera)
;; (with-slots (buf tex) actor
;; (map-g #'generic-tex-pipe buf
;; :time (mynow)
;; :scale 1f0
;; :tex tex
;; ;; :color (v! .1 .1 .8)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))))
(defmethod draw ((actor piso) camera)
(with-slots (buf scale tex) actor
(map-g #'generic-pipe buf
:scale scale
:color (v! .2 .2 .2)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))
;; (map-g #'tex-pipe buf
;; :scale 1f0
;; :albedo tex
;; :cam-pos (pos camera)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))
))
(defmethod draw ((actor box) camera)
(with-slots (buf scale) actor
(map-g #'generic-pipe buf
:scale scale
:color (v! .9 .9 .9)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
;; (defmethod draw ((actor sphere) camera)
;; (with-slots (buf scale) actor
;; (map-g #'generic-pipe buf
;; :time (mynow)
;; :scale scale
;; :color (v! 1 1 1)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))))
(defmethod draw ((actor celestial-sphere) camera)
(with-slots (buf scale) actor
(with-setf* ((cull-face) :front
;;(depth-test-function) #'always
;;(depth-mask) nil
)
(map-g #'generic-pipe buf
:scale 10f0
:color (v! .1 .9 .9)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))
;; (map-g #'light-pipe buf
;; :color (v! .5 .2 .5)
;; :scale 20f0
;; :time (mynow)
;; :model-world (model->world actor)
;; :world-view (world->view camera)
;; :view-clip (projection camera))
)))
| 2,593 | Common Lisp | .lisp | 72 | 30.402778 | 49 | 0.534819 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a2cb8bc240ef92b1ac0ef525b27ea2f7170ae2fafb73875f413d78b1d0051e6e | 9,141 | [
-1
] |
9,142 | actors.lisp | azimut_shiny/examples/dof/actors.lisp | (in-package :shiny)
(defvar *actors* nil)
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun delete-actor-name (actor-name)
(declare (keyword actor-name))
(setf *actors*
(delete-if
(lambda (x) (eq actor-name (slot-value x 'name)))
*actors*))
NIL)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*))
NIL)
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
(defclass actor ()
((name :initarg :name :initform (gensym))
(pos :initarg :pos :initform (v! 0 0 0) :accessor pos)
(rot :initarg :rot :initform (v! 0 0 0) :accessor rot)
(buf :initarg :buf :initform (box))
(scale :initarg :scale :initform 1f0)))
(defclass celestial-sphere (actor)
((buf :initform (sphere 10 10 10))))
(defclass piso (actor)
((buf :initform (lattice 50 50 2 2))
(tex :initform (get-tex "static/checker.dds"))))
(defclass box (actor)
((buf :initform (box 2 2 2))))
(defclass sphere (actor)
((buf :initform (sphere 1))))
(defun make-celestial-sphere ()
(let ((obj (make-instance 'celestial-sphere)))
(push obj *actors*)
obj))
(defun make-box (&optional (pos (v! 0 0 0)))
(let ((obj (make-instance 'box :pos pos)))
(push obj *actors*)
obj))
(defun make-sphere ()
(let ((obj (make-instance 'sphere)))
(push obj *actors*)
obj))
(defun make-piso (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj (make-instance 'piso :pos pos :rot rot)))
(push obj *actors*)
obj))
(defgeneric update (actor))
(defmethod update (actor))
(defmethod update ((actor celestial-sphere))
(setf (rot actor) (q:from-axis-angle (v! 0 1 0)
(radians 90))))
(defmethod update ((actor box))
;;(setf (pos actor) (v! 0 -.5 0))
;; (setf (slot-value actor 'scale) .5)
;; (setf (rot actor)
;; (q:from-axis-angle
;; (v! 1 1 1)
;; (radians (* 360 (sync (* .2 (mynow)))))))
)
| 2,275 | Common Lisp | .lisp | 70 | 28.271429 | 68 | 0.596259 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d64c025fb210fcaa190612d9833cb7c3d06f251391ba3d4cc71514f8fecfd953 | 9,142 | [
-1
] |
9,143 | render.lisp | azimut_shiny/examples/dof/render.lisp | (in-package :shiny)
(defparameter *exposure* 10f0)
(defun-g treat-uvs ((uv :vec2))
(v! (x uv) (- 1.0 (y uv))))
;;--------------------------------------------------
;; 3D - g-pnt with tangent info in tb-data AND textures
(defun-g vert-with-tbdata
((vert g-pnt) (tb tb-data)
&uniform
(model-world :mat4)
(world-view :mat4)
(view-clip :mat4)
(scale :float)
;; Parallax vars
(light-pos :vec3)
(cam-pos :vec3))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(uv (treat-uvs (tex vert)))
(norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(t0 (normalize
(s~ (* model-world
(v! (tb-data-tangent tb) 0))
:xyz)))
(n0 (normalize
(s~ (* model-world
(v! norm 0))
:xyz)))
(t0 (normalize (- t0 (* (dot t0 n0) n0))))
(b0 (cross n0 t0))
(tbn (mat3 t0 b0 n0)))
(values clip-pos
uv
norm
(s~ world-pos :xyz)
tbn
(* tbn light-pos)
(* tbn cam-pos)
(* tbn (s~ world-pos :xyz)))))
(defun-g frag-tex-tbn ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d)
(normap :sampler-2d)
(height-map :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; Parallax
(tan-cam-dir (- tan-cam-pos tan-frag-pos))
(newuv (parallax-mapping uv tan-cam-dir height-map .1))
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo newuv) :xyz)
(vec3 2.2)))
;;(normal (normalize frag-norm))
(nfm (norm-from-map normap newuv))
(normal (* tbn nfm))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
)
(values
;; (v! final-color 1)
;; (v! 1 1 1 1)
;;frag-pos
(normalize frag-norm))))
(defpipeline-g generic-tex-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (frag-tex-tbn :vec2 :vec3 :vec3 :mat3
;; Parallax
:vec3 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - g-pnt mesh without tangents
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(scale :float))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(tex (tex vert))
(world-norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
world-norm
(s~ world-pos :xyz))))
;; http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
(defun-g frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3) &uniform
(time :float) (color :vec3) (cam-pos :vec3))
(let* ((light-pos *pointlight-pos*)
(light-color (v! 1 .7 .4))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(direc-light-strength
(* *dirlight-mul*
light-color
(saturate
(dot frag-norm
(normalize (- *dirlight-pos* frag-pos))))))
(point-light-strength
(* light-color
light-strength
;; saturate?
(saturate (dot frag-norm dir-to-light))
;; attenuation - constant, linear, cuadratic
(/ 1f0 (+ 1f0
(* .014 (length vec-to-light))
(* .07 (pow (length vec-to-light)
2))))))
(final-color (+ (* color point-light-strength)
(* color direc-light-strength))))
(v! final-color 1)
;;(v! color 0)
))
;;--------------------------------------------------
;; 2D - Post Processing
(defun-g vert-2d ((vert :vec2))
(let* ((uv (+ .5 (* .5 vert))))
(values (v! vert 0 1)
uv)))
(defparameter *exposure* .09)
(defun-g frag-2d ((uv :vec2) &uniform (sam :sampler-2d))
(let* ((color (s~ (texture sam uv) :xyz))
;; (color
;; (s~ (nineveh.anti-aliasing:fxaa3 uv sam (v2! (/ 1 320f0))) :xyz))
(ldr (nineveh.tonemapping:tone-map-reinhard color *exposure*))
(luma (rgb->luma-bt601 ldr))
)
;;(v! (pow ldr (vec3 2.2)) 1)
(v! ldr luma)
;;(v! color 1)
;;(v! ldr 1)
))
(defpipeline-g generic-2d-pipe (:points)
:fragment (frag-2d :vec2))
;;--------------------------------------------------
;; 3D - g-pnt mesh with light shading
(defpipeline-g generic-pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - Lamp solid color
(defun-g light-frag
((uv :vec2) (frag-norm :vec3) (frag-pos :vec3)
&uniform (color :vec3) (time :float))
(nineveh.noise:perlin-noise
(+ (* .1 time) frag-pos))
)
(defpipeline-g light-pipe ()
:vertex (vert g-pnt)
:fragment (light-frag :vec2 :vec3 :vec3))
(defun-g frag-tex ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (* 10 (s~ (texture albedo (* 20 uv)) :xyz)))
;;(color (expt color (vec3 2.2)))
;;--------------------
;; Fog
;;(fog-color (v! 0 1 1))
(fog-color (* 1 (v! 0.14901961 0.3019608 0.69803923)))
;;(fog-factor (fog-linear frag-pos cam-pos .1 30))
;;(fog-factor (fog-exp2 frag-pos cam-pos .16))
;;(normal (normalize frag-norm))
;;(nfm (norm-from-map normap uv))
;; (direc-light-strength
;; (* *dirlight-mul*
;; light-color
;; (saturate
;; (dot normal
;; (normalize (- *dirlight-pos* frag-pos))))))
;; (point-light-strength
;; (* light-color
;; light-strength
;; ;; saturate?
;; (saturate (dot normal dir-to-light))
;; ;; attenuation - constant, linear, cuadratic
;; (/ 1f0 (+ 1f0
;; (* .014 (length vec-to-light))
;; (* .07 (pow (length vec-to-light)
;; 2))))))
;; (final-color
;; (+ (* color point-light-strength)
;; (* color direc-light-strength)))
)
(v! ;;(mix fog-color color (vec3 (saturate fog-factor)))
color
1
)))
(defpipeline-g tex-pipe ()
:vertex (vert g-pnt)
:fragment (frag-tex :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; Billboard
;; https://www.youtube.com/watch?v=puOTwCrEm7Q
;; - basis vectors:
;; -- 3 vectors are true orthogonal
;; -- fill space (span)
;;
(defparameter *quad-3d*
(list '(-1 -1 0) '( 1 -1 0)
'( 1 1 0) '(-1 1 0)))
(defun-g billboard-vert ((pos :vec3)
&uniform
(time :float)
(world-view :mat4))
(* world-view (v! .5 0 18.5 1)))
(defun-g billboard-geom (&uniform (camera-pos :vec3)
(view-clip :mat4))
(declare (output-primitive :kind :triangle-strip :max-vertices 4))
(let* ((p (s~ (gl-position (aref gl-in 0)) :xyz))
(to-camera (normalize (- camera-pos p)))
;;(to-camera (v! (x to-camera) 0 (z to-camera)))
(up (v! 0 1 0))
(right (cross to-camera up)))
;;
(decf p (* .5 right))
(emit ()
(* view-clip (v! p 1))
(v! 0 0))
;;
(incf (y p) 1f0)
(emit ()
(* view-clip (v! p 1))
(v! 0 1))
;;
(decf (y p) 1f0)
(incf p right)
(emit ()
(* view-clip (v! p 1))
(v! 1 0))
;;
(incf (y p) 1f0)
(emit ()
(* view-clip (v! p 1))
(v! 1 1))
(end-primitive)
(values)))
(defun-g billboard-frag ((uv :vec2) &uniform (tex :sampler-2d) (time :float))
(let* ((color (expt (texture tex (treat-uvs (* (m2:rotation-from-euler (radians (+ 0 (sin (* 5 time))))) uv))) (vec4 2.2) )))
color))
(defpipeline-g billboard-pipe (:points)
:vertex (billboard-vert :vec3)
:geometry (billboard-geom)
:fragment (billboard-frag :vec2))
;;--------------------------------------------------
;; https://forum.unity.com/threads/lineareyedepth-and-linear01depth-in-a-compute-shader-returning-infinity.487608/
;; (defun-g linear-eye-depth ((d :float))
;; (let* ((near .1)
;; (far 400f0)
;; (x (- 1 (/ near far)))
;; (y (/ near far))
;; (z (/ x near))
;; (w (/ y near)))
;; (/ 1 (+ (* z d) w))))
;; (defun-g linear-eye-depth ((d :float))
;; (let ((d (- 1 d))
;; (n .1)
;; (f 400f0))
;; (/ (* n f)
;; (+ f (* d (- n f))))))
(defun-g dof-frag ((uv :vec2) &uniform (tex :sampler-2d))
(let* ((depth (x (texture tex uv)))
(depth (linear-eye-depth depth))
(focus-distance 20f0)
(focus-range 5f0)
(coc (/ (- depth focus-distance)
focus-range))
(coc (clamp coc -1 1)))
coc))
(defpipeline-g dof-pipe (:points)
:fragment (dof-frag :vec2))
;;--------------------------------------------------
;; Bokeh - DOF
(defun-g bokeh-frag ((uv :vec2)
&uniform
(scene :sampler-2d)
(texel-size :vec2))
(let ((color (v! 0 0 0))
(weight 0))
;; (for (u -4) (<= u 4) (++ u)
;; (for (v -4) (<= v 4) (++ v)
;; (let (;;(o (* uv texel-size))
;; (o uv)
;; )
;; (when (<= (length o) 4)
;; (multf o (* texel-size 2))
;; (incf color (s~ (texture scene (+ uv o)) :xyz))
;; (incf weight 1)))))
;; (v! (* color (/ 1f0 weight))
;; 1)
(texture scene uv)
)
)
(defpipeline-g bokeh-pass (:points)
:fragment (bokeh-frag :vec2))
| 12,005 | Common Lisp | .lisp | 341 | 26.469208 | 127 | 0.443354 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 61916fce541abbeafc255daa02b2e2ac69abc4fe610d3d875e87e6b74bbb02b5 | 9,143 | [
-1
] |
9,148 | particles.lisp | azimut_shiny/examples/brio/particles.lisp | (in-package #:shiny)
;;--------------------------------------------------
;; PARTICLE LOGIC
;;--------------------------------------------------
;; Uses TTFS to delegate to the gpu all the movement logic.
;; Needs *bs* for the single stage pipeline.
;; TODO:
;; - Instacing for geomtry rendending of particles
;; - Create CL class to contain all the components nicely
;; and more importantly easily allow multiple particle systems.
;; (init-particles)
;; (update-particles)
;; (draw-particles)
;; (swap-particles)
(defvar *gar-src* NIL)
(defvar *str-src* NIL)
(defvar *tfs-src* NIL)
(defvar *gar-dst* NIL)
(defvar *str-dst* NIL)
(defvar *tfs-dst* NIL)
(defvar *blend* (make-blending-params))
(defstruct-g pdata
(pos :vec3)
(dir :vec3)
(life :float))
;;--------------------------------------------------
;; Init particles
(defun-g pinit-vert (&uniform (time :float))
(let ((id (* .001 (+ time gl-vertex-id))))
(values (v! 0 0 0 0)
(:feedback (v! 0 0 0))
(:feedback (v! 0 0 0))
(:feedback 0f0))))
(defpipeline-g pinit-pipe (:points) :vertex (pinit-vert))
(defun init-particles (&optional (n-particles 1000))
(unless *gar-src*
(setf *gar-src* (make-gpu-array
nil
:dimensions n-particles
:element-type 'pdata)
*gar-dst* (make-gpu-array
nil
:dimensions n-particles
:element-type 'pdata))
(setf *str-src* (make-buffer-stream *gar-src* :primitive :points)
*str-dst* (make-buffer-stream *gar-dst* :primitive :points))
(setf *tfs-src* (make-transform-feedback-stream *gar-src*)
*tfs-dst* (make-transform-feedback-stream *gar-dst*))
(reset-particles)))
;;--------------------------------------------------
;; Free & Reset
(defun free-particles ()
;; (free *tfs-src*)
;; (free *tfs-dst*)
(free *str-src*)
(free *str-dst*)
(free *gar-src*)
(free *gar-dst*)
(setf *str-src* NIL
*str-dst* NIL
*gar-src* NIL
*gar-dst* NIL))
(defun reset-particles ()
(with-transform-feedback (*tfs-src*)
(map-g #'pinit-pipe *bs*))
(with-transform-feedback (*tfs-dst*)
(map-g #'pinit-pipe *bs*))
(values))
;;--------------------------------------------------
;; Update particles
;; - Fudge initial alpha
;; - Color overtime to fade in/out with the alpha
;; - random init ROTATION
;; - ROTATION over lifetime
;; - random init SPRITE (static per life)
;; - change SPRITE over lifetime
;; - move over lifetime
;; - Scale X
(defparameter *distance* 0f0)
(defparameter *offset* 1f0)
(defun-g pupdate-vert ((pdata pdata)
&uniform
(time :float))
(with-slots (pos dir life) pdata
(let* ((time (* time .2 (* 2f0 gl-vertex-id)))
(life life)
(new-life (+ life .001))
(dir dir)
(pos pos)
(r (rand (vec2 time))))
(if (>= new-life 1f0)
(progn ;; Reset
(setf dir (v! (* 360 r) ;; rot
(+ 8 (* 5 r)) ;; scale
0))
(setf life (* .5 r))
(setf pos (v! (+ -15 (* 15 (rand (vec2 (* 3 time)))))
(+ -7 (sin time))
(+ -20 (- (* 5 r))))))
(progn
(setf life new-life)
(incf (x pos) .05)
(decf (z pos) -.1)))
(values (v! 0 0 0 0)
(:feedback pos)
(:feedback dir)
(:feedback life)))))
(defpipeline-g pupdate-pipe (:points) :vertex (pupdate-vert pdata))
(defun update-particles ()
(with-transform-feedback (*tfs-dst*)
(map-g #'pupdate-pipe *str-src*
:time (mynow))))
(defun swap-particles ()
(rotatef *tfs-src* *tfs-dst*)
(rotatef *str-src* *str-dst*)
(rotatef *gar-src* *gar-dst*))
;;--------------------------------------------------
;; PARTICLE DRAW/RENDER
;;--------------------------------------------------
;; All I tried so far is either A) drawing the particles as points B)
;; drawing the particles as points and then have a geometry shader
;; convert them to billboards. It is possible draw
;; triangles(geometries) using instancing. But might be the code above
;; needs change too.
;; A) POINTS
(defun-g prender-points-vert ((pdata pdata)
&uniform
(world-clip :mat4))
(with-slots (pos) pdata
(let* ((world-pos (v! pos 1))
(clip-pos (* world-clip world-pos)))
clip-pos)))
(defun-g prender-points-frag ()
(v! 1 1 1 1))
(defpipeline-g prender-points-pipe (:points)
:vertex (prender-points-vert pdata)
:fragment (prender-points-frag))
(gl:point-size 4)
(defun draw-particles-points ()
(map-g #'prender-points-pipe *str-src*
:world-clip (world->clip *currentcamera*)))
;; B) POINTS -> BILLBOARDS
(defun-g billboard-vert ((pdata pdata)
&uniform
(world-view :mat4))
(with-slots (pos life dir) pdata
(values (* world-view (v! pos 1))
life
dir)))
(defun-g billboard-geom ((life (:float 1))
(rot (:vec3 1))
&uniform
(camera-pos :vec3)
(view-clip :mat4))
(declare (output-primitive :kind :triangle-strip :max-vertices 4))
(let ((p (s~ (gl-position (aref gl-in 0)) :xyz)))
(when (and (< (aref life 0) .9f0)
(< (z p) -3))
(let* ((to-camera (normalize (- camera-pos p)))
(up (v! 0 1 0))
(right (cross to-camera up))
(life (aref life 0))
(scale (y (aref rot 0))))
;;
(decf p (/ right (* scale 2)))
(emit ()
(* view-clip (v! p 1))
(v! 0 0)
life)
;;
(incf (y p) scale)
(emit ()
(* view-clip (v! p 1))
(v! 0 1)
life)
;;
(decf (y p) scale)
(incf p (* scale right))
(emit ()
(* view-clip (v! p 1))
(v! 1 0)
life)
;;
(incf (y p) scale)
(emit ()
(* view-clip (v! p 1))
(v! 1 1)
life)
(end-primitive)
(values)))))
(defun-g billboard-frag ((uv :vec2)
(life :float)
&uniform
(time :float)
(res :vec2)
(scene :sampler-2d)
(sam :sampler-2d)
(samd :sampler-2d))
(let* ((sprites 8)
(uv (/ uv sprites))
(color (texture sam uv)))
(v! (* (s~ color :xyz)
;;(v! .18 .17843138 .1552941)
(v! 0.6392157 0.54901963 0.34509805)
;;(v! 0 -1 0)
)
(* (- 1 life)
(w color)
(calculate-fade
(z gl-frag-coord)
(x (texel-fetch samd
(ivec2 (int (round (x (s~ gl-frag-coord :xy))))
(int (round (y (s~ gl-frag-coord :xy)))))
0)))))))
;; https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf
;; https://discourse.threejs.org/t/soft-particles-render/504/3
(defun-g calculate-fade ((particle-depth :float)
(scene-depth :float))
(let* ((z-fade 1f0)
(f-distance 50f0)
(f-contrast 1f0)
(input-depth (* (- scene-depth particle-depth) f-distance)))
(if (and (> input-depth 0) (< input-depth 1))
(progn
(setf z-fade (* .5 (pow (saturate (* 2f0 (if (> input-depth .5)
(- 1 input-depth)
input-depth)))
f-contrast)))
(setf z-fade (if (> input-depth .5) (- 1 z-fade) z-fade)))
(setf z-fade (saturate input-depth)))
z-fade))
(defpipeline-g billboard-pipe (:points)
:vertex (billboard-vert pdata)
:geometry (billboard-geom (:float 1) (:vec3 1))
:fragment (billboard-frag :vec2 :float))
;; https://forum.processing.org/two/discussion/3955/textured-billboard-and-transparency-problem
(defun draw-particles ()
"textured particles blended into the scene"
;; Use a simple mask when not using soft-particles
;;(with-setf (depth-mask) nil)
(with-blending *blend*
(map-g #'billboard-pipe *str-src*
:sam *cloud-tex*
:samd *samd*
:res (resolution (current-viewport))
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*))))
| 8,806 | Common Lisp | .lisp | 247 | 26.37247 | 95 | 0.494893 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d89ca51ec8070d5923ffb80b82fe8453160cd9aaba9096a666e5275c46aff3b5 | 9,148 | [
-1
] |
9,149 | camera.lisp | azimut_shiny/examples/brio/camera.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :accessor pos)
(rot :initarg :rot :accessor rot)
(near :initarg :near :accessor near)
(far :initarg :far :accessor far)
(frame-size :initarg :frame-size
:accessor frame-size))
(:default-initargs
:pos (v! 0 0 0)
:rot (q:identity)
:near .1
:far 400f0
:frame-size nil))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initarg :fov :accessor fov))
(:default-initargs
:fov 60f0))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera2* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *cameras* (list *camera* *camera2*))
(defparameter *camera-cubemap*
(make-instance 'pers :fov 90f0))
(defparameter *currentcamera* *camera*)
(defun next-camera ()
"rotates current value on *CURRRENTCAMERA*
for each on *CAMERAS*"
(setf *cameras* (alexandria:rotate *cameras*))
(setf *currentcamera* (first-elt *cameras*))
(values))
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera)
(:method ((camera pers))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:perspective-v2
fs
(near camera)
(far camera)
(fov camera))))
(:method ((camera orth))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:orthographic
(x fs)
(y fs)
(near camera)
(far camera)))))
(defun world->clip (camera)
(m4:* (projection camera)
(world->view camera)))
;;--------------------------------------------------
;; UPDATE
;;--------------------------------------------------
(defmethod update ((camera orth)))
(defmethod update ((camera pers))
(setf (pos camera) (v! 0 0 3))
;; (setf (rot camera) (q:identity))
(setf (rot camera)
(q:from-axis-angle (v! 0 1 0)
(radians (* 360 (* .1 (mynow))))))
)
| 2,122 | Common Lisp | .lisp | 66 | 27.363636 | 61 | 0.595412 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 46b4e064e2cec735b06edb98c14ccf1a8fe58373a1dd8ee5dd81ce5ae4f2f0b1 | 9,149 | [
-1
] |
9,150 | main.lisp | azimut_shiny/examples/brio/main.lisp | (in-package :shiny)
(defvar *particle-fbo* nil)
(defvar *sam-particle-fbo* nil)
(defvar *samd-particle-fbo* nil)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *samd* nil)
(defvar *bs* nil)
;; Cubemap with clouds
(defvar *t-cubemap* nil)
(defvar *s-cubemap* nil)
;; Cubemap for the luminance
(defparameter *saved* nil)
(defvar *t-cubemap-live* nil)
(defvar *s-cubemap-live* nil)
(defvar *cloud-tex* nil)
;; Cubemap to store the mix between the clouds and own floor geometry
;; ???
;; Prefilter cubemap - for specular
(defparameter *prefilter* nil)
(defvar *t-cubemap-prefilter* nil)
(defvar *s-cubemap-prefilter* nil)
(defparameter *brdf* nil)
(defvar *f-brdf* nil)
(defvar *t-brdf* nil)
(defvar *s-brdf* nil)
(defparameter *dimensions* '(400 300))
(defparameter *dimensions* '(800 600))
(defparameter *dimensions* '(532 400))
(defun free-cubes ()
(when *t-cubemap-prefilter*
(free *t-cubemap-prefilter*)
(setf *t-cubemap-prefilter* NIL))
(when *t-cubemap*
(free *t-cubemap*)
(setf *t-cubemap* NIL))
(when *t-cubemap-live*
(free *t-cubemap-live*)
(setf *t-cubemap-live* NIL)))
(defun initialize ()
;; (unless *cloud-tex*
;; (setf *cloud-tex*
;; (get-tex "static/Cloud04_8x8.tga")))
;;(init-particles 100)
(unless *t-cubemap*
;; (setf *t-cubemap*
;; (make-cubemap-tex
;; "static/ThickCloudsWater/left.png"
;; "static/ThickCloudsWater/right.png"
;; "static/ThickCloudsWater/up.png"
;; "static/ThickCloudsWater/down.png"
;; "static/ThickCloudsWater/front.png"
;; "static/ThickCloudsWater/back.png"))
;; (setf *t-cubemap*
;; (make-cubemap-tex
;; "static/cubemap_left.bmp"
;; "static/cubemap_right.bmp"
;; "static/cubemap_bottom.bmp"
;; "static/cubemap_front.bmp"
;; "static/cubemap_top.bmp"
;; "static/cubemap_back.bmp"))
;; (setf *s-cubemap*
;; (cepl:sample *t-cubemap*
;; :wrap :clamp-to-edge
;; :magnify-filter :linear))
)
;;--------------------------------------------------
;; IBL - Diffuse ambient
;; (unless *t-cubemap-live*
;; (setf *t-cubemap-live*
;; (make-texture
;; nil
;; :element-type :rgb16f
;; :dimensions '(32 32)
;; :cubes t))
;; (setf *s-cubemap-live*
;; (cepl:sample *t-cubemap-live*
;; :minify-filter :linear
;; :magnify-filter :linear
;; :wrap :clamp-to-edge)))
;; ;;--------------------------------------------------
;; ;; IBL - Specular ambient
;; ;; 1) prefilter
;; (unless *t-cubemap-prefilter*
;; (setf *t-cubemap-prefilter*
;; (make-texture
;; nil
;; :element-type :rgb16f
;; :dimensions '(128 128)
;; :mipmap 5
;; :cubes t))
;; (setf *s-cubemap-prefilter*
;; (cepl:sample *t-cubemap-prefilter*
;; :magnify-filter :linear
;; :wrap :clamp-to-edge)))
;; ;; 2) BRDF
;; (unless *f-brdf*
;; (setf *f-brdf*
;; (make-fbo
;; (list 0 :element-type :rg16f :dimensions '(512 512))))
;; (setf *t-brdf* (attachment-tex *f-brdf* 0))
;; (setf *s-brdf*
;; (cepl:sample *t-brdf*
;; :wrap :clamp-to-edge
;; :magnify-filter :linear
;; :minify-filter :linear)))
;;--------------------------------------------------
;; Buffer stream for single stage pipelines
(unless *bs*
(setf *bs* (make-buffer-stream nil :primitive :points)))
;;--------------------------------------------------
;; HDR fbo(s)
(when *fbo* (free *fbo*))
(setf *fbo*
(make-fbo
(list 0 :element-type :rgb16f :dimensions *dimensions*)
(list :d :dimensions *dimensions*)))
(setf *sam* (cepl:sample (attachment-tex *fbo* 0)
:wrap :clamp-to-edge))
(setf *samd* (cepl:sample (attachment-tex *fbo* :d)
:wrap :clamp-to-edge))
;;--------------------------------------------------
(setf (clear-color) (v! 0 0 0 1))
;;--------------------------------------------------
(setf *actors* nil)
;;(make-pbr (v! 0 -2 0))
;;(make-pbr)
;;(make-piso (v! 0 -2 0))
;;(make-thing)
(make-box)
;;(make-cubemap)
;;(make-pbr-simple (v! 0 0 -10))
NIL)
(defun draw! ()
(let* ((res (surface-resolution (current-surface)))
(time (mynow)))
(setf (resolution (current-viewport)) res)
;;(setf (resolution (current-viewport)) (v! *dimensions*))
(update *currentcamera*)
;;(setf (pos *camera1*) *light-pos*)
(update-all-the-things *actors*)
;; (unless *prefilter*
;; (cubemap-render-to-prefilter-cubemap *camera-cubemap*
;; *t-cubemap*
;; *s-cubemap*
;; *t-cubemap-prefilter*)
;; (setf *prefilter* T))
;; (unless *brdf*
;; (setf (resolution (current-viewport)) (v! 512 512))
;; (map-g-into *f-brdf* #'brdf-pipe *bs*)
;; (setf *brdf* T))
;; (unless *saved*
;; (cubemap-render-to-irradiance-cubemap *camera-cubemap*
;; *t-cubemap*
;; *s-cubemap*
;; *t-cubemap-live*)
;; (setf *saved* T))
(with-fbo-bound (*fbo*)
(clear *fbo*)
(loop :for actor :in *actors* :do
(draw actor *currentcamera* time)))
(as-frame
(with-setf* ((depth-mask) nil
(cull-face) nil
(clear-color) (v! 0 0 0 1))
(map-g #'generic-2d-pipe *bs*
:sam *sam*)))))
(def-simple-main-loop runplay (:on-start #'initialize)
(draw!))
| 6,018 | Common Lisp | .lisp | 169 | 31.201183 | 69 | 0.49871 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 88ec1014857e06b50575b6abd41c721e4a8b7b65fc7485b5c1e7904334ce587f | 9,150 | [
-1
] |
9,151 | draw.lisp | azimut_shiny/examples/brio/draw.lisp | (in-package :shiny)
(defun render-all-the-things (actor camera time)
(declare (single-float time))
(update actor)
(draw actor camera time))
(defgeneric draw (actor camera time))
(defmethod draw (actor camera time))
(defmethod draw ((actor box) camera (time single-float))
(with-instances *instances*
(with-slots (buf scale color) actor
(map-g #'generic-pipe buf
:scale scale
:color color
:time time
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)))))
(defmethod draw ((actor pbr) camera (time single-float))
(with-slots (buf
color
albedo normal height roughness
uv-speed
scale ao uv-repeat metallic)
actor
(map-g #'pbr-pipe buf
:uv-repeat uv-repeat
:uv-speed uv-speed
:scale scale
:time time
:color color
:samd *samd*
;; Lighting
:cam-pos (pos camera)
:light-pos *light-pos*
;;
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)
;; PBR
:albedo albedo
:ao-map ao
:metallic metallic
:normal-map normal
:height-map height
:rough-map roughness
;; IBL
:brdf-lut *s-brdf*
:prefilter-map *s-cubemap-prefilter*
:irradiance-map *s-cubemap-live*)))
(defparameter *instances* 10)
(defmethod draw ((actor pbr-simple) camera (time single-float))
(with-instances *instances*
(with-slots (buf scale color roughness metallic) actor
(map-g #'pbr-simple-pipe buf
:scale scale
:color color
:time time
;; Lighting
:cam-pos (pos camera)
:light-pos *light-pos*
;;
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)
;; PBR
:roughness .1
:metallic .9
;; IBL
:brdf-lut *s-brdf*
:prefilter-map *s-cubemap-prefilter*
:irradiance-map *s-cubemap-live*))))
(defmethod draw ((actor cubemap) camera (time single-float))
(with-slots (buf) actor
(with-setf* ((cull-face) :front
(depth-test-function) #'<=)
(map-g #'cubemap-pipe buf
:tex *s-cubemap*
:mod-clip
(m4:* (projection camera)
(world->view camera))))))
| 2,704 | Common Lisp | .lisp | 80 | 23.05 | 63 | 0.533231 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 44422b3d35d19b46f0fa658590a265c6f25eb49d4ac8cdc23d7cbf7b2316c20c | 9,151 | [
-1
] |
9,152 | actors.lisp | azimut_shiny/examples/brio/actors.lisp | (in-package :shiny)
(defvar *actors* nil)
(defvar *scale* 1f0)
(defvar *color* (v! .3 .3 .3))
(defvar *rough* 1f0)
(defvar *pointlight-pos* (v! 0 0 0))
(defparameter *light-pos* (v! 0 1000 300))
(defparameter *light-color* (v! .9 .9 .9))
(defparameter *exposure* 1f0)
(defparameter *parallax-scale* .01f0)
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun delete-actor-name (actor-name)
(declare (symbol actor-name))
(setf *actors*
(delete-if
(lambda (x) (eq actor-name (slot-value x 'name)))
*actors*))
NIL)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*))
NIL)
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
;;--------------------------------------------------
(defclass actor ()
((name :initarg :name)
(pos :initarg :pos :accessor pos)
(rot :initarg :rot :accessor rot)
(buf :initarg :buf)
(color :initarg :color)
(scale :initarg :scale))
(:default-initargs
:name (gensym)
:pos (v! 0 0 0)
:rot (q:identity)
:buf (box)
:color (v! 1 1 1)
:scale 1f0))
(defclass pbr-simple (actor)
((roughness :initarg :roughness)
(metallic :initarg :metallic))
(:default-initargs
:roughness .1
:metallic .1))
(defun make-pbr-simple (&optional (pos (v! 0 0 0)))
(let ((obj
(make-instance
'pbr-simple
:buf (sphere)
:pos pos)))
(push obj *actors*)
obj))
(defclass pbr (actor)
((albedo :initarg :albedo)
(ao :initarg :ao)
(height :initarg :height)
(normal :initarg :normal)
(roughness :initarg :roughness)
(uv-repeat :initarg :uv-repeat)
(uv-speed :initarg :uv-speed)
(metallic :initarg :metallic))
(:default-initargs
:uv-repeat 1f0
:uv-speed .1
:metallic .1
:albedo (get-tex "static/37.Paint01-1k/paint_albedo.jpg" NIL T :rgb8)
:ao (get-tex "static/37.Paint01-1k/paint_ao.jpg" NIL T :r8)
:height (get-tex "static/37.Paint01-1k/paint_height.jpg" NIL T :r8)
:normal (get-tex "static/37.Paint01-1k/paint_normal.jpg" NIL T :rgb8)
:roughness (get-tex "static/37.Paint01-1k/paint_roughness.jpg" NIL T :r8)))
(defclass cubemap (actor) ())
(defun make-cubemap ()
(let ((obj (make-instance 'cubemap)))
(push obj *actors*)
obj))
(defclass piso (pbr) ())
(defun make-piso (&optional (pos (v! 0 0 0)) (rot (q:identity))
(uv-speed 0f0))
(let ((obj
(make-instance
'piso
:buf (lattice 100 100 2 2 t)
:pos pos
:uv-speed uv-speed
:uv-repeat 10f0
:rot rot)))
(push obj *actors*)
obj))
(defclass thing (pbr) ())
(defun make-thing (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj
(make-instance
'pbr-simple
:buf (sphere)
;;:buf (box 1 2 .3 t)
:pos pos
:rot rot)))
(push obj *actors*)
obj))
(defclass box (actor)
((buf :initform (box 2 2 2))))
(defun make-box (&optional (pos (v! 0 0 0)) (scale 1f0))
(let ((obj (make-instance 'box
:pos pos
:scale scale
:buf (sphere) ;;(box) ;;(box 3 10 1)
)))
(appendf *actors* (list obj))
obj))
(defgeneric update (actor))
(defmethod update (actor))
(defmethod update ((actor pbr)))
(defmethod update ((actor pbr-simple))
(with-slots (rot scale color metallic roughness) actor
(setf metallic .1)
(setf roughness .9)
(setf color (v! .03 (+ 1 (sin (* .002 (get-internal-real-time)))) .03))
(setf scale (+ 1 (cos (* .001 (get-internal-real-time)))))
(setf rot (q:from-axis-angle (v! 1 1 1)
(radians (mod (* (get-internal-real-time) .1)
360))))))
(defmethod update ((actor box))
(with-slots (rot scale color) actor
(setf color (v3! (+ .5 (sin (* .002 (get-internal-real-time))))))
(setf scale (+ .01 (coerce (get-db) 'single-float)))
(setf rot (q:from-axis-angle (v! 1 1 1)
(radians (mod (* (get-internal-real-time) .1)
360))))))
| 4,549 | Common Lisp | .lisp | 139 | 26.244604 | 78 | 0.556873 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f580ec4da6871203f6ca9fb598ed0bc712cbd7428ed7bdd39acf44a7a8cce241 | 9,152 | [
-1
] |
9,153 | cubemap.lisp | azimut_shiny/examples/brio/cubemap.lisp | (in-package #:shiny)
;; Reference: Cubemap generation mostly from
;; https://learnopengl.com/PBR/IBL/Diffuse-irradiance
(defvar *cubemap-sides* '("left" "right" "bottom" "front" "top" "back"))
(defvar *cubemap-rotations*
(list
(list (v! 0 -1 0) (v! 0 0 0) (v! 1 0 0))
(list (v! 0 -1 0) (v! 0 0 0) (v! -1 0 0))
(list (v! 0 0 -1) (v! 0 0 0) (v! 0 -1 0))
(list (v! 0 0 1) (v! 0 0 0) (v! 0 1 0))
(list (v! 0 -1 0) (v! 0 0 0) (v! 0 0 1))
(list (v! 0 -1 0) (v! 0 0 0) (v! 0 0 -1))))
;;--------------------------------------------------
;; Cubemap
;; Rendering order does not matter
;; Use it with a 1x1x1 box AND
;; depth-test-function #'<=
(defun-g cubemap-vert ((g-pnt g-pnt)
&uniform
(mod-clip :mat4))
(let* ((pos3 (pos g-pnt))
(pos4 (v! pos3 1))
(cpos4 (* mod-clip pos4)))
(values (s~ cpos4 :xyww)
pos3)))
(defun-g cubemap-frag ((tc :vec3)
&uniform
(tex :sampler-cube))
(let* ((color (expt (s~ (texture tex tc) :xyz)
(vec3 2.2))))
(v! color 1f0)))
(defpipeline-g cubemap-pipe ()
(cubemap-vert g-pnt)
(cubemap-frag :vec3))
;;--------------------------------------------------
(defun make-render-cubemap (camera &optional (pos (v! 0 0 0)))
(let ((dst-cubemap (make-texture
nil
:dimensions '(2048 2048)
:cubes t
:element-type :rgb16f)))
(cubemap-render-to-cubemap camera dst-cubemap pos)
dst-cubemap))
(defun cubemap-render-to-cubemap (camera dst-cubemap &optional (pos (v! 0 0 0)))
"Fills the provided DST-CUBEMAP texture with render of
current scene. Dimensions of the DST-CUBEMAP adviced as 2048x2048"
(assert (eq :RGB16F (element-type (texref dst-cubemap))))
(assert (texture-cubes-p dst-cubemap))
(let ((dimensions (dimensions dst-cubemap)))
(assert (apply #'= dimensions))
(setf (resolution (current-viewport)) (v! dimensions))
(setf (fov camera) 90f0)
(setf (pos camera) pos)
(with-free*
((bs (make-buffer-stream nil :primitive :points))
(external-fbo
(make-fbo
(list 0 :dimensions dimensions :element-type :rgb16f)
(list :d :dimensions dimensions)))
(external-sample (cepl:sample (attachment-tex external-fbo 0)))
(fbo
(make-fbo
(list 0 :dimensions dimensions :element-type :rgb16f)))
(pipeline
(pipeline-g (:points)
:fragment
(lambda-g ((uv :vec2) &uniform (sam :sampler-2d))
(let ((color (s~ (texture sam uv) :xyz)))
(v! color 1))))))
(loop
:for side :in *cubemap-sides*
:for rotation :in *cubemap-rotations*
:for face :from 0
:do
;; Rotate camera
(destructuring-bind (up from to) rotation
(setf (rot camera)
(q:look-at up from to)))
;; Normal draw - preferably a 16bit fbo to avoid dithering
(with-fbo-bound (external-fbo)
(clear external-fbo)
(loop :for actor :in *actors* :do
(draw actor camera 1f0)))
;; Switch FBO texture for one of the cubemap
(setf (attachment fbo 0)
(texref dst-cubemap :cube-face face))
;; Final draw to LDR (? the colors
(map-g-into fbo pipeline bs
:sam external-sample)))))
;;--------------------------------------------------
(defun cubemap-save-to-disk (camera &optional (dim '(250 250)) (pos (v! 0 0 0)) (image-format "bmp"))
"Save the current scene in *ACTORS* into 6 bmp images.
Sadly the images are saved in a 8bit LDR images.
> (cubemap-save-to-disk '(500 500) (v! 0 0 0) \"bmp\""
(declare (type string image-format))
(assert (apply #'= dim))
(assert (sequence-of-length-p dim 2))
(assert (sequence-of-length-p pos 3))
(setf (resolution (current-viewport)) (v! dim))
(setf (pos camera) pos)
(setf (fov camera) 90f0)
(with-free*
((bs (make-buffer-stream nil :primitive :points))
(external-fbo
(make-fbo
(list 0 :dimensions dim :element-type :rgb16f)
(list :d :dimensions dim)))
(external-sample
(cepl:sample (attachment-tex external-fbo 0)))
(fbo (make-fbo (list 0 :dimensions dim)))
(pipeline
(pipeline-g (:points)
:fragment
(lambda-g ((uv :vec2) &uniform (sam :sampler-2d))
(v! (pow (s~ (texture sam uv) :xyz)
(vec3 (/ 1f0 2.2)))
1)))))
(loop
:for side :in *cubemap-sides*
:for rotation :in *cubemap-rotations*
:do
;; Rotate camera
(destructuring-bind (up from to) rotation
(setf (rot camera)
(q:look-at up from to)))
;; Normal draw - preferably a 16bit fbo to avoid dithering
(with-fbo-bound (external-fbo)
(clear external-fbo)
(loop :for actor :in *actors* :do
(draw actor camera 1f0)))
;; Final draw to LDR (? the colors
(map-g-into fbo pipeline bs
:sam external-sample)
;; Read from our created fbo texture
(dirt:save-as-image
(attachment-tex fbo 0)
(asdf:system-relative-pathname
:shiny
(concatenate 'string
"static/cubemap_" side "." image-format))))))
;;----------------------------------------
;; GI - IBL - Irradiance map generator
(defun-g cube-down-frag ((frag-pos :vec3)
&uniform
(tex :sampler-cube))
(let* ((normal (normalize frag-pos))
(irradiance (v! 0 0 0))
(up (v! 0 1 0))
(right (cross up normal))
(up (cross normal right))
(sample-delta .025)
(nr-samples 0f0))
(for
(phi 0f0) (< phi (* 2 +pi+)) (setf phi (+ phi sample-delta))
(for
(theta 0f0) (< theta (* .5 +pi+)) (setf theta (+ theta sample-delta))
(let* (;; spherical to cartesian (in tangent space)
(tangent-sample (v! (* (sin theta) (cos phi))
(* (sin theta) (sin phi))
(cos theta)))
;; Tangent space to world
(sample-vec (+ (* right (x tangent-sample))
(* up (y tangent-sample))
(* normal (z tangent-sample)))))
(incf irradiance (* (s~ (texture tex sample-vec) :xyz)
(cos theta)
(sin theta)))
(incf nr-samples 1f0))))
(setf irradiance (* +pi+ irradiance (/ 1 nr-samples)))
(v! irradiance 1)))
(defpipeline-g cube-down-pipe ()
:vertex (cubemap-vert g-pnt)
:fragment (cube-down-frag :vec3))
;;--------------------------------------------------
;; GI - IBL - Irradiance light
(defun cubemap-render-to-irradiance-cubemap (camera
src-cubemap
src-cubemap-sample
dst-cubemap)
"Adviced dimensions of DST-CUBEMAP of 32x32"
(declare (type texture src-cubemap dst-cubemap))
(let ((dst-dimensions (dimensions dst-cubemap))
(src-dimensions (dimensions src-cubemap)))
(assert (eq :RGB16F (element-type (texref dst-cubemap :cube-face 0))))
(assert (apply #'= src-dimensions))
(assert (apply #'= dst-dimensions))
(setf (resolution (current-viewport)) (v! dst-dimensions))
(setf (fov camera) 90f0)
(with-free*
((fbo
(make-fbo
(list 0 :dimensions dst-dimensions :element-type :rgb16f)
(list :d :dimensions dst-dimensions))))
(loop
:for side :in *cubemap-sides*
:for rotation :in *cubemap-rotations*
:for face :from 0
:do
;; Rotate camera
(destructuring-bind (up from to) rotation
(setf (rot camera) (q:look-at up from to)))
;; Switch FBO texture for one of the cubemap
(setf (attachment fbo 0)
(texref dst-cubemap :cube-face face))
(with-setf* ((cull-face) :front
(depth-test-function) #'<=)
(with-fbo-bound (fbo)
(clear fbo)
(map-g #'cube-down-pipe (box)
:tex src-cubemap-sample
:mod-clip (m4:* (projection camera)
(world->view camera)))))))))
;;--------------------------------------------------
;; GI - IBL - Prefilter cubemap
;;
;; This gives us a sample vector somewhat oriented around the expected
;; microsurface's halfway vector based on some input roughness and the
;; low-discrepancy sequence value Xi. Note that Epic Games uses the
;; squared roughness for better visual results as based on Disney's
;; original PBR research.
(defun-g importance-sample-ggx ((xi :vec2)
(n :vec3)
(roughness :float))
(let* ((a (* roughness roughness))
(phi (* 2 +pi+ (x xi)))
(cos-theta (sqrt (/ (- 1 (y xi))
(+ 1 (* (1- (* a a)) (y xi))))))
(sin-theta (sqrt (- 1 (* cos-theta cos-theta))))
;; from spherical coordinates to cartesian coordinates
(h (v! (* (cos phi) sin-theta)
(* (sin phi) sin-theta)
cos-theta))
;; from tangent-space vector to world-space sample vector
(up (if (< (abs (z n)) .999)
(v! 0 0 1)
(v! 1 0 0)))
(tangent (normalize (cross up n)))
(bitangent (cross n tangent))
(sample-vec (+ (* (x h) tangent)
(* (y h) bitangent)
(* (z h) n))))
(normalize sample-vec)))
(defun-g prefilter-frag ((frag-pos :vec3)
&uniform
(environment-map :sampler-cube)
(roughness :float))
(let* ((n (normalize frag-pos))
;; make the simplyfying assumption that V equals R equals the normal
(r n)
(v r)
(total-weight 0f0)
(prefiltered-color (vec3 0f0)))
(dotimes (i 1024)
(let* ((xi (hammersley-nth-2d 1024 i))
(h (importance-sample-ggx xi n roughness))
(l (normalize (- (* 2 h (dot v h)) v)))
(n-dot-l (max (dot n l) 0f0)))
(when (> n-dot-l 0)
(let* ((d (distribution-ggx n h roughness))
(n-dot-h (max (dot n h) 0))
(h-dot-v (max (dot h v) 0))
(pdf (+ .0001 (/ (* d n-dot-h)
(* 4 h-dot-v))))
(resolution 512)
(sa-texel (/ (* 4 +pi+)
(* 6 resolution resolution)))
(sa-sample (/ (+ .0001 (* pdf 1024))))
(mip-level (if (= 0 roughness)
0f0
(* .5 (log2 (/ sa-sample sa-texel))))))
(incf prefiltered-color
(* (s~ (texture-lod environment-map l mip-level) :xyz)
n-dot-l))
(incf total-weight n-dot-l)))))
(divf prefiltered-color (vec3 total-weight))
(v! prefiltered-color 1)))
(defpipeline-g prefilter-pipe ()
:vertex (cubemap-vert g-pnt)
:fragment (prefilter-frag :vec3))
;;--------------------------------------------------
;; GI - IBL - Specular prefilter cubemap
;; https://learnopengl.com/PBR/IBL/Specular-IBL
(defun cubemap-render-to-prefilter-cubemap (camera
src-cubemap
src-cubemap-sample
dst-cubemap)
"Adviced DST-CUBEMAP dimensions 128x128"
(let ((dst-dimensions (dimensions dst-cubemap))
(src-dimensions (dimensions src-cubemap)))
(assert (= 5 (texture-mipmap-levels dst-cubemap)))
(assert (texture-cubes-p dst-cubemap))
(assert (texture-cubes-p src-cubemap))
(assert (eq :RGB16F (texture-element-type dst-cubemap)))
(assert (apply #'= dst-dimensions))
(setf (fov camera) 90f0)
(dotimes (mip 5)
(let* ((mip-width (floor (* 128 (expt .5 mip))))
(mip-height mip-width)
(dimensions (list mip-width mip-height))
(roughness (coerce (/ mip (- 5 1)) 'single-float)))
(setf (resolution (current-viewport)) (v! dimensions))
(with-free*
((fbo
(make-fbo
(list 0 :dimensions dimensions :element-type :rgb16f)
(list :d :dimensions dimensions))))
(loop
:for side :in *cubemap-sides*
:for rotation :in *cubemap-rotations*
:for face :from 0
:do
;; Rotate camera
(destructuring-bind (up from to) rotation
(setf (rot camera) (q:look-at up from to)))
;; Switch FBO texture for one of the cubemap
(setf (attachment fbo 0)
(texref dst-cubemap :cube-face face :mipmap-level mip))
(with-setf* ((cull-face) :front
(depth-test-function) #'<=)
(with-fbo-bound (fbo)
(clear-fbo fbo)
(map-g #'prefilter-pipe (box)
:roughness roughness
:environment-map src-cubemap-sample
:mod-clip (m4:* (projection camera)
(world->view camera)))))))))))
| 13,823 | Common Lisp | .lisp | 326 | 30.677914 | 101 | 0.502114 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | cf1062e39d40478e215698c39172c35ac73d1a020c4096746ba85edcf0255780 | 9,153 | [
-1
] |
9,154 | render.lisp | azimut_shiny/examples/brio/render.lisp | (in-package :shiny)
;;--------------------------------------------------
;; 3D - g-pnt with tangent info in tb-data AND textures
(defun-g vert-with-tbdata
((vert g-pnt) (tb tb-data)
&uniform
(model-world :mat4)
(world-view :mat4)
(view-clip :mat4)
(scale :float)
;; Parallax vars
(light-pos :vec3)
(cam-pos :vec3))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(uv (treat-uvs (tex vert)))
(norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(t0 (normalize
(s~ (* model-world (v! (tb-data-tangent tb) 0))
:xyz)))
(n0 (normalize
(s~ (* model-world (v! norm 0))
:xyz)))
(t0 (normalize (- t0 (* (dot t0 n0) n0))))
(b0 (cross n0 t0))
(tbn (mat3 t0 b0 n0)))
(values clip-pos
(treat-uvs uv)
norm
(s~ world-pos :xyz)
tbn
(* tbn light-pos)
(* tbn cam-pos)
(* tbn (s~ world-pos :xyz)))))
(defun-g frag-tex-tbn ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d)
(normap :sampler-2d)
(height-map :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; Parallax
(tan-cam-dir (- tan-cam-pos tan-frag-pos))
(newuv (parallax-mapping uv tan-cam-dir height-map .1))
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo newuv) :xyz)
(vec3 2.2)))
(normal (norm-from-map normap newuv))
(normal (normalize (* tbn normal))))
(values
;; (v! final-color 1)
;; (v! 1 1 1 1)
;;frag-pos
(normalize frag-norm))))
(defpipeline-g generic-tex-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (frag-tex-tbn :vec2 :vec3 :vec3 :mat3
;; Parallax
:vec3 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - g-pnt mesh without tangents
(defparameter *mess* .0f0)
(defparameter *messx* .0f0)
(defparameter *messy* .0f0)
(defparameter *mul* 0f0)
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(scale :float) (time :float))
(let* ((pos (* scale (+ (v! (* *mul* (cos (* *messx* time gl-instance-id)))
(* *mul* (sin (* *messy* time gl-instance-id)))
(* *mul* (sin (* *mess* time gl-instance-id))))
(pos vert))))
(norm (norm vert))
(tex (tex vert))
(world-norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
(+ gl-instance-id world-norm)
(s~ world-pos :xyz))))
;; http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
(defun-g frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(time :float)
(color :vec3)
(cam-pos :vec3))
(let* (
;;--------------------
(final-color color)
;; float3 dpdx = ddx(i.worldPos);
;; float3 dpdy = ddy(i.worldPos);
;; i.normal = normalize(cross(dpdy, dpdx));
(dpdx (d-fdx frag-pos))
(dpdy (d-fdy frag-pos))
(frag-norm (normalize (cross dpdy dpdx)))
(final-color
(dir-light-apply final-color
(v! 20 20 20)
(v! 0 1000 1000)
frag-pos
frag-norm))
(final-color
(point-light-apply final-color
(v! 10 10 10)
*light-pos*
frag-pos
frag-norm
1f0
0.014 0.07)))
(values (v! final-color 1)
(v! 0 1 0 1))))
;;--------------------------------------------------
;; 2D - Post Processing
(defun-g frag-2d ((uv :vec2)
&uniform
(sam :sampler-2d)
(sam2 :sampler-2d)
(samd :sampler-2d))
(let* (;; (color (defered-fog
;; ;;(v! .5 .6 .7)
;; (v! .18 .17 .15)
;; uv
;; sam
;; samd))
(final-color (s~ (texture sam uv) :xyz))
;; (color2 (s~ (texture sam2 uv) :xyz))
;; (color
;; (s~ (nineveh.anti-aliasing:fxaa3 uv sam (v2! (/ 1 320f0))) :xyz))
;; (final-color (+ color color2))
(ldr (tone-map-reinhard final-color *exposure*))
(luma (rgb->luma-bt601 ldr))
)
;;(v! (pow ldr (vec3 2.2)) 1)
(v! ldr luma)
;;(v! (- 1 (x color)) 0 0 1)
;;(v! color 1)
;;(v! ldr 1)
))
(defpipeline-g generic-2d-pipe (:points)
:fragment (frag-2d :vec2))
;;--------------------------------------------------
;; 3D - g-pnt mesh with light shading
(defpipeline-g generic-pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
(defun-g frag-tex ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo (* 20 uv)) :xyz)
(vec3 2.2)))
;;--------------------
;;(normal (normalize frag-norm))
;;(nfm (norm-from-map normap uv))
(color (apply-fog color
(v! .5 .6 .7)
(length (- frag-pos cam-pos))
cam-pos
(normalize (- frag-pos cam-pos)))))
(v! color 1)))
(defpipeline-g tex-pipe ()
:vertex (vert g-pnt)
:fragment (frag-tex :vec2 :vec3 :vec3))
;;--------------------------------------------------
(defun-g pbr-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(samd :sampler-2d)
(uv-repeat :float)
(uv-speed :float)
(time :float)
(color :vec3)
;; Lighting
(light-pos :vec3)
(cam-pos :vec3)
;; PBR
(metallic :float)
(albedo :sampler-2d)
(ao-map :sampler-2d)
(height-map :sampler-2d)
(normal-map :sampler-2d)
(rough-map :sampler-2d)
;; IBL
(brdf-lut :sampler-2d)
(prefilter-map :sampler-cube)
(irradiance-map :sampler-cube))
(let* (;; First change UV, then parallax!
(uv (+ (* uv uv-repeat)
(v! 0 (* uv-speed time))))
(uv (parallax-mapping-offset-flipped
uv
(normalize (- tan-cam-pos tan-frag-pos))
height-map
.03))
(roughness (x (texture rough-map uv)))
(ao (x (texture ao-map uv)))
(color (* color (expt (s~ (texture albedo uv) :xyz)
(vec3 2.2))))
;; Normal Mapping
;;(normal (normalize frag-norm))
(normal (norm-from-map normal-map uv))
(normal (normalize (* tbn normal)))
;;----------------------------------------
;; PBR
;; metallic
(n normal)
(v (normalize (- cam-pos frag-pos)))
(metallic .1)
(f0 (vec3 .04))
;;(f0 color)
(f0 (mix f0 color metallic))
;; pbr - reflectance equation
(lo (vec3 0f0))
;; lights START
(lo (+ lo (pbr-direct-lum light-pos
frag-pos
v
n
roughness
f0
metallic
color)))
;; (lo (+ lo (pbr-point-lum light-pos
;; frag-pos
;; v
;; n
;; roughness
;; f0
;; metallic
;; color)))
;; ---------- END
;;(ambient (* color ao (vec3 .03)))
;; (ambient (pbr-ambient-map-r irradiance-map
;; color
;; ao n v f0
;; roughness))
(r (reflect (- v) n))
(f (fresnel-schlick-roughness (max (dot n v) 0)
f0
roughness))
(ks f)
(kd (* (- 1 ks) (- 1 metallic)))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance color))
(prefiltered-color (s~ (texture-lod prefilter-map
r
(* roughness 4f0))
:xyz))
(env-brdf (texture brdf-lut (v! (max (dot n v) 0) (* roughness 4f0))))
(specular (* prefiltered-color (+ (* f (x env-brdf)) (y env-brdf))))
(ambient (* (+ specular (* kd diffuse)) ao))
(final-color (+ ambient lo))
;; Fog
(final-color
(fog-exp2-apply final-color
(v! .18 .17843138 .1552941)
;;(v! .2 .3 .4)
frag-pos
cam-pos .03))
)
(v! final-color 1)
;;(v! uv 0 1)
;;(v! color 1)
))
(defpipeline-g pbr-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (pbr-frag :vec2 :vec3 :vec3
:mat3 :vec3 :vec3 :vec3))
;;--------------------------------------------------
(defun-g pbr-simple-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(light-pos :vec3)
(time :float)
(roughness :float)
(metallic :float)
(color :vec3)
(cam-pos :vec3)
;; IBL
(irradiance-map :sampler-cube)
(prefilter-map :sampler-cube)
(brdf-lut :sampler-2d))
(let* (;; First change UV, then parallax!
(uv (treat-uvs uv))
(normal (normalize frag-norm))
(ao 1f0)
(color color)
;;----------------------------------------
;; PBR
;; metallic
;;(f0 (vec3 .04))
(f0 color)
(f0 (mix f0 color metallic))
;; pbr - reflectance equation
(n normal)
(v (normalize (- cam-pos frag-pos)))
(lo (vec3 0f0))
;; lights START
(lo (+ lo (pbr-direct-lum light-pos
frag-pos
v
n
roughness
f0
metallic
color)))
;; ---------- END
;; (r (reflect (- v) n))
;; (f (fresnel-schlick-roughness (max (dot n v) 0)
;; f0
;; roughness))
;; (ks f)
;; (kd (* (- 1 ks) (- 1 metallic)))
;; (irradiance (s~ (texture irradiance-map n) :xyz))
;; (diffuse (* irradiance color))
;; (prefiltered-color (s~ (texture-lod prefilter-map
;; r
;; (* roughness 4f0))
;; :xyz))
;; (env-brdf (texture brdf-lut (v! (max (dot n v) 0) (* roughness 4f0))))
;; (specular (* prefiltered-color (+ (* f (x env-brdf)) (y env-brdf))))
;; (ambient (* (+ specular (* kd diffuse)) ao))
;; (ambient (pbr-ambient-map-r irradiance-map
;; color
;; ao n v f0
;; roughness))
(ambient (* color ao (vec3 .3)))
(final-color (+ ambient lo))
;; Fog
;; (final-color
;; (fog-exp2-apply final-color
;; (v! 0 0 0)
;; frag-pos
;; cam-pos .03))
)
(v! final-color 1)))
;;----------------------------------------
;; Functions to apply the Irradiance Map ONLY
(defun-g pbr-ambient-map ((irradiance-map :sampler-cube)
(albedo :vec3)
(ao :float)
(n :vec3)
(v :vec3)
(f0 :vec3))
(let* ((ks (fresnel-schlick (max (dot n v) 0) f0))
(kd (- 1 ks))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance albedo)))
(* diffuse kd ao)))
(defun-g fresnel-schlick-roughness ((cos-theta :float)
(f0 :vec3)
(roughness :float))
(+ f0
(* (- (max (vec3 (- 1 roughness))
f0)
f0)
(pow (- 1 cos-theta) 5f0))))
(defun-g pbr-ambient-map-r ((irradiance-map :sampler-cube)
(albedo :vec3)
(ao :float)
(n :vec3)
(v :vec3)
(f0 :vec3)
(roughness :float))
(let* ((ks (fresnel-schlick-roughness (max (dot n v) 0)
f0
roughness))
(kd (- 1 ks))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance albedo)))
(* diffuse kd ao)))
(defpipeline-g pbr-simple-pipe ()
:vertex (vert g-pnt)
:fragment (pbr-simple-frag :vec2 :vec3 :vec3))
| 15,776 | Common Lisp | .lisp | 411 | 24.530414 | 84 | 0.38016 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c7010aad93d85e0257b66c042610dd95b7affad706b6b0a7638fe723184e09fe | 9,154 | [
-1
] |
9,155 | celestial-sphere.lisp | azimut_shiny/examples/brio/celestial-sphere.lisp | (in-package #:shiny)
(defclass celestial-sphere (actor)
((buf :initform (sphere))))
(defun make-celestial-sphere ()
(let ((obj (make-instance 'celestial-sphere)))
(push obj *actors*)
obj))
(defmethod draw ((actor celestial-sphere) camera time)
(with-slots (buf color scale) actor
(with-setf* ((cull-face) :front
(depth-test-function) #'<=
(depth-mask) nil)
(map-g #'celestial-pipe buf
:color color
:cam-pos (pos camera)
:mod-clip
(m4:* (projection camera)
(world->view camera))))))
(defun-g celestial-frag ((uv :vec2)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(light-pos :vec2)
(color :vec3))
(atmosphere (normalize frag-pos)
(v! 0 6372000 0)
(v! 0 0 -100)
20f0
6373000f0
6471000f0
(v! .0000055 .000013 .0000224)
.000021
8000f0 ;; rayleigh scale height
1200 ;; mie scale height
.758
3 ;; 16 AND 8
2))
(defpipeline-g celestial-pipe ()
:vertex (cubemap-vert g-pnt)
:fragment (celestial-frag :vec2 :vec3 :vec3))
| 1,346 | Common Lisp | .lisp | 40 | 21.825 | 54 | 0.488086 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 481fc6053f844b3662cd32a02f7deb1da217e71e2683cdfe411cfb51e4bb6652 | 9,155 | [
-1
] |
9,156 | particles.lisp | azimut_shiny/examples/room/particles.lisp | (in-package #:shiny)
;;--------------------------------------------------
;; PARTICLE LOGIC
;;--------------------------------------------------
;; Uses TTFS to delegate to the gpu all the movement logic.
;; Needs *bs* for the single stage pipeline.
;; TODO:
;; - Instacing for geomtry rendending of particles
;; - Create CL class to contain all the components nicely
;; and more importantly easily allow multiple particle systems.
(defvar *gar-src* NIL)
(defvar *str-src* NIL)
(defvar *tfs-src* NIL)
(defvar *gar-dst* NIL)
(defvar *str-dst* NIL)
(defvar *tfs-dst* NIL)
(defvar *blend* (make-blending-params))
(defstruct-g pdata
(pos :vec3)
(dir :vec3)
(life :float))
;;--------------------------------------------------
;; Init particles
(defun-g pinit-vert (&uniform (time :float))
(let ((id (* .001 (+ time gl-vertex-id))))
(values (v! 0 0 0 0)
(:feedback (v! 0 0 0))
(:feedback (v! 0 0 0))
(:feedback 0f0))))
(defpipeline-g pinit-pipe (:points) :vertex (pinit-vert))
(defun init-particles (&optional (n-particles 1000))
(unless *gar-src*
(setf *gar-src* (make-gpu-array
nil
:dimensions n-particles
:element-type 'pdata)
*gar-dst* (make-gpu-array
nil
:dimensions n-particles
:element-type 'pdata))
(setf *str-src* (make-buffer-stream *gar-src* :primitive :points)
*str-dst* (make-buffer-stream *gar-dst* :primitive :points))
(setf *tfs-src* (make-transform-feedback-stream *gar-src*)
*tfs-dst* (make-transform-feedback-stream *gar-dst*))
(reset-particles)))
;;--------------------------------------------------
;; Free & Reset
(defun free-particles ()
;; (free *tfs-src*)
;; (free *tfs-dst*)
(free *str-src*)
(free *str-dst*)
(free *gar-src*)
(free *gar-dst*)
(setf *str-src* NIL
*str-dst* NIL
*gar-src* NIL
*gar-dst* NIL))
(defun reset-particles ()
(with-transform-feedback (*tfs-src*)
(map-g #'pinit-pipe *bs*))
(with-transform-feedback (*tfs-dst*)
(map-g #'pinit-pipe *bs*))
(values))
;;--------------------------------------------------
;; Update particles
;; - Fudge initial alpha
;; - Color overtime to fade in/out with the alpha
;; - random init ROTATION
;; - ROTATION over lifetime
;; - random init SPRITE (static per life)
;; - change SPRITE over lifetime
;; - move over lifetime
;; - Scale X
(defparameter *distance* 0f0)
(defparameter *offset* 1f0)
(defun-g pupdate-vert ((pdata pdata)
&uniform
(time :float))
(with-slots (pos dir life) pdata
(let* ((time (* time .2 (* 2f0 gl-vertex-id)))
(life life)
(new-life (+ life .001))
(dir dir)
(pos pos)
(r (rand (vec2 time))))
(if (>= new-life 1f0)
(progn ;; Reset
(setf dir (v! (* 360 r) ;; rot
(+ 8 (* 5 r)) ;; scale
0))
(setf life (* .5 r))
(setf pos (v! (+ -15 (* 15 (rand (vec2 (* 3 time)))))
(+ -7 (sin time))
(+ -20 (- (* 5 r))))))
(progn
(setf life new-life)
(incf (x pos) .05)
(decf (z pos) -.1)))
(values (v! 0 0 0 0)
(:feedback pos)
(:feedback dir)
(:feedback life)))))
(defpipeline-g pupdate-pipe (:points) :vertex (pupdate-vert pdata))
(defun update-particles ()
(with-transform-feedback (*tfs-dst*)
(map-g #'pupdate-pipe *str-src*
:time (mynow))))
(defun swap-particles ()
(rotatef *tfs-src* *tfs-dst*)
(rotatef *str-src* *str-dst*)
(rotatef *gar-src* *gar-dst*))
;;--------------------------------------------------
;; PARTICLE DRAW/RENDER
;;--------------------------------------------------
;; All I tried so far is either A) drawing the particles as points B)
;; drawing the particles as points and then have a geometry shader
;; convert them to billboards. It is possible draw
;; triangles(geometries) using instancing. But might be the code above
;; needs change too.
;; A) POINTS
(defun-g prender-points-vert ((pdata pdata)
&uniform
(world-clip :mat4))
(with-slots (pos) pdata
(let* ((world-pos (v! pos 1))
(clip-pos (* world-clip world-pos)))
clip-pos)))
(defun-g prender-points-frag ()
(v! 1 1 1 1))
(defpipeline-g prender-points-pipe (:points)
:vertex (prender-points-vert pdata)
:fragment (prender-points-frag))
(gl:point-size 4)
(defun draw-particles-points ()
(map-g #'prender-points-pipe *str-src*
:world-clip (world->clip *currentcamera*)))
;; B) POINTS -> BILLBOARDS
(defun-g billboard-vert ((pdata pdata)
&uniform
(world-view :mat4))
(with-slots (pos life dir) pdata
(values (* world-view (v! pos 1))
life
dir)))
(defun-g billboard-geom ((life (:float 1))
(rot (:vec3 1))
&uniform
(camera-pos :vec3)
(view-clip :mat4))
(declare (output-primitive :kind :triangle-strip :max-vertices 4))
(let ((p (s~ (gl-position (aref gl-in 0)) :xyz)))
(when (and (< (aref life 0) .9f0)
(< (z p) -3))
(let* ((to-camera (normalize (- camera-pos p)))
(up (v! 0 1 0))
(right (cross to-camera up))
(life (aref life 0))
(scale (y (aref rot 0))))
;;
(decf p (/ right (* scale 2)))
(emit ()
(* view-clip (v! p 1))
(v! 0 0)
life)
;;
(incf (y p) scale)
(emit ()
(* view-clip (v! p 1))
(v! 0 1)
life)
;;
(decf (y p) scale)
(incf p (* scale right))
(emit ()
(* view-clip (v! p 1))
(v! 1 0)
life)
;;
(incf (y p) scale)
(emit ()
(* view-clip (v! p 1))
(v! 1 1)
life)
(end-primitive)
(values)))))
(defun-g billboard-frag ((uv :vec2)
(life :float)
&uniform
(time :float)
(res :vec2)
(scene :sampler-2d)
(sam :sampler-2d)
(samd :sampler-2d))
(let* ((sprites 8)
(uv (/ uv sprites))
(color (texture sam uv)))
(v! (* (s~ color :xyz)
;;(v! .18 .17843138 .1552941)
(v! 0.6392157 0.54901963 0.34509805)
;;(v! 0 -1 0)
)
(* (- 1 life)
(w color)
(calculate-fade
(z gl-frag-coord)
(x (texel-fetch samd
(ivec2 (int (round (x (s~ gl-frag-coord :xy))))
(int (round (y (s~ gl-frag-coord :xy)))))
0)))))))
;; https://developer.download.nvidia.com/whitepapers/2007/SDK10/SoftParticles_hi.pdf
;; https://discourse.threejs.org/t/soft-particles-render/504/3
(defun-g calculate-fade ((particle-depth :float)
(scene-depth :float))
(let* ((z-fade 1f0)
(f-distance 50f0)
(f-contrast 1f0)
(input-depth (* (- scene-depth particle-depth) f-distance)))
(if (and (> input-depth 0) (< input-depth 1))
(progn
(setf z-fade (* .5 (pow (saturate (* 2f0 (if (> input-depth .5)
(- 1 input-depth)
input-depth)))
f-contrast)))
(setf z-fade (if (> input-depth .5) (- 1 z-fade) z-fade)))
(setf z-fade (saturate input-depth)))
z-fade))
(defpipeline-g billboard-pipe (:points)
:vertex (billboard-vert pdata)
:geometry (billboard-geom (:float 1) (:vec3 1))
:fragment (billboard-frag :vec2 :float))
;; https://forum.processing.org/two/discussion/3955/textured-billboard-and-transparency-problem
(defun draw-particles ()
"textured particles blended into the scene"
;; Use a simple mask when not using soft-particles
;;(with-setf (depth-mask) nil)
(with-blending *blend*
(map-g #'billboard-pipe *str-src*
:sam *cloud-tex*
:samd *samd*
:res (resolution (current-viewport))
:world-view (world->view *currentcamera*)
:view-clip (projection *currentcamera*))))
| 8,723 | Common Lisp | .lisp | 243 | 26.485597 | 95 | 0.493068 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 05c35fbca9a4b118c179fb8e390d383e784a9a95945dc19313f2f485a3445667 | 9,156 | [
-1
] |
9,157 | camera.lisp | azimut_shiny/examples/room/camera.lisp | (in-package :shiny)
(defclass camera ()
((pos :initarg :pos :accessor pos)
(rot :initarg :rot :accessor rot)
(near :initarg :near :accessor near)
(far :initarg :far :accessor far)
(frame-size :initarg :frame-size
:accessor frame-size))
(:default-initargs
:pos (v! 0 0 0)
:rot (q:identity)
:near .1
:far 400f0
:frame-size nil))
(defclass orth (camera) ())
(defclass pers (camera)
((fov :initarg :fov :accessor fov))
(:default-initargs
:fov 60f0))
(defparameter *camera* (make-instance 'pers))
(defparameter *camera2* (make-instance 'pers))
(defparameter *camera1* (make-instance 'orth))
(defparameter *cameras* (list *camera* *camera2*))
(defparameter *camera-cubemap*
(make-instance 'pers :fov 90f0))
(defparameter *currentcamera* *camera*)
(defun next-camera ()
"rotates current value on *CURRRENTCAMERA*
for each on *CAMERAS*"
(setf *cameras* (alexandria:rotate *cameras*))
(setf *currentcamera* (first-elt *cameras*))
(values))
(defun world->view (camera)
(m4:* (m4:translation (v3:negate (pos camera)))
(q:to-mat4 (q:inverse (rot camera)))))
(defgeneric projection (camera)
(:method ((camera pers))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:perspective-v2
fs
(near camera)
(far camera)
(fov camera))))
(:method ((camera orth))
(let ((fs (or (frame-size camera)
(viewport-resolution (current-viewport)))))
(rtg-math.projection:orthographic
(x fs)
(y fs)
(near camera)
(far camera)))))
(defun world->clip (camera)
(m4:* (projection camera)
(world->view camera)))
;;--------------------------------------------------
;; UPDATE
;;--------------------------------------------------
(defmethod update ((camera orth))
(setf (pos camera) (v! 0 0 0))
;;(setf (frame-size camera) (v2! 10))
(setf (rot camera)
;; TOP
(q:from-axis-angle (v! 1 0 0)
(radians -90))
;; FRONT
;; (q:from-axis-angle (v! 1 0 0)
;; (radians -45))
))
(defun rot1 ()
(let ((time (* (get-internal-real-time) .001)))
(q:from-axis-angle (v! .2 .9 0)
(radians (* 10
(sin (* .1 time)))))))
(defparameter *dec* (make-line (iota 1020 :start 460 :step -.1)))
(defparameter *dec* (make-cycle '(460)))
(defmethod update ((camera pers))
(let ((time (mynow)))
(with-slots (pos rot) camera
;;(setf rot (q:identity))
(setf pos (v! 0 0 0))
(setf rot (q:*
(q:from-axis-angle (v! 0 0 1)
(radians (mod (* 20 (mynow)) 360)))
;;(q:identity)
(rot1)
))
;; (setf rot (q:from-axis-angle
;; (v! 0 1 0)
;; (radians (next *dec*))))
;; (setf pos (v! (+ 0 (* 0 (cos (* .5 time))))
;; (+ 0 (* .1 (sin (* .5 time))))
;; (+ 0 (* 1 (cos (* .5 time))))))
;;(setf rot (q:look-at (v! 0 1 0) pos (v! 0 -1 0)))
)))
| 3,211 | Common Lisp | .lisp | 95 | 27.210526 | 71 | 0.519305 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 05be3c27327e31b10ab8efea86aaab220db6c3d72c2344fdc5979e50f46f9ec9 | 9,157 | [
-1
] |
9,158 | main.lisp | azimut_shiny/examples/room/main.lisp | (in-package :shiny)
(defvar *particle-fbo* nil)
(defvar *sam-particle-fbo* nil)
(defvar *samd-particle-fbo* nil)
(defvar *fbo* nil)
(defvar *sam* nil)
(defvar *samd* nil)
(defvar *bs* nil)
;; Cubemap with clouds
(defvar *t-cubemap* nil)
(defvar *s-cubemap* nil)
;; Cubemap for the luminance
(defparameter *saved* nil)
(defvar *t-cubemap-live* nil)
(defvar *s-cubemap-live* nil)
(defvar *cloud-tex* nil)
;; Cubemap to store the mix between the clouds and own floor geometry
;; ???
;; Prefilter cubemap - for specular
(defparameter *prefilter* nil)
(defvar *t-cubemap-prefilter* nil)
(defvar *s-cubemap-prefilter* nil)
(defparameter *brdf* nil)
(defvar *f-brdf* nil)
(defvar *t-brdf* nil)
(defvar *s-brdf* nil)
(defparameter *dimensions* '(532 400))
(defparameter *dimensions* '(400 300))
(defparameter *dimensions* '(800 600))
(defun free-cubes ()
(when *t-cubemap-prefilter*
(free *t-cubemap-prefilter*)
(setf *t-cubemap-prefilter* NIL))
(when *t-cubemap*
(free *t-cubemap*)
(setf *t-cubemap* NIL))
(when *t-cubemap-live*
(free *t-cubemap-live*)
(setf *t-cubemap-live* NIL)))
(defun initialize ()
(unless *cloud-tex*
(setf *cloud-tex*
(get-tex "static/Cloud04_8x8.tga")))
(init-particles 100)
(unless *t-cubemap*
;; (setf *t-cubemap*
;; (make-cubemap-tex
;; "static/ThickCloudsWater/left.png"
;; "static/ThickCloudsWater/right.png"
;; "static/ThickCloudsWater/up.png"
;; "static/ThickCloudsWater/down.png"
;; "static/ThickCloudsWater/front.png"
;; "static/ThickCloudsWater/back.png"))
(setf *t-cubemap*
(make-cubemap-tex
"static/cubemap_left.bmp"
"static/cubemap_right.bmp"
"static/cubemap_bottom.bmp"
"static/cubemap_front.bmp"
"static/cubemap_top.bmp"
"static/cubemap_back.bmp"))
(setf *s-cubemap*
(cepl:sample *t-cubemap*
:wrap :clamp-to-edge
:magnify-filter :linear)))
;;--------------------------------------------------
;; IBL - Diffuse ambient
(unless *t-cubemap-live*
(setf *t-cubemap-live*
(make-texture
nil
:element-type :rgb16f
:dimensions '(32 32)
:cubes t))
(setf *s-cubemap-live*
(cepl:sample *t-cubemap-live*
:minify-filter :linear
:magnify-filter :linear
:wrap :clamp-to-edge)))
;;--------------------------------------------------
;; IBL - Specular ambient
;; 1) prefilter
(unless *t-cubemap-prefilter*
(setf *t-cubemap-prefilter*
(make-texture
nil
:element-type :rgb16f
:dimensions '(128 128)
:mipmap 5
:cubes t))
(setf *s-cubemap-prefilter*
(cepl:sample *t-cubemap-prefilter*
:magnify-filter :linear
:wrap :clamp-to-edge)))
;; 2) BRDF
(unless *f-brdf*
(setf *f-brdf*
(make-fbo
(list 0 :element-type :rg16f :dimensions '(512 512))))
(setf *t-brdf* (attachment-tex *f-brdf* 0))
(setf *s-brdf*
(cepl:sample *t-brdf*
:wrap :clamp-to-edge
:magnify-filter :linear
:minify-filter :linear)))
;;--------------------------------------------------
;; Buffer stream for single stage pipelines
(unless *bs*
(setf *bs* (make-buffer-stream nil :primitive :points)))
;;--------------------------------------------------
;; HDR fbo(s)
(when *fbo* (free *fbo*))
(setf *fbo*
(make-fbo
(list 0 :element-type :rgb16f :dimensions *dimensions*)
(list :d :dimensions *dimensions*)))
(setf *sam* (cepl:sample (attachment-tex *fbo* 0)
:wrap :clamp-to-edge))
(setf *samd* (cepl:sample (attachment-tex *fbo* :d)
:wrap :clamp-to-edge))
;;--------------------------------------------------
(when *particle-fbo* (free *particle-fbo*))
(setf *particle-fbo*
(make-fbo
(list 0 :element-type :rgb16f :dimensions *dimensions*)
;; (list :d :dimensions *dimensions*)
))
(setf *sam-particle-fbo* (cepl:sample (attachment-tex *particle-fbo* 0)
:wrap :clamp-to-edge))
;; (setf *samd-particle-fbo* (cepl:sample (attachment-tex *particle-fbo* :d)
;; :wrap :clamp-to-edge))
;;--------------------------------------------------
(setf (clear-color) (v! 0 0 0 1))
;;--------------------------------------------------
(setf *actors* nil)
;;(make-pbr (v! 0 -2 0))
;;(make-pbr)
(make-piso (v! 0 -2 0))
(make-thing)
(make-cubemap)
;;(make-pbr-simple (v! 0 0 -10))
NIL)
(defun draw! ()
(let* ((res (surface-resolution (current-surface)))
(time (mynow)))
(setf (resolution (current-viewport)) res)
;;(setf (resolution (current-viewport)) (v! *dimensions*))
(update *currentcamera*)
;;(setf (pos *camera1*) *light-pos*)
(update-all-the-things *actors*)
(unless *prefilter*
(cubemap-render-to-prefilter-cubemap *camera-cubemap*
*t-cubemap*
*s-cubemap*
*t-cubemap-prefilter*)
(setf *prefilter* T))
(unless *brdf*
(setf (resolution (current-viewport)) (v! 512 512))
(map-g-into *f-brdf* #'brdf-pipe *bs*)
(setf *brdf* T))
(unless *saved*
(cubemap-render-to-irradiance-cubemap *camera-cubemap*
*t-cubemap*
*s-cubemap*
*t-cubemap-live*)
(setf *saved* T))
(update-particles)
;; #1
(with-fbo-bound (*fbo*)
(clear *fbo*)
(loop :for actor :in *actors* :do
(draw actor *currentcamera* time)))
;; #2
(with-fbo-bound (*particle-fbo*)
(clear *particle-fbo*)
(draw-particles)
)
(swap-particles)
(as-frame
(with-setf* ((depth-mask) nil
(cull-face) nil
(clear-color) (v! 0 0 0 1))
(map-g #'generic-2d-pipe *bs*
:sam *sam-particle-fbo*
:sam2 *sam*
:samd *samd-particle-fbo*)))))
(def-simple-main-loop runplay (:on-start #'initialize)
(draw!))
| 6,553 | Common Lisp | .lisp | 188 | 26.521277 | 78 | 0.516435 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1bec6daa7af7a1194d552029ae17c0d89cb546610f1fb842e484bb67551741a8 | 9,158 | [
-1
] |
9,159 | draw.lisp | azimut_shiny/examples/room/draw.lisp | (in-package :shiny)
(defparameter *pointlight-pos* (v! 0 0 0))
(defun render-all-the-things (actor camera time)
(declare (single-float time))
(update actor)
(draw actor camera time))
(defgeneric draw (actor camera time))
(defmethod draw (actor camera time))
(defmethod draw ((actor box) camera (time single-float))
(with-slots (buf scale) actor
(map-g #'generic-pipe buf
:scale scale
:color (v! .001 .001 .001)
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera))))
(defmethod draw ((actor pbr) camera (time single-float))
(with-slots (buf
color
albedo normal height roughness
uv-speed
scale ao uv-repeat metallic)
actor
(map-g #'pbr-pipe buf
:uv-repeat uv-repeat
:uv-speed uv-speed
:scale scale
:time time
:color color
:samd *samd*
;; Lighting
:cam-pos (pos camera)
:light-pos *light-pos*
;;
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)
;; PBR
:albedo albedo
:ao-map ao
:metallic metallic
:normal-map normal
:height-map height
:rough-map roughness
;; IBL
:brdf-lut *s-brdf*
:prefilter-map *s-cubemap-prefilter*
:irradiance-map *s-cubemap-live*)))
(defvar *scale* 1f0)
(defmethod draw ((actor pbr-simple) camera (time single-float))
(with-slots (buf scale color roughness metallic) actor
(map-g #'pbr-simple-pipe buf
:scale *scale*
:color color
:time time
;; Lighting
:cam-pos (pos camera)
:light-pos *light-pos*
;;
:model-world (model->world actor)
:world-view (world->view camera)
:view-clip (projection camera)
;; PBR
:roughness .1
:metallic .9
;; IBL
:brdf-lut *s-brdf*
:prefilter-map *s-cubemap-prefilter*
:irradiance-map *s-cubemap-live*)))
(defmethod draw ((actor cubemap) camera (time single-float))
(with-slots (buf) actor
(with-setf* ((cull-face) :front
(depth-test-function) #'<=)
(map-g #'cubemap-pipe buf
:tex *s-cubemap*
:mod-clip
(m4:* (projection camera)
(world->view camera))))))
| 2,611 | Common Lisp | .lisp | 78 | 23.346154 | 63 | 0.539984 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 454040a0aba2194b7aa06b789744729ffbba2496afd9b108f4e2a689efb906e9 | 9,159 | [
-1
] |
9,160 | actors.lisp | azimut_shiny/examples/room/actors.lisp | (in-package :shiny)
(defparameter *exposure* .9f0)
(defvar *scale* 1f0)
(defvar *color* (v! .3 .3 .3))
(defvar *rough* 1f0)
(defvar *pointlight-pos* (v! 0 0 0))
(defvar *actors* nil)
(defparameter *light-pos* (v! 0 1000 3000))
(defparameter *light-color* (v! .9 .9 .9))
(defparameter *exposure* 1f0)
(defparameter *parallax-scale* .01f0)
(defun update-all-the-things (l)
(declare (list l))
(loop :for actor :in l :do
(update actor)))
(defun model->world (actor)
(with-slots (pos rot) actor
(m4:* (m4:translation pos)
(q:to-mat4 rot))))
(defun delete-actor-name (actor-name)
(declare (symbol actor-name))
(setf *actors*
(delete-if
(lambda (x) (eq actor-name (slot-value x 'name)))
*actors*))
NIL)
(defun delete-actor-class (class-name)
(declare (string class-name))
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*))
NIL)
(defmethod sync (x) (+ .5 (* .5 (sin x))))
(defmethod cync (x) (+ .5 (* .5 (cos x))))
;;--------------------------------------------------
(defclass actor ()
((name :initarg :name)
(pos :initarg :pos :accessor pos)
(rot :initarg :rot :accessor rot)
(buf :initarg :buf)
(color :initarg :color)
(scale :initarg :scale))
(:default-initargs
:name (gensym)
:pos (v! 0 0 0)
:rot (q:identity)
:buf (box)
:color (v! 1 1 1)
:scale 1f0))
(defclass cubemap (actor) ())
(defun make-cubemap ()
(let ((obj (make-instance 'cubemap)))
(push obj *actors*)
obj))
(defclass pbr (actor)
((albedo :initarg :albedo)
(ao :initarg :ao)
(height :initarg :height)
(normal :initarg :normal)
(roughness :initarg :roughness)
(uv-repeat :initarg :uv-repeat)
(uv-speed :initarg :uv-speed)
(metallic :initarg :metallic))
(:default-initargs
:uv-repeat 1f0
:uv-speed .1
:metallic .1
:albedo (get-tex "static/2048/pjEmy_4K_Albedo.jpg" nil t :rgb8)
:ao (get-tex "static/2048/pjEmy_4K_AO.jpg" nil t :r8)
:height (get-tex "static/2048/pjEmy_4K_Displacement.jpg" nil t :r8)
:normal (get-tex "static/2048/pjEmy_4K_Normal.jpg" nil t :rgb8)
:roughness (get-tex "static/2048/pjEmy_4K_Roughness.jpg" nil t :r8)))
(defclass piso (pbr) ())
(defclass thing (pbr) ())
(defun make-piso (&optional (pos (v! 0 0 0)) (rot (q:identity))
(uv-speed 0f0))
(let ((obj
(make-instance
'piso
:buf (lattice 100 100 2 2 t)
:pos pos
:uv-speed uv-speed
:uv-repeat 10f0
:rot rot)))
(push obj *actors*)
obj))
(defun make-thing (&optional (pos (v! 0 0 0)) (rot (q:identity)))
(let ((obj
(make-instance
'pbr-simple
:buf (box 1 2 .3 t)
:pos pos
:rot rot)))
(push obj *actors*)
obj))
(defclass pbr-simple (actor)
((roughness :initarg :roughness)
(metallic :initarg :metallic))
(:default-initargs
:roughness .1
:metallic .1))
(defun make-pbr-simple (&optional (pos (v! 0 0 0)))
(let ((obj
(make-instance
'pbr-simple
:buf (sphere)
:pos pos)))
(push obj *actors*)
obj))
(defclass box (actor)
((buf :initform (box 2 2 2))))
(defun make-box (&optional (pos (v! 0 0 0)) (scale 1f0))
(let ((obj (make-instance 'box
:pos pos
:scale scale
:buf (box) ;;(box 3 10 1)
)))
(appendf *actors* (list obj))
obj))
(defgeneric update (actor))
(defmethod update (actor))
(defparameter *uvs* -.2)
(defmethod update ((actor pbr))
(with-slots (pos uv-repeat uv-speed) actor
;;(setf pos (v! 0 -2 0))
(setf uv-speed *uvs*)
;;(setf uv-repeat 1f0)
)
)
(defvar *rotcube* 1f0)
(defmethod update ((actor pbr-simple))
(with-slots (pos rot color roughness metallic) actor
(setf pos (v! 0 0 -4))
(setf metallic .9)
(setf color (v! .03 .03 .03))
(setf roughness .8)
;;(setf color (v! .01 .01 .01))
(setf rot (q:from-axis-angle
(v! 1 .2 .8)
(radians (* *rotcube* (mod (* 10 (mynow)) 360)))))
;; (setf pos (v! 0 0 (+ -10 (- (* 5 (sin (mynow)))))))
))
(defmethod update ((actor box)))
| 4,309 | Common Lisp | .lisp | 144 | 24.506944 | 72 | 0.569947 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7ce12f3c248048cd022b9df587fb6208115894ef70a591fb14842929b228b0a1 | 9,160 | [
-1
] |
9,162 | render.lisp | azimut_shiny/examples/room/render.lisp | (in-package :shiny)
;;--------------------------------------------------
;; 3D - g-pnt with tangent info in tb-data AND textures
(defun-g vert-with-tbdata
((vert g-pnt) (tb tb-data)
&uniform
(model-world :mat4)
(world-view :mat4)
(view-clip :mat4)
(scale :float)
;; Parallax vars
(light-pos :vec3)
(cam-pos :vec3))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(uv (treat-uvs (tex vert)))
(norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos))
(t0 (normalize
(s~ (* model-world (v! (tb-data-tangent tb) 0))
:xyz)))
(n0 (normalize
(s~ (* model-world (v! norm 0))
:xyz)))
(t0 (normalize (- t0 (* (dot t0 n0) n0))))
(b0 (cross n0 t0))
(tbn (mat3 t0 b0 n0)))
(values clip-pos
(treat-uvs uv)
norm
(s~ world-pos :xyz)
tbn
(* tbn light-pos)
(* tbn cam-pos)
(* tbn (s~ world-pos :xyz)))))
(defun-g frag-tex-tbn ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d)
(normap :sampler-2d)
(height-map :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; Parallax
(tan-cam-dir (- tan-cam-pos tan-frag-pos))
(newuv (parallax-mapping uv tan-cam-dir height-map .1))
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo newuv) :xyz)
(vec3 2.2)))
(normal (norm-from-map normap newuv))
(normal (normalize (* tbn normal))))
(values
;; (v! final-color 1)
;; (v! 1 1 1 1)
;;frag-pos
(normalize frag-norm))))
(defpipeline-g generic-tex-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (frag-tex-tbn :vec2 :vec3 :vec3 :mat3
;; Parallax
:vec3 :vec3 :vec3))
;;--------------------------------------------------
;; 3D - g-pnt mesh without tangents
(defun-g vert
((vert g-pnt) &uniform
(model-world :mat4) (world-view :mat4) (view-clip :mat4)
(scale :float))
(let* ((pos (* scale (pos vert)))
(norm (norm vert))
(tex (tex vert))
(world-norm (* (m4:to-mat3 model-world) norm))
(world-pos (* model-world (v! pos 1)))
(view-pos (* world-view world-pos))
(clip-pos (* view-clip view-pos)))
(values clip-pos
tex
world-norm
(s~ world-pos :xyz))))
;; http://wiki.ogre3d.org/tiki-index.php?page=-Point+Light+Attenuation
(defun-g frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(time :float)
(color :vec3)
(cam-pos :vec3))
(let* (
;;--------------------
(final-color color)
(final-color
(dir-light-apply final-color
(v! 20 20 20)
(v! 0 1000 1000)
frag-pos
frag-norm))
(final-color
(point-light-apply final-color
(v! 10 10 10)
*light-pos*
frag-pos
frag-norm
1f0
0.014 0.07)))
(values (v! final-color 1)
(v! 0 1 0 1))))
;;--------------------------------------------------
;; 2D - Post Processing
(defun-g frag-2d ((uv :vec2)
&uniform
(sam :sampler-2d)
(sam2 :sampler-2d)
(samd :sampler-2d))
(let* (;; (color (defered-fog
;; ;;(v! .5 .6 .7)
;; (v! .18 .17 .15)
;; uv
;; sam
;; samd))
(color (s~ (texture sam uv) :xyz))
(color2 (s~ (texture sam2 uv) :xyz))
;; (color
;; (s~ (nineveh.anti-aliasing:fxaa3 uv sam (v2! (/ 1 320f0))) :xyz))
(final-color (+ color color2))
(ldr (tone-map-reinhard final-color *exposure*))
(luma (rgb->luma-bt601 ldr))
)
;;(v! (pow ldr (vec3 2.2)) 1)
(v! ldr luma)
;;(v! (- 1 (x color)) 0 0 1)
;;(v! color 1)
;;(v! ldr 1)
))
(defpipeline-g generic-2d-pipe (:points)
:fragment (frag-2d :vec2))
;;--------------------------------------------------
;; 3D - g-pnt mesh with light shading
(defpipeline-g generic-pipe ()
:vertex (vert g-pnt)
:fragment (frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
(defun-g frag-tex ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(cam-pos :vec3)
(albedo :sampler-2d))
(let* ((light-pos *pointlight-pos*)
;; ---------
(light-color (v! 1 1 1))
(light-strength 1f0)
;;--------------------
(vec-to-light (- light-pos frag-pos))
(dir-to-light (normalize vec-to-light))
;;--------------------
(color (expt (s~ (texture albedo (* 20 uv)) :xyz)
(vec3 2.2)))
;;--------------------
;;(normal (normalize frag-norm))
;;(nfm (norm-from-map normap uv))
(color (apply-fog color
(v! .5 .6 .7)
(length (- frag-pos cam-pos))
cam-pos
(normalize (- frag-pos cam-pos)))))
(v! color 1)))
(defpipeline-g tex-pipe ()
:vertex (vert g-pnt)
:fragment (frag-tex :vec2 :vec3 :vec3))
;;--------------------------------------------------
(defun-g pbr-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
(tbn :mat3)
(tan-light-pos :vec3)
(tan-cam-pos :vec3)
(tan-frag-pos :vec3)
&uniform
(samd :sampler-2d)
(uv-repeat :float)
(uv-speed :float)
(time :float)
(color :vec3)
;; Lighting
(light-pos :vec3)
(cam-pos :vec3)
;; PBR
(metallic :float)
(albedo :sampler-2d)
(ao-map :sampler-2d)
(height-map :sampler-2d)
(normal-map :sampler-2d)
(rough-map :sampler-2d)
;; IBL
(brdf-lut :sampler-2d)
(prefilter-map :sampler-cube)
(irradiance-map :sampler-cube))
(let* (;; First change UV, then parallax!
(uv (+ (* uv uv-repeat)
(v! 0 (* uv-speed time))))
(uv (parallax-mapping-offset-flipped
uv
(normalize (- tan-cam-pos tan-frag-pos))
height-map
.03))
(roughness (x (texture rough-map uv)))
(ao (x (texture ao-map uv)))
(color (* color (expt (s~ (texture albedo uv) :xyz)
(vec3 2.2))))
;; Normal Mapping
;;(normal (normalize frag-norm))
(normal (norm-from-map normal-map uv))
(normal (normalize (* tbn normal)))
;;----------------------------------------
;; PBR
;; metallic
(n normal)
(v (normalize (- cam-pos frag-pos)))
(metallic .1)
(f0 (vec3 .04))
;;(f0 color)
(f0 (mix f0 color metallic))
;; pbr - reflectance equation
(lo (vec3 0f0))
;; lights START
(lo (+ lo (pbr-direct-lum light-pos
frag-pos
v
n
roughness
f0
metallic
color)))
;; (lo (+ lo (pbr-point-lum light-pos
;; frag-pos
;; v
;; n
;; roughness
;; f0
;; metallic
;; color)))
;; ---------- END
;;(ambient (* color ao (vec3 .03)))
;; (ambient (pbr-ambient-map-r irradiance-map
;; color
;; ao n v f0
;; roughness))
(r (reflect (- v) n))
(f (fresnel-schlick-roughness (max (dot n v) 0)
f0
roughness))
(ks f)
(kd (* (- 1 ks) (- 1 metallic)))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance color))
(prefiltered-color (s~ (texture-lod prefilter-map
r
(* roughness 4f0))
:xyz))
(env-brdf (texture brdf-lut (v! (max (dot n v) 0) (* roughness 4f0))))
(specular (* prefiltered-color (+ (* f (x env-brdf)) (y env-brdf))))
(ambient (* (+ specular (* kd diffuse)) ao))
(final-color (+ ambient lo))
;; Fog
(final-color
(fog-exp2-apply final-color
(v! .18 .17843138 .1552941)
;;(v! .2 .3 .4)
frag-pos
cam-pos .03))
)
(v! final-color 1)
;;(v! uv 0 1)
;;(v! color 1)
))
(defpipeline-g pbr-pipe ()
:vertex (vert-with-tbdata g-pnt tb-data)
:fragment (pbr-frag :vec2 :vec3 :vec3
:mat3 :vec3 :vec3 :vec3))
;;--------------------------------------------------
(defun-g pbr-simple-frag ((uv :vec2)
(frag-norm :vec3)
(frag-pos :vec3)
&uniform
(light-pos :vec3)
(time :float)
(roughness :float)
(metallic :float)
(color :vec3)
(cam-pos :vec3)
;; IBL
(irradiance-map :sampler-cube)
(prefilter-map :sampler-cube)
(brdf-lut :sampler-2d))
(let* (;; First change UV, then parallax!
(uv (treat-uvs uv))
(normal (normalize frag-norm))
(ao 1f0)
(color color)
;;----------------------------------------
;; PBR
;; metallic
;;(f0 (vec3 .04))
(f0 color)
(f0 (mix f0 color metallic))
;; pbr - reflectance equation
(n normal)
(v (normalize (- cam-pos frag-pos)))
(lo (vec3 0f0))
;; lights START
(lo (+ lo (pbr-direct-lum light-pos
frag-pos
v
n
roughness
f0
metallic
color)))
;; ---------- END
(r (reflect (- v) n))
(f (fresnel-schlick-roughness (max (dot n v) 0)
f0
roughness))
(ks f)
(kd (* (- 1 ks) (- 1 metallic)))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance color))
(prefiltered-color (s~ (texture-lod prefilter-map
r
(* roughness 4f0))
:xyz))
(env-brdf (texture brdf-lut (v! (max (dot n v) 0) (* roughness 4f0))))
(specular (* prefiltered-color (+ (* f (x env-brdf)) (y env-brdf))))
(ambient (* (+ specular (* kd diffuse)) ao))
;; (ambient (pbr-ambient-map-r irradiance-map
;; color
;; ao n v f0
;; roughness))
;;(ambient (* color ao (vec3 .3)))
(final-color (+ ambient lo))
;; Fog
;; (final-color
;; (fog-exp2-apply final-color
;; (v! 0 0 0)
;; frag-pos
;; cam-pos .03))
)
(v! final-color 1)))
;;----------------------------------------
;; Functions to apply the Irradiance Map ONLY
(defun-g pbr-ambient-map ((irradiance-map :sampler-cube)
(albedo :vec3)
(ao :float)
(n :vec3)
(v :vec3)
(f0 :vec3))
(let* ((ks (fresnel-schlick (max (dot n v) 0) f0))
(kd (- 1 ks))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance albedo)))
(* diffuse kd ao)))
(defun-g fresnel-schlick-roughness ((cos-theta :float)
(f0 :vec3)
(roughness :float))
(+ f0
(* (- (max (vec3 (- 1 roughness))
f0)
f0)
(pow (- 1 cos-theta) 5f0))))
(defun-g pbr-ambient-map-r ((irradiance-map :sampler-cube)
(albedo :vec3)
(ao :float)
(n :vec3)
(v :vec3)
(f0 :vec3)
(roughness :float))
(let* ((ks (fresnel-schlick-roughness (max (dot n v) 0)
f0
roughness))
(kd (- 1 ks))
(irradiance (s~ (texture irradiance-map n) :xyz))
(diffuse (* irradiance albedo)))
(* diffuse kd ao)))
(defpipeline-g pbr-simple-pipe ()
:vertex (vert g-pnt)
:fragment (pbr-simple-frag :vec2 :vec3 :vec3))
;;--------------------------------------------------
;; Wind - Raymarching
;; https://www.shadertoy.com/view/XtfSWX
(defun-g height ((p :vec2))
(multf p (vec2 .2))
(+ (* .4 (sin (y p)))
(* .4 (sin (x p)))))
;;--------------------------------------------------
(defun-g tri ((x :float))
(abs (- (fract x) .5)))
(defun-g tri3 ((p :vec3))
(v! (tri (+ (z p) (tri (y p))))
(tri (+ (z p) (tri (x p))))
(tri (+ (y p) (tri (x p))))))
(defun-g tri-noise-3d ((p :vec3))
(let ((z 1.4)
(rz 0f0)
(bp (vec3 0f0)))
(dotimes (i 4)
(let ((dg (tri3 bp)))
(incf p dg)
(multf bp (vec3 2f0))
(multf z 1.5)
(multf p (vec3 1.2))
(incf rz (/ (tri (+ (z p) (tri (+ (x p) (tri (y p))))))
z))
(incf bp (vec3 .14))))
rz))
(defun-g fogmap ((p :vec3)
(d :float)
(time :float))
(incf (x p) time)
(incf (z p) (* time .5))
(* (tri-noise-3d (/ (* p 2.2) (+ d 8f0)))
(smoothstep .7 .0 (y p))))
(defun-g fog ((col :vec3)
(ro :vec3)
(rd :vec3)
(mt :float)
(time :float))
(let ((d .5))
(dotimes (i 7)
(let* ((pos (+ ro (* d rd)))
(rz (fogmap pos d time)))
(setf col (mix col (v! .85 .65 .5) (clamp (* rz (smoothstep d (* 1.8 d) mt)) 0f0 1f0)))
(multf d 1.8)
(if (> d mt) (break))))
col))
| 16,598 | Common Lisp | .lisp | 446 | 23.504484 | 95 | 0.375171 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b3a1c340195fecda2f8cc16dc35a33969ae6013187e64e77a73d22977a0c4356 | 9,162 | [
-1
] |
9,164 | cyr.lisp | azimut_shiny/compositions/cyr.lisp | (in-package :shiny)
;; https://github.com/efairbanks/Cybin/blob/1a482bb824910ca2d16c94e4b8b16b8a5d9f2125/main.lua#L277
;; https://musical-artifacts.com/artifacts/415
(all-piano 22)
(fp 0 7 8)
(freverb-toggle 1)
(freverb-preset 6)
(fp 0 40)
(defun ff ())
(let ((notes '(7 0 3 0)))
(defun ff (time)
(let ((offset (mod (* 7 (floor (/ (get-universal-time) 8))) 12))
(note (elt notes (mod (get-universal-time) 4))))
(p time (+ note 60 offset) 35 1.1 0)
(when (or (zmodt 4 0)
(zmodt 4 2))
(p time (+ note offset 53) 60 1 1)
;; (p time (+ note offset 55) 60 1 1)
)
(when (or (zmodt 8 6)
(zmodt 8 0))
(p time (+ offset 36) 60 1 2)
(p time (+ offset 48) 60 1 3)))
(aat (+ time 1) #'ff it)))
(ff (quant 4))
| 812 | Common Lisp | .lisp | 25 | 27.24 | 98 | 0.560664 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5d320a6b7c19942cb87eb02e9bd3b1c4e2485d14cc387ffa504d04efd7b4c3bc | 9,164 | [
-1
] |
9,165 | burnout.lisp | azimut_shiny/compositions/burnout.lisp | (in-package #:shiny)
;;--------------------------------------------------
;; Code for "burnout"
;; https://www.youtube.com/watch?v=TcabByrOzow
;;--------------------------------------------------
;; Visual interaction code
(setf *exposure* 0f0)
(setf *sun-intensity* .1f0)
(box 10f0 10f0 10f0 t) ;; EVALUATE! to cache the geometry
(defparameter *g-exposure* (make-line (iota 10 :start .1 :step .05)))
(defparameter *g-sun* (make-line (iota 5 :start 0f0 :step 1f0)))
(defmethod play-midi :after (time note velocity duration channel))
(defmethod play-midi :after (time (note fixnum) velocity duration channel)
(at time
(lambda () (appendf *actors*
(list
(make-instance
'planet
:name :asda
:buf (box 10f0 10f0 10f0 t)
:pos (v! (between -45f0 20f0)
70f0
(between -100f0 0f0))
:scale (random 1f0)
:rot (q:from-axis-angle (v! (random 1f0)
(random 1f0)
(random 1f0))
(radians 30))))))))
(defun dall (class-name)
(setf *actors*
(delete-if
(lambda (x) (string= class-name (class-name (class-of x))))
*actors*)))
(defun ds (name)
(declare (keyword name))
(setf *actors*
(delete-if (lambda (x) (eq name (slot-value x 'name)))
*actors*)))
(defun cs (name &optional
(buf (box))
(pos (v! 0 2 0))
(scale 1f0)
(instance 'box)
(rot (q:identity)) )
(or (and (position-if (lambda (x) (equal name (slot-value x 'name))) *actors*)
(ds name))
(appendf
*actors*
(list
(make-instance
instance
:scale scale
:buf buf
:name name
:pos pos
:rot rot)))))
;;--------------------------------------------------
;; Dexer - "Cirrus" sound
;; Nudruz - code shamefully copied from official repo "scratch.lisp"
(defparameter *c5-branch*
(cm::generic-branch
#'cm::tonnetz-func
(cm::mod12 (cm::expand (list (cm::m7 (cm::indices 12)) '(0 4 7))))))
(defparameter *smoothpits*
(cm::shuffle-all
(cm::smoothlist
(cm::transp (mapcar #'cm::stack-up (cm::shuffle-all (cm::flatter *c5-branch*))) 60))))
(defparameter *notes* (make-cycle (cm::flatten *smoothpits*)))
(defparameter *durs* (make-cycle (cm::ornadurs *smoothpits* .5)))
(f (now))
(defun f ())
(defun f (time)
(let* ((ns (next *notes* 3))
(ds (next *durs* 3))
(d (reduce #'+ ds)))
(dall "BOX")
(dall "PLANET")
(setf *sun-intensity* (next *g-sun*))
(setf *exposure* (* 999200f0 (next *g-exposure*)))
(play-midi-arp time ns 40 ds 0 (d2o ds))
(if (member 0.25 ds)
(progn
(dall "BOX")
(dall "PLANET")
(play-midi time (+ 12 (car ns)) 80 d 0)
(cs (gensym)
(box 10f0 10f0 10f0 t)
(v! (between -4f0 4f0)
0f0
(between -100f0 0f0))
(random 10f0)
'box
(q:from-axis-angle (v! (random 1f0)
(random 1f0)
(random 1f0))
(radians 30)))
)
)
(aat (+ time #[d b])
#'f it)))
| 3,589 | Common Lisp | .lisp | 100 | 24.68 | 90 | 0.457769 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 8df5746b93895d18c5a9330a60e86cd2697688999061af435376a9817752ddd1 | 9,165 | [
-1
] |
9,166 | rush.lisp | azimut_shiny/compositions/rush.lisp | (in-package :shiny)
(load-csound
(merge-orcs
(get-orchestra :ourvoice)
(get-orchestra :physmodl 0)
(get-orchestra :phaser)
(get-orchestra :hallown '(5 3))))
(make-play bass "i2" :amp 1000 :keynum 60 :pluckdur .25 :left 1f0 :right 1f0)
(make-play phaser "i3" :amp 3000 :keynum 60)
(make-play phaser-effect "i4" :change .9)
(make-play phaser-reverb "i5" :p1 .93 :p2 1.2 :p3 1 :p4 7000 :p5 1)
(make-play bell "i6" :amp 1000 :keynum 60 :pan 1f0 :outch1 3 :outch2 4)
(make-play organ "i7" :amp 200 :keynum 60 :pan .5 :outch1 1 :outch2 2)
(play-bell 60 1 :pan .8 :amp 3000)
(play-phaser-effect 180)
(defun g ())
(defun f ())
(let ((pan (make-palindrome (iota 20 :start .1 :step .1)))
(up (make-cycle '(70 80 90 90)))
(lead (make-cycle (ov-scale :c4 :minor))))
(defun g (time)
(and (zmodt 2) (funcall
(pick #'play-voice-a #'play-voice-e
#'play-voice-iy #'play-voice-o)
(next lead) 2.2 :amp 4000))
(and (zmodt 3)
(destructuring-bind (a b c)
(make-chord 60 (next up) 3 (scale 0 'minor))
(and (odds .4)
(play-voice-a a 1 :amp (rcosr 950 100 4) :left (next pan)))
(and (odds .5)
(play-voice-e b 1 :amp (rcosr 950 100 5) :right (next pan)))
(and (odds .9)
(play-voice-oo c 1 :amp (rcosr 950 100 3) :left (next pan)))))
(aat (+ time #[1 b]) #'g it)))
(let ((rhythm (make-weighting '((.5 .9) 1 0)))
(i (make-cycle '(V II I IV))))
(defun f (time)
(let ((r (next rhythm)))
(and (zmodt 2)
(play-bass 30 .2 :amp 100 :pluckdur .1 :left .2))
(play-organ-arp
(make-chord 50 60 2 (pc-diatonic 0 '- (next i)))
(* r (pick .5 .4 .6))
(* r .5))
(aat (+ time #[r b]) #'f it))))
(let ((rhythm (make-weighting '((.5 .9) 1 0)))
(i (make-cycle '(V II I IV))))
(defun f (time)
(let ((r (next rhythm)))
(and (zmodt 2)
(play-bass 30 .2 :amp 100 :pluckdur .1 :left .3 :right 1.2))
(if (odds .9)
(play-organ-arp
(make-chord 50 60 2 (pc-diatonic 0 '- (next i)))
(* r (pick .5 .4 .6))
(* r .5))
(play-bell
(pick 0 (make-chord 60 70 2 (pc-diatonic 0 '- (next i))))
(+ 1 r)
:amp 700 :pan (pick .3 .7)))
(aat (+ time #[r b]) #'f it))))
(f (tempo-sync #[3 b]))
(g (tempo-sync #[1 b]))
| 2,456 | Common Lisp | .lisp | 64 | 31.09375 | 78 | 0.519094 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 043ac94be7ede1e62c3984d91630e653911db256a90f3e216e956b718f596de7 | 9,166 | [
-1
] |
9,167 | blizzard_symphony.lisp | azimut_shiny/compositions/blizzard_symphony.lisp | (in-package :shiny)
(defvar subkick 1)
(defvar clapsnare 2)
(defvar glitchy 3)
(defvar clickhat 4)
(defvar openhat 5)
(defparameter pats
`((,subkick . (1---)) ;; 4
(,clapsnare . (----1--1---1-1--)) ;; 16
(,glitchy . (-1--------------)) ;; 16
(,clickhat . (-1----)) ;; 6
(,openhat . (--1-)))) ;; 4
(defparameter pats
`((,subkick (1---)) ;; 4
(,clapsnare (----1--1---1-1--)) ;; 16
(,glitchy (-1--------------)) ;; 16
(,clickhat (-1----)) ;; 6
(,openhat (--1-)))) ;; 4
(setf (bpm *tempo*) 200)
(all-piano)
(defparameter *pats*
'((1 (1---))
(2 (--1-))
(3 (-1----))
(4 (-1--------------))
(5 (----1--1---1-1--))))
(p (now) 60 80 1 0)
(defun live-perc-sequencer (metro live-patterns &optional beat start-beat)
(if (not beat)
(let ((cur-beat (funcall metro 'get-beat)))
(live-perc-sequencer metro live-patterns cur-beat cur-beat))
(progn
(dolist (pattern live-patterns)
(when (= 1 (nth (mod (- beat start-beat) (length pattern)) pattern))
(p (now) 60 90 1 pattern)))
(let ((next-beat (funcall metro 'get-beat 1)))))))
;; Simple version
(defun live-perc-sequencer (time patterns &optional (beat 0))
(dolist (pattern patterns)
(let ((inst (car pattern))
(beats (coerce (string (cadr pattern)) 'list)))
(when (eql #\1 (nth (mod beat (length beats)) beats))
(p time 60 90 1 inst))))
(aat (+ time #[1 b]) #'live-perc-sequencer it patterns (1+ beat)))
(live-perc-sequencer (now) pats)
;; Simple, fix all integer bug
(defun live-perc-sequencer (time &optional (beat 0))
(dolist (pattern pats)
(let ((inst (car pattern))
(beats (coerce (write-to-string (caadr pattern)) 'list)))
(when (eql #\1 (nth (mod beat (length beats)) beats))
(p time 60 80 1 inst))))
;;(when (odds .1) (fluidsynth:program-change *synth* (1+ (random 5)) (random 100)))
(aat (+ time #[.5 b]) #'live-perc-sequencer it (1+ beat)))
;; qcosr
(defun live-perc-sequencer (time &optional (beat 0))
(dolist (pattern *pats*)
(let* ((inst (car pattern))
(raw-beats (caadr pattern))
(beats (if (integerp raw-beats)
(write-to-string raw-beats)
(symbol-name raw-beats)))
(beats (coerce beats 'list)))
(when (eql #\1 (nth (mod beat (length beats)) beats))
(p time (qcosr *phrygian* 65 10 1/2) 40 (pick 1 3/4) inst))))
;;(when (odds .1)
;; (fluidsynth:program-change *synth* (1+ (random 5)) (random 100)))
(aat (+ time 1) #'live-perc-sequencer it (1+ beat)))
(live-perc-sequencer (now))
(defparameter *pats*
'((3 (1-1-))
(4 (----1---))))
(defparameter *pats*
'((3 (01011101010111010))
(4 (01101100010010011))
(5 (00010010010010011))
(1 (00110110110010110))))
(all-piano)
(off-with-the-notes)
(flush-pending)
(fluidsynth:program-change *synth* 1 33)
(fluidsynth:program-change *synth* 2 13)
(fluidsynth:program-change *synth* 3 23)
(fluidsynth:program-change *synth* 4 40)
(fluidsynth:program-change *synth* 3 53)
(fluidsynth:program-change *synth* 4 9)
(fluidsynth:program-change *synth* 5 41)
;; --------------------------
(defun pcc (time chord)
(mapcar (lambda (x) (p time x 70 1 1))
(apply #'chord chord)))
(defun pcc (time chord)
(dolist (x (apply #'chord chord))
(p time x 70 2 1)))
(defun pc (time chord)
(dolist (x chord)
(p time x 70 2 1)))
(defvar chord-progression '((:b3 :m6) (:b3 :7) (:d4 :M7) (:b3 :7)))
(pc (now) (chord :b3 :m6))
(pcc (now) (pickl chord-progression))
(defun f (time chords)
(pcc time (pickl chords))
(aat (+ time #[ (pick 1 2 3/2) b]) #'f it chords))
(defun f (time chords)
(pcc time (car chords))
(aat (+ time #[ (pick 1 2 3/2) b]) #'f it (rotate chords 1)))
(defun f (time chords)
(pcc time (car chords))
(aat (+ time #[ (pick 4 3/4) b]) #'f it (rotate chords 1)))
(f (now) chord-progression)
;;;
;; mad_beats.clj
;;;
;; funky organ - 33 - 17
(fluidsynth:program-change *synth* 1 33)
(try-sounds (now) 1 33)
(defparameter chord-progression
'((:A#2 :9sus4) (:A#2 :9sus4) (:B2 :M7) (:C#3 :7)
(:D#3 :m7) (:D#3 :m9) (:G#2 :7) (:G#2 :7)))
;;;
;; screen_cast.clj
;;;
(defparameter chord-progression
'((:G#2 :m7) (:G#2 :m7) (:A#2 :m7) (:A#2 :7)
(:D#3 :m7) (:D#3 :m9) (:D#3 :7) (:D#3 :9)))
;;;
;; endlessly_rising.clj
;;;
;; Here the need for a way to associate a note with a rhythm is bigger
(defparameter *notes* '(:f4 :d4 :f4 :a4 :d5 :c5 :b4
:c5 :f#4 :e4 :f#4 :g4 :d4 :g4 :a4 :a#4
:a#4 :a4 :g4 :f4 :g4 :f4 :e4
:d4 :d#4 :e4 :e4 :f4 :e4 :d4
:c#4 :d4 :c#4 :d4 :e4 :d4 :c4 :b3 :a3 :b3 :c4 :d4 :b3 :c4 :d4
:e4 :d5 :c5 :b4 :c5 :a4 :f#4 :b4 :a4
:g#4 :a4 :b4 :c5 :d#5 :e4 :_
:_ :e4 :g4 :f#4 :e4 :d#4 :e4 :f#4 :g4 :a4 :c5 :b4 :a4))
(defparameter *rhythms* '(1/16 1/16 1/16 1/16 1/2 1/8 1/8
5/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 3/8
1/8 1/8 1/8 5/16 1/16 1/16 1/16
1/8 1/8 1/4 1/8 1/8 1/8 1/8
1/8 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16
1/8 1/4 1/16 1/16 1/8 1/8 1/8 1/16 1/16
1/8 1/16 1/16 1/8 1/8 1/4 1/4
1/8 3/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16 1/16))
(setf (bpm *tempo*) 10)
(setf (fluidsynth:setting *fluid-settings* "synth.gain") .1)
(fluidsynth:program-change *synth* 1 0)
(defun f (time notes rhythms)
(let ((note (car notes))
(rhythm (car rhythms)))
(when (not (eql note :_))
(p time (+ 1 (note note)) 60 rhythm 1))
(aat (+ time #[rhythm b]) #'f it (rotate notes -1) (rotate rhythms -1))))
(f (now) *notes* *rhythms*)
| 5,685 | Common Lisp | .lisp | 155 | 32.522581 | 85 | 0.564528 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 69da8c332343347585522c93599a0d7773ac96777c2b42842f240772c423570c | 9,167 | [
-1
] |
9,168 | ghosts.lisp | azimut_shiny/compositions/ghosts.lisp | (in-package :shiny)
;;;
;; ghosts.lisp
;; from notes in metalevel
;; kind of translated to a temporal recursion
;;;;
(defvar *metro* nil)
(setf *metro* (make-metro 60))
;; gestures
;; hitnote - note time
;; (+ note 24)
;; .5 amp
;; dur is exponentially growing
(defun hitnote (time pitch vel dur c)
(play-midi-note time (+ pitch 24) vel (mod dur 16) c))
;; thump - note time
;; 1) -18 note
;; .4 amp
;; .05 dur
;; 2) -23 note
;; .4 amp
;; .05
(defun thump (time pitch vel dur c cc)
(play-midi-note time (- pitch 18) vel dur c)
(play-midi-note time (- pitch 23) vel dur cc))
;; riff - note rhy
(defun riff (note)
(do ((i (+ 39 (mod note 13)) (+ i 13))
(k '() (push i k))
(j 0 (1+ j)))
((> j 4) (reverse k))))
(defun ghosts (beat time root i)
(let* ((c-beat (random-elt #(1 1/2 3/2)))
(n-beat (+ beat c-beat)))
(play-midi-note time root 30 .5 1)
(when (> root 65)
;; ghost/thumb
(play-midi-note time
(+ 24 root)
35
(+ 5 (mod (+ i 1) 10))
10)
; (at (+ time #[.1 b]) #'play-midi-arpeggio time (riff root) 20 .1 13))
;; (when (= c-beat 3/2)
;; (thump time root 30 .5 15 16))
(aat (funcall *metro* n-beat) #'ghosts n-beat it
(cm:ran :from 53 :below 77) (1+ i))))
(ghosts (funcall *metro* 'get-beat 4)
(funcall *metro* (funcall *metro* 'get-beat 4))
(cm:ran :from 53 :below 77) 0)
(fluidsynth:program-change *synth* 1 1)
(fluidsynth:program-change *synth* 10 43)
(flush-pending)
(off-with-the-notes *synth*)
| 1,663 | Common Lisp | .lisp | 54 | 25.888889 | 77 | 0.539087 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2f9750dbda7bdb6c729152f1ad5abcdaceca876fdd2e71cd5f16daf10f611119 | 9,168 | [
-1
] |
9,169 | fractional.lisp | azimut_shiny/compositions/fractional.lisp | (in-package :shiny)
;; https://github.com/laurasirco/The-Algorithmic-Composer-MAC/blob/master/src/FractionalNoiseComposer.cpp
;; From what I see the algorithm works by:
;; - Creating a list/array with all the notes from a scale across
;; several octaves.
;; - Elements from that array then are pick by a our random function using
;; the array index value.
;; The random function has a concept of a "seed" that is self-feed across
;; calls. Making it less random. I guess.
;; compose()
(defparameter max-pitch 96)
(defparameter min-pitch 36)
(defparameter *seed* nil)
(defparameter *pitches-noises* nil)
;; set-pitches-based-on-scale-and-octaves()
;;(defparameter *scale* 1)
(defparameter *pitches* nil)
(defparameter *pitches-array* nil)
;; (defvar min-octave 1)
;; (defvar max-octave 6)
;; (defparameter *scale-chromatic*
;; (make-array 12 :initial-contents (scale 0 'chromatic)))
;; (defparameter *scale-pentatonic*
;; (make-array 5 :initial-contents (scale 0 'pentatonic)))
;; (defparameter *myscales*
;; (make-array 2 :initial-contents
;; (list *scale-chromatic*
;; *scale-pentatonic*)))
;; ------------------------
;; Set pitches from scale
;; ------------------------
(defun set-pitches-based-on-scale-and-octaves (pc min-octave max-octave)
(let ((max (length pc)))
(setf *pitches* nil
*pitches-array* nil)
(loop :for octave :from min-octave :upto max-octave :do
(loop :for tone :below max :do
(let ((pitch (+ (* 10 (+ octave 2))
(+ 4 (* octave 2))
(nth tone pc))))
(push pitch *pitches*))))
(setf *pitches-array*
(make-array (length *pitches*) :initial-contents *pitches*))))
;; (defun set-pitches-based-on-scale-and-octaves ()
;; (let ((max 7))
;; (cond ((equal *scale* 0) (setf max 12))
;; ((equal *scale* 1) (setf max 5)))
;; (setf *pitches* nil
;; *pitches-array* nil)
;; (loop :for octave :from min-octave :upto max-octave :do
;; (loop :for tone :below max :do
;; (let ((pitch (+ (* 10 (+ octave 2))
;; (+ 4 (* octave 2))
;; (aref (aref *myscales* *scale*) tone))))
;; (push pitch *pitches*))))
;; (setf *pitches-array*
;; (make-array (length *pitches*) :initial-contents *pitches*))))
;; ----------------------
;; Mapping functions
;; ----------------------
(defun map-interpolate (x in-min in-max out-min out-max)
(let ((returnvalue (+ out-min
(/ (* (- x in-min)
(- out-max out-min))
(- in-max in-min)))))
returnvalue))
(defun map-value (value min max)
(let ((returnvalue (round (+ min (* value (- max min))))))
returnvalue))
(defparameter *dtype* #(d-whole whole d-half half
d-quarter quarter d-eighth eighth
d-sixteenth sixteenth
d-thirty-second thirdty-second
sixty-fourth))
(defun type-to-duration (tt)
(let ((d 0))
(case tt
((d-whole) (setf d (+ 1.0 0.5 )))
((whole) (setf d 1.0))
((d-half) (setf d (+ 0.5 (/ 0.5 2))))
((half) (setf d 0.5))
((d-quarter) (setf d (+ 0.25 (/ 0.25 2))))
((quarter) (setf d 0.25))
((d-eighth) (setf d (+ 0.125 (/ 0.125 2))))
((eighth) (setf d 0.125))
((d-sixteenth) (setf d (+ 0.0625 (/ 0.0625 2))))
((sixteenth) (setf d 0.0625))
((d-thirty-second) (setf d (+ 0.03125 (/ 0.03125 2))))
((thirty-second) (setf d 0.03125))
((sixty-fourth) (setf d 0.015625)))
(* d 4)))
;; ----------------------
;; Random functions
;; ----------------------
(defun r8-uniform-01 ()
"returns a unit pseudorandom R8."
(let* ((i4-huge 2147483647)
(seed *seed*)
(k (round (/ seed 127773)))
(seed (- (* 16807 (- seed (* k 127773)))
(* k 2836)))
(seed (if (< seed 0) (+ seed i4-huge) seed))
(r (* seed 4.656612875 (expt 10 -10))))
(setf *seed* seed)
r))
;; Simulating a "constant" variable
(let ((used 0)
(seed1 0) (seed2 0) (seed3 0)
(v2 0.0))
(defun r8-normal-01 ()
"returns a unit pseudonormal R8
The standard normal probability distribution function (PDF) has
mean 0 and standard deviation 1."
(let ((v1 0)
(r1 0)
(r2 0))
;; If USED is odd but the input SEED does not match
;; the output SEED on the previous call, then the user has changed
;; the seed. Wipe out internal memory.
(when (and (equal (mod used 2) 1)
(not (equal *seed* seed2)))
(setf used 0
seed1 0 seed2 0 seed3 0
v2 0.0))
(if (equal (mod used 2) 0)
(progn
(setf seed1 *seed*
r1 (r8-uniform-01)
seed2 *seed*
r2 (r8-uniform-01)
seed3 *seed*
*seed* seed2
v1 (* (sqrt (* -2.0 (log r1)))
(cos (* 2.0 pi r2)))
v2 (* (sqrt (* -2.0 (log r1)))
(sin (* 2.0 pi r2)))))
(progn
(setf v1 v2
*seed* seed3)))
(incf used)
v1)))
(defun r8vec-sftb (n azero a b)
"computes a \"slow\" backward Fourier transform of real data"
(let ((r (make-array n :initial-element azero)))
(loop :for i :from 0 :below n :do
(loop :for k :from 0 :below (/ n 2) :do
(let ((theta (/ (* (* (1+ k) i 2) pi)
n)))
(incf (aref r i)
(+ (* (aref a k) (cos theta))
(* (aref b k) (sin theta)))))))
r))
(defun r8vec-sftf (n r)
"computes a \"slow\" forward Fourier transform of real data."
(let ((azero 0.0)
(a (make-array
(/ n 2) :initial-element 0.0))
(b (make-array
(/ n 2) :initial-element 0.0)))
(loop :for i :below n :do
(incf azero (aref r i)))
(divf azero n)
(loop :for i :below (/ n 2) :do
(loop :for j :below n :do
(let ((theta (/ (* (* 2 j (1+ i)) pi)
n)))
(incf (aref a i)
(* (aref r j) (cos theta)))
(incf (aref b i)
(* (aref r j) (sin theta)))))
(divf (aref a i) n)
(divf (aref b i) n)
(when (not (equal i (1- (/ n 2))))
(mulf (aref a i) 2.0)
(mulf (aref b i) 2.0)))
(values azero a b)))
(defun f-alpha (n q-d alpha)
"generates a 1/F^ALPHA noise sequence."
(let ((q-d (sqrt q-d))
(hfa (make-array (* 2 n) :initial-element 0.0))
(wfa (make-array (* 2 n) :initial-element 0.0))
(h-a) (h-b) (w-a) (w-b) (h-azero) (w-azero)
(wr) (wi)
(x1 (make-array n)) (x2 (make-array n))
(ii (1- n)))
;; Generate the coefficients Hk
(setf (aref hfa 0) 1.0)
(loop :for i :from 1 :below n :do
(setf (aref hfa i) (/ (* (aref hfa (1- i))
(+ (* 0.5 alpha)
(1- i)))
i)))
;; Fill Wk with white noise
(loop :for i :from 0 :below n :do
(setf (aref wfa i)
(* q-d (r8-normal-01))))
;; Perform the discrete FT of Hk and Wk
(multiple-value-bind (azero a b) (r8vec-sftf (* 2 n) hfa)
(setf h-azero azero h-a a h-b b))
(multiple-value-bind (azero a b) (r8vec-sftf (* 2 n) wfa)
(setf w-azero azero w-a a w-b b))
;; Multiple the two complex vectors
(mulf w-azero h-azero)
(loop :for i :from 0 :below n :do
(setf wr (aref w-a i)
wi (aref w-b i))
(setf (aref w-a i) (- (* wr (aref h-a i))
(* wi (aref h-b i)))
(aref w-b i) (+ (* wi (aref h-a i))
(* wr (aref h-b i)))))
;; This scaling is introduced only to match the behavior
;; of the Numerical recipes code...
(mulf w-azero (* 2 n))
(loop :for i :from 0 :below (1- n) :do
(mulf (aref w-a i) n)
(mulf (aref w-b i) n))
(mulf (aref w-a ii) (* 2 n))
(mulf (aref w-b ii) (* 2 n))
;; Take the inverse FT of the result
(setf x2 (r8vec-sftb n w-azero w-a w-b))
(loop :for i :from 0 :below n :do
(setf (aref x1 i) (aref x2 i)))
x1))
;; ----------------------
;; Use random functions
;; ----------------------
(defun get-fractional-noise-sequence (size)
(setf *seed* (get-universal-time))
(let* ((x (f-alpha size 1.0 1.0))
(output (make-array size))
(max 0.0)
(min 0.0))
(loop :for i :from 0 :below size :do
(when (< (aref x i) min)
(setf min (aref x i)))
(when (> (aref x i) max)
(setf max (aref x i))))
;; map the values
(loop :for i :from 0 :below size :do
(setf (aref output i)
(map-interpolate (aref x i) min max 0.0 1.0 )))
output))
;; (defun compose ()
;; (let ((l-pitches (length *pitches*))
;; (position 0)
;; (pitch 0)
;; (mypitches '()))
;; (set-pitches-based-on-scale-and-octaves)
;; (setf *pitches-noises* (get-fractional-noise-sequence 300))
;; (loop :for i :from 0 :below l-pitches :do
;; (setf position (map-value (aref *pitches-noises* i)
;; 0 (1- l-pitches))
;; pitch (aref *pitches-array* position))
;; (when (< pitch min-pitch)
;; (setf pitch min-pitch))
;; (when (> pitch max-pitch)
;; (setf pitch max-pitch))
;; (push pitch mypitches))
;; mypitches))
(defun compose (pc min-octave max-octave)
(let ((l-pitches (length *pitches*))
(position 0)
(pitch 0)
(duration 0)
(mytype)
(mypitches '())
(mydurations '()))
(set-pitches-based-on-scale-and-octaves pc min-octave max-octave)
(setf *pitches-noises* (get-fractional-noise-sequence 300))
(loop :for i :from 0 :below l-pitches :do
(setf position (map-value (aref *pitches-noises* i)
0 (1- l-pitches))
pitch (aref *pitches-array* position)
mytype (aref *dtype*
(map-value (aref *pitches-noises* i)
0 12))
duration (type-to-duration mytype))
(when (< pitch min-pitch)
(setf pitch min-pitch))
(when (> pitch max-pitch)
(setf pitch max-pitch))
(push pitch mypitches)
(push duration mydurations))
(values mypitches mydurations)))
#|
(fluidsynth:program-change *synth* 1 60)
(setf (fluidsynth:setting *fluid-settings* "synth.gain") .5)
;; 46 harp
(all-piano 46)
(defun playthis (time notes)
(unless notes
(setf notes (compose)))
(p time (car notes) 50 1 (random 4))
;; (aat (+ time .5) #'playthis it (cdr notes))
)
(playthis (now) (compose))
(pa (quant 4) '(76 62 64 55 62 62 69 50 36 48 57 60 50 38 62 62 52 60 69) .5 50 1 .5)
(defun playthis (time notes dur)
(p time (car notes) 60 (car dur) 1)
(aat (+ time (car dur))
#'playthis it (cdr notes) (cdr dur)))
(multiple-value-bind (notes duration)
(compose) (playthis (now) notes duration))
(flush-pending)
|#
| 11,435 | Common Lisp | .lisp | 305 | 30.006557 | 105 | 0.510638 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4fce6f3f66ac013df1627abb43b8952255051b21353089779c338a5adcdd77f3 | 9,169 | [
-1
] |
9,170 | mondaycv.lisp | azimut_shiny/compositions/mondaycv.lisp | (in-package :shiny)
;;--------------------------------------------------
;; Monday blues - sonic-pi
;; THIS NEEDS examples/cv.lisp EVALUATED FIRST
(defun f ())
(defun ff ())
(defun fff ())
(let ((r (make-cycle (list (make-cycle '(.5) 6)
(make-cycle '(.125) 8)))))
(defun f (time)
(let ((d (next r)))
(p time 60 50 d 0)
(aat (+ time d) #'f it))))
(fp 0 0);;ctk 86 - nice 28
(f (quant 4))
(fluidsynth:cc *synth* 1 10 64)
(defun ff (time)
(p time 52 50 1 1)
(fluidsynth:cc *synth* 1 10 (pick 0 127))
;;(setf *p* 1)
;;(push (make-instance 'to-sec :sec 16) *vevents*)
(aat (+ time 1) #'ff it))
(fp 1 50)
(ff (quant 1))
(let ((notes (make-cycle '(:F4 :C4 :D4 :D4 :G4 :C4 :D4 :D4)))
(wh (make-heap '(100 300 500 200))))
(defun fff (time)
(let ((note (cm:keynum (next notes))))
(and (= note (cm:keynum :D4))
(progn
(if *fh* (setf *fh* nil) (setf *fh* 1))
(push (make-instance 'to-sec :sec (pick 300 900 800)) *vevents*)))
;;(p (+ .5 time) (+ 12 note) 50 .5 10)
;;(if *hsv* (setf *hsv* nil) (setf *hsv* 1))
;; (let ((x (next wh)))
;; (setf *w* x
;; *h* x))
(and (odds .5) (p (+ .75 time) (+ (pick 7 12 7) note) 45 .5 10))
(pa (+ .5 time) (make-chord-fixed note 3 (scale 0 'minor)) .4 60 9 .4)
(p time (+ -12 note) 60 1 2)
(p time (+ -24 note) 60 1 2)
(aat (+ time 1) #'fff it))))
(fp 2 100);; ctk 100 - nice 28
(fp 10 1)
(fff (quant 1))
(fp 9 80)
| 1,526 | Common Lisp | .lisp | 46 | 28.304348 | 79 | 0.488451 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 401c5507737a17aa2097c3003a3d5f7045ccdc9452a1521089cf7ef060f1ed2c | 9,170 | [
-1
] |
9,171 | zmod.lisp | azimut_shiny/compositions/zmod.lisp | (in-package :shiny)
(setf (bpm *tempo*) 200)
;; Note: change repeat beat
(setf (fluidsynth:setting *fluid-settings* "synth.gain") .2)
(flush-pending)
(off-with-the-notes *synth*)
(loop :for x :from 10 :to 30
:do (fluidsynth:program-change *synth* x (pick 52 53)))
(defun f (time notes)
(when (zmodt 1)
(p time (car notes) 80 1 1)
(setf notes (rotate notes -1)))
(when (zmodt 2)
(p time (cadr notes) 50 10 (+ 10 (random 20))))
(aat (+ time #[1 b]) #'f it notes))
(defun f (time notes)
(when (zmodt 1)
(p time (car notes) 80 1 1)
(setf notes (rotate notes -1)))
(when (zmodt 2)
(p time (cadr notes) 50 2 3))
(aat (+ time #[1 b]) #'f it notes))
;; violin
(fluidsynth:program-change *synth* 2 40)
(defun f (time notes)
(when (zmodt 1)
(p time (car notes) 80 1 1)
(setf notes (cdr notes)))
(when (zmodt 2)
(p time (cadr notes) 50 2 3)
(p time (cadr notes) 50 5 2)
)
(unless notes
(setf notes (make-chord 60 90 3 *phrygian*)))
(when notes
(aat (+ time #[1 b]) #'f it notes)))
(defun f (time notes)
(when (zmodt 1)
(p time (car notes) 80 1 1)
(setf notes (cdr notes)))
(when (zmodt 2)
(p time (cadr notes) 50 2 0)
(p time (cadr notes) 50 5 2))
(unless notes
(setf notes (make-chord 60 90 3 *phrygian*)))
(when (zmodt 6)
(p time (- (car notes) 24) 60 2 4))
(when notes
(aat (+ time #[1 b]) #'f it notes)))
(f (now) (make-chord 60 70 3 *phrygian*))
(flush-pending)
(off-with-the-notes *synth*)
(defvar *r* nil)
(defun f (time notes)
(when (zmodt 1)
(p time (car notes) 80 1 1)
(setf notes (cdr notes)))
(when (zmodt 2)
(when (cadr notes) (setf *r* (cadr notes)))
(p time (cadr notes) 50 (pick 2 3) 2))
(unless notes
(setf notes (make-chord 60 90 3 *phrygian*)))
(when notes
(aat (+ time #[1 b]) #'f it notes)))
(defun g (time)
(when (and *r* (zmodt 1))
(p time (qcosr *phrygian* *r* 7 3/2) 80 .5 3))
(aat (+ time #[.5 b]) #'g it))
(g (now))
(flush-pending)
(off-with-the-notes *synth*)
(fluidsynth:program-change *synth* 3 24)
| 2,091 | Common Lisp | .lisp | 72 | 25.638889 | 60 | 0.601699 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | da0ba50051ee20245b668bf52ac92ba505f4f76d4a91c88bf4fb47b15937474c | 9,171 | [
-1
] |
9,172 | markov.lisp | azimut_shiny/compositions/markov.lisp | (in-package :shiny)
;; http://lib.bsu.edu/beneficencepress/mathexchange/10-01/markovchainschordprogressions.pdf
(defparameter *markov-bach-minor*
(cm:new cm:markov :of
'((i :-> (i 0) (ii .18) (iii .01) (iv .20) (v .41) (vi .09) (viio .12))
(ii :-> (i .01) (ii 0) (iii .03) (iv 0) (v .89) (vi 0) (viio .07))
(iii :-> (i .06) (ii .06) (iii 0) (iv .25) (v .19) (vi .31) (viio .13))
(iv :-> (i .22) (ii .14) (iii 0) (iv 0) (v .48) (vi 0) (viio .15))
(v :-> (i .80) (ii 0) (iii .02) (iv .06) (v 0) (vi .10) (viio .02))
(vi :-> (i .03) (ii .54) (iii .03) (iv .14) (v .19) (vi 0) (viio .08))
(viio :-> (i .81) (ii 0) (iii .01) (iv .03) (v .15) (vi 0) (viio 0)))))
(defparameter *markov-palestrina-minor*
(cm:new cm:markov :of
'((i :-> (i 0) (ii .15) (iii .13) (iv .28) (v .14) (vi .22) (viio .08))
(ii :-> (i .08) (ii 0) (iii .15) (iv .13) (v .28) (vi .14) (viio .22))
(iii :-> (i .22) (ii .08) (iii 0) (iv .15) (v .13) (vi .28) (viio .14))
(iv :-> (i .14) (ii .22) (iii .08) (iv 0) (v .15) (vi .13) (viio .28))
(v :-> (i .28) (ii .14) (iii .22) (iv .08) (v 0) (vi .15) (viio .13))
(vi :-> (i .13) (ii .28) (iii .14) (iv .22) (v .08) (vi 0) (viio .15))
(viio :-> (i .15) (ii .13) (iii .28) (iv .14) (v .22) (vi .08) (viio 0)))))
(defparameter *markov-mozart-minor*
(cm:new cm:markov :of
'((i :-> (i 0) (ii .08) (iii 0) (iv .07) (v .68) (vi .06) (viio .11))
(ii :-> (i .37) (ii 0) (iii 0) (iv 0) (v .46) (vi 0) (viio .17))
(iii :-> (i 0) (ii 0) (iii 0) (iv .1) (v 0) (vi 0) (viio 0))
(iv :-> (i .42) (ii .10) (iii 0) (iv 0) (v .39) (vi 0) (viio .09))
(v :-> (i .82) (ii 0) (iii 0) (iv .05) (v 0) (vi .07) (viio .05))
(vi :-> (i .14) (ii .51) (iii 0) (iv .16) (v .05) (vi 0) (viio .14))
(viio :-> (i .76) (ii .01) (iii 0) (iv 0) (v .23) (vi 0) (viio 0)))))
;; From CM tutorial
(defun chant-dur (tone dur)
;; adjust dur if tone is D, F or A.
(let ((doub (* dur 2)))
(cond ((cm:scale= tone 'd4)
(odds .7 doub dur))
((cm:scale= tone 'a4)
(odds .5 doub dur))
((cm:scale= tone 'f4)
(odds .25 doub dur))
(t dur))))
(defparameter *markov-gregorian*
(new markov
:of '((d4 :-> (d4 .1) (e4 .35) (f4 .25) (g4 .1) (a4 .15))
(e4 :-> (d4 .35) (f4 .35) (e4 .1) (g4 .1) (a4 .1))
(f4 :-> (d4 .2) (e4 .2) (f4 .1) (g4 .2) (a4 .12))
(g4 :-> (d4 .2) (e4 .1) (f4 .3) (g4 .1) (a4 .3) (bf4 .2))
(a4 :-> (d4 .1) (e4 .2) (f4 .25) (g4 .3) (a4 .1) (bf4 .3))
(bf4 :-> (a4 1)))))
| 2,791 | Common Lisp | .lisp | 48 | 49.125 | 91 | 0.41213 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c9d26b4deea7650befd4ee60508fb1ca0927f248594f6e84a847d55dfd951940 | 9,172 | [
-1
] |
9,173 | metalsof.lisp | azimut_shiny/compositions/metalsof.lisp | (in-package :shiny)
;; Trying to understand the code in:
;; https://github.com/namin/metasolfeggio/tree/master/overtone
(defvar *harmony-degrees*
(mapcar (lambda (x) (mapcar #'1- x))
'((3 6 2 4 5)
(5 7)
(6)
(5 7)
(1)
(2 4)
(1))))
(defun degree-chord (d)
(mapcar (lambda (x) (mod (+ d x) 7))
(let ((ds '(0 2 4)))
(if (member (1+ d) '(5 7))
(append ds '(6))
ds))))
(defun degree-contains? (a b)
(when (find b (degree-chord a))
t))
(defun harmony-tab (ds)
(mapcar (lambda (d) (filter (lambda (x) (degree-contains? x d)) ds))
(loop for i upto 87 collect i)))
(defparameter *harmony* (mapcar #'harmony-tab *harmony-degrees*))
| 785 | Common Lisp | .lisp | 25 | 23.84 | 70 | 0.514589 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 49ae73c5ad6ce3b0d79e3d7cda0b14790d8ca29678444c7d853df75f316ff843 | 9,173 | [
-1
] |
9,174 | moonlight.lisp | azimut_shiny/compositions/moonlight.lisp | ;;;
;; Moonlight
;; https://github.com/devinroth/GenerativeMusic
;; trying to translate it...but is ending up in a different thing
;; which is fine because I am getting used to "traditional"
;; things like bass notes and arpeggios
;;;
(defun play-midi-arpeggio (time notes vel dur chan)
(let ((l-notes (length notes)))
(mapcar (lambda (x y) (play-midi-note (+ time #[x b])
y vel dur chan))
(do ((i dur (+ i dur))
(l '() (push i l)))
((> i (* dur l-notes)) (reverse l)))
notes)))
(defun play-note-mord (time pitch vol dur pc chan)
(play-midi-note time
pitch
(- vol 10)
(/ dur 2)
chan)
(play-midi-note (+ time #[1/4 b])
(pc-relative pitch 1 pc)
(- vol 10)
(/ dur 2)
chan)
(play-midi-note (+ time #[1/4 b])
pitch
vol dur chan))
(defun make-chord-random (&optional (upper 100))
(let* ((n (random 12))
(tri (+ n 3))
(fif (+ n 5)))
(mapcar (lambda (x) (let ((nn (+ 48 x)))
(if (> nn upper)
(- nn 12)
nn)))
(list n tri fif))))
(defun make-chord-random (&optional (upper 100))
(let* ((n (random 12))
(tri (+ n 3 (random 2)))
(fif (+ n 7)))
(sort (mapcar (lambda (x) (let ((nn (+ 48 x)))
(if (> nn upper)
(- nn 12)
nn)))
(list n tri fif))
'<)))
(defun make-chord-random-pc ()
(let* ((n (random 12))
(tri (+ n 3 (random 2)))
(fif (+ n 7)))
(list n tri fif)))
(defun make-chord-from-pc (pc &optional (upper 100))
(sort (mapcar (lambda (x) (let ((nn (+ 48 x)))
(if (> nn upper)
(- nn 12)
nn)))
pc)
'<)))
(defvar *metro* (make-metro 90))
(defvar *m1* nil)
(defvar *m2* nil)
(setf *m1* (make-metre '(2) 4))
(setf *m2* (make-metre '(2) 4))
#|
//melody generator
func generateMelody(_ chord: [Int]) -> Int {
var melody = chord[random(3)] + 72
if melody > 84 {
melody -= 12
}
return melody
}
|#
(defun moonlight (beat time)
(let* ((n-beat (+ beat 1)))
(play-midi-note time 45 27 .5 1)
(aat (funcall *metro* n-beat) #'moonlight n-beat it)))
(defun moonlight (beat time)
(let* ((n-beat (+ beat 1))
(chord (make-chord-random 60)))
(play-midi-note time 45 27 .5 1)
(when (funcall *m1* beat 1.0)
(if (cm:odds .6)
(play-midi-arpeggio time chord 40 2 2)
(play-midi-arpeggio time (ivl-transpose 6 chord) 40 2 2)))
(aat (funcall *metro* n-beat) #'moonlight n-beat it)))
(defun moonlight (beat time)
(let* ((n-beat (+ beat 1))
(chord (make-chord-random 60))
(r-chord (nth (random 3) chord))
(r-n-chord (+ 72 r-chord))
(r-nn-chord (if (> r-n-chord 84)
(- r-n-chord 48)
r-n-chord)))
(play-midi-note time 45 27 .5 1)
(when (funcall *m1* beat 1.0)
(play-midi-arpeggio time chord 40 2 2))
(when (funcall *m2* beat 1.0)
(if (cm:odds .3)
(play-midi-note time r-chord (cm:odds .3 45 35) 3 4)
(play-note-mord time r-nn-chord 35 3 '(0 4 7) 4)))
(aat (funcall *metro* n-beat) #'moonlight n-beat it)))
(defun moonlight (beat time)
(let* ((n-beat (+ beat 1))
(pc (make-chord-random-pc))
(chord (make-chord-from-pc pc 60))
(r-pc (nth (random 3) pc))
(r-chord (nth (random 3) chord))
(r-n-chord (+ 72 r-pc))
(r-nn-chord (if (> r-n-chord 84)
(- r-n-chord 12)
r-n-chord)))
;; beat
;; (play-midi-note time 45 27 .5 3)
;; (play-midi-note time (random-elt #(60 45)) 27 .5 3)
;; bass + melody
;; bass slightly less loud
(when (funcall *m1* beat 1.0)
(play-midi-note time
(+ 36 (nth 0 pc))
(+ 15 (random 10))
20 (random 2))
(play-midi-note time
r-nn-chord
(+ 20 (random 10))
20 (random 2)))
;; ;; arpeggio
;; - violin
(when (funcall *m1* beat 1.0)
(play-midi-arpeggio time chord 30 1.8 11))
;; - trompet
;; (when (funcall *m1* beat 1.0)
;; ;; (play-midi-note time
;; ;; (+ 24 (nth 0 chord))
;; ;; 40 20 (+ 20 (random 2)))
;; (play-midi-arpeggio time chord 40 2 2))
;; trompet solo - kill beat
;; (when (funcall *m1* beat 1.0)
;; (play-midi-arpeggio time chord 40 2 24))
;; ghost
;; (play-midi-note time 72 30 20 (+ 20 (random 2)))
;; mord or note
;; (when (funcall *m2* beat 1.0)
;; (if (cm:odds .6)
;; (play-midi-note time r-chord (cm:odds .3 35 30) 3 4)
;; (play-note-mord time r-nn-chord 30 3.5 '(0 4 7) 7)))
;; ;; (play-midi-note time r-nn-chord 55 5 4)))
(aat (funcall *metro* n-beat) #'moonlight n-beat it)))
(moonlight (funcall *metro* 'get-beat 4)
(funcall *metro* (funcall *metro* 'get-beat 4)))
(fluidsynth:program-change *synth* 1 1)
(fluidsynth:program-change *synth* 4 46)
(fluidsynth:program-change *synth* 7 38)
(fluidsynth:program-change *synth* 11 21) ;; 33
(fluidsynth:program-change *synth* 21 43)
(fluidsynth:program-change *synth* 20 43)
(flush-pending)
(off-with-the-notes)
| 5,705 | Common Lisp | .lisp | 160 | 26.68125 | 68 | 0.492545 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4b58258547e442e04c8591a77a27e6809318c6080465ba6cd9e4b60aa7e78c00 | 9,174 | [
-1
] |
9,175 | notalent.lisp | azimut_shiny/compositions/notalent.lisp | (in-package :shiny)
;; some inspiration from jazz.lisp
(fp 0 10)
(fp 1 20)
(fp 4 11)
(fp 3 20)
(fg 2.0)
(fp 0 0)
(fp 1 11)
(defvar *notes* nil)
(defun spawn-circle (pitch life
&key growth (pos (v2! 0)) (color (v3! 0))
(shape 0)
(selfcolor (v3! 1))
(pencil 1)
(rotation 0f0)
(fade 0))
(let ((mypitch pitch))
(when (eq 'cons (type-of mypitch))
(setf mypitch (first mypitch)))
(when (> mypitch 0)
(push (make-instance 'circle-note
:pos pos
:pencil pencil
:color color
:selfcolor selfcolor
:shape shape
:growth growth
:life life
:die-at (+ (get-universal-time)
(round life))
:pitch mypitch
:rotation rotation
:fade (if (= 1 fade) (float life) -1f0))
*notes*)))
pitch)
(defun spawn-circle (pitch &rest rest)
pitch)
(fg 1.0)
;;--------------------------------------------------
(let ((notes (make-cycle '(0 41))))
(defun ff (time)
(let ((note (next notes)))
(p time (spawn-circle
note 1
:shape 0
:pencil 0
:fade 1
:growth '-
;;;;;;; :selfcolor (v! 1 0 0)
;;:color (v! 0 0 0)
)
50 1 1))
(aat (+ time 1) #'ff it)))
(defun ff ())
(ff (quant 4))
(fg .1)
(let ((rhythms (make-cycle '(2/3 4/3)))
(notes (make-weighting '(60 (0 .1) (53 .1)))))
(defun f (time)
(let ((rhythm (next rhythms))
(note (next notes)))
(p time (spawn-circle note rhythm
;; :shape 1
;; :pos (v! (cm:interp note 30 -.5 90 .5) -.5)
:growth (if (= note 60) nil '+)
)
30 rhythm 0)
(aat (+ time rhythm) #'f it))))
(defun f ())
(f (tempo-sync #[1 b]))
(aat (quant 4) #'f it)
(defun fff ())
(let ((notes (make-weighting '(60 62 (59 .1))))
(rhythms (make-weighting '(4 3 (2 .5))))
(amps (make-weighting '(45 (50 .1)))))
(defun fff (time)
(let ((rhythm (next rhythms)))
(p time (spawn-circle (+ (pick 0 12 12) (next notes))
rhythm
:selfcolor (v! 1 0 0)
:shape 3
:growth '-
:rotation (random 45f0))
(next amps) .5 3)
(aat (+ time rhythm) #'fff it))))
(fff (tempo-sync #[1 b]))
(fff (quant 4))
(freverb-toggle 1)
(freverb-preset 6)
(let* ((i (make-cycle '(i iv v iv) (make-weighting '(3 (2 .1)))))
;; (b (make-cycle '(65 68 70) 10))
(c (make-cycle (pval (make-chord-fixed 75 4 (pc-diatonic 0 '- (next i))))
(make-weighting '(1 (2 .4) 3))))
(r (make-weighting '(.5 3/2 (2 .1)))))
(defun bb (time)
(let ((rhythm (next r))
(notes (next c 3)))
(p time (spawn-circle (nths notes
(pick '(0 3) '(0) '(0) '(0 2)))
rhythm
;; :growth '-
;; :pos (v! (random 1f0) (random 1f0))
:shape 1
:rotation (if (> (first notes) 70)
0f0
(random 90f0))
;; :selfcolor (v3! 0 (random .8))
)
65 rhythm 5)
(aat (+ time rhythm) #'bb it))))
(defun bb ())
(fp 5 0)
(bb (tempo-sync #[1 b]))
(bb (quant 4))
(aat (quant 4) #'bb it)
(fg .4)
| 3,963 | Common Lisp | .lisp | 117 | 21.777778 | 80 | 0.391634 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 460c2c8cf3c9788c3772feb6584d5c62218ec1d9f00d1afc049199c1f1920533 | 9,175 | [
-1
] |
9,176 | jazz.lisp | azimut_shiny/compositions/jazz.lisp | ;;;
;; jazz.lisp
;;;
(defparameter *jazz-scale* ; dorian with decorated octave
'(0 2 3 5 7 9 10 12 14))
(defparameter *jazz-changes* ; key changes
#(bf3 ef4 bf3 bf ef4 ef bf3 bf f4 ef bf3 bf))
#|
(defun jazz-high-hat (time &optional notes)
(when (null notes)
(setf notes (cm:next
(cm:new cm:cycle
:of (list 0 *gm-closed-hi-hat*
0 *gm-closed-hi-hat*))
't)))
(play-midi-note time (first notes) (round (cosr 35 5 1/2)) .33 1)
(aat (+ time #[1 b]) #'jazz-high-hat it (rest notes)))
(defun jazz-high-hat ())
(defun jazz-high-hat (time)
(p time 42 (rcosr 25 3 1/2) 1/3 1)
(aat (+ time 2) #'jazz-high-hat it))
(jazz-high-hat (quant 4))
|#
(fp 1 104)
(fg 1.0)
(fp 1 49)
(defbeat hithat 1 "x-x-"
(p time 42 (rcosr 40 3 1/2) 1/3 1))
(hithat)
(defun %hithat ())
(fp 0 13)
(let ((notes (make-weighting
'((0 .25)
40
35)))
(rhythms (make-cycle '(2/3 4/3)))
(amps (make-weighting '(51 (60 .1)))))
(defun jazz-drums (time)
(let ((rhythm (next rhythms)))
(p time (next notes) (next amps) rhythm 0)
(aat (+ time rhythm) #'jazz-drums
it))))
(defun jazz-drums ())
(jazz-drums (quant 4))
;; wt
;; is weight of resting relative to playing
;; return weighting pattern that slightly prefers
;; playing a ride 1 pattern - 51
;; over a ride 2 pattern - 59
(defun or12r (wt)
(make-weighting
(list
(list (make-weighting `(51 (0 ,wt)) 1) 1.5)
(make-weighting `(59 (0 ,wt)) 1))
2))
;; (defun lamps (amps)
;; (mapcar
;; #'round
;; (mapcar
;; (lambda (x) (cm:interp x 0.0 30 1.0 80))
;; (cm:amplitude amps))))
; Triplet 8th: 1 2 3 4 5 6 7 8 9 10 11 12
; Cymbals: 1 - x 1 - 1 1 x x 1 x 1
(fp 4 9)
(fg 2.0)
(let ((notes (make-cycle
(list
51 0 (or12r 5)
51 0 51
51 (or12r 7) (or12r 7)
51 (or12r 3) 51)))
(amps (make-cycle '(:mf :mp :fff :f
:mp :ffff :mf :mp
:fff :f :mp :ffff))))
(defun jazz-cymbals (time rhythm)
(p time (next notes)
(round (* 60 (cm:amplitude (next amps))))
rhythm 4)
(aat (+ time rhythm) #'jazz-cymbals
it rhythm)))
(jazz-cymbals (quant 4) (cm:rhythm 't8 60))
(defun jazz-cymbals ())
;;;
;; <3
;;;
(fp 11 20)
(let ((notes (make-weighting
(list
(list (make-heap *jazz-scale*
(make-weighting '(1 2 3 4)))
:weight (make-weighting '(1.5 1.65)))
0)))
(amps (make-weighting (list (make-cycle '(.5 .4 .7))
(make-cycle '(.6 .5 .8)))))
(rhythms (make-weighting (list (list (make-cycle '(2/3 1/3) 12) .4)
(list (make-cycle '(1/3) 8) .6)))))
(defun jazz-piano (time &optional root)
(and (odds .4)
(setf root (pickl *jazz-changes*)))
(let ((rhythm (next rhythms)))
(p
time
(cm:keynum (transpose (next notes) root))
(round (* 50 (next amps)))
rhythm
11)
(aat (+ time rhythm)
#'jazz-piano
it
root))))
(fp 11 99)
(fg 4.0)
(jazz-piano (quant 4))
(defun jazz-piano ())
(jazz-high-hat (funcall *metro* (funcall *metro* 'get-beat 4)) )
(jazz-cymbals (funcall *metro* (funcall *metro* 'get-beat 2)) (cm:rhythm 't8 60))
(jazz-piano (funcall *metro* (funcall *metro* 'get-beat 4)) )
(flush-pending)
(let* ((tonics (make-weighting (nths *jazz-scale* '(0 2 4 6 7))))
(colors (make-weighting (nths *jazz-scale* '(1 3 5 6 8))))
(amps (make-cycle '(.5 .4 1.0 .9 .4 .9 .5 .4 1.0 .9 .5 .9)))
(durs (make-cycle '(2/3 1/3 1/3)))
;; beat map. t is tonic, c is color, r is rest
(bmap (make-cycle (list
;; 5 possible patters for triplets 1-4
(make-weighting (list (rancyc '(:t r r :c) 1.0)
(rancyc '(:t r r r) .25)
(rancyc '(:t r :t :c) .22)
(rancyc '(:t :c :t :c) .065)
(rancyc '(:t :c :t r) .014))
1)
;; 5 possible patterns for 5-7
(make-weighting (list (rancyc '(r r :t) 1.0)
(rancyc '(r r r) .25)
(rancyc '(r :c :t) .22)
(rancyc '(:t :c :t) .038)
(rancyc '(:t :c r) .007))
1)
;; 5 possible patterns for 8-10
(make-weighting (list (rancyc '(r r :c) 1.0)
(rancyc '(r :t :c) .415)
(rancyc '(r r r) .25)
(rancyc '(:c :t :c) .11)
(rancyc '(:c :t r) .018))
1)
;; 2 possible values for 11
(make-weighting '((r :weight 1) (:t :weight .25)) 1)
;; 2 possible values for 12
(make-weighting '((r :weight 1) (:c :weight .25)) 1)))))
(defun jazz-bass (time)
(let ((x (next bmap))
(d (next durs))
(a (next amps))
(k nil))
(case x
(:t (setf k (next tonics)))
(:c (setf k (next colors))))
(when (numberp k)
(p time (transpose k 60)
(round (* 30 a))
d 10))
(aat (+ time 1/3) #'jazz-bass it))))
(fp 10 99)
(jazz-bass (quant 4))
(defun jazz-bass ())
| 6,102 | Common Lisp | .lisp | 165 | 24.8 | 84 | 0.430626 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d14f22db307239ceaeda81cca58c6de9161ef5a41dd5ca83811b678b462f712d | 9,176 | [
-1
] |
9,177 | all-i-wanted.lisp | azimut_shiny/compositions/all-i-wanted.lisp | (in-package :shiny)
;; Used by examples/cvmultiple.lisp
(defparameter *factor* 1)
(defparameter *single* 50)
(defparameter *hsv* nil)
(defparameter *size* .01)
(defparameter *stop* nil)
;; instruments were attempts to copy the ones from ctford song
;; from overtone/supercollider to incudine, some thing I dunno how to translate
;; melody is just me trying to make things sound less awful, haven't read original
;; song melody just yet
(bbuffer-load "/home/sendai/curso/furi-dream-cc.wav")
(bbuffer-load "/home/sendai/curso/furi-better-cc.wav")
(bbuffer-load "/home/sendai/curso/furi-eternity-cc.wav")
(bbuffer-load "/home/sendai/curso/furi-forget-cc.wav")
(bbuffer-load "/home/sendai/curso/furi-search-cc.wav")
(bbuffer-load "/home/sendai/curso/furi-clock-cc.wav")
(put-phrase "nothing" "furi-better-cc.wav" 1.7 1.9)
(put-phrase "better" "furi-better-cc.wav" 0 1.2)
(put-phrase "stuck" "furi-better-cc.wav" 4 1.45)
(put-phrase "jstuck" "furi-better-cc.wav" 4.35 .46)
(put-phrase "real" "furi-better-cc.wav" 5.4 4)
(put-phrase "dream" "furi-dream-cc.wav" 0 6)
(put-phrase "feel" "furi-dream-cc.wav" 6.05 5)
(put-phrase "eternity" "furi-eternity-cc.wav" 0 4.1)
(put-phrase "wait" "furi-eternity-cc.wav" 3.2 .6)
(put-phrase "into" "furi-forget-cc.wav" 0 4.7)
(put-phrase "matters" "furi-forget-cc.wav" 2.5 2)
(put-phrase "forget" "furi-forget-cc.wav" 15.4 2.3)
(put-phrase "her" "furi-forget-cc.wav" 19 2)
(put-phrase "search" "furi-search-cc.wav" 0 5)
(put-phrase "searchsearch" "furi-search-cc.wav" 0 2.6)
(put-phrase "hope" "furi-search-cc.wav" 6 4.2)
(put-phrase "missing" "furi-search-cc.wav" 13.4 2.2)
(put-phrase "time" "furi-clock-cc.wav" 0 4.7)
(put-phrase "still" "furi-clock-cc.wav" 6.9 4)
(put-phrase "stop" "furi-clock-cc.wav" 11.8 1.8)
(put-phrase "tick" "furi-clock-cc.wav" 16.5 3.5)
;; (word-play "tick" 1d0 :attenuation 2d0 :id 40 :loop-p t)
;; (bplay (gethash "furi-better-cc.wav" *buffers*) 1 0 nil :attenuation 2 :id 40)
;; (corrupt (now) 40 .2 .9 1.1)
(defun corrupt (time node &optional (time-step .2) (min-rate .9) (max-rate 1.5))
"send erratic rate changes
(bplay (gethash \"furi-better-cc.wav\" *buffers*) 1 0 nil :attenuation 2 :id 40)
(corrupt (now) 40 .2 .9 1.1)"
(let ((alive (node-id (node node))))
(when alive
(set-control node :rate (cm:between min-rate max-rate))
(aat (+ time #[time-step b]) #'corrupt it node))))
;;<3
;;--------------------------------------------------
(defun f ())
(f (tempo-sync #[12 b]))
(let* ((pc (scale 0 'aeolian))
(r 1)
(bass (make-cycle '(t nil nil nil)))
(upper (make-cycle '(t nil)))
(factor (make-heap '(1 2 3)))
(lead (make-cycle (make-chord-fixed 60 5 pc)))
(phrase nil)
(phrase (make-cycle '("dream" nil nil nil "better" nil
"real" nil
"stuck" nil "stuck" nil "jstuck" nil "jstuck" nil nil nil)))
;; (phrase (make-cycle '("dream" nil nil nil)))
;; (phrase (make-cycle '("wait" nil nil)))
)
(defun f (time)
(let ((chord (make-chord 50 70 2 pc))
(d (next r)))
;; (and (not (node-id (node 40)))
;; (word-play (next phrase)
;; :rate .9
;; :attenuation 2f0
;; :id 40))
(green (cm:hertz (car (next chord)))
:dur (pick d (/ d 2))
:volume .2
:id 10)
(if *hsv* (setf *hsv* nil) (setf *hsv* t))
(green (cm:hertz (next lead))
:dur (/ d 2)
:volume .2
:id 11)
(at (+ time #[ (/ d 2) b])
#'green (cm:hertz (next lead))
:dur (/ d 2)
:volume .4)
(when (next bass)
(setf *single* (pick 50 100 50 25))
(bass (cm:hertz (+ -12 (car chord)))
:dur 4
:volume .25
:id 2))
(when (next upper)
(setf *factor* (next factor))
(keen (cm:hertz (+ (pick 0 12) (cadr chord)))
:dur (* 2 d)
:volume .2
:id 3))
(at (+ time #[d b]) #'f (+ time #[d b])))))
(f (tempo-sync #[12 b]))
(defun f ())
;; just repeat the lead note twice
(let* ((pc (scale 0 'aeolian))
(r 1)
(factor (make-heap '(1 2 3 1 1)))
(bass (make-cycle '(nil nil nil t)))
(upper (make-cycle '(nil t)))
(phrase nil)
(phrase (make-cycle '("into" nil nil nil
"matters" nil nil nil
"into" nil
"matters" nil "matters" nil nil nil)))
(lead (make-cycle (make-chord-fixed 60 5 pc))))
(defun f (time)
(let ((chord (make-chord 50 70 2 pc))
(d (next r)))
(if *hsv* (setf *hsv* nil) (setf *hsv* t))
(and (not (node-id (node 40)))
(word-play (next phrase)
:rate .9
:attenuation 2f0
:id 40))
(green (cm:hertz (car (next chord)))
:dur (pick d (/ d 2))
:volume .2)
(let ((n (next lead)))
(green (cm:hertz n)
:dur (/ d 2)
:volume .2)
(at (+ time #[ (/ d 2) b])
#'green (cm:hertz n)
:dur (/ d 2)
:volume .4))
;; (let ((n (next lead)))
;; (green (cm:hertz n)
;; :dur (/ d 2)
;; :volume .2)
;; (at (+ time #[.25 b])
;; #'green (cm:hertz n)
;; :dur (/ d 2)
;; :volume .4)
;; (at (+ time #[.5 b])
;; #'green (cm:hertz n)
;; :dur (/ d 2)
;; :volume .4)
;; (at (+ time #[.75 b])
;; #'green (cm:hertz n)
;; :dur (/ d 2)
;; :volume .4))
(when (next bass)
(setf *single* (pick 50 100 50))
(bass (cm:hertz (+ -12 (car chord)))
:dur 4
:volume .25))
(when (next upper)
(setf *factor* (next factor))
(keen (cm:hertz (+ (pick 0 12) (cadr chord)))
:dur (* 2 d)
:volume .2))
(at (+ time #[d b]) #'f (+ time #[d b])))))
(defvar *reps* .1)
(setf *reps* .9)
(let* ((pc (scale 0 'aeolian))
(r 1)
(factor (make-heap '(2 3 4 3 4)))
(bass (make-cycle '(nil nil nil t)))
(upper (make-cycle '(nil t)))
(lead (make-cycle (make-chord-fixed 60 5 pc)))
(phrase nil)
(phrase (make-cycle '("search" nil nil nil
"searchsearch" nil nil nil
"hope" nil nil nil
"searchsearch" nil nil nil
"missing" nil nil nil nil)))
;; (phrase "wait")
(odds (make-weighting `(.1 (.5 ,(pval *reps*))))))
(defun f (time)
(let ((chord (make-chord 50 70 2 pc))
(d (next r)))
(and (not (node-id (node 40)))
(word-play (next phrase)
:rate .9
:attenuation 2f0
:id 40))
(if *hsv* (setf *hsv* nil) (setf *hsv* t))
(green (cm:hertz (car (next chord)))
:dur (pick d (/ d 2))
:volume .2)
(let ((n (next lead)))
(green (cm:hertz n)
:dur (/ d 2)
:volume .2)
(and (odds (next odds))
(at (+ time #[.25 b])
#'green (cm:hertz n)
:dur (/ d 2)
:volume .4))
(at (+ time #[.5 b])
#'green (cm:hertz n)
:dur (/ d 2)
:volume .4)
(and (odds (next odds))
(at (+ time #[.75 b])
#'green (cm:hertz n)
:dur (/ d 2)
:volume .4))
)
(setf *single* (pick 50 50 25))
(when (next bass)
;; (setf *single* (pick 50 100 50))
(bass (cm:hertz (+ -12 (car chord)))
:dur 4
:volume .25))
(when (next upper)
(setf *factor* (next factor))
(keen (cm:hertz (+ (pick 0 12) (cadr chord)))
:dur (* 2 d)
:volume .2))
(at (+ time #[d b]) #'f (+ time #[d b])))))
;;--------------------------------------------------
(let ((phrase (make-cycle '("time" nil nil nil
"still" nil nil nil
"stop" nil nil nil
"tick" nil nil nil))))
(defun f (time)
(setf *factor* 1)
(setf *single* 100)
(setf *size* 1f0)
(setf *stop* t)
(and (not (node-id (node 40)))
(word-play (next phrase) 1d0
:attenuation 2f0
:id 40))
(at (+ time #[1 b]) #'f (+ time #[1 b]))))
;;--------------------------------------------------
(let* ((pc (scale 0 'aeolian))
(r 1)
(bass (make-cycle '(nil nil nil t)))
(upper (make-cycle '(nil t)))
(factor (make-heap '(2 3 4 3 4)))
(lead (make-cycle (make-chord-fixed 60 5 pc))))
(defun f (time)
(let ((chord (make-chord 50 70 2 pc))
(d (next r)))
;; (setf *stop* nil)
(if *hsv* (setf *hsv* nil) (setf *hsv* t))
(green (cm:hertz (car (next chord)))
:dur (pick d (/ d 2))
:volume .4)
(green (cm:hertz (next lead))
:dur (/ d 3)
:volume .2)
(at (+ time #[(/ d 3) b])
#'green (cm:hertz (next lead))
:dur (/ d 3)
:volume .3)
(at (+ time #[(* 2 (/ d 3)) b])
#'green (cm:hertz (next lead))
:dur (/ d 3)
:volume .4)
(when (next bass)
(setf *single* (pick 50 100 50 25))
(bass (cm:hertz (+ -12 (car chord)))
:dur 4
:volume .25))
(when (next upper)
(setf *factor* (next factor))
(keen (cm:hertz (+ (pick 0 12) (cadr chord)))
:dur (* 2 d)
:volume .2))
(at (+ time #[d b]) #'f (+ time #[d b])))))
;; (defun gg ())
;; (defun gg (time)
;; (let ((d (pick 2 2 2 2 2 2 2 2 2 2 1)))
;; (organ (cm:hertz (pick 48 48 48 48 48 48 48 48 60))
;; :dur d
;; :volume .2
;; :id 20)
;; (at (+ time #[d b]) #'gg (+ time #[d b]))))
;; (gg (tempo-sync #[12 b]))
;; LOAD FLUIDSYNTH for this
(let* ((main (make-cycle '(nil nil nil nil nil t)))
(lead (make-heap (make-chord-fixed 75 3 (scale 0 'aeolian))))
(sizes (make-heap '(.2 .3 .4 .5 .6 .7 .8 .9)))
(phrase nil)
(phrase (make-cycle '("her" nil nil nil
"her" nil nil nl
nil nil nil nil
nil nil nil nil)))
)
(defun dd (time)
(let ((l (next lead)))
(p time l (rcosr 70 5 5) 1 1 :pan (pick 0 127))
(and (not (node-id (node 40)))
(word-play (next phrase)
:rate .9
:attenuation 2f0
:id 40))
(setf *size* .01)
(when (next main)
(p time (+ -12 l) (rcosr 60 5 5) 1 2)
(setf *size* (next sizes))
(green (cm:hertz l) :dur 6 :volume .5d0)
(at (+ time #[.2 b])
#'green (cm:hertz l) :dur 6.1 :volume .5d0)
))
(at (+ time #[1 b]) #'dd (+ time #[1 b]))))
(dd (tempo-sync #[12 b]))
(defun dd ())
(fp 2 2)
(fp 1 4)
(fg 1f0)
(f (tempo-sync #[12 b]))
(flush-pending)
(setf *stop* t)
(defun f ())
(incudine:free (node 0))
;;--------------------------------------------------
;; BELOW THIS POINT WIP...
;; (bass)
;; (incudine:free (node 0))
;; (dsp! organ (freq dur volume)
;; (:defaults 440 1 1)
;; (with-samples
;; ((in (mod (sine freq) 1d0))
;; (in (lpf in 500 1))
;; (in (hpf in
;; (* 200 (+ 1 (sine 9)))
;; .1))
;; (in (* in (envelope (make-adsr .001 .8 .1 1)
;; (line 1 0 dur #'free)))))
;; (out in in)))
;; (organ)
;; (incudine:free (node 0))
| 12,019 | Common Lisp | .lisp | 335 | 27.41194 | 90 | 0.465022 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7fe7dbdacf4baf74e3d0213f8a5b9d11573bd0c4d2cc1b6370298a83453b9722 | 9,177 | [
-1
] |
9,178 | overtone_at_all.lisp | azimut_shiny/compositions/overtone_at_all.lisp | (in-package :shiny)
;;;
;; at_all.clj
;;;
(defun zipmap (keys vals)
(let ((a (loop :for k :in keys :for v :in vals
:collect (cons k v))))
(alexandria:alist-hash-table a)))
(defun triad (scale root)
(zipmap '(:i :iii :v)
(list (funcall scale root)
(funcall scale (+ root 2))
(funcall scale (+ root 4)))))
;; NOTE: quot (!
(defun ionian (degree)
(let* ((interval (mod degree 7))
(note (nth interval '(0 2 4 5 7 9 11)))
(octave (floor (/ (- degree interval) 7))))
(+ (* 12 octave) note)))
(defun lower (note) (- note 12))
(defun raise (note) (+ note 12))
(defun with-base (chord)
(setf (gethash :base chord) (lower (gethash :i chord)))
chord)
(defvar I (with-base (triad #'ionian 0)))
(defvar II (with-base (triad #'ionian 1)))
(defvar V (with-base (triad #'ionian 4)))
(defparameter progression (list I I II II II V I))
(defvar *base* 60)
(defun even-melody (time notes)
(play-midi-note time (+ *base* (car notes)) 30 1 1)
(aat (+ time #[1 b]) #'even-melody it (cdr notes)))
(even-melody (now) (repeat 32 (mapcar #'ionian '(5 4))))
(even-melody (now) (mapcar #'ionian '(2 4 5 4 4 2 4)))
(even-melody (now) (mapcar #'ionian '(-2 1 2 2 1 1 -2 1)))
| 1,257 | Common Lisp | .lisp | 35 | 31.857143 | 58 | 0.590421 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a262453cb88d851e95ba3cf59b57c849763f740d5b9d0d2c813cdb0397dd29e8 | 9,178 | [
-1
] |
9,179 | insideout.lisp | azimut_shiny/compositions/insideout.lisp | (in-package :shiny)
(at (tempo-sync #[8 b])
#'eval
(let ((s (make-cycle '(.2 1 1 1))))
(defpattern pat1 ('("-x-x-" "x-x-" "xxxx----" "---x--------") .4)
(bbplay "kick_OH_F_9.wav" :rate 2)
(bbplay "snare_OH_FF_9.wav" :rate 1 :left (next s))
(bbplay "hihatClosed_OH_F_20.wav" :rate 2)
(bbplay "hihatOpen_OH_FF_6.wav" :rate (pick 1 2)))))
(defun pat1 ())
(pat1 (tempo-sync #[4 b]))
| 427 | Common Lisp | .lisp | 11 | 33.454545 | 71 | 0.516908 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 9c29192f65d7708862d924c96c13471930e91a3ceb8bfe327a80492893cbf6b1 | 9,179 | [
-1
] |
9,180 | faze.lisp | azimut_shiny/compositions/faze.lisp | (in-package :shiny)
(pat1 (now))
(all-piano 0)
(fp 2 10)
(fp 1 80)
(fp 3 22)
(defparameter *trigger* (make-trigger))
(defun pat1 ())
(defpattern pat1 ((get-pattern 'newday) .3)
(p time 50 50 (/ d 3) 0)
(p time 50 50 d 1)
(with-trigger-expire (*trigger* .1)
(p time 50 50 d 3)))
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/Casio/cab.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/Casio/iron.ogg")
()
(defun f ())
(let ((s (make-cycle (scale 0 'aeolian)))) (defun f (time)
;; (and (odds .1) (bbplay (gethash "cab.ogg" *buffers*)
;; :attenuation 1d0
;; :rpitch (next s)))
(bbplay (gethash "iron.ogg" *buffers*)
:attenuation 1d0
:rpitch (funcall (pick #'+ #'-) (next s)))
(aat (+ time #[1 b]) #'f it)))
(f (now))
| 865 | Common Lisp | .lisp | 26 | 28.307692 | 69 | 0.55649 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 71885c9d328e8a140bdbc5df11a94136a28b8cd8f23d506663d1b8ee7c519828 | 9,180 | [
-1
] |
9,181 | molecularmusicbox.lisp | azimut_shiny/compositions/molecularmusicbox.lisp | (in-package :shiny)
;; --------------------------------------------------------------------
;; The rules for the algorithm are as follows :
;;
;; two different note lengths need to be defined, e.g. "4" and "3"
;; a scale needs to be defined, e.g. C major (the white keys on a piano), let's say we start on the E note, the list of notes will then contain : E, F, G, A, B, C
;; a pattern length needs to be defined, e.g. 4 bars
;;
;; The algorithm will then function like so (keeping the above definitions in mind) :
;;
;; the first note of the scale (E) is played at the length of the first defined note length (4)
;; each time the duration of the played note has ended, the NEXT note in the scale (F) is played
;; once the first pattern length has been reached (4 bars), a new pattern will start
;; the previously "recorded" pattern will loop its contents indefinitely while the new patterns are created / played
;; if a newly played note sounds simultaneously with another note from a PREVIOUS pattern, the note length will change (in above example from 4 to 3).
;; this will be the new note length to use for ALL SUBSEQUENT added notes, until another simultaneously played note is found, leading it to switch back to the previous note length (in above example, back to 4).
;; as the pattern is now played over an existing one, it is likely that notes will be played in unison, leading to the switching of note length
;; as more patterns are accumulated, a perfectly mathematical pattern of notes are weaving in and out of the notes of the other patterns
;;
;; https://github.com/igorski/molecular-music-generator
;; --------------------------------------------------------------------
(defvar *mtempos* nil)
(setf *mtempos* nil)
;; Specially needed the first "off" on ptterns
;; might be a reason to drop midi :S
(defun play-midi-note-loop (time pitch velocity dur c)
;; (at (- time #[2 b]) #'fluidsynth:noteoff *synth* c pitch)
(fluidsynth:noteoff *synth* c pitch)
(callback time #'fluidsynth:noteon *synth* c pitch velocity)
(callback (+ time dur) #'fluidsynth:noteoff *synth* c pitch))
(defun play-midi-note (time pitch velocity dur c)
;; (at (- time 10) #'fluidsynth:noteoff *synth* c pitch)
(callback time #'fluidsynth:noteon *synth* c pitch velocity)
(callback (+ time dur) #'fluidsynth:noteoff *synth* c pitch))
(defun spattern (time notes pattern lengths r)
"Repeats the given pattern infinitly. You might want to comment the push to *mtempos* once the pattern are all done. Also you can play around by adding a probabily to NOT play the pattern. Instead of just fade away.
TIME the (now) time in samples where the sample will begin.
NOTES a list midi notes to play
PATTERN a list with 0's and 1's that indicate when to play the beat
LENGTHS a list of duration in beats a note should play
R is the midi channel used."
(print pattern)
(print r)
(let* ((lpattern (length pattern))
(t-lpattern (+ time (/ lpattern 2)))
(pbeat (loop
:for beat :in pattern
:for nbeat :from 0 :upto 64
:when (= 1 beat)
:collect nbeat)))
;; Take the list of beats where a note is played
;; pbeat '(0 4 8 32) and schedule it
(loop :for cbeat :in pbeat :do
(let ((note (next notes))
(length (next lengths)))
(push cbeat *mtempos*)
(if (= cbeat 0)
(play-midi-note-loop time note 25 length r)
(play-midi-note-loop (+ time (/ cbeat 2)) note 25 length r))))
(aat t-lpattern #'spattern it notes pattern lengths r)))
;; I need to use (mod) to get the next beat where there is a note
(defun ppattern (time lpattern notes length1 length2 &key
(cbeat 0)
(ibeat 0)
(chan 2)
(pchan 0)
accumbeats
accumnotes
accumlengths
play
pbeat)
(if (not (null notes))
(let ((nbeat (+ .5 cbeat))
(nibeat (+ 1 ibeat))
(nchan (if (= 9 (+ 1 chan)) (+ 2 chan) (+ 1 chan)))
(npchan (mod (+ pchan 1) 2))
(t-nbeat (+ time .5))
(note (first notes)))
;; play now
(if (or (eq play 'yes)
(= pbeat ibeat))
(progn
(play-midi-note time note 35 length1 pchan)
(setf notes (cdr notes)
pbeat (mod (+ ibeat (* length1 2))
lpattern))
(push note accumnotes)
(push 1 accumbeats)
(push length1 accumlengths))
(push 0 accumbeats))
;; reset when the next .5 beat is the last beat of the pattern
;; if not is business as usual and we stick with this pattern
(if (= lpattern nibeat)
(progn
(print "endpattern")
(aat t-nbeat #'spattern it
(new cycle :of (reverse accumnotes))
(reverse accumbeats)
(new cycle :of (reverse accumlengths))
chan)
;; This works to match agains the prev NOT the global
(if (and (= 1 (first accumbeats))
(= pbeat 0))
(progn
(print "endswap")
;;; (setf *mtempos* (append *mtempos* (list '(0))))
(aat t-nbeat #'ppattern it lpattern notes length2 length1
:pbeat pbeat
:chan nchan
:pchan npchan))
(aat t-nbeat #'ppattern it lpattern notes length1 length2
:pbeat pbeat
:chan nchan
:pchan npchan)))
(if (and (= pbeat (mod nibeat lpattern))
(numberp (position pbeat *mtempos*)))
(progn
(print "middle swap")
(aat t-nbeat #'ppattern it lpattern notes length2 length1
:accumnotes accumnotes
:accumbeats accumbeats
:accumlengths accumlengths
:cbeat nbeat
:chan chan
:ibeat nibeat
:pbeat pbeat))
(progn
(aat t-nbeat #'ppattern it lpattern notes length1 length2
:accumnotes accumnotes
:accumbeats accumbeats
:accumlengths accumlengths
:cbeat nbeat
:chan chan
:ibeat nibeat
:pbeat pbeat)))))))
(defun mbox (time lpattern note length1 length2 bottom up pc
&optional startchan)
(setf *mtempos* nil)
(let* ((midinote (cm:keynum note))
(notes (loop
:for x :from bottom :to up
:collect (pc-relative midinote x pc)))
(notes (rest notes)))
(ppattern time lpattern notes length1 length2 :play 'yes)))
#|
(mbox (funcall *metro* (funcall *metro* 'get-beat 4))
32 :E 4 3 -7 7 (scale 1 'dorian))
(mbox (tempo-sync #[1 b]) 32 :C 9 14.5 -14 14 (scale 0 'dorian))
(mbox (tempo-sync #[1 b]) 32 :G 10 3.5 -14 14 (scale 0 'dorian))
(mbox (tempo-sync #[1 b]) 32 :C 8 14.5 -7 14 (scale 0 'dorian))
(mbox (tempo-sync #[1 b]) 32 :D 9 1.5 -14 14 (scale 0 'dorian))
(mbox (tempo-sync #[1 b]) 32 :C 7 3 -7 14 (scale 0 'aeolian))
(mbox (quant 4) 32 :C 7 3 -7 14 (scale 0 'ryukyu))
(mbox (quant 4) 32 :C 9 14.5 -14 14 (scale 0 'dorian))
|#
#|
(all-piano *synth*)
(fluidsynth:program-change *synth* 3 43)
(fluidsynth:program-change *synth* 4 33)
(fluidsynth:program-change *synth* 6 43)
|#
#|
(flush-pending)
(off-with-the-notes)
|#
| 8,305 | Common Lisp | .lisp | 165 | 37.581818 | 217 | 0.535846 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6013398dc21fc3081b30e96466d833ad22541101454a1f2e0e7e7141310a670e | 9,181 | [
-1
] |
9,182 | xyz.lisp | azimut_shiny/compositions/xyz.lisp | (in-package :shiny)
(make-orc :ourvoice
:filename "ourvoice"
:filepath "/home/sendai/projects/csound-instruments/pinkston/")
;;(start-csound (get-orchestra :ourvoice))
(start-thread)
(start-csound
(merge-orcs
(get-orchestra :ourvoice)
(get-orchestra :xanadu)))
(make-play voice-a "i1"
:amp 10000 :keynum 60 :fmt1 609 :db1 0 :fmt2 1000 :db2 -6
:fmt3 2450 :db3 -12 :fmt4 2700 :db4 -11 :fmt5 3240 :db5 -24
:left 1f0 :right 1f0)
(make-play voice-e "i1"
:amp 10000 :keynum 60 :fmt1 400 :db1 0 :fmt2 1700 :db2 -9
:fmt3 2300 :db3 -8 :fmt4 2900 :db4 -11 :fmt5 3400 :db5 -19
:left 1f0 :right 1f0)
(make-play plucke "i2" :p4 0 :keynum 60)
(make-play pluck "i3" :p4 0 :keynum 60)
(make-play newfm "i4" :p4 0 :keynum 60 :llimit .2 :rlimit 2.0)
(bbuffer-load "/home/sendai/Downloads/sample/OH/kick_OH_F_9.wav")
(bbuffer-load "/home/sendai/Downloads/sample/OH/snare_OH_F_9.wav")
(bbuffer-load "/home/sendai/clips/obsession.wav")
(put-phrase "obsessed" "obsession.wav" 1.8 .4)
(put-phrase "mind" "obsession.wav" .4 2.8)
(put-phrase "filter" "obsession.wav" 3.5 4)
(word-play "filter" :amp .2)
(word-play "mind" :amp .2)
(bbplay "obsession.wav" :amp .2)
(defpattern k (("x-x- x-x- x-x- x-xx"
"--x") .25)
(bbplay "kick_OH_F_9.wav" :amp .03 :rate (between .8 1.2))
(if (odds .5)
(bbplay "snare_OH_F_9.wav" :amp .03 :rate (between .8 1.2))
(play-plucke 30 .5)))
(defun k ())
(k (tempo-sync #[1 b]))
(fp 0 22)
(let ((voice (parse-patternc "xxx-"))
(lead (make-heap (append '(0) (ov-scale :C3 :minor)))))
(defun f (time)
(p time (next lead) 40 1 0)
(and (and (odds .01) (not (node-alive 9)))
(word-play "obsessed" :id 9 :amp .2))
(if (next voice)
(play-voice-a 60 1 :amp 522 :right .1)
(play-voice-e 60 1 :amp 522 :left .1))
(aat (+ time #[1 b]) #'f it)))
(defun f ())
(f (tempo-sync #[1 b]))
(let* ((voice (parse-patternc "xxx-"))
(prob (make-line (iota 30 :start .1 :step .01)))
(q (make-weighting (list (make-cycle 1 2)
2
.5)))
(chords (new weighting :of
`(((40 43 47) :weight .9)
((40 44 47) :weight .9)
((40 43 46) :weight ,(pval (next prob)) :max 1)))))
(defun f (time)
(let ((c (next chords))
(r (next q)))
(if (next voice)
(play-voice-a 60 1 :amp 522 :right .1)
(play-voice-e 60 1 :amp 522 :left .1))
(pa time c (* r .333) '(50 45 45) 1 (* r .333))
;; (pa time (cm::tintab (cm::transp c 10) cm::ionian)
;; (* r .333) 50 2 (* r .333))
(and (and (odds .1) (not (node-alive 9)))
(word-play "obsessed" :id 9 :amp .2))
(aat (+ time #[r b]) #'f it))))
(fp 2 21)
(fp 1 22)
(fp 2 20)
;; (bbuffer-load "/home/sendai/clips/numerologist.wav")
;; (bbplay "numerologist.wav" :amp .2)
;; (put-phrase "soon" "numerologist.wav" 0 1.7)
;; (put-phrase "discard" "numerologist.wav" 1.7 3)
;; (put-phrase "longer" "numerologist.wav" 5.1 2.8)
;; (put-phrase "numerologist"
;; "numerologist.wav" 8.3 2)
;; (word-play "soon" :amp .2)
;; (word-play "discard" :amp .2)
;; (word-play "longer" :amp .2)
;; (word-play "numerologist" :amp .2)
;; (bbplay "obsession.wav" :amp .2 :downsamp 6)
;; SHINY> (nths '(4 2 1 3 2) (ov-scale :C3 :minor))
;; (55 51 50 53 51)
;; '(48 56 58 60)
| 3,485 | Common Lisp | .lisp | 90 | 32.966667 | 73 | 0.563038 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7d485be38001da96a2a29b10caa1ea0cc2d961c328eda31df644aee0000f3475 | 9,182 | [
-1
] |
9,183 | june.lisp | azimut_shiny/compositions/june.lisp | (in-package :shiny)
;; June
;; Verse: Dm, Em, C, Am
;; Chorus: F, Dm, Am, F, Am, F
(defparameter *chords*
(mapcar (lambda (x) (apply #'chord x))
'((:D4 :minor) (:E4 :minor) (:C4 :major) (:A4 :minor))))
(defparameter *chords*
(mapcar (lambda (x) (apply #'chord x))
'((:F4 :major) (:D4 :minor) (:A4 :minor)
(:F4 :major) (:A4 :minor) (:F4 :major))))
(defparameter *chords*
'((55 65 71) (57 65 71) (57 63 71) (53 63 71) (53 63 69) (53 59 69) (53 59 67)
(61 59 67) (61 57 67) (61 57 63) (59 57 63) (59 53 63) (57 53 63) (57 55 63)
(61 55 63) (61 55 65) (61 59 65) (61 59 67) (65 59 67) (65 59 69)))
(defparameter *chords*
(cm::transp (cm::tzrandchain '(0 3 4) 20) 50))
(let ((chord (make-cycle *chords*)))
(defun f (time)
(destructuring-bind (x y z)
(cm:transpose (next chord) -24)
(play-organ x .3 :pan .9)
(at (+ time #[.333 b]) #'play-organ y .3 :pan .7)
(at (+ time #[.666 b]) #'play-organ z .3))
(aat (+ time #[1 b]) #'f it)))
(defun f ())
(f (now))
| 1,040 | Common Lisp | .lisp | 27 | 34.185185 | 80 | 0.537239 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a0e592b5423c723c121e6895940916f2ce3360b059ffdf00ba879df222b77e37 | 9,183 | [
-1
] |
9,184 | cc.lisp | azimut_shiny/compositions/cc.lisp | (in-package :shiny)
(bbuffer-load "/home/sendai/clips/arvo1.wav")
(bbplay "arvo1.wav" :amp .2)
(put-phrase "sound" "arvo1.wav" 3 4.4)
(put-phrase "kill" "arvo1.wav" 25 3.5)
(put-phrase "free" "arvo1.wav" 53 3.5)
(put-phrase "art" "arvo1.wav" 57 3)
(put-phrase "but" "arvo1.wav" 61 3)
(put-phrase "necessary" "arvo1.wav" 64 2.5)
(word-play "sound" :amp .2)
(word-play "kill" :amp .2)
(word-play "free" :amp .2)
(word-play "art" :amp .2)
(word-play "but" :amp .2)
(word-play "necessary" :amp .2)
(bbuffer-load "/home/sendai/clips/obsession.wav")
(put-phrase "obsessed" "obsession.wav" 1.8 .4)
(put-phrase "mind" "obsession.wav" .4 2.8)
(put-phrase "filter" "obsession.wav" 3.5 4)
(bbuffer-load "/home/sendai/clips/go.wav")
(bbplay "go.wav" :amp .2)
(put-phrase "cosmos" "go.wav" 0 5)
(put-phrase "simple" "go.wav" 6.45 3.95)
(put-phrase "endless" "go.wav" 11 3.6)
(word-play "cosmos" :amp .2 :downsamp 8 :beat-length 4)
(word-play "simple" :amp .2 :downsamp 6 :beat-length 4)
(word-play "endless" :amp .2 :downsamp 8 :beat-length 4)
(word-play "mind" :amp .5 :downsamp 6)
(word-play "filter" :amp .5 :downsamp 6)
(aat (tempo-sync #[4 b]) #'f it 0 -12 20)
(aat (tempo-sync #[4 b]) #'f it 1 0 100)
(aat (tempo-sync #[4 b]) #'f it 2 12 64)
(aat (tempo-sync #[4 b]) #'f it 2 24 64)
(fp 2 1)
(fp 0 37)
(fg 1f0)
(defparameter *golang*
(new cycle
:of '("cosmos" "simple" "endless")
:repeat 1))
(defparameter *art*
(new cycle
:of '("art" "but" "necessary")
:repeat 1))
(fg .5)
(defparameter *c0* 0)
(defun f ())
(let* ((d (pval *c0*))
(s (ov-scale :C3 :phrygian))
(n (nths '(4 2 1 3 2) s))
(c (nths '(0 5 6 7) s))
(p (new weighting
:of
`((,c :weight 1)
(,n :weight ,d)
((0) :weight .25 :max 1))))
(q (make-weighting
(list 1/16 1/8 (make-cycle 1/32 2)))))
(defun f (time chan offset pan)
(unless (= chan 0)
(let ((r (rhythm (next q) 20))
(note (pickl (next p))))
(when (not (= note 0))
(and (odds .1) (incf *c0* .01))
(when (= chan 0)
(unless (node-alive 38)
(when (odds .1) (word-play (next *golang*) :id 38 :amp .4 :pan (pick .2 .5 .8))))
(if (member note n)
(viseq:push-cvideo
:pi "/home/sendai/clips/pi.mp4"
;; :pos 23
)
(viseq:push-cvideo
:pi "/home/sendai/clips/pi.mp4"
:pos 22
:rotation (between 10f0 40f0)
:xpos 50
:ypos 50
))
(at (+ time #[1 b]) #'viseq:delete-cvideo :pi))
(when (= chan 1)
(if (member note n)
(viseq:push-cvideo
:pi2 "/home/sendai/clips/pi-rest.mp4"
:pos 40
:repeat (pick 2 4)
:is-negative t)
(viseq:push-cvideo
:pi2 "/home/sendai/clips/pi-rest.mp4"
:pos (between 10 40)
))
(at (+ time #[2 b]) #'viseq:delete-cvideo :pi2))
(when (and (odds .1) (= chan 2))
(unless (node-alive 38)
(when (word-play (pick "art" "necessary" "kill" "sound" "free")
:downsamp (pick 4 8)
:id 38 :amp .4 :pan (pick .2 .5 .8))
(viseq:push-ctext :obs (pick "car" "la") (between 20 50) (between 20 50))
(at (+ time #[3 b]) #'viseq:delete-ctext :obs))))
(p
time
(cm:transpose note offset)
(rcosr 43 3 4)
r
chan
:pan pan))
(aat (+ time #[r b]) #'f it chan offset pan)))))
| 3,796 | Common Lisp | .lisp | 107 | 26.813084 | 95 | 0.500681 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 791711e8a8f605cf30953f51a89787534d77a758f61128a116627df519d1bcb7 | 9,184 | [
-1
] |
9,185 | ryukyu.lisp | azimut_shiny/compositions/ryukyu.lisp | (in-package :shiny)
;;; -----------
;; ryukyu scale (aka ionic pentantonic scale)
;;
;; "Algorithmic Composition with Impromptu"
;; https://vimeo.com/6587048
;; https://ianring.com/musictheory/scales/2225
;;
;; Just a random walk over the scale has an interesting sound
;;; -----------
(defun play-midi-arpeggio (time notes vel dur chan)
(let ((l-notes (length notes)))
(mapcar (lambda (x y) (play-midi-note (+ time #[x b])
y vel dur chan))
(do ((i dur (+ i dur))
(l '() (push i l)))
((> i (* dur l-notes)) (reverse l)))
notes)))
(setf (bpm *tempo*) 90)
(defvar *metro* nil)
(defvar *metre* nil)
(setf *metro* (make-metro 90))
(setf *metre* (make-metre '(20) .5))
(defvar *metre2* nil)
(setf *metre2* (make-metre '(10) .5))
(defun newscale2 ())
(defun newscale2 (time pitch)
(p time pitch (if (odds .3) 0 50) .3 1)
(aat (+ time (pick .5 .25 .5 .5))
#'newscale2 it
(if (and (odds .4)
(ispitch pitch '(0))
(not (= pitch 60)))
60
(pc-relative
pitch
(pick 1 -1)
(scale 0 'ryukyu)))))
(newscale2 (quant 4) 60)
(setf *metre2* (make-metre '(8) .5))
(setf *metre3* (make-metre '(8) .5))
;; Nice overall, BUT the chord progression feels
;; awkward at times..
;; Also I would like strings eventually...how sync them?
(defun newscale (beat time &optional (pitch 60))
(let ((n-beat (+ beat .5)))
;; (when (funcall *metre2* beat 1.0)
;; (play-midi-note time 48
;; 45
;; (random-elt #(1 1.5)) 1))
;; piano chord (?
;; (when (funcall *metre3* beat 1.0)
;; (let ((pitch (+ pitch 12)))
;; (play-midi-arpeggio
;; time
;; (list pitch (+ pitch 3 (random 2)) (+ pitch 7))
;; 35 .3 1)))
;; (when (funcall *metre2* beat 1.0)
;; (play-midi-note time (+ 24 pitch) 30 65 (+ 23 (random 2))))
;; violin
;; (when (funcall *metre* beat 1.0)
;; (play-midi-note time pitch 18 2 20)
;; (play-midi-note time (+ 12 pitch) 20 40 10))
;; chord
(when (funcall *metre* beat 1.0)
(dolist (x (make-chord 48
72
(random-elt #(2 3)) '(0 4 5 7 11)))
(p time x 25 4 8)))
(when (funcall *metre* beat 1.0)
(if (odds .9)
(let ((c (sort (make-chord
60
84
3 '(0 4 5 7 11))
'<)))
;; ghost
(p time (+ 24 pitch) 30 65 (+ 23 (random 2)))
(pa time c .5 35 :channel 14))
(let ((x (make-chord 48
72
(random-elt #(2 3))
'(0 4 5 7 11))))
(p time x 25 4 7))))
(p time pitch (odds .1 25 35) .3 1)
(aat (funcall *metro* n-beat) #'newscale
n-beat it
(if (and (odds .4)
(ispitch pitch '(0))
(not (= pitch 60)))
60
(pc-relative pitch (random-elt #(1 -1)) '(0 4 5 7 11))))))
(newscale (funcall *metro* 'get-beat 4)
(funcall *metro* (funcall *metro* 'get-beat 4)))
(setf *metre* (make-metre '(2 3 2) 0.5))
(setf *metre* (make-metre '(3) .5)) ;; 3/8
(all-piano *synth*)
(fluidsynth:program-change *synth* 10 34)
(fluidsynth:program-change *synth* 20 34)
(fluidsynth:program-change *synth* 20 34)
(fluidsynth:program-change *synth* 2 43)
(fluidsynth:program-change *synth* 8 77)
(fluidsynth:program-change *synth* 7 77)
(fluidsynth:program-change *synth* 23 43)
(fluidsynth:program-change *synth* 24 43)
(fluidsynth:program-change *synth* 25 43)
(setf (fluidsynth:setting *fluid-settings* "synth.gain") 1.)
(flush-pending)
(off-with-the-notes)
| 3,923 | Common Lisp | .lisp | 109 | 27.798165 | 71 | 0.509389 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 8312636fce80c6c161de2100dc8a3d086c7a6d004cd9a9a72730a599dd3fd732 | 9,185 | [
-1
] |
9,186 | fever.lisp | azimut_shiny/compositions/fever.lisp | (in-package :shiny)
(gmeplay "/home/sendai/nin2/Mega Man 2.nsfe" 4 0
:amp .005 :length 18 :voices '(2 0)
;; :load-only t
)
(gmeplay "/home/sendai/nin2/Mega Man 2.nsfe" 5 0
:amp .005 :length 30 :voices '(3)
;; :load-only t
)
(incudine:free (node 5))
(defun f (time)
(bbplay (gethash "/home/sendai/nin2/Mega Man 2.nsfe4" *playing*)
:id 4 :amp .01)
(bbplay (gethash "/home/sendai/nin2/Mega Man 2.nsfe5" *playing*)
:id 5 :amp .01)
(aat (+ time #[1 b]) #'f it))
(f (tempo-sync #[1 b]))
(defun f ())
(let* ((mod12 (cm::scanons 4 7 3))
(mel1 (make-cycle (cm:transpose mod12 40)))
(mel2 (make-cycle (alexandria:rotate (cm:transpose mod12 60))))
(pan1 (make-palindrome (iota 127)))
(lin2 (make-line (iota 35 :start 10)))
(pan2 (make-line (iota 64 :start 127 :step -1))))
(defun f (time)
(pa time (next mel1) .25 50 0 '(.2 .2 .2 .25) :pan (next pan1))
(pa (+ #[.1 b] time) (next mel2) .333 (next lin2) 1 .333 :pan (next pan2))
(aat (+ time #[1 b]) #'f it)))
(let* ((mod12 (cm::scanons 4 7 3))
(mel1 (make-cycle (cm:transpose mod12 40)))
(mel2 (make-cycle (alexandria:rotate (cm:transpose mod12 60))))
(pan1 (make-palindrome (iota 127))))
(defun f (time)
(pa time (next mel1) .25 50 0 '(.2 .2 .2 .25) :pan (next pan1))
(pa (+ #[.1 b] time) (next mel2) .333 45 1 .333 :pan 64)
(aat (+ time #[1 b]) #'f it)))
(fg 1f0)
(fp 1 32)
(fp 2 2)
(defun f ())
(f (now))
(cm::tintab '(60 62 64) cm::stravmode)
(let* ((mod12 (cm::scanons 4 7 3))
(mel1 (make-cycle (cm:transpose mod12 40)))
(mel2 (make-cycle (mapcar (lambda (x) (cm::tintab x cm::stravmode))
(cm::transpose mod12 60))))
(pan1 (make-palindrome (iota 127))))
(defun f (time)
(pa time (next mel1) .25 50 0 '(.2 .2 .2 .25) :pan (next pan1))
(let ((*window-name* "sec"))
(pa (+ #[.1 b] time) (fourth (next mel2)) .333 45 1 .333 :pan 64))
(aat (+ time #[1 b]) #'f it)))
(fp 1 0)
(f (now))
(defun f ())
(defparameter *notes* (cm::heapvec 20 10 50))
(defparameter *strums* (cm::strums 20 2 6 4 6))
(defparameter *rhythm* (cm::ferney '(1) '(5) *strums*))
(let ((rhythm (make-cycle (cm::ferney '(1) '(4) *strums*)))
(notes (make-cycle *notes*)))
(defun f (time)
(let ((r (next rhythm)))
(p time (next notes) 50 r 0)
(aat (+ time #[r b]) #'f it))))
(let ((rhythm (make-cycle (cm::ferney '(1) '(3) *strums*)))
(notes (make-cycle (cm::transp *notes* 21))))
(defun ff (time)
(let ((r (next rhythm)))
(p time (next notes) 50 r 0)
(aat (+ time #[r b]) #'ff it))))
(f (now))
(ff (now))
(defun f ())
(defun ff ())
;;--------------------------------------------------
(let ((chords (make-cycle
(cm::transp
(append
(cm::generic-path
#'cm::tonnetz-func
'(0 4 7) '(3 6 10)))
50))))
(defun f (time)
(play-synth-arp (next chords) .333 .333 :amp .01)
(aat (+ time #[1 b]) #'f it)))
(defun f ())
(f (now))
| 3,148 | Common Lisp | .lisp | 87 | 30.586207 | 78 | 0.523026 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5ca069d48f1cd3532930fd24f005bf95a4e7760d189673d7bb4f5b01f878f436 | 9,186 | [
-1
] |
9,187 | fractals.lisp | azimut_shiny/compositions/fractals.lisp | (in-package :shiny)
;; Fractal music
;; https://github.com/holgafreak/maxann-grace
;; https://web.archive.org/web/20000118053335/http://www.sci.fi/~mjkoskin/fractal.cm
(defun kamtorus (max &key (angle 1.3) (F 0.9)
(step 0.2) (stop 1) (orb -1) (comp 10))
(let ((xold)
(yold)
(x)
(y)
(maxl)
(skip)
(compr comp)
(o orb)
(output))
(loop :while (< o stop) :do
(setf o (+ o step))
(setf xold (/ o 3))
(setf yold (/ o 3))
(setf maxl (+ max 100))
(setf skip 100)
(loop :for i :from 0 :below maxl :do
(setf x (+ (* xold (cos angle))
(* (- (* xold xold) yold) (sin angle))))
(setf y (- (* xold (sin angle))
(* (- (* xold xold)(* F yold)) (cos angle))))
(when (< skip 0)
(decf compr)
(when (= compr 0)
(push (list x y) output)
(setf compr comp)))
(decf skip)
(setf xold x)
(setf yold y)))
(reverse output)))
(defun sign(x)
(if (< x 0)
(- 1)
1))
(defun threeply (max &key (a -55) (b -1) (c -42) (comp 1))
(let ((xold 0)
(yold 0)
(x)
(y)
(output)
(compr comp))
(loop for i from 0 below max do
(setf x (- (+ (- yold (* (sign xold) (abs (sin xold)) (cos b))) c)
(* xold (sin (+ a b c)))))
(setf y (- a xold))
(decf compr)
(when (= 0 compr)
(push (list x y) output)
(setf compr comp))
(setf xold x)
(setf yold y))
(reverse output)))
(defun lorenz (max &key (dt 0.02) (a 5) (b 15) (c 1) (comp 1))
(let ((xold 1)
(yold 1)
(zold 1)
(x)
(y)
(z)
(output)
(tt dt)
(compr comp))
(loop for i from 0 below max do
(setf x (+ xold (* (- a) xold tt) (* a yold tt)))
(setf y (- (+ yold (* b xold tt)) (* yold tt) (* zold xold tt)))
(setf z (+ zold (* (- c) zold tt) (* xold yold tt)))
; (format t "~D ~S ~S ~S ~%" i x y z)
(decf compr)
(when (= 0 compr)
(push (list x y) output)
(setf compr comp))
(setf xold x)
(setf yold y)
(setf zold z))
(reverse output)))
;;; -------------------------------------------
;; Play
;;; -------------------------------------------
;;(ql:quickload :arrow-macros)
(defvar *n1* nil)
(defvar *t1* nil)
(defvar *n2* nil)
(defvar *n3* nil)
(setf *n1* (loop :for x :in (nthcdr 0 (kamtorus 12 :angle 1.2 :comp 9))
:collect (-> x
(first)
(cm:interp -0.3 25 0.3 95)
(round))))
(setf *n2* (loop :for x :in (nthcdr 0 (kamtorus 24))
:collect (-> x
(first)
(cm:interp -0.3 25 0.3 95)
(round))))
(setf *n2* (loop :for x :in (nthcdr 0 (lorenz 50 :dt 0.01 :a 4 :b 10))
:collect (-> x
(first)
(cm:interp -15 25 15 95)
(round))))
(setf *t1* (loop :for x :in (nthcdr 0 (kamtorus 12))
:collect (-> x
(first)
(cm:interp -0.3 0 0.3 2.0)
(round))))
(defun fractaltest (time &optional notes rhythms)
(when (null notes)
(if (cm:odds .9)
(setf notes *n1*)
(setf notes (reverse *n1*))))
(when (null rhythms) (setf rhythms (repeat 24 '(1))))
;; (setf rhythms *t1*))
(let ((rhythm (first rhythms)))
(play-midi-note
time (first notes) (round (cosr 40 5 3/4)) rhythm 1)
(aat (+ time #[rhythm b])
#'fractaltest
it (rest notes) (rest rhythms))))
(defun fractaltest2 (time &optional notes rhythms)
;; normal
;; transpose
;; reverse
(when (null notes)
(let ((r (random 1.0)))
(cond ((> r .5)(setf notes *n2*))
((> r .1)(setf notes (mapcar (lambda (x) (- x 12)) *n2*)))
(t (setf notes (reverse *n2*))))))
(when (null rhythms)
(setf rhythms (repeat 24 '(.5))))
(let ((rhythm (first rhythms)))
(play-midi-note
time (first notes) 30 (cm:pick .3 .2 .5) 2)
(aat (+ time #[rhythm b])
#'fractaltest2
it (rest notes) (rest rhythms))))
(defun fractaltest3 (time &optional notes rhythms)
(when (null notes)
(if (cm:odds .9)
(setf notes *n2*)
(setf notes (reverse *n2*))))
(when (null rhythms)
(setf rhythms (cm:next (cm:new cm:weighting :of '(.5 .25 .5 .5 1 .75 .75 .5 .5 .5)) 't) ))
(let ((rhythm (first rhythms)))
(play-midi-note
time (first notes) 70 rhythm 3)
(aat (+ time #[rhythm b])
#'fractaltest3
it (rest notes) (rest rhythms))))
(fractaltest (funcall *metro* (funcall *metro* 'get-beat 4)))
(fractaltest2 (funcall *metro* (funcall *metro* 'get-beat 4.5)))
(fractaltest3 (funcall *metro* (funcall *metro* 'get-beat 4.5)))
(flush-pending)
(fluidsynth:program-change *synth* 1 49)
(fluidsynth:program-change *synth* 2 1)
#|
(defvar *notes* nil)
(defvar *rhythms* nil)
(setf *notes* nil)
(setf *rhythms* nil)
(defun generate-notes()
(let ((rhythm '(0))
(note-data nil))
(loop :for i :from 0 :below 96
:do (push (list
i
(cm:pick 1.0 1.33 0.666))
note-data))
(loop :for i :from 1 :below 5
:do (push (/ 2.0 (expt 2 i)) rhythm))
(push '-0.5 rhythm)
(push '-1.0 rhythm)
(values (reverse rhythm)
(reverse note-data))))
(multiple-value-bind (x y) (generate-notes)
(setf *rhythms* x) (setf *notes* y))
;;; func to calc note and rhythm
(defun trig(x y maxx minx maxy miny start-n start-r mode)
(let ((note-val)
(picker)
(rhyt)
(diff)
(rpick))
(if (< minx 0)
(setf diff (- x minx))
(setf diff (+ x minx)))
(setf picker (round (+ (* diff maxx) start-n)))
(when (> picker (length *notes*))
(setf picker (1- (length *notes*))))
(when (< picker 0) (setf picker 0))
(setf note-val (nth picker *notes*))
(unless (null mode)
(if (< miny 0)
(setf diff (- y miny))
(setf diff (+ y miny)))
(setf picker (round (+ (* diff maxy) start-r)))
(when (< picker 0) (setf picker 0))
(when (> picker (length *rhythms*))
(setf picker (1- (length *rhythms*))))
(setf rhyt (nth picker *rhythms*))
(setf note-val (list (car note-val) rhyt)))
(format t "~S ~S ~S~%"x y note-val)
note-val))
(defun trig(x y maxx minx maxy miny start-n start-r mode)
(let ((note-val)
(picker)
(rhyt)
(diff)
(rpick))
(if (< minx 0)
(setf diff (- x minx))
(setf diff (+ x minx)))
(setf picker (round (+ (* diff maxx) start-n)))
(when (> picker (length *notes*))
(setf picker (1- (length *notes*))))
(when (< picker 0) (setf picker 0))
(setf note-val (nth picker *notes*))
(unless (null mode)
(if (< miny 0)
(setf diff (- y miny))
(setf diff (+ y miny)))
(setf picker (round (+ (* diff maxy) start-r)))
(when (< picker 0) (setf picker 0))
(when (> picker (length *rhythms*))
(setf picker (1- (length *rhythms*))))
(setf rhyt (nth picker *rhythms*))
(setf note-val (list (car note-val) rhyt)))
(format t "~S ~S ~S~%"x y note-val)
note-val))
(defun fract-music (tim amp fract-pairs &key (f-rhythm nil) (note-ex '(24 95)) (rhythm-ex '(0 5)) (func 'copy-list) (compr 1))
(let ((x2 0)
(y2 0)
(note-val 0)
(y 0)
(yold 0)
(maxx 0)
(minx 0)
(maxy 0)
(miny 0)
(compression compr)
(f-p)
(angle 0))
(setf f-p (funcall func fract-pairs))
(loop for n in f-p do
(setf x2 (car n))
(setf y2 (cadr n))
(if (> x2 maxx)
(setf maxx x2))
(if (< x2 minx)
(setf minx x2))
(if (> y2 maxy)
(setf maxy y2))
(if (< y2 miny)
(setf miny y2)))
(format t "max x ~S min x ~S max y ~S min y ~S~%" maxx minx maxy miny)
(setf maxy (/ (- (cadr rhythm-ex) (car rhythm-ex)) (- maxy miny))) ;; rhythms now scaled
(setf maxx (/ (- (cadr note-ex) (car note-ex)) (- maxx minx)))
(loop for i from 0 below (length f-p) do
(setf x2 (car (nth i f-p)))
(setf y2 (cadr (nth i f-p)))
(when (= compression 0)
(setf note-val (trig x2 y2 maxx
minx maxy miny (car note-ex)
(car rhythm-ex) f-rhythm))
(print (car note-val))
;; (if (< (cadr note-val) 0)
;; (object rest rhythm (abs (cadr note-val)))
;; (object midi-note note (note (car note-val)) rhythm (cadr note-val) amplitude amp))
(setf compression compr))
(setf compression (1- compression)))))
|#
| 9,086 | Common Lisp | .lisp | 273 | 25.091575 | 128 | 0.492171 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5981a514784bbd646288019f69484eed724f0e9c9d971c201abe5fe3f542db13 | 9,187 | [
-1
] |
9,188 | lightiscalling.lisp | azimut_shiny/compositions/lightiscalling.lisp | (in-package :shiny)
(fp 2 44)
(defparameter *current-note* 120)
(defun v ())
(let ((n (new cycle :of '(2 4 0 2)))
(i (new cycle :of '(i iv v))))
(defun v (time)
(let ((c (make-chord 50 70 3 (pc-diatonic 0 '- (next i)))))
;; (setf *current-note* (first c))
(p time c 35 (next n) 2))
(aat (+ time 2) #'v it)))
(v (quant 4))
(fg 1f0)
(fp 1 89)
(defun g ())
(let* ((pan 63)
(pan (make-cycle '(0 127))))
(defun g (time)
(p time 60 (rcosr 45 5 1/2) 1.2 1 :pan (next pan))
(aat (+ time 1) #'g it)))
(g (quant 4))
(fp 8 52)
(fp 0 40)
(defparameter *other-note* 40)
(defun c ())
(defun c (time start pitch &optional duration)
(p time pitch 20 duration 0)
;; (setf *other-note* pitch)
(aat (+ time duration) #'c it
(if (> pitch (- start 12))
start
(pc-relative start -1 (scale 0 'ryukyu)))
(if (> pitch (- start 12))
(pc-relative pitch -1 (scale 0 'ryukyu))
start)
(random-elt #(1 2 3))))
(c (quant 4) 72 72 1)
;; --------------------------------------------------
(fp 0 89)
(fp 4 5)
(freverb-toggle 1)
(freverb-preset 6)
(fg .5)
(defparameter c (make-chord 60 75 4 (scale 0 'lydian)))
(defun piano1 ())
(defun piano1 (time)
;; (pa time c 2 20 0 2)
(and (odds .25) (p time (+ -12 (random-elt c)) 25 (pick 4 8) 4))
(and (odds .75) (p time (+ 12 (random-elt c)) 30 (pick 4 8) 4))
(aat (+ time 8) #'piano1 it))
(piano (quant 4))
(pa (quant 4) c 4 20 0 4)
(piano1 (quant 4))
(all-piano 80)
(defun piano ())
(defun piano (time &optional (channel 0))
(let ((cc nil))
(if (> (random 1.0) .75)
(setf cc (list (first c) (second c) (1+ (third c)) (fourth c)))
(setf cc c))
(pa time cc .25 20 channel .15)
(pa (+ 1 time) cc .25 40 channel .15)
(pa (+ 2 time) cc .25 40 channel .15)
(pa (+ 3 time) cc .25 40 channel .15))
(aat (+ time 4) #'piano it channel) )
(piano (quant 4) 0)
(piano (quant 2) 30)
(fp 30 59)
(fp 3 22)
(defun g ())
;;(let ((l (new cycle :of '(0 0 0 0 1 1 2 3 4)))))
(defun g (time)
(synth 'soprano :freq (nth 1 c) :sus .6 :fmod .2 :amp .1 :rate 2 :pan (random-elt #(0 1)))
(aat (+ time 1) #'g it))
(g (quant 4))
;; !!
(fp 1 72)
(fp 1 52)
(fp 1 80) ;; majora piano
(defun cla ())
(defun cla (time)
(p time (qtanr (scale 0 'lydian) 80 5 3) 60 2 1)
(aat (+ time 2) #'cla it))
(cla (quant 4))
(fp 10 30)
(fp 10 29)
(fp 10 28)
(fp 10 50)
(defun strin ())
(defun strin (time)
(let ((r (pick 4 2 2 1)))
(p time (qcosr (scale 0 'lydian) 80 5 4) 40 r 10)
(aat (+ time r) #'strin it)))
(strin (quant 4))
(fp 11 29)
(defun f ())
(let ((i (new cycle :of '(i vi ii v)))
(r (new cycle :of '(2 2 2 2))))
(defun f (time)
(let ((mychord (make-chord 80 90 3 (pc-diatonic 0 'major (next i))))
(rr (next r)))
;; (pa time mychord .5 90 1 .5)
(p time mychord 40 rr 11)
(aat (+ time rr) #'f it))))
(f (quant 4))
| 2,925 | Common Lisp | .lisp | 105 | 24.714286 | 92 | 0.541592 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b598263adeb6882466319cff9819a83d001a3d08a2383e0d48d43bcbdc57cb4a | 9,188 | [
-1
] |
9,189 | julia.lisp | azimut_shiny/compositions/julia.lisp | (in-package :shiny)
(let* ((chord (make-chord-fixed 60 3 (ov-pc-scale :melodic-minor)))
(cc (make-cycle (list (make-cycle (first chord) 8)
(make-cycle (rest chord) 8))))
(rhythm (make-cycle (list (make-cycle 1 8)
(make-cycle 1/4 8))))
(chan (make-cycle '(0 127))))
(defun f (time)
(let ((r (next rhythm)))
(pa time (print (nth-inc 0 -12 (next cc))) (* .5 r) 50 0 (* .5 r)
:pan (if (= 1 r) (next chan) 62))
(aat (+ time r) #'f it))))
(let* ((chord (make-chord-fixed 60 3 (ov-pc-scale :melodic-minor)))
(cc (make-cycle
(list (make-cycle (list (list (first chord) 1)) 8)
(make-cycle (list (list (rest chord) 1/4)) 4))))
(chan (make-cycle '(0 127))))
(defun f (time)
(destructuring-bind (n r) (next cc)
(pa time (nth-inc 0 -12 n) (* .5 r) 50 0 (* .5 r)
:pan (if (= 1 r) (next chan) 62))
(aat (+ time r) #'f it))))
(f (quant 4))
(defun f ())
(let* ((chord (make-chord-fixed 60 3 (ov-pc-scale :melodic-minor)))
(notes (make-cycle
(append (repeat 8 (list (list (first chord) 1)))
(repeat 8 (list (list (rest chord) 1/2)))))))
(defun f (time)
(destructuring-bind (n r) (print (next notes))
(if (listp n)
(pa time n (* .5 r) 50 0 (* .5 r))
(p time n 50 r 0))
(aat (+ time r) #'f it))))
(f (quant 4))
(fp 0 72)
(fp 1 30)
(fg 1f0)
(let* ((chord (make-chord-fixed 48 3 (ov-pc-scale :melodic-minor)))
(cc (make-cycle (first chord)))
(mel (make-heap chord)))
(defun f (time)
(p time (next cc) 50 1 0)
(let ((m (next mel)))
(pa time (pick m m m (list m (pc-relative m +2 (ov-pc-scale :melodic-minor)))) 1 50 1 1))
(aat (+ time 1) #'f it)))
(f (now))
| 1,871 | Common Lisp | .lisp | 47 | 32.06383 | 95 | 0.500275 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | efeddc8cf424d46f4be9560f13cbeda83c1cf8a0c466a916c17c82af3ab7f87d | 9,189 | [
-1
] |
9,190 | foster.lisp | azimut_shiny/compositions/foster.lisp | (in-package :shiny)
(defun play-midi-note (time pitch velocity dur c)
(when (and
(not (equal pitch "r"))
(> pitch 0)
(> velocity 0)
(> dur 0))
(progn
(at time #'fluidsynth:noteon
*synth* c pitch velocity)
(at (+ time #[dur b]) #'fluidsynth:noteoff
*synth* c pitch))))
;;; Second-order Markov process. The transition table is taken
;;; from chapter 8 of "Computer Music" by Dodge/Jerse. Sounds
;;; best with slow strings.
(defparameter *m-foster*
(new cm:markov
:of '((b3 d4 :-> d4)
(cs4 d4 :-> (d4 .3125) (e4 .3125) (a4 .3125))
(d4 d4 :-> (cs4 .125) (d4 .125) (e4 .5625) (fs4 .125) (a4 .0625))
(e4 d4 :-> (b3 .0625) (d4 .0625) (e4 .25) (fs4 .3125) (a4 .0625) (cs5 .0625) (d5 .1875))
(fs4 d4 :-> (e4 .75) (fs4 .1875) (g4 .0625))
(a4 d4 :-> (e4 .6875) (fs4 .3125))
(b4 d4 :-> d4)
(d4 b3 :-> d4)
(d4 cs4 :-> d4)
(e4 cs4 :-> d4)
(d4 e4 :-> (d4 .1875) (e4 .25) (fs4 .5) (a4 .0625))
(e4 e4 :-> (cs4 .0625) (d4 .75) (e4 .0625) (fs4 .125))
(fs4 e4 :-> (cs4 .125) (d4 .4375) (e4 .1875) (fs4 .125) (a4 .0625) (d5 .0625))
(d4 fs4 :-> (e4 .4375) (fs4 .1875) (g4 .125) (a4 .25))
(e4 fs4 :-> (d4 .0625) (e4 .1875) (fs4 .3125) (g4 .25) (a4 .0625) (b4 .0625))
(fs4 fs4 :-> (d4 .1875) (e4 .25) (fs4 .3125) (g4 .125) (a4 .0625))
(g4 fs4 :-> (e4 .5) (g4 .5))
(a4 fs4 :-> (d4 .3125) (e4 .25) (fs4 .1875) (g4 .0625) (a4 .125) (b4 .0625))
(b4 fs4 :-> (e4 .6875) (fs4 .3125))
(d4 g4 :-> (fs4 .6875) (b4 .3125))
(fs4 g4 :-> (fs4 .25) (g4 .1875) (a4 .3125) (b4 .1875))
(g4 g4 :-> (g4 .5) (a4 .5))
(a4 g4 :-> fs4)
(b4 g4 :-> b4)
(a4 gs4 :-> a4)
(d4 a4 :-> (fs4 .25) (a4 .75))
(e4 a4 :-> (a4 .8125) (b4 .1875))
(fs4 a4 :-> (fs4 .125) (a4 .625) (b4 .1875) (d5 .0625))
(g4 a4 :-> (d4 .125) (a4 .625) (d5 .25))
(gs4 a4 :-> a4)
(a4 a4 :-> (fs4 .25) (g4 .0625) (gs4 .0625) (a4 .3125) (b4 .3125))
(b4 a4 :-> (d4 .0625) (fs4 .5625) (g4 .0625) (a4 .125) (b4 .0625) (d5 .125))
(d5 a4 :-> (fs4 .875) (a4 .125))
(e5 a4 :-> a4)
(fs4 b4 :-> a4)
(g4 b4 :-> a4)
(a4 b4 :-> (d4 .0625) (fs4 .0625) (a4 .75) (b4 .0625) (b4 .0625))
(b4 b4 :-> (fs4 .125) (a4 .75) (d5 .125))
(cs5 b4 :-> a4)
(d5 b4 :-> (g4 .0625) (a4 .3125) (b4 .3125) (d5 .25))
(d4 cs5 :-> d5)
(d5 cs5 :-> (b4 .75) (d5 .25))
(e5 cs5 :-> d5)
(d4 d5 :-> (a4 .125) (b4 .6875) (cs5 .1875) )
(e4 d5 :-> cs5)
(a4 d5 :-> (a4 .3125) (b4 .3125) (cs5 .1875) (d5 .125))
(b4 d5 :-> (a4 .5625) (b4 .125) (cs5 .3125))
(cs5 d5 :-> (b4 .3125) (e5 .625))
(d5 d5 :-> b4)
(d5 e5 :-> (a4 .3125) (cs5 .6875)))))
;; p2 is rhythmic pattern that randomly selects
;; between several rhythmic motives that are
;; characterisitic of Foster's sytle
(defparameter *r-foster*
(make-weighting
`((,(make-cycle '(h h)) :weight .375)
(,(make-cycle '(q q q q)) :weight .125)
(,(make-cycle '(h q q)) :weight .125)
(,(make-cycle '(q q h)) :weight .125)
(,(make-cycle '(q h q)) :weight .25)
(w :weight .125))))
(defun foster (time &optional notes rhythms root chan)
(let ((rhythm (cm:rhythm (cm:next rhythms) 120)))
(p time (cm:keynum (cm:transpose (cm:next notes) root)) 30 rhythm chan)
(aat (+ time rhythm)
#'foster
it notes rhythms root chan)))
(fp 1 20)
(fp 2 30)
(fp 3 40)
(defun foster ())
(foster (quant 4) *m-foster* *r-foster* -12 0)
(foster (quant 12) *m-foster* *r-foster* 0 1)
(foster (quant 24) *m-foster* *r-foster* 12 2)
(foster (quant 36) *m-foster* *r-foster* 24 3)
(all-piano *synth*)
(flush-pending)
(off-with-the-notes *synth*)
(fluidsynth:program-change *synth* 1 *nk-oboe*)
(fluidsynth:program-change *synth* 2 77)
(fluidsynth:program-change *synth* 2 38)
(fluidsynth:program-change *synth* 0 34)
(fluidsynth:program-change *synth* 3 77)
| 4,269 | Common Lisp | .lisp | 100 | 35.24 | 100 | 0.484601 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | d7b1358c699f94014efd4dd1400919002e7fc1475035e47802d27fd04a33724f | 9,190 | [
-1
] |
9,191 | otomata.lisp | azimut_shiny/compositions/otomata.lisp | (in-package :shiny)
;; http://earslap.com/page/otomata.html
;; https://pastebin.com/dPWLZDBs
;;
;; Each alive cell has 4 states: Up, right, down, left. at each cycle,
;; the cells move themselves in the direction of their internal
;; states. If any cell encounters a wall, it triggers a pitched sound
;; whose frequency is determined by the xy position of collision, and
;; the cell reverses its direction. If a cell encounters another cell
;; on its way, it turns itself clockwise.
;;
;; - 9x9 cells
;; - Tempo
;; - Scale: akebono, yue-diao?, bayati, dorian, harmonic minor, hijaz, hijaz kar, huzam, ionian, kokin choshi, kourd-atar, lydian, yu diao, neveseri, niavent, nirz rast, gong-diao, zhi-diao, purvi, pygmy, rast, rumanikos, sabah, segiah, sho, blues, goonkali, iwato, kumoi, locrian, magen abot, melog, mixolydian, noh, phrygian, pyeong jo, shang-diao, zokuso,
;;
;; NOTES: It does NOT MATTER if hits up or down on a column, same note is play.
;;--------------------------------------------------
;; Tonematrix
;; https://github.com/Babkock/ToneMatrix
;; Is a 16-step drum machine. The Y (vertical) axis
;; represents eight different sounds, and more than one can be
;; played at a time. The X (horizontal) axis represents one
;; measure in sixteenth-notes.
;;(fluidsynth:sfload *synth* "/home/sendai/Downloads/sf2/CTK-230_SoundFont.sf2" 1)
(bbuffer-load "/home/sendai/Downloads/Silent Hill/Ambience/Silent Hill Homecoming/Dreams of Leaving/Train Cars.wav")
(freverb-toggle 1)
(fluidsynth:set-reverb *synth* .6d0 .1d0 .9d0 25d0)
(all-piano 22)
(all-piano 33)
(defpattern k (("--------x-------"
"----x-----------"
"----------x-----"
"---x---x--------"
"-------------x--"
"----------------"
"-----------x----"
"------x--------x")
.5)
(progn
(let ((*clef* "g")
(*window-name* "lead"))
(p time (pickl (ov-scale :C4 :minor)) 50 4 11))
(p time (+ -12 60) (rcosr 60 5 5) (sinr 2 1 4) (random 9)))
(progn
(let ((*clef* "g")
(*window-name* "lead2"))
(p time (pickl (ov-scale :C5 :minor)) 50 (pick 3 4) 12))
(p time (+ -12 62) (rcosr 60 5 4) (sinr 2 1 5) (random 9)))
(progn
(bbplay "Train Cars.wav" :id 2 :amp .2 :rate .8 :downsamp 8 :left (random 1f0) :right (random 1f0))
(p time (+ -12 63) (rcosr 60 5 3) (sinr 2 1 3) (random 9)))
(p time (+ -12 65) (rcosr 60 5 6) (sinr 2 1 2) (random 9))
(p time (+ -12 67) (rcosr 60 5 7) (sinr 2 1 5) (random 9))
(p time (+ -12 68) (rcosr 60 5 1) (sinr 2 1 6) (random 9))
(p time (+ -12 70) (rcosr 60 5 5) (sinr 2 1 8) (random 9))
(p time (+ -12 72) (rcosr 60 5 3) (sinr 2 1 3) (random 9)))
(let ((level (make-palindrome (iota 127))))
(defun panover (time)
(dotimes (channel 10)
(fluidsynth:cc *synth* channel 10 (next level)))
(aat (+ time #[.5 b]) #'panover it)))
(defun panover ())
(panover (tempo-sync #[(* .5 16) b]))
(inscore-reset)
(inscore-init)
(inscore-reset "lead" t)
(k (tempo-sync #[.5 b]))
(defun k ())
| 3,084 | Common Lisp | .lisp | 68 | 41.014706 | 358 | 0.593875 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 28b0fa7b4369d5d5ad8530bff18730cce0929a1d0360a2306e1c39ccc36e1067 | 9,191 | [
-1
] |
9,192 | whynot.lisp | azimut_shiny/compositions/whynot.lisp | (in-package :shiny)
(let ((scale (make-cycle (list (scale 0 'aeolian)
(nth-inc 3 (scale 0 'aeolian) -1))
3))
(top (make-cycle '(70 75) 6))
(n (make-cycle '(0 2) 12)))
(defun f (time)
(let ((c (make-chord 60 (next top) 3 (next scale))))
(p (list time (+ time 1))
(nth (next n) c)
50
.5 0)
(if (odds .5)
(progn
(pa time c 2/3 60 2 :dur 2/3)
(pa (+ .5 time) (reverse c) 2/4 60 2 :dur 2/4))
(p time c 40 2 2)))
(aat (+ time 2) #'f it)))
(defun f ())
(f (now
))
(fp 2 90);;megadrive 90
(fp 4 80)
(fp 6 32)
(fg 1.0)
(let ((scale (make-cycle (list (scale 0 'aeolian)
(nth-inc 4 (scale 0 'aeolian) -1))
3))
(top (make-cycle '(70 75) 6))
(dur (make-cycle '(2 1 .75 .5) 12))
;; (dur (make-cycle '(.5 .75 1 2) 12))
;; (dur 2)
)
(defun f (time)
(let ((c (reverse (make-chord 60 (next top) 3 (next scale))))
(d (next dur)))
;;(pa time (subseq c 0 2) (/ d 2) 50 0 (/ d 2))
(p time c 40 d 2)
(aat (+ time d) #'f it))))
(fp 2 0)
(fp 4 0)
(let ((scale (make-cycle (list (scale 0 'aeolian)
(nth-inc 4 (scale 0 'aeolian) -1))))
(top (make-cycle '(70 75) 6))
(fac (make-cycle '(1 1 1 1 1 1 1 1 1 1 1 2 2 2 2)))
(song (make-cycle '(72 70 67 65 63 65 68 63 60 63 55 72 67 62 70 75 60 68 65 67 75 70 72 72 62 63 58 60)))
(dur 2))
(defun f (time)
(let* ((myscale (next scale))
(c (make-chord-waltz 60 (next top) myscale))
(d (next dur))
(f (next fac)))
;; (and (odds .6) (p time (next song) 60 .5 0))
;; (p (+ .5 time) (next song) 50 .25 1)
;; (and (odds .5) (p (+ .75 time) (next song) 50 .25 0))
;; (and (odds .1) (p (+ 1 time) (next song) 50 .5 1))
(and (odds (* f .7))
(p time
(+ 12 (pickl (second c)))
60 .45 1))
(let ((note (+ 12 (pickl (second c)))))
(and (odds (* f .8))
(p (+ .5 time)
note
60 .25 1))
(and (odds (* f .2))
(p (+ .75 time)
(pc-relative note (pick +1 +1 0) myscale)
60 .5 3)))
;;(pa time (subseq (second c) 0 2) (/ d 2) 50 0 (/ d 2))
(if (odds .5)
(pa time c '(0 1 1.5) (list (rcosr 40 5 5) 35 35) '(2 4 2) (list 1 (pick .4 .5) (pick .4 .5)))
(pa time (subseq c 0 2) '(0 1) (list (rcosr 40 5 35) 35) '(2 4) '(1 1)))
(aat (+ time d) #'f it))))
;;--------------------------------------------------
(defparameter *bach*
(mapcar (lambda (x) (cm:keynum x))
'(g3 fs3 e3 d3 d3 b2 c3 d3 g2)))
;; 4.5.3 - BWV 1087
(let ((n (make-cycle *bach*))
(m (make-cycle (reverse *bach*))))
(defun f (time)
(p time (next n) 50 1 0)
(p time (next m) 50 1 1)
(aat (+ time 1) #'f it)))
;; 4.5.4 - BWV 1072
;; choir 1
(let ((n (make-cycle
(list (make-cycle (chord :C4 :major) 1)
(make-cycle (chord :D4 :minor) 1))))
(r (make-cycle '(1.5 .5))))
(defun f (time)
(let ((d (next r))
(note (next n)))
(p time note 50 d 2)
(p (+ .5 time) note 50 (max .5 d) 4)
(p (+ 1 time) note 50 (max .5 d) 6)
(aat (+ time d) #'f it))))
;; choir2
(let ((n (make-cycle
(list (make-cycle (chord :D4 :minor) 1)
(make-cycle (chord :C4 :major) 1))))
(r (make-cycle '(1.5 .5))))
(defun ff (time)
(let ((d (next r)))
(p time (+ 12 (next n)) 50 d 2)
(aat (+ time d) #'ff it))))
(f (quant 3))
(ff (quant 3))
(fff (quant 3))
(fg .1)
(defun f ())
(defun ff ())
(defun fff ())
(let ((n (make-cycle
(list (make-cycle (invert
(chord :C4 :major)
) 1)
(make-cycle (invert
(chord :D4 :minor)
) 1))))
(r (make-cycle '(1.5 .5))))
(defun fff (time)
(let ((d (next r)))
(p time (+ 12 (next n)) 50 d 3)
(aat (+ time d) #'fff it))))
(fp 3 0);;mega 50
;;--------------------------------------------------
;; 4.5.6
;; Arvo Part - Cantus
;; ME: basically a descending scale playing at different offsets
;; adding some stuff
(let ((pitches (make-cycle '(0 69 0)))
(durations (make-cycle '(3 3 6))))
(defun bell (time)
(let ((d (next durations))
(p (next pitches)))
(p time p 70 d 5)
;; (and (odds .2)
;; (p (+ .5 time) p 70 d 5))
(aat (+ time d) #'bell it))))
(bell (quant 3))
(defun bell ())
(let ((pitches (make-cycle (reverse (ov-scale :A4 :locrian))))
(durations (make-cycle '(.5 .25))))
(defun violin (time)
(let ((d (next durations))
(pitch (next pitches)))
(p time pitch 50 d 0)
(and (odds .2) (p time (+ 12 pitch) (rcosr 80 2 5) d (pick 1 0)))
(p (+ time .5) pitch 50 d 1)
(p (+ time 1) (+ -12 pitch) 50 (* 2 d) 2)
(p (+ time 1) (+ -12 pitch) 50 (* 2 d) 3)
;;(p (+ time 1) (+ -12 pitch) 50 (* 2 d) 4)
(aat (+ time d) #'violin it))))
(fg .2)
(fp 2 33)
(violin (quant 3))
(defun violin ())
(mapcar (lambda (x) (fp x 0)) '(0 1 2 3 4))
(fp 2 0)
;; ?
(freverb-preset 6)
(defun frev (time)
(freverb-toggle 0)
(freverb-toggle 1)
(aat (+ time 2) #'frev it))
(frev (quant 4))
(defun frev ())
(fluidsynth:cc *synth* 2 10 65)
(fluidsynth:cc *synth* 1 10 0)
(fluidsynth:cc *synth* 0 10 127)
(defun fpan (time)
(and (odds .2)
(fluidsynth:cc *synth* (pick 0 1) 10 (pick 0 127)))
(aat (+ time 1) #'fpan it))
(fpan (quant 4))
(defun fpan ())
;;--------------------------------------------------
(let ((notes (make-weighting '(:b1 :b2 :e1 :e2 :b3 :e3))))
(defun f (time)
(p time (pick (chord (next notes) :minor)) 50 (cosr .7 .3 3) 0)
;;(fpitch 0 (between 10000 15000))
(aat (+ time .5) #'f it)))
(f (quant 4))
(defun f ())
(freset)
(fpitch 0 (between 1000 10000))
(fluidsynth:cc *synth* 0 10 64)
| 6,118 | Common Lisp | .lisp | 189 | 25.671958 | 112 | 0.461265 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 9351a5788d6227bd928d3b230ae67015ce0c1f67e8994eda52c2d3cf30d5f421 | 9,192 | [
-1
] |
9,193 | overtone.lisp | azimut_shiny/compositions/overtone.lisp | (in-package :shiny)
;; p - amplitude
;; pick - generic
;; weight - without :weight
(defparameter *c* (make-chord 40 50 3 (ov-pc-scale :scriabin)))
(defparameter *c* '(40 45 49))
(callback (quant 3) #'(lambda () (setf *c* (subseq (chord-degree :iii :c3 :scriabin) 0 3))))
(fg .5)
(let ((h (make-heap *c*)))
(defun bass (time)
(p time (+ -12 (next h)) (rcosr 40 5 1/2) 3 3)
(aat (+ time 3) #'bass it)))
;; invert-chord
;; arpegio subseq
(defun ff (time)
(let* ((n-notes (pick 2 3 1))
(beat-dur 1)
(l-notes (/ beat-dur n-notes))
(*c* (mapcar (lambda (x) (+ 12 x)) *c*)))
;; (and (odds .2) (p time (mapcar (lambda (x) (+ 7 x))
;; (loop repeat (+ 1 (random n-notes))
;; :collect (pickl *c*)))
;; (rcosr 60 4 1/2)
;; 1 2))
(pa time (pick (subseq *c* 0 n-notes)
(reverse *c*)
;;(invert-chord *c* (pick 2 1 0))
)
l-notes
'(55 55 60) '(0 1 2)
(list (pick l-notes)
(pick l-notes (/ l-notes 2))
(pick l-notes (/ l-notes 2))))
(aat (+ time beat-dur) #'ff it)))
(ff (quant 3))
(bass (quant 3))
(fp 0 20)
(fp 1 20)
(fp 2 20)
(fp 3 51)
(fp 2 41)
(defun ff ())
(defun bass ())
;; --------------
;; EWW
(defvar *c* '())
(let ((s (ov-scale :c4 :scriabin)))
(defun fff (time)
(let ((beat-length (* .4 16))
(*c* (list (first *c*)
(third *c*)
(second *c*))))
(pa time (transpose *c* -3) .3 50 1 .2)
(if (odds .5)
(pa (+ time .9) *c* .3 50 1 '(.2 .2 .3))
(p (+ time .9) *c* 40 .9 1))
(if (odds .5)
(pa (+ time 1.8) (transpose *c* +3) .3 50 1 .2)
(pa (+ time 1.8) (invert-chord *c* 3) .3 50 1 .2))
(p (+ time 2.7) (first *c*) 50 3 1)
(aat (+ time beat-length) #'fff it))))
(fff (quant (* .4 16)))
(defun ff ())
(defun ff (time)
(let* ((beat-length (* .4 16))
(pc (ov-pc-scale :scriabin))
(c (make-chord-alberti
55 75 pc)))
(setf *c* c)
;; (setf c (transpose c -12))
(p time (pc-relative (first c)
(pick -8 -5 -3)
pc)
25 beat-length 8)
;; (pa time c
;; (cumsum (repeat 4 (list (/ beat-length 10))))
;; 30 10 (/ beat-length 4))
(aat (+ time beat-length) #'ff it)))
(ff (quant (* .4 16)))
| 2,505 | Common Lisp | .lisp | 79 | 25.265823 | 92 | 0.44449 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 9f5bb5fe155cd7ec4e177f8fb322de88619bd167c9e613f12c5f9f4e07269761 | 9,193 | [
-1
] |
9,194 | shortcircuit.lisp | azimut_shiny/compositions/shortcircuit.lisp | (in-package #:shiny)
;; FIXME: merge-beats is defined twice ATM, redefine it from lib/molecular.lisp
(f (now))
(fg 2f0)
(defun f ())
(mbox 4 32 :C 9 14.5 -14 14 (scale 0 'minor))
(defvar *scale* 1f0)
(defvar *color* (v! .3 .3 .3))
(defvar *rough* 1f0)
;; SHIMMER 3
(defparameter *exp* (make-line (iota 50 :start 0f0 :step .01)))
(setf *exposure* 0f0)
(let ((r (make-cycle (parse-pattern (get-mbeats 0 8))))
(n (make-cycle (get-mnotes 0 8)))
(a (make-cycle (parse-pattern (get-mbeats 5 13))))
(b (make-cycle (get-mnotes 5 13)))
(rr (make-cycle (parse-pattern (get-mbeats 10 17))))
(nn (make-cycle (get-mnotes 10 17)))
(appear (make-line (iota 20 :start .01 :step .01))))
(defun f (time)
(setf *exposure* (next *exp*))
;; (when (next a)
;; (setf *rough* (random 1f0))
;; (when (odds .1)
;; (setf *light-pos* (v! (random 1000f0) (random 1000f0) (random 1100f0))))
;; (p time (+ 12 (next b)) 30 (next appear) 0))
(when (next r)
(setf *scale* (random 2f0))
(let ((nn (next n)))
(play-midi time nn 50 .8 0)))
(when (next rr)
(setf *color* (v! .2 (random 1f0) .3))
(let ((n (next nn)))
(play-midi time n 50 .5 1)))
(and (odds .4)
(play-midi time 65 30 .2 0))
(aat (+ time #[.2 b]) #'f it)))
(f (now))
(fp 0 52)
(fp 1 49)
(setf *exposure* 1f0)
| 1,381 | Common Lisp | .lisp | 41 | 29.487805 | 83 | 0.562874 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2ce69a5f0860395d16c6a3892e02d0be7c552d3c6255f4991090b1085e92e6b9 | 9,194 | [
-1
] |
9,195 | sunken.lisp | azimut_shiny/compositions/sunken.lisp | (in-package :shiny)
;; sunken
(gmeplay-beat
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc" 2 1
:amp .5
:aubio-p t
:control-only t
;; :load-only t
:length 20
:offset 80
:lpf 200
;; :right .2
;; :left .3
;; :voices '(4 5 6 7)
:voices '(0 1 2 3)
:rate .5)
(viseq:reset)
(viseq:push-cvideo
:gondola
"/home/sendai/clips/psy.mkv"
:glitch nil
:hsv nil
;; :stop-pos 1
:stop-pos most-positive-fixnum
:is-negative nil
:scale 1f0
:rotation 0f0)
(progn
(defparameter *beats*
(remove-sides
(test-onset (gethash
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc3"
*playing*))))
(let* ((hsv (make-cycle '(t nil)))
(buf
(gethash
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc3"
*playing*))
(sample-rate (buffer-sample-rate buf))
(rate 1)
(frames (buffer-frames buf))
(dur (abs (* (/ 1 rate) (/ frames sample-rate)))))
(defun f (time)
(bplay buf :id 10 :amp .2 :rate rate :left .3 :lpf 400)
(in-times *beats*
(lambda () (viseq:push-cvideo
:gondola "/home/sendai/clips/psy.mkv"
:scale 1f0
:xpos 0
:ypos 0
:hsv (next hsv))))
(aat (+ time #[dur b]) #'f it ))))
(f (now))
(let ((left (make-palindrome (iota 20 :start 0 :step .05))))
(defun panning (time)
(set-control 10 :left (next left))
(set-control 10 :right (abs (1- (next left))))
(aat (+ time #[.5 b]) #'panning it)))
(panning (now))
(defun panning ())
(defun f ())ff
(incudine:free (node 0))
(flush-pending)
(f (now))
| 1,708 | Common Lisp | .lisp | 64 | 20.75 | 78 | 0.562232 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 6a885fac0d5804053a8c56acfae7c8646e101f1083667eb97f1ba3e8ac7d994d | 9,195 | [
-1
] |
9,196 | snow-world.lisp | azimut_shiny/compositions/snow-world.lisp | (in-package :shiny)
;; https://www.youtube.com/watch?v=4lyI7O7kLP0
(all-piano 0)
(fp 1 20 0)
(fp 2 20 0)
(fp 3 20 0)
(fp 4 20 0)
(fp 1 30 0)
(fp 2 30 0)
(fp 3 20 0)
(fp 4 20 0)
(fp 22 0)
(defparameter *triggered* (trigger-once))
(defparameter *triggered2* (trigger-once))
(defun ff ())
(defun ff (time)
(let* ((c (make-chord 60 80 3 (scale 0 'phrygian)))
(bass (+ -12 (first c)))
(c (reverse c))
)
(when (zmodt 1)
;; (p time bass 50 1 22)
(pa time c .333 '(60 50 50 50) '(0 10 20 10) (pick .4 .4 .1 .3 .5))
)
)
(let ((c (+ 1 (random 4))))
(when (zmodt 4)
(if (or (= c 1)
(= c 2))
(with-trigger (*triggered2* time)
(p it (pick 70 72 73) 50 7 c))
(with-trigger-expire (*triggered* time 1)
(p time (pick 70 72 73) 50 7 c)))
)
(aat (+ time 1) #'ff it)))
(ff (quant 4))
(defun ff ())
| 921 | Common Lisp | .lisp | 37 | 20.081081 | 73 | 0.517674 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | e040255f7ef60c1095b0fc080d99cfbae8a138fd3871785ece7e7f06588164af | 9,196 | [
-1
] |
9,197 | ray.lisp | azimut_shiny/compositions/ray.lisp | (in-package :shiny)
;;; Code from "undo" video, along with examples/20180810.lisp
(let ((bd (make-cycle (bd (get-pattern 'cold))))
(sn (make-cycle (sn (get-pattern 'cold))))
(ch (make-cycle (ch (get-pattern 'cold))))
(oh (make-cycle (oh (get-pattern 'cold))))
(cch (make-cycle '(1 1 .9)))
(tt (make-weighting '(.2 (.15 .01))))
(c (make-cycle (make-chord 80 90 3 (scale 0 'dorian)))))
(defun f (time)
(when (next bd)
(play-instrument 'drum *gm-kick* .5))
(when (next sn)
(play-instrument 'drum *gm-snare* .5))
(when (next ch)
(play-instrument 'drum *gm-closed-hi-hat* 1 1 (pick .9 1 1.1)))
(when (next oh)
(pa time
(nth-inc 0 -12 (make-chord 70 90 (pick 2 3 3 3 4) (scale 0 'dorian)))
(pick .3 .2 .15 .1) 90 0 .3)
(play-instrument 'drum *gm-open-hi-hat* (pick 1 1 1 .5 .25) (pick .8 .6 .7) (pick .8 .9 1)))
(aat (+ time #[(next tt) b])
#'f it)))
(fg .5)
(defun f ())
(f (now))
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/ice.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/hat.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/kick.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/openhat.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/snare.ogg")
(freverb-toggle 1)
(freverb-preset 5)
(let ((lead (make-heap (make-chord 80 90 3 (scale 0 'dorian)))))
(defun f (time)
(let ((c (make-chord-alberti 60 75 (scale 0 'dorian))))
(p time (next lead) 80 2 3)
;; (pa time (nth-inc 0 -12 c) .5 '(60 65 70) '(0 1 2) '(.5 1 1))
)
(aat (+ time #[2 b])
#'f it)))
(fp 3 24)
(let* ((p (get-pattern 'kml))
(bd (make-cycle (bd p)))
(sn (make-cycle (sn p)))
(oh (make-cycle (oh p)))}
(ch (make-cycle (ch p))))
(defun g (time)
(when (next bd) (bbplay (gethash "kick.ogg" *buffers*)
:attenuation .2
:beat-length .1))
(when (next oh) (bbplay (gethash "openhat.ogg" *buffers*)
:attenuation .2
:beat-length 1))
(when (next ch) (bbplay (gethash "hat.ogg" *buffers*)
:attenuation .2
:beat-length .5))
(when (next sn) (bbplay (gethash "snare.ogg" *buffers*)
:attenuation .2
:beat-length .5))
(aat (+ time #[.2 b])
#'g it)))
(fg 1f0)
(fp 0 0)
(fp 1 0)
(f (tempo-sync #[.2 b]))
(defun g ())
(g (tempo-sync #[2 b]))
;;--------------------------------------------------
;; https://www.systemshock.org/shocklogs/
(bbuffer-load "/home/sendai/Downloads/sample/LOG0119.wav")
(bbuffer-load "/home/sendai/Downloads/sample/LOG0120.wav")
(put-phrase "joy" "LOG0120.wav" 5.5 3.7)
(put-phrase "apart" "LOG0120.wav" 9 4)
(put-phrase "separate" "LOG0120.wav" 13 .8)
(put-phrase "individual" "LOG0120.wav" 14.5 4)
(put-phrase "undo" "LOG0119.wav" 17 2.2)
(bbuffer-load "/home/sendai/Downloads/sample/Dirt-Samples-master/gtr/0001_cleanC.wav")
(bbuffer-load "/home/sendai/Downloads/sample/Dirt-Samples-master/gtr/0002_ovrdC.wav")
(bbuffer-load "/home/sendai/Downloads/sample/Dirt-Samples-master/gtr/0003_distC.wav")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/hat.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/kick.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/openhat.ogg")
(bbuffer-load "/home/sendai/projects/Moonlet/Samples/snare.ogg")
(let* ((c (make-heap (scale 0 'dorian)))
(p (get-pattern 'getup))
(bd (make-cycle (bd p)))
(sn (make-cycle (sn p)))
(oh (make-cycle (oh p)))
(ch (make-cycle (ch p)))
(guitar (make-cycle '(700 701 702 703 704 705 706 707 708 709 710)))
(h (make-cycle '(nil nil nil nil nil nil nil nil nil nil
nil nil nil nil nil nil nil nil t))))
(defun g (time)
(when (next bd)
(bbplay (gethash "kick.ogg" *buffers*)
:attenuation (pick .8 .5)
:beat-length (pick .5 -.5)
)
(word-play "separate" :attenuation .5 :id 90 :corrupt t)
)
(when (next sn)
(bbplay (gethash "snare.ogg" *buffers*)
:attenuation .6
:beat-length .5)
;; (word-play "undo" :attenuation .5 :corrupt t :id 90)
)
(when (next oh)
(bbplay (gethash "openhat.ogg" *buffers*)
:attenuation .6
:beat-length .5)
;; (word-play "joy" :attenuation .5 :corrupt t)
)
;; (when (next ch)
;; (with-trigger (*trigger*)
;; (bbplay (gethash "hat.ogg" *buffers*)
;; :attenuation .6
;; :beat-length (pick -.5 .5 nil)
;; )))
(and (odds .9) (bbplay (gethash "0001_cleanC.wav" *buffers*)
:rpitch (+ 12 (next c))
:attenuation .2
:id (next guitar)))
;; (when (next h)
;; (let ((buf (gethash "0003_distC.wav" *buffers*)))
;; (with-trigger-expire (*vtrigger* 1.5)
;; (play-lsample-f buf
;; :dur 4
;; :loopstart 0 ;;(* .3 (buffer-frames buf))
;; :loopend 0 ;;(* .7 (buffer-frames buf))
;; :rate (pitch-to-ratio (next c))
;; :amp .1
;; :id 30
;; ))))
(aat (+ time #[.25 b])
#'g it)))
(defun g ())
(g (now))
(incudine:free (node 0))
| 5,624 | Common Lisp | .lisp | 139 | 33.561151 | 98 | 0.531016 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 0d3b758b8c247bd2c435639b7096254a6e1e3e39851dfcc65e20c99c81925a67 | 9,197 | [
-1
] |
9,198 | drunk.lisp | azimut_shiny/compositions/drunk.lisp | (in-package :shiny)
;; Trying CM drunk, random walk
(defun plank (time root)
(p time root 60 1 1)
(aat (+ time #[.5 b]) #'plank
it
(pc-quantize (drunk root 5 :low 50 :high 70)
(scale 0 'ryukyu))))
(defun plank (time root)
(p time root 60 1 1)
(aat (+ time #[.5 b]) #'plank
it
(pc-relative root (pick 1 -1)
(scale 0 'ryukyu))))
(plank (now) 60)
(defvar pat1
(cm:new cm:cycle
:of (list (cm:new cm:chord
:of '(c5 d ef f g af bf c6))
(cm:new cm:chord
:of '(c4 d ef f g af bf c5) )
(cm:new cm:chord
:of '(c3 d ef f g af bf c) ))))
(defvar pat2
(cm:new cm:cycle
:of (list '(c5 d ef f g af bf c6)
'(c4 d ef f g af bf c5)
'(c3 d ef f g af bf c) )))
(defvar pat3
(cm:new cm:cycle
:of (list (cm:new cm:chord
:of (cm:new cm:heap :notes '(c5 d ef f g af bf c6)
:for (cm:new cm:weighting :of '(4 5))))
(cm:new cm:chord
:of (cm:new cm:heap :notes '(c4 d ef f g af bf c5)
:for (cm:new cm:weighting :of '(4 5))))
(cm:new cm:chord
:of (cm:new cm:heap :notes '(c3 d ef f g af bf c)
:for (cm:new cm:weighting :of '(4 5)))))))
| 1,410 | Common Lisp | .lisp | 39 | 24.820513 | 70 | 0.451542 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3e82715eeeeef2080143f19340b0f76465badd0d881d4350ea6ec317e77efd07 | 9,198 | [
-1
] |
9,199 | course2.lisp | azimut_shiny/compositions/course2.lisp | (in-package :shiny)
;; 1 - Consistency a.k.a. Patterns
;; "The more patterns the more boring it gets..."
;; The set of notes is already a pattern, but the heap makes
;; it less predictable by choosing elements not twice in a cycle.
;; Alternatively you can add some repetition (stuttering) by creating a cycle
;; and provide it to the :for of the pattern with a stutter every N.
;; "Still, the more repetitions the melody make the more stronger.
;; The ear likes repetition"
(let ((h (make-heap (make-chord 50 70 5 (scale 0 'ryukyu))
(make-cycle '(1 1 1 1 1 2)))))
(defun h (time)
(p time (next h) 60 1 0)
(aat (+ time 1) #'h it)))
(defun h ())
(h (quant 4))
;; 2 - Flow - Direction/Momentum
;; "Give the melody landing points"
(fp 0 79)
(fp 1 79)
(fp 2 79)
(fp 3 79)
(fp 4 79)
(let ((r (make-cycle '(1 1 1 1 1 2)))
(h (make-heap (make-chord 50 70 5 (scale 0 'ryukyu))
(make-cycle '(1 1 1 1 1 2)))))
(defun h (time)
(let ((rr (next r)))
(p time (next h) 60 rr 0)
(aat (+ time rr) #'h it))))
(defun h ())
(h (quant 4))
;; 3 - interesting shape
;; "not random"
;; we use zmodt to play something here and there, the interesting result
;; here is that sometimes it plays 2 notes instead of 1 due this is scheduled
;; might be twice per "beat"
(fp 17 5)
(fp 18 0)
;; <3
(let ((r (make-cycle '(1 1 1 1 1 2)))
(h (make-heap (make-chord 50 70 5 (scale 0 'ryukyu))
(make-cycle '(1 1 1 1 1 2 1 1 3))))
(b (make-weighting '(3 (4 :weight .5) 2))))
(defun h (time)
(let ((rr (* (pick .25 .5 .5 .5 .5 .5) (next r)))
(n (next h)))
(when (zmodt 4) (p time n (drunk 45 5) 4 (+ 5 (random 10))))
;;;;; (when (zmodt 8) (p (+ .25 time) (+ 12 n) 65 (pick .5 1 2 .5) 17))
(when (= rr 1)
(pa time (make-chord-alberti 75 85 (scale 0 'ryukyu))
(/ rr (next b))
'(40 40 45 40) '(20 21 22 24) rr))
;;(p time n (rcosr 65 5 10) (+ (pick .6 .8 1 2 3) rr) (random 5))
(aat (+ time rr) #'h it))))
(freverb-toggle 1)
(freverb-preset 1)
(fg 1.0)
(freverb :roomsize 0.6d0 :damp 0.1d0 :width 0.9d0 :level .8d0)
(defun h ())
(h (quant 4))
(let ((r (make-cycle '(1 1 1 1 1 2))))
(defun h (time)
(let ((rr (* (pick .25 .5 .5 .5 .5 .5) (next r))))
(p time
;;(qtanr (scale 0 'ryukyu) 60 10 10)
(qcosr (scale 0 'ryukyu) 60 10 10)
(rcosr 60 5 5) rr 0)
(aat (+ time rr) #'h it))))
;; 4 - catch | low/hig
;; "we follow what's different"
;; "it's all about contrast" ... like have a pattern and add something
(make-cycle )
| 2,670 | Common Lisp | .lisp | 73 | 31.794521 | 84 | 0.561193 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 001970e07cc28d7183d8ccd4774eb4783b07e2a7a76ef7cc297265dca4f7ad7e | 9,199 | [
-1
] |
9,200 | gme.lisp | azimut_shiny/compositions/gme.lisp | (in-package :shiny)
(ql:quickload :cl-gme/incudine)
;; .00001 needed for gme...
;; (dsp! bplay ((buf buffer) rate start-pos (loop-p boolean) attenuation)
;; (:defaults 0d0 1 0 nil .00001)
;; (foreach-channel
;; (cout (* attenuation
;; (incudine.vug:buffer-play buf rate start-pos loop-p #'stop)))))
(define-vug rms (in hp)
(:defaults 0 60)
(with-samples ((b (- 2 (cos (* hp *twopi-div-sr*))))
(c2 (- b (sqrt (the non-negative-sample (1- (* b b))))))
(c1 (- 1 c2))
(in2 (* in in))
(q +sample-zero+))
(sqrt (the non-negative-sample (~ (+ (* c1 in2) (* c2 it)))))))
(define-vug crossfade (in1 in2 pos)
(with-samples ((alpha (* incudine.util:+half-pi+
pos)))
(+ (* (cos alpha) in1)
(* (sin alpha) in2))))
(dsp! bplay ((buf buffer) rate start-pos (loop-p boolean) attenuation rms cfreq)
(:defaults 0d0 -1 0 nil .00001 0 100)
(with-samples ((in (incudine.vug:buffer-play
buf rate start-pos loop-p #'stop))
(inn (* in attenuation))
(inn (+ inn
;; (incudine.vug:lpf inn cfreq 1)
;; (incudine.vug:hpf inn cfreq 2)
;; (incudine.vug:butter-hp inn 10)
)))
(out inn
inn)))
(defun cfreqp ())
(let ((c (make-palindrome '(300d0 200d0 100d0)))
(r (make-palindrome '(.5 10))))
(defun cfreqp (time)
(set-control 2 :cfreq (cm:next c))
(aat (+ time #[(cm:next r) b]) #'cfreqp it)))
(cfreqp (now))
;; (lin->db (control-value 2 'rms))
(incudine:free (node 0))
(gmeplay "/home/sendai/Downloads/sf2/ff3.nsf" 2 15
:attenuation .1
:length 20
:offset 10
:voices '(2)
:rate 1
:fade-time 1
:fade-curve 2)
(gmeplay "/home/sendai/Downloads/chrono/108 A Strange Happening.spc" 3 0
:length 18
:offset 89
:rate 1
:attenuation .2
:voices '(0 7 5)
:fade-time 10
:fade-curve 2
;; :load-only t
)
(gmeplay "/home/sendai/Downloads/chrono/108 A Strange Happening.spc" 5 0
:length 9
:offset 30
:rate 1.
:attenuation .1
:voices '(1 0 7 2)
:fade-time 20f0
:fade-curve 2
;; :load-only t
)
(gmeplay "/home/sendai/Downloads/chrono/213 Brink of Time.spc" 5 0
:length 9
:offset 30
:rate 1.
:attenuation .1
;; :voices '(1 0 7 2)
:fade-time 20f0
:fade-curve 2
;; :load-only t
)
(set-control 2 :cfreq 100)
(set-control 4 :attenuation .00001)
(set-control 2 :rate .2)
(set-control 2 :fade-curve 2)
(gmeclean)
(incudine:free (node 0))
(let ((upper (make-cycle '(t nil)))
(pan (make-cycle '(0 127)))
(pro (make-cycle '(i iv v))))
(defun bf (time)
(let ((buf (gethash
"/home/sendai/Downloads/chrono/108 A Strange Happening.spc3"
*playing*)))
(bbplay buf :beat-length 4 :attenuation .1)
;; (p time 48 80 3 2)
;; (p (+ #[3 b] time) 48 80 3 2)
;; ?
;; (pa time (nths (pick '(0) '(0 1) '(0 0))
;; (make-chord 60 70 3 (pc-diatonic 0 'minor (next pro))))
;; 3
;; (rcosr 62 2 5) 1 3)
(aat (+ time #[4 b])
#'bf it))))
(fg 1f0)
(fp 0 20)
(fp 2 20)
(fp 1 20)
(freverb-toggle 1)
(freverb-preset 6)
(defun bf ())
(bf (tempo-sync #[4 b]))
(flush-pending)
;;--------------------------------------------------
(defvar *status* nil)
(defvar *status2* nil)
(defvar *status3* nil)
(defvar *status4* nil)
(defun status (time)
(let ((cvalue (control-value 2 'rms))
(ccvalue (control-value 3 'rms))
(cccvalue (control-value 4 'rms)))
(when (numberp cvalue)
(if (> (abs (lin->db cvalue)) 90)
(setf *status* 1)
(setf *status* nil)))
(when (numberp ccvalue)
(if (> (abs (lin->db ccvalue)) 90)
(setf *status2* (list (list (between 20 300) (between 40 200))
(list (between 20 300) (between 80 200))))
(setf *status2* nil)))
(when (numberp cccvalue)
(if (> (abs (lin->db cvalue)) 10)
(progn
(setf *status3* (list (between 20 300) (between 40 200)))
(setf *status4* (* 30 (pick 10 20 30 40))))
(setf *status3* nil)))
)
(at (+ time #[.1 b]) #'status (+ time #[.1 b])))
;;(defun status ())
;;(status (now))
| 4,591 | Common Lisp | .lisp | 140 | 26.007143 | 80 | 0.51322 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 703906c7f5ce6668d32dd7906db6796818153a9a597194436db10b247244ded1 | 9,200 | [
-1
] |
9,201 | empty.lisp | azimut_shiny/compositions/empty.lisp | (in-package :shiny)
;; needs quickload of lib/csound.lisp
;; uses examples/walls/ for visuals
(start-csound (gethash :xanadu *orcs*))
(bt:make-thread
(lambda ()
(loop (let ((frame (csound:csoundperformksmps *c*)))
(when (not (= frame 0))
(return))))))
;; XANADU
(make-play plucke "i1" 0)
(make-play pluck "i2" 0)
(make-play newfm "i3" 0 .2 2.0)
(defun f ())
(defun make-random-v3 ()
(v! (+ 0 (random 40)) (+ 50 (random 30)) (+ 20 (random 10))))
(defparameter *wave* 1f0)
(let ((stars (make-heap '(.991 .99 .99)))
(intent (make-heap '(5f0 1f0 2f0 3f0)))
(crot (make-heap '(nil t)))
(chord (make-heap (make-chord-fixed 60 3 (scale 0 'ryukyu))))
(here (make-cycle '(t nil)))
(lead (make-heap (make-chord-fixed 80 5 (scale 0 'ryukyu)))))
(defun f (time)
(let ((n (next chord)))
(setf *wave* 500f0)
(play-newfm n 2 0 .2 2)
;; (if (odds .5)
;; (progn
;; (setf *light-factor* (next intent))
;; (p time 60 60 1 0))
;; ;; (progn
;; ;; (setf *head* (v! 0 50 0))
;; ;; (p time 60 60 .5 2 :pan 0)
;; ;; (p (+ time #[.5 b]) 60 60 .5 3 :pan 127))
;; )
;; (progn
;; (setf *crotate* (next crot))
;; (pa time (list (pickl '(79 83 84 88 89)) 0)
;; 4 (rcosr 40 5 5) 4 4))
;; (when (next here)
;; (setf *stars* (next stars))
;; (play-pluck (+ 12 (next lead)) 4 0))
)
(aat (+ time #[2 b])
#'f it)))
(fg .5f0)
(fp 4 23)
(defun f ())
(f (tempo-sync #[1 b]))
| 1,600 | Common Lisp | .lisp | 50 | 26.92 | 68 | 0.500325 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7bea65352cf419f4b9c1617b298817564d8575642823df7cea688f25ef0dcaa9 | 9,201 | [
-1
] |
9,202 | euclidean.lisp | azimut_shiny/compositions/euclidean.lisp | (in-package :shiny)
;; ----------------------------
;; Euclidean Rythms
;; https://github.com/overtone/overtone/blob/master/src/overtone/examples/compositions/euclidean_rhythms.clj
;; ----------------------------
(setf (bpm *tempo*) 60)
(defun f ())
(defparameter *metro* (make-metro 60))
(defparameter *metre* (make-metre '(2 3 2) 2))
(let ((r (make-cycle (parse-pattern (bjorklund 3 8))))
(s (make-cycle (parse-pattern (bjorklund 5 12))))
(q (make-cycle (parse-pattern (bjorklund 4 12)))))
(defun f (time &optional (beat 0))
(when (funcall *metre* beat 1)
(play-crash 72 2))
(when (next r) (play-bass 60 .5 :amp .1 :bars 120))
(when (next s) (play-snare .5 :amp 5000))
(when (next q) (play-hihat 1 :amp 5000))
(aat (+ time #[.5 b]) #'f it (+ .5 beat))))
(f (now))
| 809 | Common Lisp | .lisp | 20 | 37.3 | 108 | 0.586514 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a3d661634e914fb3fb86f395e585a76079f5aeea2b4aa97dcab00d14388e69ff | 9,202 | [
-1
] |
9,203 | hell.lisp | azimut_shiny/compositions/hell.lisp | (in-package :shiny)
(fg 2f0)
(freverb-toggle 1)
(freverb-preset 6)
(fp 0 40)
(fp 1 0)
(setf *instances* 1)
(defun pat1 ())
(defpattern pat1 ((get-pattern 'blood) .5)
(p time *gm-kick* (rcosr 60 5 3) .35 1)
(p time *gm-snare* (rcosr 60 5 3) .35 1)
(p time *gm-closed-hi-hat* (rcosr 60 5 3) .35 1)
(p time *gm-open-hi-hat* (rcosr 65 5 3) .35 1))
(pat1 (tempo-sync #[4 b]))
(defun f ())
(off-with-the-notes)
(bbuffer-load "/home/sendai/Downloads/sample/Dirt-Samples-master/click/000_click0.wav")
(bbuffer-load "/home/sendai/Downloads/sample/Dirt-Samples-master/click/001_click1.wav")
(bbuffer-load "/home/sendai/Downloads/sample/EM0505.wav")
(bbuffer-load "/home/sendai/Downloads/sample/EM0902-EM0902.wav")
(put-phrase "fear" "EM0505.wav" 1 9)
(put-phrase "afraid" "EM0505.wav" 10 4.2)
(put-phrase "existence" "EM0505.wav" 14.2 5.8)
(put-phrase "memories" "EM0902-EM0902.wav" 1 6)
(put-phrase "ffear" "EM0902-EM0902.wav" 8 3)
(put-phrase "bye" "EM0902-EM0902.wav" 17 18)
(word-play "memories" :id 20 :attenuation .5)
(incudine:free (node 0))
(defun f ())
(defun pat1 ())
(let ((i (make-heap '(180 100 140 50 180 100 140 1)))
(c (make-cycle (reverse (make-chord-fixed 60 3 (scale 0 'lydian))))))
(defun f (time)
(setf *instances* (next i))
(when (and (odds .1) (not (node-alive 40)))
(word-play (pickl (list-words)) :id 40 :attenuation .1
:rate (pick .9 .8)))
(bbplay (pick "000_click0.wav" "001_click1.wav")
:rate (pick 1 -1))
(let ((n (next c)))
(p time n 50 2 0)
(with-trigger-expire (*trigger* 1)
(p time (+ 12 n) 70 (pick .25 .1 .5) 0))
)
(aat (+ time #[2 b]) #'f it)))
(f (tempo-sync #[2 b]))
(setf (clear-color) (v! .2 .2 1 0))
(fp 2 52)
| 1,758 | Common Lisp | .lisp | 48 | 33.1875 | 87 | 0.630769 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | f735370a8ed5ac0fcf0495f954e6d33525d01ce9ca6ffcc4d41701673bd7b1e5 | 9,203 | [
-1
] |
9,204 | lluvia.lisp | azimut_shiny/compositions/inlovewithaghost/lluvia.lisp | (in-package :shiny)
(buffer-read "/home/sendai/Downloads/lluvia.wav")
(defsynth :sample ((bufnum 0) (rate 1) (start 0) (amp .5) (out 0))
(let ((sig (play-buf.ar 2 bufnum (* rate (buf-rate-scale.ir bufnum))
:start-pos (* start (buf-frames.ir bufnum))
:act :free
:loop 1)))
(out.ar out (* amp sig))))
(defparameter *some* (synth 'sample :bufnum 0))
(ctrl *some* :rate .1)
(free *some*)
| 471 | Common Lisp | .lisp | 11 | 33.909091 | 70 | 0.544858 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 1327be56a617b2c676e69e75af1a322a1461b7f46a2b7bbcfa0543e98be8bcb8 | 9,204 | [
-1
] |
9,205 | 1.lisp | azimut_shiny/compositions/inlovewithaghost/1.lisp | (in-package :shiny)
;; Trying the ideas on the song
;; https://www.youtube.com/watch?v=Ql_dEdMEjl4
;; https://musescore.com/skyfox125/scores/3871256
(let ((o (new cycle :of '(1.5 1.25 1 1.25) :repeat 1)))
(defun f (time)
(let ((offset (next o))
(mychord (make-chord-5 55 70 *phrygian*))
(schord (make-chord 55 70 4 *phrygian*)))
;; sax
(pa time (if (odds .9)
schord
(reverse schord))
offset 40 1 offset)
;; goblin
;; (pa time mychord offset (list 20 15) 2 (list offset (* 3 offset)))
;;; tuba
;; (p (+ time (* 3 offset)) mychord (rcosr 16 3 1/2) offset 4)
;; (p (+ time (* 3 offset)) (first mychord) 15 (* offset 2) 5)
(aat (+ time (* 4 offset)) #'f it)
)))
(f (quant 4))
(fp 4 58)
(fp 5 42)
(fg .9)
(fp 1 65)
(fg .3)
(fp 2 101 0)
(fp 1 52 0)
(fp 1 0)
(fp 3 49)
(fp 1 80 8)
(fpitch 1 1000)
;; normal
(freverb-toggle 1)
(freverb :roomsize .2d0)
(freverb-preset 6)
;; eerie
(freverb :roomsize .6d0 :damp .4d0 :level .9d0 :width 5d0)
(freverb :roomsize .6d0 :damp .4d0 :level .9d0 :width 25d0)
(freset)
(pa (now) '(60 62 64) .5 60 1 1)
(off-with-the-notes)
| 1,206 | Common Lisp | .lisp | 43 | 23.930233 | 75 | 0.570808 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 3637aef23c4777b41277c442137c5a76ec1fceecfba42af2b13f21784c62519e | 9,205 | [
-1
] |
9,206 | 4.lisp | azimut_shiny/compositions/inlovewithaghost/4.lisp | (in-package :shiny)
(let ((i (make-cycle '(iv v iii vi))))
(defun ff (time)
(let* ((pc (pc-diatonic 0 'major (next i)))
(lchord 1) ;; !
(larp (/ 1 lchord))
(mychord (make-chord 55 75 lchord pc))
;;(mychord (mapcar (lambda (x) (pc-relative x -3 pc)) mychord))
(r (reverse mychord))
(r (mapcar (lambda (x) (pc-relative x 5 pc)) r))
;;(r (mapcar (lambda (x) (pc-relative x -100 pc)) r))
(rr (append (list (pc-relative (first r) -1 pc))
(subseq r 1 lchord))))
(pa time (nths mychord '(0 1 2)) (* 2 larp) 60 13 (* 2 larp))
(pa (+ time 2) (nths mychord '(1 0 1)) (* 2 larp) 60 13 (* 2 larp))
(if (odds 1)
(pa time
;;r
(pick r mychord)
;;(pick r (reverse (mapcar (lambda (x) (pc-relative x +1 pc)) mychord)))
larp '(65 55 50 50) 5 (+ -.1 larp))
(pa time r '(0 .5 .5 .5) 50 5 .5))
(if (odds 1)
(pa (+ 1 time) rr larp 50 6 (+ -.1 larp))
(p (+ 1 time) rr 50 (+ -.1 larp) 6))
(if (odds 1)
(pa (+ 2 time)
;;r
(pick r rr)
;;(pick r (mapcar (lambda (x) (pc-relative x +1 pc)) mychord))
larp '(65 50 50 50) 7 (+ -.1 larp))
(pa (+ 2 time) r '(0 .5 .5 .5) 50 5 .5))
;; bass
(if (odds .5)
(p (+ time 1) (pick-random-list mychord 2) (rcosr 55 5 1/2) 3 10)
(progn
(p (+ time 1) (first mychord) (rcosr 55 5 1/2) 2 2)
(p (+ time 3) (pick (list (second mychord) (+ -12 (third mychord)))
(first mychord))
(rcosr 55 5 1/2) 1 2)))
(pa (+ 3 time) rr larp 50 8 (+ -.1 larp))
(aat (+ time 4) #'ff it))))
(defun ff ())
(fp 2 20)
(ff (quant 4))
(fp 10 20)
(fg 1.0)
(fp 10 20 0)
| 1,947 | Common Lisp | .lisp | 48 | 29.625 | 88 | 0.431144 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 334d95e69e806a0e5f5b75d8988480ec47b2882fd0b18be1b9644d079b8deb90 | 9,206 | [
-1
] |
9,207 | 3.lisp | azimut_shiny/compositions/inlovewithaghost/3.lisp | (in-package :shiny)
;; Trying the ideas on the song
;; https://www.youtube.com/watch?v=Ql_dEdMEjl4
;; https://musescore.com/skyfox125/scores/3871256
(freverb-toggle 1)
(freverb :roomsize .6d0 :damp .1d0 :level .9d0 :width 10d0)
(fp 10 80 8) ;; sine 80 - 8
(fp 2 101 0)
(fp 10 14)
(fp 10 0 0)
(try-sounds (quant 4) 10 10 4)
;; !!
;; slow down and speed up chord rhythm and bar length
(let ((o (new palindrome :of '(.75 .6 .5 .45) :elide t)))
(defun f (time)
(let ((offset (next o))
(mychord (make-chord 55 70 4 *phrygian*)))
(pa time mychord offset '(60 60 55 50) 10 (list offset
offset
offset
(+ offset (pick .1 .2))))
(p (+ time (* 2 offset)) mychord (rcosr 35 5 1/2) offset 3)
(p (+ time (* 3 offset)) (first mychord) 40 (* offset 2) 2)
(aat (+ time (* 4 offset)) #'f it))))
(defun f ())
(f (quant 4))
(fp 11 116 8)
(fp 1 0)
(fp 2 0)
(fp 3 0)
(fp 4 0)
(fp 5 69)
(defun f ())
(defun f (time chan)
(let* ((c (make-chord 65 80 5 *phrygian*))
(s (second c))
(ss (make-chord-fixed s 3 *phrygian*))
)
(pa time (reverse c) .2 60 chan '(.2 .2 .2 .2 1))
;; a problem with a bass here is that it might not change from the previous
;; bass, a heap like structure would help. Also it won't matter that much if
;; the bass doesn't chant through the composition...i think
(p (+ time 1.2) (transpose ss -12) 25 1.5 (1+ chan)))
(aat (+ time 2.5) #'f it chan))
(f (quant 4) 1)
(f (quant 4) 3)
;; <3
;; alternate between:
;; - a descending arpeggio
;; - the same descending arpeggion but with the first note an interval below
;; add some "melody" by playing a random part of the chord
(defun ff ())
(defun ff (time)
(let* ((pc (ov-pc-scale :lydian))
(mychord (make-chord 55 70 4 pc))
(r (reverse mychord))
(rr (append (list (pc-relative (first r) -1 pc))
(subseq r 1 4))))
(if (odds .5)
(pa time r .25 '(65 55 50 50) 5 .25)
(pa time r '(0 .5 .5 .5) '(65 55 50 50) 5 .5))
(pa (+ 1 time) rr .25 50 6 .25)
(if (odds .5)
(pa (+ 2 time) r .25 '(65 50 50 50) 7 .25)
(pa (+ 2 time) rr '(0 .5 .5 .5) '(65 50 50 50) 7 .5))
(if (odds .1)
(p (+ time 1) (pick-random-list mychord 3) (rcosr 45 5 1/2) 3 2)
(progn
(p (+ time 1) (first mychord) (rcosr 45 5 1/2) 2 2)
(p (+ time 3) (pick (list (second mychord) (third mychord))
(first mychord))
(rcosr 45 5 1/2) 1 2)))
(pa (+ 3 time) rr .25 50 8 .25)
(aat (+ time 4) #'ff it)))
;;;;
(fg .5)
(let (;;(i (make-cycle '(i vi iii vii)))
(i (make-cycle '(iv v iii vi)))
;;(i (make-cycle '(iv^7 v7 iii7 vi7)))
)
(defun ff (time)
(let* (;;(pc (ov-pc-scale :lydian))
;;(mychord (make-chord 55 75 4 pc))
(pc (pc-diatonic 0 'major (next i)))
(lchord 4) ;; !
(larp (/ 1 lchord))
(mychord (make-chord 55 75 lchord pc))
;; (mychord (mapcar (lambda (x) (pc-relative x -7 pc)) mychord))
(r (reverse mychord))
;; (r (mapcar (lambda (x) (pc-relative x 2 pc)) r))
;;(r (mapcar (lambda (x) (pc-relative x -100 pc)) r))
(rr (append (list (pc-relative (first r) -1 pc))
(subseq r 1 lchord))))
;; (if (odds 1)
;; (pa time
;; r
;; ;;(pick r mychord)
;; ;;(pick r (reverse (mapcar (lambda (x) (pc-relative x +1 pc)) mychord)))
;; larp '(65 55 50 50) 5 larp)
;; (pa time r '(0 .5 .5 .5) '(65 55 50 50) 5 .5))
(pa (+ 1 time) rr larp 50 6 larp)
;; (if (odds 1)
;; (pa (+ 2 time)
;; r
;; ;;(pick r rr)
;; ;;(pick r (mapcar (lambda (x) (pc-relative x +1 pc)) mychord))
;; larp '(65 50 50 50) 7 larp)
;; (pa (+ 2 time) rr '(0 .5 .5 .5) '(65 50 50 50) 7 .5))
;; (pa (+ time 1.5) (repeat 2 (list (+ (pick 0 12) (pickl mychord)))) .5 (pick 40 55) 11 .3)
;; (pa (+ time 2.5) (repeat 2 (list (+ (pick 0 12) (pickl mychord)))) .5 (pick 40 55) 11 .3)
(if (odds 1)
(p (+ time 1) (pick-random-list mychord 2) (rcosr 35 5 1/2) 3 10)
(progn
(p (+ time 1) (first mychord) (rcosr 40 5 1/2) 2 2)
(p (+ time 3) (pick (list (second mychord) (+ -12 (third mychord)))
(first mychord))
(rcosr 40 5 1/2) 1 2)))
(pa (+ 3 time) rr larp 50 8 larp)
(aat (+ time 4) #'ff it))))
;;;;;; -----------------
(fp 13 35)
(fp 10 49)
(fp 2 0)
(fp 11 6)
(defun ff ())
(ff (quant 4))
(fpress 2 0)
(fp 2 49)
(fp 10 49)
(fg 1.0)
(fp 2 52)
;;(fp 2 80)
;;(fp 5 80)
;; Majora
(loop for x from 5 upto 8 do (fp x 41))
;; Megadrive
(fp 5 12 0)
(fp 6 12 0)
(fp 7 12 0)
(fp 8 12 0)
(freverb-toggle 0)
(fp 8 44 0)
(p (quant 4) 60 60 1 8)
(pa (quant 4) '(60 62 64) .2 60 1 .2)
(fg .9)
(f (quant 4))
(fg .3)
(fp 1 52 0)
(fp 1 0)
(fp 3 49)
(fpitch 1 1000)
;; normal
(freverb :roomsize .2d0)
;; eerie
(freverb :roomsize .6d0 :damp .1d0 :level .9d0 :width 5d0)
(freset)
(pa (now) '(60 62 64) .5 60 0)
(off-with-the-notes)
| 5,491 | Common Lisp | .lisp | 158 | 28.335443 | 98 | 0.491404 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b84e78cd4ccabd22cf416ec9e8b56777f83b2162d01ac746e3c1ebc93d3d08c1 | 9,207 | [
-1
] |
9,208 | 2.lisp | azimut_shiny/compositions/inlovewithaghost/2.lisp | (in-package :shiny)
;; Trying the ideas on the song
;; https://www.youtube.com/watch?v=Ql_dEdMEjl4
;; https://musescore.com/skyfox125/scores/3871256
(freverb-toggle 1)
(freverb :roomsize .6d0 :damp .1d0 :level .9d0 :width 10d0)
(fp 10 80 8) ;; sine 80 - 8
(fp 2 101 0)
(let ((o (new palindrome :of '(.75 .6 .5 .45) :elide t)))
(defun f (time)
(let ((offset (next o))
(mychord (make-chord 55 70 4 *phrygian*)))
(pa time mychord offset '(60 60 55 50) 10 (+ offset .1))
;; (p (+ time (* 2 offset)) mychord (rcosr 35 5 1/2) offset 3)
;; (p (+ time (* 3 offset)) (first mychord) 40 (* offset 2) 2)
;; (aat (+ time (* 4 offset)) #'f it)
)))
(f (quant 4))
(fp 11 116 8)
(let ((o (new cycle :of '(1 3))))
(defun f (time)
(let ((mychord (make-chord-5 55 70 *phrygian*)))
(pa time mychord '(0 1) '(60 50) 1 '(1 3))
(pa (+ time (random-elt #(1 2 0))) (cdr mychord) .5 60 2 .5)
;; (pa time (mapcar (lambda (x) (+ 12 x)) (if (odds .6)
;; (reverse (cadr mychord))
;; (cadr mychord)))
;; .5 60 3 .5)
;; (aat (+ time 4) #'f it)
)))
(freverb-toggle 0)
(f (quant 4))
(pa (quant 4) '(60 62 64) .2 60 1 .2)
(fg .9)
(f (quant 4))
(fg .3)
(fp 1 52 0)
(fp 1 0)
(fp 3 49)
(fpitch 1 1000)
;; normal
(freverb :roomsize .2d0)
;; eerie
(freverb :roomsize .6d0 :damp .1d0 :level .9d0 :width 5d0)
(freset)
(pa (now) '(60 62 64) .5 60 0)
(off-with-the-notes)
;; THIS SYNTX SUCKS!!!
(pa (quant 4) (repeat 4 '(60))
(mapcar #'rhythm `(1/4 2/4 ,(+ 2/4 1/8) 3/4))
60
11
(mapcar #'rhythm `(1/4 2/4 ,(+ 2/4 1/8) 3/4)))
(defmacro drumthis (time note beats velocity channel)
(alexandria:with-gensyms (lbeats nbeats)
`(let ((,lbeats (length ,beats))
(,nbeats (mapcar #'rhythm ,beats)))
(pa ,time (repeat ,lbeats (list ,note))
,nbeats ,velocity ,channel ,nbeats))))
;; ?
(fp 7 115)
(drumthis (quant 4) 60 '(1/4 2/4 5/8 3/4) 20 7)
| 2,046 | Common Lisp | .lisp | 62 | 29.516129 | 71 | 0.5436 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c6e5ab12f028c9484acfca3c67cdf9efab9b65866ff8202fc2f213aaecd96667 | 9,208 | [
-1
] |
9,209 | extempore-chirstmas-carol.lisp | azimut_shiny/compositions/inlovewithaghost/extempore-chirstmas-carol.lisp | (in-package :shiny)
(fp 0 40)
(defun f (time)
(p time 0))
| 61 | Common Lisp | .lisp | 4 | 13.5 | 19 | 0.625 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7aa2e14ac5b65626748fe6b75c505821ae13b89b6218f4c24a639eeb2eb908f1 | 9,209 | [
-1
] |
9,210 | nudruz2.lisp | azimut_shiny/compositions/drafts/nudruz2.lisp | (in-package :shiny)
(dsp! green (freq dur volume rms)
(:defaults 440 1 1 0)
(with-samples
((in (incudine.vug:sine (+ freq (* 3 (incudine.vug:sine 3)))))
(in (incudine.vug:clip in -.4d0 .4d0))
(in (incudine.vug:lpf in 800d0 1))
(in (* in (envelope (make-adsr .001 .8 .1 1)
(incudine.vug:line 1 0 dur #'incudine:free))))
(in (* in volume)))
(setf rms in)
(out in in)))
(defvar *notes* nil)
(setf
*notes*
(cm::transp (cm::tzrandchain '(5 15 21) 200) 50)
;; (cm::transp (cm::tzrandchain '(0 3 4) 20) 50)
;; (cm::fromto '(61 72 75) '(50 65 75))
;;(cm::smoothlist (cm::entropy (cm::transp '(50 36 57) 12)))
;;(cm::smoothlist (cm::entropy (cm::transp '(50 36 57 61) 12)))
;;(cm::transp (mapcar (lambda (x) (car (cm::stack-by x 7))) (cm::flatter (mapcar (lambda (x) (cm::stravrot x 'n)) (cm::subsequences (cm::randhexrow) 6)))) 45)
)
(fg 1f0)
(defun f ())
(let ((notes (make-cycle (cm::entropy (cm::transp '(50 36 57) 12)))))
(defun f (time)
(let ((n (next notes)))
(green (midihz (first n)) .5)
(when (second n)
(at (+ time #[.5 b]) #'green (midihz (second n)) .5))
(when (third n)
(at (+ time #[1 b]) #'green (midihz (third n)) .5)))
(aat (+ time #[1.5 b]) #'f it)))
(f (now))
(fp 0 28)
(let ((notes (make-cycle *notes*))
(rhythm (make-cycle (cm::code->durs (cm::resclassvec 3 5 7))))
(incident (make-cycle '(t nil))))
(defun f (time)
(let* ((r (next rhythm))
(n (next notes))
(l 4)
(n (subseq n 0 (min l (length n)))))
(p time (nth-inc 0 24 n) 60 r 1 :pan (pick 0 127))
(when (next incident)
(pa time n '(0 .25) 60 2 '(.25 1))
(pa (+ time #[1 b])
(pick (cm::transp n 12) n)
'(0 .25) 60 2 '(.25 1)))
(aat (+ time #[r b]) #'f it))))
(fp 2 35)
(fp 3 50)
(freverb-toggle 1)
(freverb-preset 5)
(fchorus-toggle 1)
(f (now))
(defun f ())
(fp 0 20)
;;?
(let ((rhythms (make-cycle (cm::ferney '(7) (cm::randvec 50 3 3))))
(notes (make-cycle
(loop for n in (shuffle '(1 2 3 4 5))
append (cm::extract-intervals (cm::transp (cm::stack-up cm::row-34) 24) n)))))
(defun f (time)
(let ((d (* .25 (next rhythms))))
(p time (next notes) 40 d 0)
(aat (+ time #[d b]) #'f it))))
;; ***
(let ((rhythms (make-cycle '(.125)))
(notes (make-cycle
(cm::chooser
(cm::mod12 (cm::drunkvec 5 100))
(cm::transp (cm::stack-up cm::row-34) 24))))
(pan (make-weighting '(0 127))))
(defun f (time)
(let ((d (next rhythms)))
(p time (next notes) 40 d 0)
(if (zmodt 10)
(p time (pickl '(24 28 37 46 50 59 68 77 81 90 99 103))
60 1 1 :pan (next pan)))
(aat (+ time #[d b]) #'f it))))
(defun f ())
(fg 1f0)
(f (now))
(fp 0 10)
(let ((notes (make-cycle
(cm::transpose
(shuffle
(cm::diachrom-filt
(cm::subsets-len (cm::indices 12) 4) 2/4)) 60))))
(defun f (time)
(pa time (subseq (next notes) 3)
(list 0 .1 (pick .1 .15 .15 .15) .3)
'(50 50 60 50)
0
'(.1 .1 .3 .3) :pan 63)
(aat (+ time #[.7 b]) #'f it)))
(defun f ())
(setf (bpm *tempo*) 20)
(defun k ())
(defpattern k ('("x---" "xxxx----" "----x-------xx--" "---x") .25)
(p time *gm-kick* 20 d 10)
(p time *gm-snare* 20 d 10)
(p time *gm-closed-hi-hat* 20 d 10)
;; (play-instrument 'drum *gm-open-hi-hat* :dur d :amp .02)
)
(k (tempo-sync #[.7 b]))
(fp 0 23)
(f (now))
(setf (bpm *tempo*) 90)
(let ((notes (make-cycle *notes*)))
(defun f (time)
(let ((n (next notes)))
(pa time n 1 60 2 1))
(aat (+ time #[3 b]) #'f it)))
(defun f ())
(f (now))
(let ((rhythm
(parse-patternc
(cm::flatter
(cm::fromto-stepper '(0 1 1 0 1 0 0 0) '(1 0 0 1 0 1 0 0))))))
(defun f (time)
(when (next rhythm)
(p time 60 60 .2 2))
(aat (+ time #[.2 b])
#'f it)))
;;--------------------------------------------------
(let ((rhythm (make-weighting '(1 .9) .5))
(notes
(make-cycle
(cm::smoothlist (cm::entropy (make-chord 40 60 3 (scale 0 'minor)))))))
(defun f (time)
(let* ((n (next notes))
(l (length n))
(r (next rhythm)))
(if (= l 1)
(pa time n r 60 1 r)
(pa time n (* r .3333) 60 0 (* r .3333)))
(aat (+ time #[r b]) #'f it))))
(defun f ())
(fp 0 38)
(fp 1 20)
(f (now))
;;--------------------------------------------------
(defun f ())
(let ((notes (make-cycle
(cm::make-poly
(cm::transp
(cm::flatten
(loop for y in (cm::entropy '(0 1 3 5))
collect
(cm::give-contour-to-mel '(1 2 0 3) y))) 52) '(2 1 3 1 1)))))
(defun f (time)
(let* ((r 1f0)
(n (next notes))
(l (if (listp n) (length n) 1)))
(pa time n (print (/ r l)) 60 0 (/ r l))
(aat (+ time #[r b]) #'f it))))
(f (now))
| 5,093 | Common Lisp | .lisp | 159 | 25.836478 | 159 | 0.479201 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 67dc175a65eee31c553eeb97dd77fcbc3da09cc1f87fa4c17777c657214261e5 | 9,210 | [
-1
] |
9,211 | fluid-examples.lisp | azimut_shiny/compositions/drafts/fluid-examples.lisp | (in-package :shiny)
(defun play-midi-note (time pitch velocity dur c)
(at time #'fluidsynth:noteon *synth* c pitch velocity)
(at (+ time #[dur b]) #'fluidsynth:noteoff *synth* c pitch))
(defun play-midi-note (time pitch velocity dur c)
(when (and
(not (equal pitch "r"))
(> pitch 0)
(> velocity 0)
(> dur 0))
(progn
(at time #'fluidsynth:noteon
*synth* c pitch velocity)
(at (+ time #[dur b]) #'fluidsynth:noteoff
*synth* c pitch))))
(defun play-midi-note (time pitch velocity dur c)
(when (and
(not (equal pitch "r"))
(> pitch 0)
(> velocity 0)
(> dur 0))
(progn
(at time #'fluidsynth:noteon
*synth* c pitch velocity)
(at (+ time #[dur sa]) #'fluidsynth:noteoff
*synth* c pitch))))
#|
(flush-pending)
(define play-midi-note
(lambda (time device pitch velocity duration channel)
(callback time 'midi_send device *midi-note-on* channel pitch velocity)
(callback (+ time duration) 'midi_send device *midi-note-off* channel pitch velocity)))
|#
(defun play-midi-note (time pitch velocity dur c)
(at time #'fluidsynth:noteon *synth* c pitch velocity)
(at (+ time #[dur s]) #'fluidsynth:noteoff *synth* c pitch)
)
(play-midi-note (now) 60 90 2 15)
(play-midi-note (now) 36 60 1 1)
(play-midi-note (now) 36 60 10 (random 6))
;; ----------------------
;; DANCING PHALANGES
(setf (bpm *tempo*) 60)
(defvar *root* nil)
(setf *root* 0)
(defvar *degree* nil)
(setf *degree* 'i)
(defvar *scale* nil)
(setf *scale* (scale 0 'phrygian))
(defun melody (time ms rs)
(if (not ms)
'done
(let ((p (car ms))
(d (car rs)))
;; (play-midi-note time
;; (quant (+ 48 *root* p) *scale*)
;; (round (cosr 60 40 1/2))
;; (* d (cosr 4. .2 1/2))
;; 1)
(play-midi-note time
(quant (+ 55 *root* p) *scale*)
(round (cosr 60 40 1/2))
(* d (cosr 4. .2 1/2))
2)
(aat (+ time #[d b]) #'melody it (cdr ms) (cdr rs))
)))
(defun right (degree)
(setf *degree* degree)
(setf *root* (car (diatonic 0 '- degree)))
(at (+ (now) #[4 b]) #'right (random-list (cdr (assoc degree '((i n6 iii vii)
(n6 v7)
(iii v7)
(vii vi)
(vi vii v7 v7)
(v7 i))))))
)
(right 'i)
(defun left (time dur)
(if (> (random 1.0) .85) (melody time '(0 1 0 -1) '(1/3 2/3 2/3 1)))
; (play-midi-note time
; (+ 48 *root*)
; (round (cosr 80 30 1))
; (* dur (cosr 2.2 .3 1/7))
; 2)
(play-midi-note time
36
(round (cosr 40 30 1))
(* dur (cosr .6 .3 1/7))
0)
(aat (tempo-sync #[dur b]) #'left it (random-list '(1 2/3))))
(left (now) 2/3)
(flush-pending)
(incudine:free 0)
;; -----------------------------------
;; Overtone example
;; "Piano phase" - https://en.wikipedia.org/wiki/Piano_Phase
;; ----------------------------------
(defparameter *piece* '(:E4 :F#4 :B4 :C#5 :D5 :F#4 :E4 :C#5 :B4 :F#4 :D5 :C#5))
(repeat 1000 *piece*)
;;(setf (bpm *tempo*) 35)
(defun player ())
(defun player (time speed notes c)
(let ((note (first notes))
(notes (cdr notes)))
(when note
(p time
(note-name-to-midi-number (symbol-name note))
;;(rcosr 60 5 5)
55
(+ -.1 speed)
c)
(aat (+ time speed) #'player it speed notes c))))
#|
(player (now) #[.335 b] *piece* 0)
(flush-pending)
|#
(fp 3 108)
(let ((time (quant 4)))
(player time .338 *piece* 3)
(player time .335 *piece* 3))
(let ((time (now)))
(player time #[.338 b] *piece* 3)
(player time #[.335 b] *piece* 3))
;; --------------------------------------------------------------------
;; Another late christmas
;; --------------------------------------------------------------------
(setf (bpm *tempo*) 30)
(defvar *root* nil)
(setf *root* 72)
(defun loop1 (time dur)
(play-midi-note time
(if (= (mod (get-internal-real-time) 12) 0)
67
(random-list '(60 60 60 58)))
50
dur
0)
(aat (tempo-sync #[(* .5 dur) b]) #'loop1 it dur))
(defun s ()
;; '(0)
'(0 2 3 5)
)
(defun loop2 (time dlist slist)
(if (car slist)
(play-midi-note time
(relative *root* (car slist) (s))
(rrandom 60 80)
(car dlist)
1))
(aat (tempo-sync #[(car dlist) b]) #'loop2 it
(alexandria:rotate dlist -1)
(alexandria:rotate slist -1)))
#|
(loop1 (now) 1)
(loop2 (now) '(1 1/2 1/2 1/2 1/2) '(2 1 2 0 nil))
(setf *root* 72)
(setf *root* 63)
(flush-pending)
|#
;; Ah!...tempo-sync...I mean beat...without it I cannot sync two things...dah!
;; -----------
;; Playground
;; https://digego.github.io/extempore/note-level-music.html
;; http://impromptu.moso.com.au/tutorials/making_music/
;; -----------
(setf (fluidsynth:setting *fluid-settings* "synth.gain") 1.)
;; arpeggio
(mapcar (lambda (note delay vel c)
(play-midi-note (+ (now) #[delay b]) note vel 2 c)
)
'(60 64 67 70)
'(1 2 3 4)
'(90 50 50 60)
'(0 1 2 3)
)
;; chord
(let ((time (now)))
(mapcar (lambda (note c)
(play-midi-note time note 80 5 c)
)
'(60 64 67)
'(0 1 2)
))
;; 1/f
(defun 1f (repeats)
(mapcar (lambda (note delay vel c)
(play-midi-note (+ (now) #[delay b]) note vel 2 c))
(mapcar (lambda (x) (+ 60 x)) (1-over-f repeats))
(range (round (/ repeats 2)) :min 1 :step .5)
(repeat repeats '(60))
(repeat repeats '(0))))
(1f 30)
(defun brown (time chan dur notes)
(play-midi-note time (cm:next notes) 30 dur chan)
(aat (+ time #[dur b]) #'brown it chan dur notes))
(brown (tempo-sync #[1 b]) 0 1
(cm:new cm:cycle :of (brownian-motion 40 6)))
(brown (tempo-sync #[.5 b]) 1 1
(cm:new cm:cycle :of (brownian-motion 60 6)))
;; --------------------------------------------------------------------
;; GOTO 2014 • Programming In Time - Live Coding for Creative Performances
;; https://www.youtube.com/watch?v=Sg2BjFQnr9s
;; -------------------------------------------------------
(defvar *root* nil)
(defvar *myscale* nil)
(setf *root* 60)
(setf *myscale* (scale 0 'aeolian))
(setf (bpm *tempo*) 60)
(defun left (time dur)
(setf *root* (alexandria:random-elt
(cdr (assoc *root* '((60 58 55)
(58 60 56)
(56 55 58)
(55 60 56))))))
(play-midi-note time (+ *root* -12) 30 dur 0)
(aat (+ time #[3/2 b])
#'play-midi-note it (+ -5 *root*) 30 (- dur 3/2) 1)
(aat (+ time #[dur b]) #'left it dur))
(defun right (time dur)
(play-midi-note time
(round (qcosr *myscale* *root* 7 1.1))
(round (cosr 30 7 1.1))
dur 2)
(aat (+ time #[dur b]) #'right it dur))
(left (tempo-sync #[4 b]) 4)
(right (tempo-sync #[4 b]) 1/4)
(flush-pending)
;; All piano
(dotimes (i 32) (fluidsynth:program-change *synth* i 1) )
(fluidsynth:program-change *synth* 4 34)
(fluidsynth:program-change *synth* 2 1)
(fluidsynth:program-change *synth* 3 42)
(fluidsynth:program-change *synth* 4 33)
(fluidsynth:program-change *synth* 5 0)
(fluidsynth:program-change *synth* 6 77)
(fluidsynth:program-change *synth* 7 77)
(fluidsynth:program-change *synth* 5 0)
(fluidsynth:program-change *synth* 2 0)
(fluidsynth:program-change *synth* 3 43)
(fluidsynth:program-change *synth* 3 4)
(fluidsynth:program-change *synth* 7 1)
(fluidsynth:program-change *synth* 6 1)
(dotimes (i 32) (fluidsynth:program-change *synth* i ) )
(fluidsynth:set-reverb *synth* 0.2d0 0.0d0 0.5d0 0.9d0)
(fluidsynth:set-reverb *synth* 0.4d0 0.2d0 0.5d0 0.8d0)
(fluidsynth:set-reverb *synth* 0.6d0 0.4d0 0.5d0 0.7d0)
(fluidsynth:set-reverb *synth* 0.8d0 0.7d0 0.5d0 0.6d0)
(fluidsynth:set-reverb *synth* 0.8d0 1.0d0 0.5d0 0.5d0)
(fluidsynth:set-chorus *synth* 3 10.0d0 0.3d0 8.0d0 0)
(fluidsynth:set-chorus *synth* 3 4.1d0 0.3d0 1.0d0 1)
(setf (fluidsynth:setting *fluid-settings* "synth.gain") .3)
;; --------------------------------------------------------------------
;; Genetic music
;; https://www.reddit.com/r/algorithmicmusic/comments/3xlrvk/some_music_composed_by_a_program_i_wrote_genetic/
;; https://soundcloud.com/music-organism
;;
;; Basically, the program is based on a genetic algorithm. There are different "organisms/species" that are in charge of creating pieces of a song. For instance, one "species" generates a synthesizer definition. This species has 5 chromosomes: 1 for overall synth configuration (vibrato, envelope, etc.), and 4 that control signal generators (square wave, sine, tri, etc.) along with definitions for optional filters for each signal generator.
;;
;; There are similar "species" for overall song structure (bpm, meter, number of instruments/synths), pattern structure (allowed note range, on/off beat notes, etc.), and one for the actual melody (produces a list of notes, with durations and rests).
;;
;; The basic idea is that when a song is generated, it will choose 2 "organisms" from from a set from each type of "species". It mates these "organisms" together using common genetic algorithm techniques (crossover, mutation, etc). It will then use the offspring organism to create the different parts of the song. The whole thing gets exported to a format that supercollider can play, and I listen to it to see if it's any good (and the best ones get posted on the soundcloud account). The "organisms" that were used to make a "good" song get saved back to the set of possible organisms to choose from for the next song.
;;
;; Or that's how I want it to eventually work. Right now, it's already working like this for the synthesizer species, but the other species are basically just generating random organisms as a starting generation and then running a simple generation-based learning loop to try to produce "interesting" organisms. But soon, I'll make those species work the same as the synths.
;;
;; I don't have a website yet. Eventually the plan is to basically have it streaming music 24/7 where people would be able to listen and say "yeah this
;; is cool" or "no this is garbage", which would then feed back into the algorithm and influence the next song.
;; --------------------------------------------------------------------
;; --------------------------------------------------------------------
;; https://www.youtube.com/watch?v=J_4zr0Qk6o0
;; Major and minor eleventh chords in 5 limit just intonation modulate in a variety of ways. It doesn't stick to a fixed set of pitches, so it can modulate arbitrarily without intonation problems.
;;
;; As usual it's all PD with no samples or VSTs or anything.
;;
;; Basically I'm constructing major and minor eleventh chords from two chains of fifths (1/1, 3/2, 9/4) separated by a third (major or minor). The size of the major third can be set arbitrarily, and the minor third is derived from that. I can modulate to other chords in a number of ways:
;;
;; -Transpose the base pitch by 3/2 or 4/3 (dominant/subdominant)
;; -Transpose the base pitch up or down by the third and toggle between major/minor thirds (diatonic mediant/submediant)
;; -Transpose the base pitch up or down by the third (chromatic mediant/submediant)
;; -Toggle between major/minor
;; -Transpose by the interval between the major/minor thirds and toggle between major/minor (I'm not proficient enough to know what this is supposed to be called, but it's like alternating between Cm and BM).
;;
;; Sometimes several of these are combined (up to 4). This has to be done carefully to keep it from sounding too weird. I tried a couple other things besides that (hexatonic poles, etc.), but I thought they didn't work very well.
;;
;; Originally the idea was to use some exotic interval for the major third, but I found that most of them sounded too dissonant. For major thirds larger than about 32/25 (427 cents), some of the resulting intervals get too small. And for major thirds smaller than 5/4 (386 cents), the major and minor intervals are too close together. So the useful range is pretty small, and a lot of the ones I wanted to try (9/7, 11/9) don't really work. I thought the only major third sizes that worked well were 14/11, 81/64 (Pythagorean) and 5/4. I went with 5/4. But I want to revisit this idea with more exotic intervals. I'll just have to construct the chord differently so that it works better.
;; --------------------------------------------------------------------
#|
m maxima q quarter
l longa e eighth
b brevis s sixteenth
w whole t thirty-second
h half x sixty-fourth
|#
;; https://github.com/benmca/csound-pieces/
;; http://listenfaster.tumblr.com/
(defun play-midi-note (time pitch velocity dur c)
;; (fluidsynth:noteoff *synth* c pitch)
(at time #'fluidsynth:noteon *synth* c pitch velocity)
(at (+ time #[dur b]) #'fluidsynth:noteoff *synth* c pitch))
;; trompet
(fluidsynth:program-change *synth* 3 42)
(fluidsynth:program-change *synth* 2 43)
(fluidsynth:program-change *synth* 1 46)
(fluidsynth:program-change *synth* 4 1)
(fluidsynth:program-change *synth* 3 33)
(fluidsynth:program-change *synth* 1 1)
(fluidsynth:program-change *synth* 2 1)
(defvar *metro* nil)
(setf *metro* (make-metro 90))
(defun pp (chan time keys rhythms)
(let ((note (cm:keynum (next keys)))
(rhythm (cm:rhythm (next rhythms) 30)))
(p time
note
40 rhythm chan)
(aat (+ time rhythm) #'pp chan it keys rhythms)))
(defun pp ())
(defun ppp ())
(pp 1
(quant 4)
(make-cycle '(e3 gs4 b4 ds4))
(make-cycle '(e s q e. s.)))
(pp 2
(quant 4)
(make-cycle '(e4 gs4 b4 ds4))
(make-cycle '(s e s. e. q)))
#|
(flush-pending)
(off-with-the-notes)
|#
(defun p+ ())
(defun p+ (chan vel time keys rhythms amps &key life)
(if (or (null life)
(> life 0))
(let* ((amp (cm:next amps))
(note (if (= amp 1) (cm:keynum (cm:next keys)) 0))
(rhythm (cm:rhythm (cm:next rhythms) 30))
(life (if (integerp life) (1- life) nil)))
(if (not (= note 0))
(p time
(cm:keynum note)
vel rhythm chan ))
(aat (+ time rhythm) #'p+ chan vel it keys rhythms amps
:life life))))
(defun q1 (chan vel time keys &key (life nil))
(let ((rhythms (make-cycle '(s s s s s s s s+q q)))
(amps (make-cycle '(0 1 0 1 0 1 0 1 0))))
(p+ chan vel time keys rhythms amps :life life)))
(defun q2 (chan vel time keys &key (life nil))
(let ((rhythms (make-cycle '(e e e e+q q)))
(amps (make-cycle '(1 1 1 1 0))))
(p+ chan vel time keys rhythms amps :life life)))
(defun q3 (chan vel time keys &key (life nil))
(let ((rhythms (make-cycle '(s q e.+q q)))
(amps (make-cycle '(1 1 1 0))))
(p+ chan vel time keys rhythms amps :life life)))
(defun q4 (chan vel time keys &key (life nil) )
(let ((rhythms (make-cycle '(e s s s s s s+q q)))
(amps (make-cycle '(1 1 1 1 1 1 1 0))))
(p+ chan vel time keys rhythms amps :life life)))
(q1 1 50 (quant 4) (make-heap '(gs4 b4 a4 fs4)))
(q2 2 50 (quant 4) (make-heap '(gs4 b4 a4 fs4)))
(q3 3 50 (quant 4) (make-heap '(e4 fs5)))
(q4 4 55 (quant 4) (make-heap '(fs3)))
;; 33 sting
;; 40 trumpet
;; 37- winds wood
;; 40- winds brass
;; 46- winds synth
(fluidsynth:program-change *synth* 1 40)
(fluidsynth:program-change *synth* 2 1)
(fluidsynth:program-change *synth* 3 1)
(fluidsynth:program-change *synth* 1 1)
(fluidsynth:program-change *synth* 3 33)
(fluidsynth:program-change *synth* 4 40)
(q4 3 40
(quant 4)
(cm:new cm:cycle :of '(e3 gs4 b4 ds4)))
(p+ 4 30 (tempo-sync #[1 b])
(cm:new cm:cycle :of '(e3 gs4 b4 ds4))
(cm:new cm:cycle :of '(s e s. e. q))
(cm:new cm:cycle :of '(1)))
;; emergen.scm - launchOB
(all-piano 0)
(progn
(q1 1 30 (quant 4)
(make-heap '(gs4 b4 a4 fs4)) :life 10)
(q2 2 30 (quant 8)
(make-heap '(gs4 b4 a4 fs4)) :life 10)
(q3 4 35 (quant 12)
(make-heap '(e4 fs5)) :life 10)
(q4 4 45 (quant 16)
(make-heap '(fs3)) :life 10) )
(defun q5 (rhythms)
(let* ((rhythm (cm:rhythm (next rhythms) 30)))
(print "hey")
(q1 1 30 (quant 4)
(make-heap '(gs4 b4 a4 fs4)) :life 10)
(q2 2 30 (quant 4)
(make-heap '(gs4 b4 a4 fs4)) :life 10)
(q3 4 35 (quant 4)
(make-heap '(e4 fs5)) :life 10)
(q4 4 45 (quant 4)
(make-heap '(fs3)) :life 10)
(aat (+ (now) (* 10 rhythm)) #'q5 rhythms)))
(defun q5 ())
(fg .4)
(all-piano 0)
(q5 (make-cycle '(e s s s s s s+q q)))
(q5 (make-cycle '(w w+h w+w w+w+w)))
(q1 1 30 (quant 4) (make-heap '(gs4 b4 as4 fs4)))
#|
(flush-pending)
(off-with-the-notes)
|#
;; --------------------
;; CM archive mailing list
;; ftp://ccrma-ftp.stanford.edu/pub/Lisp/old-cmdist.html
;; --------------------
(defvar chorale1 nil)
(setf chorale1 '((G2 B2 D3) (G3 B3 D4) (C4 E3 G3) (C4 E3 G3) (D4 FS3 A3)
(G3 B3 D4) (B3 D3 FS3) (B3 D3 FS3) (E3 G3 B3) (C3 E3 G3)
(C3 E3 G3) (C4 E4 G4) (FS3 A2 C3) (G2 B2 D3) (D3 FS3 A3)
(G2 B2 D3) (D3 FS2 A2) (E3 G2 B2 D3) (FS3 A2 C3) (G3 B2 D3)
(A3 C3 E3 G3) (D3 FS3 A3) (D3 FS3 A3 C4) (G2 B2 D3) (G2 B2 D3)
(G2 B2 D3) (G2 B2 D3) (A2 C3 E3) (FS3 A2 C3) (G3 B2 D3)
(G3 B2 D3) (G3 B2 D3) (G3 B2 D3) (G3 B2 D3) (D3 FS3 A2 C3)
(G2 B2 D3) (D3 FS3 A3) (E3 G3 B3) (E3 G3 B3) (B3 D3 FS3)
(B3 D3 FS3) (A3 C3 E3) (G3 B2 D3) (G3 B2 D3) (G3 B2 D3)
(D3 FS3 A3 C4) (D3 FS3 A3 C4) (G2 B2 D3) (G2 B2 D3) (G3 B2 D3)
(G2 B2 D3 F3) (C3 E3 G3) (G2 B2 D3) (D3 FS2 A2) (D3 FS2 A2 C3)
(G2 B2 D3) (G2 B2 D3) (FS3 A2 C3) (G3 B2 D3) (G2 B2 D3)
(D3 FS3 A3) (D3 FS3 A3 C4) (E3 G3 B3) (E3 G3 B3) (C3 E3 G3)
(C3 E3 G3) (G2 B2 D3) (G2 B2 D3) (D3 FS3 A3) (G3 B3 D4)
(D4 FS3 A3) (D4 FS3 A3) (C4 E3 G3) (C4 E3 G3) (E3 G3 B3)
(E3 G3 B3) (A3 C3 E3 G3) (D3 FS3 A3) (D3 FS3 A3 C4)
(G2 B2 D3)))
#|
(defprocess play-chords (num chords rhy dur amp)
(process repeat num
for c = (next chords)
do
(dolist (k c)
(output (new midi time (now) duration dur
keynum k amplitude amp)))
(wait rhy)))
(events (play-chords 50 (markov-analyze chorale1 :order 1 :print nil)
.5 .4 .2)
"midi.port")
|#
(defun m (time chords)
(let ((chord (cm:next chords))
(vel (round (cosr 35 5 .5))))
(dolist (k chord)
(p (now) (cm:keynum k) vel 1 (random 10)))
(aat (+ time #[1 b]) #'m it chords)))
(m (tempo-sync #[1 b])
(cm:markov-analyze chorale1 :order 1 :print? nil))
(defun m (time chords)
(let ((chord (cm:next chords)))
(play-midi-note time (cm:keynum (nth 0 chord)) 30 1 1)
(play-midi-note (+ time #[1 b]) (cm:keynum (nth 1 chord)) 30 1 1)
(play-midi-note (+ time #[2 b]) (cm:keynum (nth 2 chord)) 30 1 1)
(aat (+ time #[3 b]) #'m it chords)))
;; --------------------------------
(defvar idxdur '((0.018 q) (.697 q) (1.376 s)
(1.538 e) (1.869 s) (2.032 s)
(2.2 e) (2.543 s) (2.705 q)
(3.373 e.)(3.895 e) (4.232 q)
(4.894 e) (5.236 s)))
(defun quarterDur->tempo (quarterdur)
(* 60 (/ 1.0 quarterdur)))
;; --------------------------------
#|
(flush-pending)
(off-with-the-notes *synth*)
|#
;; --------------------------------
;; https://www.quicklisp.org/beta/UNOFFICIAL/docs/fomus/doc/ch09s03.html
;; 50 80 / 40 70
;; 60 80 / 40 60
(defun q (time rhythms)
(let ((rhythm (cm:rhythm (cm:next rhythms) 30)))
(p time (cm:between 50 70) 30 1 10)
(p time (cm:between 50 70) 30 1 20)
(p time (cm:between 50 70) 30 1 30)
(aat (tempo-sync #[rhythm b]) #'q it rhythms)))
(q (tempo-sync #[1 b]) (cm:new cm:cycle :of '(e q s s q)))
;; Data set of Bach
;; https://archive.ics.uci.edu/ml/datasets/Bach+Chorales
;; ----------------------------------
;; Morse-Thue
;; From:
;; - "Music composition with lisp"
;; - nudruz
(defvar mtrules nil)
(setf mtrules '((0 :-> (0 1))
(1 :-> (1 0))))
;; RW-NEXT -- returns next complete generation of rewrite
;; rwthing = rules; alist = input string
;; example: (rw-next mtrules '(1 0)) = (1 0 0 1)
(defun rw-next (rwthing alist)
(let* ((this-rw (cm:new cm:rewrite
:of (append rwthing '((rw-end :-> rw-end)))
:initially (append alist (list 'rw-end))))
(sink (cm:next this-rw (+ (length alist) 1))))
(loop for x = (cm:next this-rw) until (eql x 'rw-end) collect x)))
;; RWGEN -- returns arbitrary generation of rewrite
;; (rwgen mtrules '(1 0) 2) = (1 0 0 1 0 1 1 0)
(defun rwgen (rwrules initgen gennbr)
(case gennbr
(0 initgen)
(1 (rw-next rwrules initgen))
(t (rw-next rwrules (rwgen rwrules initgen (- gennbr 1))))))
(defun pw ())
(defun pw (chan time notes amps)
(let ((amp (next amps)))
(if (= amp 1)
(p time (next notes) 40 1 chan))
(aat (+ time .5) #'pw chan it notes amps)))
; clav - 19
; brass - 40
(fluidsynth:program-change *synth* 1 16)
(fluidsynth:program-change *synth* 2 41)
(defvar *chord* nil)
(setf *chord* (make-chord 50 60 3 (scale 0 'aeolian)))
(defvar *cycle* nil)
(setf *cycle* (cm:new cm:cycle :of *chord*))
(pw 1
(quant 4)
;; (tempo-sync #[4 b])
;; (funcall *metro* (funcall *metro* 'get-beat 4.0))
(cm:new cm:cycle :of *chord*)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 2)))
(pw 2
(tempo-sync #[2.5 b])
;; (funcall *metro* (funcall *metro* 'get-beat 2.5))
(cm:new cm:cycle :of *chord*)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 4)))
#|
(flush-pending)
(off-with-the-notes *synth*)
|#
;; This one has "dynamic" chord progression
(setf (bpm *tempo*) 60)
(defvar *chord* nil)
(defvar *notes* nil)
(setf *chord* (make-chord 50 65 5 (scale 0 'phrygian)))
(setf *notes* (cm:new cm:cycle :of *chord*))
(defun pw (chan time amps)
(let* ((amp (cm:next amps)))
(if (= amp 1)
(play-midi-note time (cm:next *notes*) 40 1 chan))
(aat (tempo-sync #[1 b]) #'pw chan it amps)))
(defun pw (chan time amps)
(let* ((amp (cm:next amps)))
(if (= amp 1)
(play-midi-note (funcall *metro* time)
(cm:next *notes*)
40
(funcall *metro* 'dur 1) chan))
(at (funcall *metro* (+ time 1)) #'pw chan (+ time 1) amps)))
(pw 1
;; (tempo-sync #[1 b])
;; (funcall *metro* (funcall *metro* 'get-beat 1.75))
(funcall *metro* 'get-beat 1.0)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 2)))
(pw 2
;; (tempo-sync #[2.75 b])
;; (funcall *metro* (funcall *metro* 'get-beat 2.))
(funcall *metro* 'get-beat 2.75)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 4)))
;; --------------------------------
;; https://www.quicklisp.org/beta/UNOFFICIAL/docs/fomus/doc/ch09s03.html
;; 50 80 / 40 70
;; 60 80 / 40 60
(defun q (time rhythms)
(let ((rhythm (cm:rhythm (cm:next rhythms) 30)))
(play-midi-note time (cm:between 50 70) 30 1 1)
(play-midi-note time (cm:between 50 70) 30 1 2)
(play-midi-note time (cm:between 50 70) 30 1 2)
(aat (tempo-sync #[rhythm b]) #'q it rhythms)))
(q (tempo-sync #[1 b]) (cm:new cm:cycle :of '(e q s s q)))
;; Data set of Bach
;; https://archive.ics.uci.edu/ml/datasets/Bach+Chorales
;; ----------------------------------
;; Morse-Thue
;; From:
;; - "Music composition with lisp"
;; - nudruz
(defvar mtrules nil)
(setf mtrules '((0 :-> (0 1))
(1 :-> (1 0))))
;; RW-NEXT -- returns next complete generation of rewrite
;; rwthing = rules; alist = input string
;; example: (rw-next mtrules '(1 0)) = (1 0 0 1)
(defun rw-next (rwthing alist)
(let* ((this-rw (cm:new cm:rewrite
:of (append rwthing '((rw-end :-> rw-end)))
:initially (append alist (list 'rw-end))))
(sink (cm:next this-rw (+ (length alist) 1))))
(loop for x = (cm:next this-rw) until (eql x 'rw-end) collect x)))
;; RWGEN -- returns arbitrary generation of rewrite
;; (rwgen mtrules '(1 0) 2) = (1 0 0 1 0 1 1 0)
(defun rwgen (rwrules initgen gennbr)
(case gennbr
(0 initgen)
(1 (rw-next rwrules initgen))
(t (rw-next rwrules (rwgen rwrules initgen (- gennbr 1))))))
(defun pw (chan time notes amps)
(let* ((amp (cm:next amps)))
(if (= amp 1)
(play-midi-note time (cm:next notes) 40 1 chan))
(aat (tempo-sync #[1 b]) #'pw chan it notes amps)))
; clav - 19
; brass - 40
(fluidsynth:program-change *synth* 1 33)
(fluidsynth:program-change *synth* 2 41)
(defvar *chord* nil)
(setf *chord* (make-chord 50 60 3 (scale 0 'aeolian)))
(defvar *cycle* nil)
(setf *cycle* (cm:new cm:cycle :of *chord*))
(pw 1
(tempo-sync #[1 b])
(cm:new cm:cycle :of *chord*)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 2)))
(pw 2
(tempo-sync #[1 b])
(cm:new cm:cycle :of *chord*)
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 4)))
#|
(flush-pending)
(off-with-the-notes *synth*)
|#
;; This one has "dynamic" chord progression
(setf (bpm *tempo*) 60)
(defvar *chord* nil)
(defvar *notes* nil)
(setf *chord* (make-chord 50 65 5 (scale 0 'phrygian)))
(setf *notes* (cm:new cm:cycle :of *chord*))
(defun pw (chan time amps)
(let* ((amp (cm:next amps)))
(if (= amp 1)
(play-midi-note time (cm:next *notes*) 40 1 chan))
(aat (tempo-sync #[1 b]) #'pw chan it amps)))
(pw 1
(tempo-sync #[1 b])
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 2)))
(pw 2
(tempo-sync #[1 b])
(cm:new cm:cycle :of (rwgen mtrules '(1 0) 4)))
;; -------------------------------------------------
;; Playground
;; -------------------------------------------------
(defun play-midi-note (time pitch velocity dur c)
(at time #'fluidsynth:noteon *synth* c pitch velocity)
(at (+ time #[dur sa]) #'fluidsynth:noteoff *synth* c pitch))
(defvar *metro* nil)
(setf *metro* (make-metro 60))
(defun harmony (time duration pitch)
(play-midi-note (funcall *metro* time)
(round (qcosr '(0 4 7) pitch 5 .3))
30
(funcall *metro* 'dur duration)
1)
(aat (funcall *metro* (+ time duration)) #'harmony
(+ time duration)
duration
pitch
))
(defun melody (time duration)
(let ((next (funcall *metro* (+ time duration))))
(play-midi-note (funcall *metro* time)
(round (qcosr '(0 4 7) 65 10 .3))
(if (funcall *metre2* 1.0) 25 20)
(funcall *metro* 'dur duration)
2)
(at next
#'melody
(+ time duration)
(cm:pick .75 .5))))
(harmony (funcall *metro* 'get-beat 2) 1 40)
(melody (funcall *metro* 'get-beat 4) .75)
;;; -----------------------------------------------
;; Tone Rows
;; http://www.algorithmiccomposer.com/2011/09/tone-rows-puredata-and-max.html
;;
;; G, Bb, D, F#, A, C, E, G#, B, C#, Eb, F
(defvar *tonerow* nil)
(defvar *notes* nil)
(defvar *pc* nil)
(setf *tonerow* '(g4 bf4 d4 fs4 a4 c4 e4 gs4 b4 cs4 ef4 f4))
(setf *notes* (cm:keynum *tonerow*))
(setf *pc* (mapcar #'cm:pitch-class *notes*))
;; Play a random note from the PC
(defun playme (time pc)
(play-midi-note time (pc-random 60 70 pc) 40 1 0)
(aat (+ time #[1 b]) #'playme it pc))
(playme (tempo-sync #[1 b]) *pc*)
;; Play sequentially
(setf (bpm *tempo*) 35)
(defun playme2 (time notes dur)
(play-midi-note time (cm:next notes) 60 dur 1)
(aat (+ time #[dur b]) #'playme2 it notes dur))
;; Phasing (ew)
(playme2 (tempo-sync #[1 b]) (cm:new cm:cycle :of *notes*) .335)
(playme2 (tempo-sync #[1 b]) (cm:new cm:cycle :of *notes*) .338)
(defun playme3 (time notes rhythms)
(let ((dur (cm:next rhythms))
(chan (random 10)))
(play-midi-note time (cm:next notes) 40 dur chan)
(aat (+ time #[dur b]) #'playme3 it notes rhythms)))
(playme3 (tempo-sync #[1 b])
(cm:new cm:cycle :of *notes*)
(cm:new cm:heap :of (cm:rhythm '(0 0 0 0 x x t t s s e q) 30)))
(fluidsynth:program-change *synth* 1 52)
(fluidsynth:program-change *synth* 0 53)
;; ----------------------------
(defun hithat (time &optional (ry 1))
(play-midi-note time 40 30 3 5)
(aat (+ time #[ry b])
#'hithat it 4))
(hithat (funcall *metro* (funcall *metro* 'get-beat 4)))
(fluidsynth:program-change *synth* 5 1)
;; -------------------------
| 29,296 | Common Lisp | .lisp | 724 | 34.951657 | 687 | 0.571524 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 45f1fdba253aba0ce43116e2e00c3a4ea60a7cc13f3219f435aed868b9a84fbf | 9,211 | [
-1
] |
9,212 | drum.lisp | azimut_shiny/compositions/drafts/drum.lisp | (in-package :shiny)
;; THIS SYNTX SUCKS!!!
(pa (quant 4) (repeat 4 '(60))
(mapcar #'rhythm `(1/4 2/4 ,(+ 2/4 1/8) 3/4))
60
11
(mapcar #'rhythm `(1/4 2/4 ,(+ 2/4 1/8) 3/4)))
(defmacro drumthis (time note beats velocity channel)
(alexandria:with-gensyms (lbeats nbeats)
`(let ((,lbeats (length ,beats))
(,nbeats (mapcar #'rhythm ,beats)))
(pa ,time (repeat ,lbeats (list ,note))
,nbeats ,velocity ,channel ,nbeats))))
;; ?
(drumthis (quant 4) 60 '(1/4 2/4 5/8 3/4) 60 3)
(p (quant 4) 60 60 1 0)
| 548 | Common Lisp | .lisp | 16 | 29.8125 | 53 | 0.579545 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c845fd79187877488e3c524a634c5dd29cd0d6eaa80c48647d5e06ac4e906d08 | 9,212 | [
-1
] |
9,213 | f0plugins.lisp | azimut_shiny/compositions/drafts/f0plugins.lisp | (in-package :sc)
(setf *s* (sc:make-external-server "localhost" :port 4444))
(sc:server-boot *s*)
(sc:server-quit *s*)
;; NOTE: different sounds have different tunnings
;; bass=pitfall square=~lead saw!=.*
(defparameter atari-sounds
'((saw . 1) (engine . 3) (square . 4) (bass . 6)
(pitfall . 7) (noise . 8) (lead . 12) (buzz . 15)))
;; kick - buzz(15) - 30
;; hat - noise(8) - 0
;; snare - noise(8) - 8
;; " - buzz (15) - 6
;; https://www.youtube.com/watch?v=q59427J96wU
;; http://hiphoptranscriptions.com/page/2
;; "512" = 2 channel - 16 timbres - 32 notes
;; que en realidad son
;; audvX - volume register - 4bit
;; audcX - control register - 4bit - timbre
;; audfX - frequency divider - 5bit - 32 freqs per timbre
;; AUDC4/5 - AUDC12/13
(defugen (atari2600 "Atari2600")
(&optional (audc0 1) (audc1 2)
(audf0 3) (audf1 4)
(audv0 5) (audv1 5) (rate 1))
((:ar (multinew new 'pure-ugen audc0 audc1 audf0 audf1 audv0 audv1 rate))))
(defsynth atari ((out 0) (gate 1)
(tone0 5) (tone1 8)
(freq0 10) (freq1 20)
(vol0 1) (vol1 0)
(rate 1)
(amp 1) (pan 0)
(dur 5))
(let* ((e (env-gen.kr (linen .002 .2 dur) :gate gate :act :free))
(z (* amp (atari2600.ar tone0 tone1 freq0 freq1 vol0 vol1 rate))))
(out.ar out (pan2.ar (* z e) pan))))
(in-package :shiny)
(defparameter *synth* (synth 'atari :tone0 15 :freq0 30 :vol1 0 :vol0 1))
(free *synth*)
(defun ff ())
(defun ff (time)
(synth 'atari :tone0 15 :freq0 6
:vol1 0 :vol0 1 :dur .5)
(callback (+ time 1) #'ff (+ time 1)))
(ff (quant 4))
(defpattern pat1 ((get-pattern 'gogo) .25)
(synth 'atari :dur (/ d 50) :tone0 15 :freq0 30 :rate 2 :amp .2)
(synth 'atari :dur (/ d 50) :tone0 8 :freq0 8 :rate 1 :amp .2)
(synth 'atari :dur (/ d 55) :tone0 8 :freq0 0 :rate 20 :amp .1))
(defun pat1 ())
(defbeat kick .3 (bjorklund-s 5 13)
(synth 'atari :dur (/ d 2) :tone0 15 :freq0 30 :rate 2))
(defbeat kick2 .3 (bjorklund-s 4 4)
(synth 'atari :dur (/ d 1) :tone0 15 :freq0 30 :rate 1))
(defbeat kick3 .3 (bjorklund-s 3 8)
(synth 'atari :dur (/ d 4) :tone0 15 :freq0 30 :rate 1))
;;--------------------------------------------------
(in-package :sc)
(defugen (nes2 "Nes2")
(&optional (trig 0.)
(a0 0.) (a1 0.) (a2 0.) (a3 0.)
(b0 0.) (b1 0.) (b2 0.) (b3 0.)
(c0 0.) (c2 0.) (c3 0.)
(d0 0.) (d2 0.) (d3 0.)
(e0 0.) (e1 0.) (e2 0.) (e3 0.)
(smask 0.))
((:ar (multinew new 'pure-ugen trig a0 a1 a2 a3 b0 b1 b2 b3 c0 c2 c3 d0 d2 d3 e0 e1 e2 e3 smask))))
(defsynth nes2-square ((trig 0) (dutycycle 0) (loopenv 0) (envdecay 0)
(vol 10) (sweep 0) (sweeplen 0) (sweepdir 0)
(sweepshi 0) (freq 100) (vbl 0))
(let* ((a0 (* (clip.kr (round dutycycle 1) 0 3) 64))
(a0 (logior a0 (* (clip.kr (round loopenv 1) 0 1) 32)))
(a0 (logior a0 (* (clip.kr (round envdecay 1) 0 1) 16)))
(a0 (logior a0 (clip.kr (round vol 1) 0 15)))
(a1 (* (clip.kr (round sweep 1) 0 1) 128))
(a1 (logior a1 (* (clip.kr (round sweeplen 1) 0 7) 16)))
(a1 (logior a1 (* (clip.kr (round sweepdir 1) 0 1) 8)))
(a1 (logior a1 (clip.kr (round sweepshi 1) 0 7)))
(a2 (mod (round (max 0 freq) 1) 256))
(a3 (clip.kr (floor (/ freq 256)) 0 7))
(a3 (logior a3 (* (clip.kr (round vbl 1) 0 31) 8))))
(out.ar 0 (nes2.ar trig a0 a1 a2 a3 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1))))
(in-package :shiny)
| 3,643 | Common Lisp | .lisp | 83 | 37.554217 | 101 | 0.539288 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 887f87562693cc1b7cbe2df4bc1cb3de7c6ee0c584b36130a348380f911ea033 | 9,213 | [
-1
] |
9,214 | radiovago.lisp | azimut_shiny/compositions/drafts/radiovago.lisp | (in-package :shiny)
;; Radio vago the sinking (trying to get the sounds)
#|
SynthDef(”softfrog_”++x, {
arg out, freq=440, prate=180, pwidth=0.5,
sustain=0.3, amp=0.1;
var env, u;
env = Env.linen(Rand(0.001, 0.003), Rand(0.1, 0.3), 0.01);
freq = freq + LFNoise2.kr(5, 10);
u = SinOsc.ar(
freq,
LFPulse.perform(x,
prate,
0,
Line.kr(pwidth, 0, sustain)
),
amp
);
u = BRF.ar(u, freq, 0.1) * EnvGen.kr(env, doneAction:2);
Out.ar(out, Pan2.ar(u, Ra nd(-1,1)))})
|#
(defsynth nice ((out 0) (freq 440) (prate 180) (pwidth .5) (sustain .3) (amp .1))
(let* ((env (linen (rand.ir .001 .003)
(rand.ir .1 .3)
.01))
(freq (+ freq (lf-noise2.kr 5 10)))
(u (sin-osc.ar freq
(lf-pulse.kr prate 0 (line.kr pwidth 0 sustain))
amp))
(u (* (env-gen.kr env :act :free)
(brf.ar u freq .1))))
(out.ar out (pan2.ar u (rand.ir -1 1)))))
(defparameter *some* (synth 'nice :amp .1))
(defun f (time sca)
(let ((mc (make-chord 50 70 3 *phrygian*)))
(synth 'nice :freq (midicps (first mc)) :prate 170 :pwidth .2)
(at (+ time .25)
(synth 'nice :freq (midicps (second mc)) :prate 170 :pwidth .2))
(at (+ time 5)
(synth 'nice :freq (midicps (third mc)) :prate 170 :pwidth .2)))
;; (aat (+ time 1) #'f it sca)
)
(rlpfd.ar )
(f (quant 4) (ov-scale :c4 :major))
;;----------------------------------------------------------------------
| 1,826 | Common Lisp | .lisp | 45 | 27.866667 | 81 | 0.423403 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 7e2b0d574f869d4a2150783832ca6b72ff1c33ca9cce7ab5a3fa97e3f0591642 | 9,214 | [
-1
] |
9,215 | draft1.lisp | azimut_shiny/compositions/drafts/draft1.lisp | (in-package :shiny)
(fp 2 1)
(let ((notes (make-cycle (subseq (palin (make-chord-fixed 60 6 (scale 0 'ryukyu))) 2)))
(rhythm (make-weighting '(.4 (1 .1)))))
(defun f (time)
(let ((r (print (next rhythm))))
(p time (next notes) 60 r 2)
(aat (+ time #[r b]) #'f it))))
(f (now))
(fg .2)
(defun f ())
(make-chord )
| 338 | Common Lisp | .lisp | 12 | 25 | 87 | 0.552469 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | c2f448938f465d1ade998d4b26e756eb6c2c2c23cd2c7c5ed4eccbbfff81e9db | 9,215 | [
-1
] |
9,216 | extempore-demo.lisp | azimut_shiny/compositions/drafts/extempore-demo.lisp | (in-package :shiny)
;; -----------------------------------------------
;; Extempore - An Overview
;; https://vimeo.com/21956071
;; at 11:30
;; -----------------------------------------------
#|
(define loop
(lambda (beat dur root)
(for-each (lambda (p offset)
(play (+ offset) sampler p 100 (* 2.0 dur)))
(pc:make-chord 40 (cosr 75 10 1/32) 5
(pc:chord root (if (member root '(10 8))
'^7
'-7)))
'(1/3 1 3/2 1 2 3))
(callback (*metro* (+ beat (* .5 dur))) 'loop (+ dur beat)
dur
(if (member root '(0 8))
(random '(2 7 10))
(random '(0 8))))))
(loop (*metro* get-beat 4) 4 0)
|#
(fluidsynth:set-reverb *synth* 0.7d0 0.3d0 0.5d0 0.9d0)
(defparameter *metro* (make-metro 60))
(defvar *beat-offset* nil)
(setf *beat-offset* '(1/3 1 3/2 1 2 3))
(setf *beat-offset* '(1/3 4 1 1.5))
(setf (bpm *tempo*) 60)
(flush-pending)
(defvar *scale* (scale 0 'aeolian))
(defun sometune (beat time dur root)
(let ((n-beat (+ beat 4)))
(if (= 0.0 (mod beat 12))
(progn (p time (+ root 72) 90 4 3)
(p (+ time 6)
(pc-relative (+ root 72) (random-elt #(-1 -2 -3)) *scale*)
90 4 4))
(p time (pc-quantize (+ root 67) *scale*) 90 2 2))
(p (+ time 3) 36 90 (* 3.0 dur) (+ 10 (random 10)))
(mapcar (lambda (x y) (p (+ time y) x 100 (* 2.0 dur) 0))
(make-chord 40 (rcosr 75 10 1/32) 5
(pc-chord root (if (member root '(10 8))
'^7
'-7)))
*beat-offset*)
(aat (funcall *metro* n-beat) #'sometune n-beat it dur
(if (member root '(0 8))
(random-list '(2 7 10))
(random-list '(0 8))))))
(sometune (funcall *metro* 'get-beat 4)
(funcall *metro* (funcall *metro* 'get-beat 4))
4 0)
(defun sometune ())
(fluidsynth:program-change *synth* 2 53)
(fluidsynth:program-change *synth* 3 52)
(fluidsynth:program-change *synth* 1 1)
(fluidsynth:program-change *synth* 0 1)
(fluidsynth:program-change *synth* 2 110)
(fluidsynth:program-change *synth* 2 78)
(fluidsynth:program-change *synth* 3 78)
(setf *beat-offset* (reverse *beat-offset*))
(setf *beat-offset* '(0 0.1 1/3 0.7 0.9 0.9))
(setf *beat-offset* '(0 0.2 1/3 0.5 0.8))
(setf *beat-offset* '(0 0.2 0.4 0.6 0.8))
(setf *beat-offset* '(0 0.1 0.2 0.3 0.4))
(setf *beat-offset* '(0 0.1 0.11 0.13 0.15 0.17 0.2 0.4 0.5 0.55 0.6 0.8))
| 2,725 | Common Lisp | .lisp | 67 | 30.970149 | 89 | 0.477255 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | fb574956e0f32397e9aead92ff2a893a8d07af985c7577a68d124239f2db742e | 9,216 | [
-1
] |
9,217 | rsg.lisp | azimut_shiny/compositions/drafts/rsg.lisp | (in-package :shiny)
;; "silverline"
;; "Each major scale has a relative minor scale, and you
;; can determine the relative minor by using the major
;; scale's sixth note"
(defvar *maj* (ov-scale :C4 :major))
(defvar *min* (ov-scale :A4 :minor))
(make-orc :ourvoice
:filename "ourvoice"
:filepath "/home/sendai/projects/csound-instruments/pinkston/")
(start-csound (get-orchestra :ourvoice))
(start-thread)
(make-play voice-a "i1"
:amp 10000 :keynum 60 :fmt1 609 :db1 0 :fmt2 1000 :db2 -6
:fmt3 2450 :db3 -12 :fmt4 2700 :db4 -11 :fmt5 3240 :db5 -24
:left 1f0 :right 1f0)
(fg 1f0)
(freverb-toggle 1)
(freverb-preset 5)
(fp 0 0)
(fp 1 1)
(fp 2 0)
(fp 3 0)
(viseq::wait-key 100)
(viseq:push-cvideo
:la "/home/sendai/clips/lali-machines.mp4"
:stop-pos 180
:scale .01f0
:glitch nil
:is-negative nil)
(viseq:push-cvideo
:car "/home/sendai/clips/lali-machines.mp4"
:is-visible nil
:repeat 2
:stop-pos (* 25 77)
:pos (* 25 75)
:restart-pos (* 25 75)
:scale 1f0
:is-negative nil)
(f (tempo-sync #[1 b]))
(defun f ())
(defparameter *appear-video*
(make-line (append (iota 20 :start .01 :step .05) '(1f0))))
(defparameter *appear-vol*
(make-line (iota 15 :start 10 :step 3)))
(let* ((maj (make-weighting *maj* 3))
(min (make-weighting *min* 3))
(chan (make-cycle '(0 1)))
(notes (make-cycle (list maj min))))
(defun f (time)
(viseq:push-cvideo :la "/home/sendai/clips/lali-machines.mp4"
:scale (next *appear-video*) :xpos 50 :ypos 50)
(let ((v (next *appear-vol*)))
(pa time (next notes 3) .3333 (rcosr v 3 4) (next chan) .3333)
(pa (+ time #[.15 b])
(next notes 3)
'(0 .33333)
(list v (+ v 10))
3
.2))
(aat (+ time #[1 b])
#'f it)))
(defparameter *appear* (make-line (iota 50 :start 50 :step -.5)))
(defparameter *oddity* .01)
(let* ((maj (make-weighting *maj* 3))
(min (make-weighting *min* 3))
(chan (make-cycle '(0 1)))
(voice (make-line (iota 15 :start .2 :step .02)))
(oddity (make-weighting (list .1 (list 1 (pval *oddity*)))))
(notes (make-cycle (list maj min)))
(voi (make-cycle *min*))
(vis (make-weighting (list '(nil 1) (list t (pval *oddity*))))))
(defun f (time)
(incf *oddity* .05)
(pa time (next notes 3) .3333 50 (next chan) .3333)
(pa (+ time #[.15 b])
(next notes 3)
'(0 .3333)
50
3
.2)
(let ((ttime (+ time #[(pick .666 .333 .333 .333) b])))
(if (next vis)
(progn
(at ttime (lambda () (viseq:push-cvideo
:car "/home/sendai/clips/lali-machines.mp4"
:is-visible t
:repeat 2
:flip (pick -2 1)
:stop-pos (* 25 82)
;; :pos (* 25 80)
:restart-pos (* 25 70)
:scale 1f0
:is-negative (pick nil t))))
(at (+ time #[(pick .3333 .66666) b])
(lambda () (play-voice-a
(let ((v (next voi)))
(list v (+ v -12) (+ v -24)))
.66666 :left (random 1f0) :right (random 1f0) :amp (* (next *appear*) 500)
))))
(viseq:push-cvideo
:car "/home/sendai/clips/lali-machines.mp4"
:is-visible nil))
(pa ttime
(if (odds (next oddity))
(reverse (next notes 3))
(next notes 3))
'(.3333)
(round (next *appear*))
2
1))
(aat (+ time #[1 b])
#'f it)))
(bbuffer-load "/home/sendai/quicklisp/local-projects/aubio/static/au")
(f (now))
(defun f ())
| 3,908 | Common Lisp | .lisp | 116 | 25.206897 | 97 | 0.512331 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 333f6064ba961ae894fe2f02d0c5ab490fbcd50df00693d6e0b2de4a4db7d2ab | 9,217 | [
-1
] |
9,218 | coursera-progression.lisp | azimut_shiny/compositions/drafts/coursera-progression.lisp | (in-package :shiny)
;; lesson 3 - basic progresssions
(freverb-toggle 1)
(freverb-preset 3)
;; I IV V I - familiar
(defun f ())
(let ((i (new cycle :of '(i vi ii v)))
(r (new cycle :of '(2 2 2 2))))
(defun f (time)
(let ((mychord (make-chord 50 70 3 (pc-diatonic 0 'major (next i))))
(rr (next r)))
(pa time mychord .5 90 1 .5)
(p time mychord 60 rr 4)
(aat (+ time rr) #'f it))))
(f (now))
(fpitch 1 1000)
;; harpsichord (esque) on 0
(fpitch 1 15000)
(fsens 1 20)
;; nice with 52
(fpitch 1 10000)
(fsens 1 20)
(setf (bpm *tempo*) 90)
(flush-pending)
(off-with-the-notes)
(progn
(fpress 1 0)
(fpress 4 0))
(fpitch 3 12700)
(fp 1 52)
(fp 4 44) ;; tremolo!
(fp 4 49) ;; 42 cello
(fpress 4 127)
;; I IV V I
(let ((i (new cycle :of '(i iv v))))
(defun f (time)
(p (now)
(make-chord 50 70 3 (pc-diatonic 0 'major (next i)))
50 2 3)
(aat (+ time #[2 b]) #'f it)))
(f (now))
;; I V I
(all-piano 0)
(fp 2 41)
(fp 3 40)
;; using function constants (might be I can use this for a macro later)
;; another way is with a closure (i think) like make-tempo
(let ((c (new cycle :of '(2 3)))
(i (new cycle :of '(i v))))
(defun f (time)
(p (now)
(make-chord 50 70 3 (pc-diatonic 0 'major (next i)))
30 2 (next c))
(aat (+ time #[2 b]) #'f it)))
(f (now))
#|
/----------
IV - vii - iii - vi - IV - V - I - * (ANY)
ii vii
|#
(defparameter *mymarkov*
(new markov :of '((i :-> ii iii iv v vi vii)
(ii :-> v vii)
(iii :-> vi iv ii)
(iv :-> v vii)
(v :-> i)
(vi :-> iv ii)
(vii :-> i ))))
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'major (next *mymarkov*))) 60 1.5 3)
(defun f (time)
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'major (next *mymarkov*))) 60 1.5 3)
(aat (+ time #[1.5 b]) #'f it))
(f (now))
(defparameter *assocmarkov*
'((i ii iii iv v vi vii)
(ii v vii)
(iii vi iv ii)
(iv v vii)
(v i)
(vi iv ii)
(vii iii i)))
(defun f (time degree)
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'major degree)) 60 1.5 3)
(aat (+ time #[1.5 b]) #'f it (pickl (cdr (assoc degree *assocmarkov*)))
))
(f (now) 'i)
;;; -------------
;; I <-> V/vii
;;; -------------
(fp 3 52)
;; ew!
(defparameter *mychord*
(new cycle :of
`((maj 1)
,(new cycle :of '((maj 5) (min 7)) :for 1))))
(p (now) (make-chord 50 70 3 (apply #'pc-diatonic 0 (next *mychord*))) 60 1.5 3)
;;; all major
(defparameter *mychord*
(new cycle :of `(i ,(new weighting :of '(v vii) :for 1))))
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'maj (next *mychord*))) 60 1.5 3)
;; some glitch with midi
(defparameter *r* (new cycle :of '(1.5 2)))
(defun f (time)
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'maj (next *mychord*))) 60 (next *r*) 3)
(aat (+ time #[1.5 b]) #'f it))
(f (now))
;; without randomness in place i can just write it down, without nesting
;; but still need the cycle
(defparameter *mychord* (new cycle :of '((maj 1) (maj 5) (maj 1) (min 7))))
(p (now) (make-chord 50 70 3 (apply #'pc-diatonic 0 (next *mychord*))) 60 1.5 3)
;; unless I had a destructive pick and rotate function
(defparameter *mychord* '((maj 1) (maj 5) (maj 1) (min 7)))
;;?
;;(p (now) (make-chord 50 70 3 (apply #'pc-diatonic 0 (pick *mychord*))) 60 1.5 3)
(progn
(fp 3 (random 60))
(p (now) (make-chord 50 70 3 (pc-diatonic 0 'maj (pick 1 (pick 5 7)))) 60 1.5 3))
;;; ---------------------
;; Lesson 4 - voice leading
;;;
;; Common tones - approach
;; In classical era music, one often "tries" to keep the
;; common tones between two chords when voice leading.
;; So in, I IV or I V there are common notes/tones between them
(fg .8)
(fp 3 52)
(let ((i (new cycle :of '(i v i)))
(r (new cycle :of '(1 1 2))))
(defun f (time)
(let ((b (next r)))
(p (now)
(make-chord 50 70 3 (pc-diatonic 0 'major (next i)))
60 b 3)
(aat (+ time #[b b]) #'f it))))
(f (now))
(flush-pending)
(off-with-the-notes)
;;; Week 3 - Circle of fifths
(let ((d '((i ii iii iv v vi vii)
(ii v vii)
(iii vi iv ii)
(iv v vii)
(v i)
(vi iv ii)
(vii iii i)))))
(let ((d (new cycle :of '(i iv vii° iii vi ii v i))))
(defun f (time)
(p time (make-chord 50 70 3 (pc-diatonic 0 'maj (next d)))
60 1 3)
(aat (+ time #[1 b]) #'f it)))
(f (now))
| 4,554 | Common Lisp | .lisp | 151 | 25.874172 | 86 | 0.537474 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 294543a088585774c097f1cba9c2f096668938fa95b20efe79c0198953eaeda4 | 9,218 | [
-1
] |
9,219 | extempore-misc.lisp | azimut_shiny/compositions/drafts/extempore-misc.lisp | (in-package :shiny)
;; extempore - a study in part
;; this basically covers a scale descendent
;; cambiar los random
;; +
(fp 8 52)
(defun g ())
(defun g (time start pitch &optional duration)
(print (format nil "~a ~a" start pitch))
(p time pitch 60 duration 8)
(aat (+ time duration) #'g it
(if (> pitch (- start 12))
start
(pc-relative start -1 *phrygian*))
(if (> pitch (- start 12))
(pc-relative pitch -1 *phrygian*)
start)
(random-elt #(1 2 3))))
(g (quant 4) 72 72 1)
;;; extempore - an evening livecoding
(fp 11 50)
(defun g (time)
(let ((c (make-chord 65 75 2 (list (pick 10 0 0 1)
(pick 1 3 3 5)
(pick 7 8 8 10)))))
(print c)
(p time c 60 4 11))
(aat (+ time 4) #'g it))
(g (quant 4))
;;; same , but synth
(defun g (time)
(let ((c (make-chord 65 75 2 (list (pick 10 0 0 1)
(pick 1 3 3 5)
(pick 7 8 8 10)))))
(print c)
(mapcar (lambda (x) (synth 'soprano
:fmod .1
:freq (midicps x)
:amp .2 :sus 4)) c)
;; (aat (+ time 4) #'g it)
))
(g (quant 4))
| 1,289 | Common Lisp | .lisp | 42 | 21.809524 | 56 | 0.468119 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | be5359dd0cb49b34d6008dbc89887a72039b36ddd136ffbc2b6529e32cc9df05 | 9,219 | [
-1
] |
9,220 | rms.lisp | azimut_shiny/compositions/drafts/rms.lisp | (in-package #:shiny)
(define-vug rms (in hp)
(:defaults 0 60)
(with-samples ((b (- 2 (cos (* hp *twopi-div-sr*))))
(c2 (- b (sqrt (the non-negative-sample (1- (* b b))))))
(c1 (- 1 c2))
(in2 (* in in))
(q +sample-zero+))
(incudine.util:linear->db (sqrt (the non-negative-sample (~ (+ (* c1 in2) (* c2 it))))))))
(dsp! rms-monitor (rms)
(:defaults 0)
(setf rms (rms (audio-out 0))))
(rms-monitor :id 99)
(defun get-db (&optional (id 99))
(let ((rms (control-value id 'rms)))
(when rms
(let ((output (incudine.util:linear->db rms)))
(cm:interp (- (realpart output))
-50 0f0 -10 1f0)))))
| 714 | Common Lisp | .lisp | 19 | 30.105263 | 94 | 0.505065 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 5c78a3793af89083f9409844a4f116a50efcf878760b6f7eefec48d2db18c875 | 9,220 | [
-1
] |
9,221 | incudinetest.lisp | azimut_shiny/compositions/drafts/incudinetest.lisp | (in-package :shiny)
(enable-sharp-t-syntax)
(dsp! vuglet-test (freq amp)
(vuglet ((osc (freq amp)
(* amp (sin (* (phasor freq 0)
+twopi+))))
(fm (fcar fmod amp (k fixnum))
(osc (+ fcar (osc fmod (* fcar (/ k)))) amp))
(lp (in)
(* 0.5 (+ in (delay1 in))))
(lp4 (in) #4t(lp in)))
(with-samples ((f1 freq)
(f2 (- 20000 f1))
(g (* amp .5))
(this (+ (lp (fm f1 111 g 8))
(lp4 (fm f2 70 g 18)))))
(out this this))))
(vuglet-test 100 .2 :id 2)
(set-control 2 :freq (if (odds .2) 110 220))
(incudine:free (node 0))
(dsp! highest-note-test ((chan fixnum) a d s r)
"Highest priority monosynth (single trigger)."
(with ((keynum (incudine.vug:midi-highest-keynum chan)))
(with-samples ((glide (incudine.vug:exp-midi-cc chan 1 0.01 1.2))
(amp (incudine.vug:midi-amp
incudine.vug:*linear-midi-table*
chan keynum))
(amp-prev +sample-zero+)
(gate +sample-zero+))
(if (zerop amp)
(setf gate +sample-zero+ amp amp-prev) ; Note off.
(setf gate (sample 1) amp-prev amp))
(stereo (* (envelope (make-adsr a d s r) gate 1 #'identity)
(incudine.vug:gbuzz (incudine.vug:lag (incudine.vug:midi-cps *default-tuning* keynum) glide)
(incudine.vug:lag amp 0.02) 20 1 .6))))))
| 1,551 | Common Lisp | .lisp | 35 | 31.828571 | 109 | 0.490391 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 0f7e79c0887d95dbfe158a7a19b9536c7ff9acdd2452300b27afa722295e63db | 9,221 | [
-1
] |
9,222 | nudruz.lisp | azimut_shiny/compositions/drafts/nudruz.lisp | (in-package :shiny)
(fluidsynth:program-change *synth* 1 33)
(fluidsynth:program-change *synth* 1 40)
(fluidsynth:program-change *synth* 1 74)
(all-piano 1)
;; expwarp test
;; Try:
;; - Modify the dur and aat
;; - Reduce the notes on make-chord
;; - Change the pc scale
(defun ew (time &optional chords)
(let ((x (make-chord 35 64 2 (scale 0 'ryukyu))))
(setp chords (loop :for n :from 1 :to 2 :by .1 :collect
(expwarp x n))))
(let ((chord (car chords)))
(dolist (k chord)
(p time k (rcosr 40 5 3/4) 2 4))
(aat (+ time 2) #'ew it (cdr chords))))
(ew (quant 4))
(defun ew ())
| 621 | Common Lisp | .lisp | 20 | 27.75 | 59 | 0.623116 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 2ef647813385fbe425305f2475d7c1c2fc925b2429d61a9022193a962f917870 | 9,222 | [
-1
] |
9,223 | inscore.lisp | azimut_shiny/compositions/drafts/inscore.lisp | ;; (inscore-reset)
;; (inscore-init)
;;(inscore-stream :meter "4/4")
;; (inscore-write (pick "_" "a" "b" "c" "d" "f" "g" "h"))
;; (inscore-write "_/32")
;; (inscore-write "a*1/4")
;; (inscore-write "a/2")
;; file:///home/sendai/projects/inscore/doc/OSCMsg/OSCMsgch7.html
(osc:message *oscout* "/ITL/scene/l/v1" "sss" "set" "video" "/home/sendai/bunny.mp4")
;; OR JUST THE 4th color param
;; the less the more transparent
(osc:message *oscout* "/ITL/scene/l/v1" "si" "alpha" 100)
;; move Y = -.5 .5
;; move X = -1.0 1.0
;; (osc:message *oscout* "/ITL/scene/l/v1" "sf" "x" 0f0)
;; (osc:message *oscout* "/ITL/scene/l/v1" "sf" "y" 0f0)
;; play 1, does not loop...does nothing if already playing
;; play 0, pause
;;(osc:message *oscout* "/ITL/scene/l/v1" "si" "play" 1)
;; volume max 1f0
;;(osc:message *oscout* "/ITL/scene/l/v1" "si" "volume" .1f0)
;; scale video
;;(osc:message *oscout* "/ITL/scene/l/v1" "sf" "scale" 2.4f0)
;; del
;;(osc:message *oscout* "/ITL/scene/l/v1" "s" "del")w
;; rate - changing the rate on the flay makes all janky...
;;(osc:message *oscout* "/ITL/scene/l/v1" "sf" "rate" .5f0)
(osc:message *oscout* "/ITL/scene/l/v1" "si" "vdate" 20000)
(osc:message *oscout* "/ITL/scene/l/v1" "sf" "rotatez" 0f0)
(osc:message *oscout* "/ITL/scene/l/v1" "ssi" "effect" "blur" 9)
;; strength, tint
(osc:message *oscout* "/ITL/scene/l/v1" "ssfiii" "effect" "colorize"
0.5 0 255 10)
(osc:message *oscout* "/ITL/scene" "si" "alpha" 255)
(osc:message *oscout* "/ITL/scene/l/background" "si" "alpha" 255)
;; FIXME: this yells object! use CLOS!
(defun inscore-video
(video dur
&key (window-name *window-name*) (layer-name *layer-name*)
(video-name *video-name*) (volume .1) (scale 1f0 scale-p)
(rate 1f0 rate-p) (x 1f0 x-p) (y 1f0 y-p) (alpha 100 alpha-p)
(rotatex 0f0 rotatex-p) (rotatey 0f0 rotatey-p) (rotatez 0f0 rotatez-p))
(let ((osc-path
(format nil "/ITL/~a/~a/~a" window-name layer-name video-name)))
(assert (uiop:file-exists-p video))
;;(inscore-init)
(osc:message *oscout* osc-path "sss" "set" "video" video)
(osc:message *oscout* osc-path "sf" "volume" volume)
(osc:message *oscout* osc-path "si" "play" 1)
(when alpha-p
(osc:message *oscout* osc-path "si" "alpha" alpha))
(when rotatex-p
(osc:message *oscout* osc-path "sf" "rotatex" rotatex))
(when rotatey-p
(osc:message *oscout* osc-path "sf" "rotatey" rotatey))
(when rotatez-p
(osc:message *oscout* osc-path "sf" "rotatez" rotatez))
(when x-p
(osc:message *oscout* "/ITL/scene/l/v1" "sf" "x" x))
(when y-p
(osc:message *oscout* "/ITL/scene/l/v1" "sf" "y" y))
(when rate-p
(osc:message *oscout* osc-path "sf" "rate" rate))
(when scale-p
(osc:message *oscout* osc-path "sf" "scale" scale))
(at (+ (now) #[dur b])
#'(lambda () (osc:message *oscout* osc-path "s" "del")))))
| 2,923 | Common Lisp | .lisp | 67 | 39.910448 | 85 | 0.620605 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 75671fd306de67739f631949938c370701a9eda897dfa315b30a5a0068c2ab0a | 9,223 | [
-1
] |
9,224 | ruby_music_theory.lisp | azimut_shiny/compositions/drafts/ruby_music_theory.lisp | (in-package :shiny)
;;;
;; arpeggios.rb
;;;
;; frequency = 293.665 # Middle D
;; twelfth = 2 ** (1.0/12)
;;
;; next = frequency * twelfth
;; = 311.127
;;
;; (293.665 311.12723 329.6278 349.22852 369.99472 391.99576 415.30502 440.00034 466.16412 493.8837 523.2515 554.3657 587.33)
;;
;; http://subsynth.sourceforge.net/midinote2freq.html
;; 62 = 293.665
;; 63 = 311.127
;; 64 = 329.627
(defun make-arpeggio (note mode)
"makes a very peculiar kind of arpeggio
> (make-arpeggio :D4 :major) => (62 69 74 67 69)
Basically it create the scale midi notes and then picks
elements from it based on the PC of the mode selected"
(let* ((n (ov-scale note mode))
(nn (append n n))
(steps (cdr (assoc mode +scale+)))
(sum-steps (loop :for (x y) :on steps
:by #'cddr
:collect (apply #'+ (remove nil (list x y))))))
(loop :for x :in (append '(0) sum-steps)
:with z = 0
:collect (nth (incf z x) nn))))
#|
> y scale.scale_notes.map(&:frequency)
- 293.665
- 329.6278174167721
- 369.994715117378
- 391.9957457748432
- 440.00034773099077
- 493.8836915709643
- 554.3657000673392
- 587.3300000000002
(62 64 66 67 69 71 73 74)
2 2 1 2 2 2 1
> (ov-scale :D4 :major)
(62 64 66 67 69 71 73 74)
> (scale 0 'ionian)
(0 2 4 5 7 9 11)
> y scale.i.chord.third.all_notes.map(&:frequency)
- 293.665
- 440.00034773099077
- 587.3300000000002
- 391.9957457748432
- 440.00034773099077
(62 69 74 67 69)
> y scale.ii.chord.third.all_notes.map(&:frequency)
- 329.6278174167721
- 493.8836915709643
- 659.2556348335443
- 440.00034773099077
- 493.8836915709643
(64 71 76 69 71)
|#
| 1,665 | Common Lisp | .lisp | 61 | 24.491803 | 125 | 0.654568 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | a48fbcc5f316c6f69b17cb506b8f8bc1adf8974f11f6812e7fe7cc5203837bcb | 9,224 | [
-1
] |
9,225 | schumann.lisp | azimut_shiny/compositions/drafts/schumann.lisp | (in-package :shiny)
(defparameter *scale* (ov-scale :G4 :minor))
(defparameter *ncrypt* (decrypt-melody "carla"))
(defparameter *theme* (nths *ncrypt* *scale*))
(defun div (num div)
"/ with zero divisor support-ish"
(when (> div 0)
(/ num div)))
(fg 2f0)
(p (now) 50 80 1 0)
(defun f ())
(let* ((bass (make-cycle (list (make-cycle *theme* 1)
(make-cycle 0 3))))
(c-a-r (nths '(0 1 2) *theme*))
(l-a (nths '(3 4) *theme*))
(mel (make-cycle (list (make-cycle c-a-r)
(make-cycle l-a) 0)))
(rhy (make-weighting '((1 .9) .5))))
(defun f (time)
(let ((r (next rhy)))
(p time (+ -12 (next bass)) 50 r 0)
(let* ((n (pick 1 2 3 1 2))
(f (div r n))
(m (next mel n))
(m (nth-inc (min (pick 0 1 2) (1- n))
(pick 0 -12 0 0) m))
)
(and (odds .1) (p time (+ 12 (pickl l-a)) 90 5 3))
;;(pa time m f 50 '(2 4 6) f)
(pa (+ #[.5 b] time) (reverse m) f 50 '(6 4 2) f)
)
(aat (+ time #[r b]) #'f it))))
(f (now))
(fp 2 82)
(fp 3 59)
(fp 4 82)
(fp 6 82)
(fg .9)
;;--------------------------------------------------
(setf (bpm *tempo*) 100)
(defun f ())
(let ((notes
(make-cycle
(nths (decrypt-melody "car")
(ov-scale :C3 :ryukyu)))))
(defun f (time)
(pa time (nth-inc 2 12 (next notes 3)) 1/3 '(30 30 40) '(0 0 0)
(list 1/3 1/3 (pick 1/3 1 .1)))
(pa (+ time #[.2 b]) (nth-inc 2 12 (next notes 3)) 1/3 '(30 30 40) '(1 1 1)
(list 1/3 1/3 (pick 1/3 1 .1)))
(p time *gm-kick* 30 6 (pick 22 23 24) :pan (pick 0 200))
(aat (+ time #[3 b]) #'f it)))
(fp 22 10 2)
(fp 23 10 2)
(fp 24 10 2)
(fp 0 0)
(fp 1 40)
(f (tempo-sync #[1 b]))
| 1,821 | Common Lisp | .lisp | 58 | 25.103448 | 79 | 0.454909 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | b09d5d60fae433533d9881f6ae9c66ad44ae384170824188506df76a40ac990e | 9,225 | [
-1
] |
9,226 | moonsetter.lisp | azimut_shiny/compositions/drafts/moonsetter.lisp | (in-package :shiny)
;; https://musescore.com/user/335926/scores/629201
(defparameter c (make-chord 60 80 4 (scale 0 'harmonic)))
(defparameter song (list (first c) (rest c) 0 (rest c)
(first c) (rest c) 0 (rest c)
(first c) (rest c) 0 (rest c)
(first c) (rest c) (first c) (rest c)))
(pa (quant 4) song .5 50 0 .5)
(defun moon ())
(defmacro repeat-at-beat (name beat-duration &body body)
`(defun ,name (&optional (time (funcall #'quant 4)))
,@body
(aat (+ time ,beat-duration) #',name it)))
(pa (quant 4) song .5 50 0 '(.5 .5 0 .25
.5 .5 0 .25
.5 .5 0 .25
.5 .5 .5 .5))
(repeat-at-beat moon (* .4 (length song))
(pa (quant 4) song .4 50 0 (mapcar (lambda (x) (+ 0 x))
'(.4 .4 0 .2
.4 .4 0 .2
.4 .4 0 .2
.4 .4 .4 .4))))
(moon)
(fp 0 52)
(fg 2f0)
(freverb-toggle 1)
(freverb-preset 6)
(defun moon ())
| 1,141 | Common Lisp | .lisp | 29 | 26.551724 | 64 | 0.435967 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 4daa970125a1413c52c47876ef2bbfaec2987d6f6f0073734b07d16300beff0b | 9,226 | [
-1
] |
9,227 | aubio.lisp | azimut_shiny/compositions/drafts/aubio.lisp | (in-package :shiny)
;;--------------------------------------------------
;;(ql:quickload :cl-gme/incudine)
(defun gmeplay-beat
(filename node track-number
&key (amp 1) (rate 1f0) (start-pos 0)
(fade-curve 3) (fade-time 0f0) (loop-p t)
(left 1f0) (right 1f0)
(length 1) (offset 0) (voices '())
;; Filters
(lpf 0d0) (hpf 0d0) (bpf 0d0)
;; controlers
load-only control-only aubio-p)
(declare (integer node track-number length offset) (boolean load-only))
(let ((alive (node-id (node node)))
(hashkey (concatenate 'string filename (write-to-string node))))
;; fill empty slot
(unless control-only
(setf (gethash hashkey *loading*)
(gmebuffer filename
:track-number track-number
:len length
:voices voices
:offset offset))
(when aubio-p
(multiple-value-bind (_ frames)
(test-beats (gethash hashkey *loading*))
(declare (ignore _))
(let* ((frames (remove-sides frames))
(start-frame (first frames))
(end-frame (lastcar frames)))
(setf (gethash hashkey *loading*)
(slice-buffer (gethash hashkey *loading*)
start-frame end-frame))))))
(when alive
(if control-only
(at (tempo-sync #[1 b])
#'set-controls
node
:rate rate
:loop loop-p
:left left
:right right
:lpf lpf
:hpf hpf
:bpf bpf
:fade-curve fade-curve
:fade-time fade-time
:amp amp)
(at (tempo-sync #[1 b])
#'set-controls
node
:buf (gethash hashkey *loading*)
:rate rate
:loop loop-p
:left left
:right right
:lpf lpf
:hpf hpf
:bpf bpf
:fade-curve fade-curve
:fade-time fade-time
:amp amp)))
(unless load-only
(at (tempo-sync #[1 b])
#'bplay
(gethash hashkey *loading*) rate 0 loop-p
:id node
:left left
:hpf hpf
:lpf lpf
:bpf bpf
:custom-id node
:right right
:fade-curve fade-curve
:fade-time fade-time
:amp amp))
(unless control-only
(rotatef (gethash hashkey *loading*)
(gethash hashkey *playing*))
(incudine:free (gethash hashkey *loading*)))))
(progn
(incudine.external:foreign-zero-sample (buffer-data *buf1*) 512)
(incudine.external:foreign-zero-sample (buffer-data *buf2*) 512)
(incudine.external:foreign-zero-sample (buffer-data *buf3*) 512)
(incudine.external:foreign-zero-sample (buffer-data *buf4*) 512))
(incudine:free (node 0))
(gmeclean)
(defparameter *gmesong*
"/home/sendai/Downloads/sf2/contra.nsf")
(defparameter *gmetrack* 2)
(defparameter *gmerate* .7)
(gmeplay-beat
*gmesong* 1 *gmetrack*
:amp .1
:aubio-p t
:length 40 :offset 70
:voices '(0)
:rate *gmerate*)
(gmeplay-beat
*gmesong* 2 *gmetrack*
:amp .1 :aubio-p t :length 40 :offset 70
:voices '(1)
:rate *gmerate*)
(gmeplay-beat
*gmesong* 3 *gmetrack*
:amp .4 :aubio-p t
:length 40 :offset 30 :left .2
:voices '(2)
:rate *gmerate*)
(gmeplay-beat
*gmesong* 4 *gmetrack*
:amp .3 :aubio-p t :length 40 :offset 30 :right .2
:voices '(3)
:rate *gmerate*)
;;--------------------------------------------------
;;--------------------------------------------------
;;--------------------------------------------------
(gmeplay-beat
"/home/sendai/Downloads/sf2/mother.nsf" 3 19
:amp .01
:aubio-p t
:length 30
:offset 20
:right .2
:voices '(1)
:rate .7)
;;--------------------------------------------------
(gmeplay-beat
"/home/sendai/Downloads/sf2/ff3.nsf" 3 13
:amp .05
:aubio-p t
;; :load-only t
;; :loop-p nil
:length 20
:offset 10
:left .2
:voices '(2)
:rate .7)
(gmeplay-beat
"/home/sendai/Downloads/sf2/ff3.nsf" 2 13
:amp .01
:aubio-p t
:load-only t
;; :loop-p nil
:length 20
:offset 70
:voices '(3 1)
:rate .7)w
;;--------------------------------------------------
(incudine:free (node 0))
(gmeplay-beat
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc" 2 1
:amp .5
:aubio-p t
:control-only t
;; :load-only t
:length 20
:offset 80
:lpf 200
;; :right .2
;; :left .3
;; :voices '(4 5 6 7)
:voices '(0 1 2 3)
:rate .5)
(incudine:free (node 2))
(gmeplay-beat
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc" 3 9
:amp .2
;; :control-only t
;; :aubio-p t
:load-only t
:length 30
:hpf 400
:lpf 400
:offset 120
:left .9
:voices '(0)
:rate 1)
(gmeplay-beat
"/home/sendai/Downloads/chrono/111 Secret of the Forest.spc" 4 9
:amp .2
:control-only t
;; :aubio-p t
;; :load-only t
:length 30
:hpf 400
:lpf 800
:offset 120
:left .9
:voices '(6 7)
:rate 1)
;;----------------------------------------
(incudine:free (node 0))
(gmeplay-beat
"/home/sendai/Downloads/sf2/ff3.nsf" 2 7
:amp .2
:aubio-p t
;; :load-only t
;; :loop-p nil
:length 40
:offset 10
;; :left .2
:voices '(2 3)
:rate .7)
(gmeplay-beat
"/home/sendai/Downloads/sf2/ff3.nsf" 3 7
:amp .2
:aubio-p t
;; :load-only t
;; :loop-p nil
:length 40
:offset 70
;; :left .2
:voices '(2)
:rate .7)
(gmeclean)
(defparameter *buf*
(gethash "loop_amen.wav" *buffers*))
(defparameter *buf*
(gethash "/home/sendai/Downloads/sf2/ff3.nsf3" *playing*))
(defparameter *buf*
(gethash "/home/sendai/Downloads/chrono/111 Secret of the Forest.spc2" *playing*))
(defparameter *buf*
(bbuffer-load "/home/sendai/quicklisp/local-projects/aubio/static/loop_amen.wav"))
(defparameter *sets*
(loop :for (x y)
:on (multiple-value-bind (_ frames)
(test-onset *buf*)
(declare (ignore _))
(remove-sides frames))
:when (and x y)
:collect (list x y)))
(let ((sets (make-heap *sets*)))
(defun f (time)
(let* ((set (next sets))
(start-pos (car set))
(loopend (lastcar set))
(rate 1)
(dur (* (/ 1 rate) (/ (- loopend start-pos) 44100f0))))
(play-lsample-f
*buf*
:amp .1 :start-pos start-pos :loopend loopend
:dur dur :rate rate)
(aat (+ time #[dur b]) #'f it))))
(incudine:free (node 0))
(defun f ())
(f (now))
| 6,572 | Common Lisp | .lisp | 248 | 20.842742 | 84 | 0.545888 | azimut/shiny | 18 | 2 | 0 | GPL-3.0 | 9/19/2024, 11:26:41 AM (Europe/Amsterdam) | 9da299db4f168fe6ec49bbe9063e81b72a41c863990a1da412c0f93480a28a67 | 9,227 | [
-1
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.