hsmusic/hsmusic.lisp
2024-04-14 21:21:53 -04:00

39 lines
1.4 KiB
Common Lisp

(ql:quickload '(:cl-yaml :alexandria :cl-graph :cl-ppcre))
(defpackage :hsmusic
(:use :common-lisp :alexandria :cl-graph))
(in-package :hsmusic)
(defparameter tracks
(loop for path in (directory #p"album/*.yaml")
appending (loop for entry in (yaml:parse path :multi-document-p t)
when (and (not (symbolp entry)) (gethash "Track" entry))
collect entry)))
; terrible, idc
; lossy! (not surprising)
(defun normalize-name (name)
(ppcre:regex-replace-all
"(^track:|\W)"
(sb-unicode:normalize-string (string-downcase name) :nfkd)
""))
(defparameter graph (containers:make-container 'graph-container :default-edge-type :directed))
(loop for track in tracks
do
(loop for ref in (append (gethash "Referenced Tracks" track) (gethash "Sampled Tracks" track))
do (format t "~a -> ~a~%" (normalize-name (gethash "Track" track)) (normalize-name ref))
do (add-edge-between-vertexes
graph
(normalize-name (gethash "Track" track))
(normalize-name ref))))
(defun track-vertex (name)
(find-vertex-if graph (lambda (x) (equal (slot-value x 'element) (normalize-name name)))))
; instead of this whole graph thing, i *could* do an alist
; rassoc exists
; BUT the graph library has :o algorithms :o
; BUT still would be faster than 1st attempt