From 0e3a606164bcfeb562d1c84772168a20ebb84616 Mon Sep 17 00:00:00 2001 From: Michael Edwards Date: Wed, 13 Nov 2024 19:46:38 +0100 Subject: [PATCH] periodicity can use a list of lists also --- src/utilities.lsp | 7 ++++++- tests/sc-test-suite.lsp | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utilities.lsp b/src/utilities.lsp index 6d1388e4..b2d03663 100644 --- a/src/utilities.lsp +++ b/src/utilities.lsp @@ -17,7 +17,7 @@ ;;; ;;; Creation date: June 24th 2002 ;;; -;;; $$ Last modified: 19:38:18 Wed Nov 13 2024 CET +;;; $$ Last modified: 19:46:21 Wed Nov 13 2024 CET ;;; ;;; **** ;;; Licence: Copyright (c) 2010 Michael Edwards @@ -6784,6 +6784,9 @@ yes_foo, 1 2 3 4; ;;; Given a list of integers > 0, representing perhaps the number of items ;;; (e.g. pitches, rhythms etc.) in an arbitrary number of lists, calculate the ;;; cycle length before we repeat, i.e. start again at the beginning. +;;; +;;; NB for convenience the argument can be a list of lists, the lengths of which +;;; will then be used as above. ;;; ;;; ARGUMENTS ;;; a list of integers > 0 @@ -6813,6 +6816,8 @@ yes_foo, 1 2 3 4; ;;; SYNOPSIS (defun periodicity (proportions) ;;; **** + (when (every #'listp proportions) + (setq proportions (loop for p in proportions collect (length p)))) (assert (and proportions (listp proportions) (every #'integer>0 proportions))) (let ((nds (remove-duplicates proportions diff --git a/tests/sc-test-suite.lsp b/tests/sc-test-suite.lsp index dcf861e4..0ea10883 100644 --- a/tests/sc-test-suite.lsp +++ b/tests/sc-test-suite.lsp @@ -17,7 +17,7 @@ ;;; ;;; Creation date: 7th December 2011 (Edinburgh) ;;; -;;; $$ Last modified: 19:38:49 Wed Nov 13 2024 CET +;;; $$ Last modified: 19:45:19 Wed Nov 13 2024 CET ;;; ;;; SVN ID: $Id: sc-test-suite.lsp 6249 2017-06-07 16:05:15Z medward2 $ ;;; @@ -16427,6 +16427,7 @@ (and (= p period) (equalp l props))))) (sc-test-check (test-it '(1 2 5) 10 '(2 5)) + (test-it '((1 2 3) (1 2 3 4 5) (a b c d e f)) 30 '(5 6)) (test-it '(1 2 3 4 5 6) 120 '(4 5 6)) (test-it '(1 2 3 4 5 6 20) 120 '(6 20)) (test-it '(1 2 3 4 5 6 16) 480 '(5 6 16)))))