From ce07ab9308e1b8d359b8c8c67fd31790e3f01cbf Mon Sep 17 00:00:00 2001 From: mehbark Date: Sun, 14 Apr 2024 21:21:53 -0400 Subject: [PATCH] gonna uncomplect --- flake.lock | 40 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 29 +++++++++++++++++++++++++++++ hsmusic.lisp | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 hsmusic.lisp diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..132ff83 --- /dev/null +++ b/flake.lock @@ -0,0 +1,40 @@ +{ + "nodes": { + "flake-schemas": { + "locked": { + "lastModified": 1697467827, + "narHash": "sha256-j8SR19V1SRysyJwpOBF4TLuAvAjF5t+gMiboN4gYQDU=", + "rev": "764932025c817d4e500a8d2a4d8c565563923d29", + "revCount": 29, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/DeterminateSystems/flake-schemas/0.1.2/018b3da8-4cc3-7fbb-8ff7-1588413c53e2/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/DeterminateSystems/flake-schemas/%2A.tar.gz" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712867921, + "narHash": "sha256-edTFV4KldkCMdViC/rmpJa7oLIU8SE/S35lh/ukC7bg=", + "rev": "51651a540816273b67bc4dedea2d37d116c5f7fe", + "revCount": 557634, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2311.557634%2Brev-51651a540816273b67bc4dedea2d37d116c5f7fe/018ed69f-a175-7ab0-bc05-651225022c5a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/%2A.tar.gz" + } + }, + "root": { + "inputs": { + "flake-schemas": "flake-schemas", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..c90b8db --- /dev/null +++ b/flake.nix @@ -0,0 +1,29 @@ +# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.9) +{ + inputs = { + flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*.tar.gz"; + nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz"; + }; + outputs = { self, flake-schemas, nixpkgs }: + let + supportedSystems = [ "x86_64-linux" ]; + forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f { + pkgs = import nixpkgs { inherit system; }; + }); + in { + schemas = flake-schemas.schemas; + + devShells = forEachSupportedSystem ({ pkgs }: { + default = pkgs.mkShell { + + packages = with pkgs; [ + nixpkgs-fmt + ]; + + LD_LIBRARY_PATH=pkgs.lib.makeLibraryPath [ pkgs.openssl pkgs.libyaml ]; + # not necessary + # LIBRARY_PATH="${pkgs.raylib}/include"; + }; + }); + }; +} diff --git a/hsmusic.lisp b/hsmusic.lisp new file mode 100644 index 0000000..1cfdca7 --- /dev/null +++ b/hsmusic.lisp @@ -0,0 +1,38 @@ +(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 +