chord.lsp Version 1.00 31 October 2004 Author Steven Jones Contact jones57@swbell.net include the word "nyquist" in subject line The contents of this file are released under the terms of the GNU General Public License. See the file LICENSE.txt Functions for the creation of chords where a "chord" is simply a list of MIDI key numbers.
function
(chord:append-octave (lst flag [steps]) Conditionally add octave to list. lst - list. A list of MIDI key numbers. (A B C) --> (A B C A+12) flag - bool. If false an un-altered copy of lst is returned. If true the sum of step(12) and the car of lst is appended to the end of lst, effectively adding an octave interval to the list. steps - integer. The size of an octave in half-steps. Default 12 return - list.
function
(chord:invert lst n) Return a chord inversion. The process works by taking each i from 0 to n, removing the first interval of the list, add an octave to the removed interval, and finally place the transposed interval to the end of the list. lst - list. A list of MIDI key numbers n - integer. Number of inversions. n >= 0 return - list.
function
(chord:make-chord template inversion octave) Create new chord list by applying inversion and octaves to template. arg - template. list The chords template. For example a major chord consist of the 0th 4th and 7th half-steps. The template is therefore (0 4 7) inversion - integer. Number of inversions. octave - bool. If true an octave of the first list element is appended to the list end. The octave is added after any inversions. return - list.
macro
(defchord name template) Creates a new function named name with lambda list #'(lambda (&optional (root 0)(inversion 0)(octave 'NIL))) name - symbol. The name of the new function template - list. The interval template
function
(major [root [inversion [octave]]]) A chord function with template '( 0 4 7)) See defchord macro
function
(minor [root [inversion [octave]]]) A chord function with template '( 0 3 7)) See defchord macro
function
(dominant7 [root [inversion [octave]]]) A chord function with template '( 0 4 7 10)) See defchord macro
function
(major7 [root [inversion [octave]]]) A chord function with template '( 0 4 7 11)) See defchord macro
function
(minor7 [root [inversion [octave]]]) A chord function with template '( 0 3 7 10)) See defchord macro
function
(major9 [root [inversion [octave]]]) A chord function with template '( 0 4 7 10 14)) See defchord macro
function
(minor9 [root [inversion [octave]]]) A chord function with template '( 0 3 7 10 14)) See defchord macro
function
(major11 [root [inversion [octave]]]) A chord function with template '( 0 4 7 10 14 17)) See defchord macro
function
(minor11 [root [inversion [octave]]]) A chord function with template '( 0 3 7 10 14 17)) See defchord macro
function
(major13 [root [inversion [octave]]]) A chord function with template '( 0 4 7 10 14 17 20)) ;With 11th See defchord macro
function
(major13-11 [root [inversion [octave]]]) A chord function with template '( 0 4 7 10 14 20)) ;Without 11th See defchord macro
function
(minor13 [root [inversion [octave]]]) A chord function with template '( 0 3 7 10 14 17 20)) ;With 11th See defchord macro
function
(minor13-11 [root [inversion [octave]]]) A chord function with template '( 0 3 7 10 14 20)) ;Without 11th See defchord macro
function
(major6 [root [inversion [octave]]]) A chord function with template '( 0 4 7 9)) See defchord macro
function
(minor6 [root [inversion [octave]]]) A chord function with template '( 0 3 7 9)) See defchord macro
function
(diminished [root [inversion [octave]]]) A chord function with template '( 0 3 6)) See defchord macro
function
(diminished7 [root [inversion [octave]]]) A chord function with template '( 0 3 6 9)) See defchord macro
function
(augmented [root [inversion [octave]]]) A chord function with template '( 0 4 8)) See defchord macro
function
(augmented7 [root [inversion [octave]]]) A chord function with template '( 0 4 8 10)) See defchord macro
function
(d powerchord-1 [root [inversion [octave]]]) A chord function with template '( 0 4 7 12 16 24)) See defchord macro
function
(powerchord-2 [root [inversion [octave]]]) A chord function with template '( 0 7 12 16 19 24)) See defchord macro
function
(powerchord-3 [root [inversion [octave]]]) A chord function with template '(-5 0 7 12 16 24)) See defchord macro
function
(powerchord-min1 [root [inversion [octave]]]) A chord function with template '( 0 3 7 12 15 24)) See defchord macro
function
(powerchord-min2 [root [inversion [octave]]]) A chord function with template '( 0 7 12 15 19 24)) See defchord macro
function
(powerchord-min3 [root [inversion [octave]]]) A chord function with template '(-5 0 7 12 15 24)) See defchord macro
;; chord.lsp ;; Version 1.00 31 October 2004 ;; Author Steven Jones ;; ;; Contact jones57@swbell.net include the word "nyquist" in subject line ;; ;; The contents of this file are released under the terms of the GNU General ;; Public License. See the file LICENSE.txt ;; ;; Functions for the creation of chords where a "chord" is simply a list of ;; MIDI key numbers. ;; (require 'math) (provide 'chord) (current-file "chord") ;; @doc function chord:append-octave ;; (chord:append-octave (lst flag [steps]) ;; Conditionally add octave to list. ;; ;; lst - list. A list of MIDI key numbers. ;; (A B C) --> (A B C A+12) ;; ;; flag - bool. ;; If false an un-altered copy of lst is returned. ;; If true the sum of step(12) and the car of lst is appended to ;; the end of lst, effectively adding an octave interval to the list. ;; ;; steps - integer. The size of an octave in half-steps. Default 12 ;; ;; return - list. ;; (defun chord:append-octave (lst flag &optional (steps 12)) (if flag (reverse (cons (+ (car lst) steps)(reverse lst))) lst)) ; *************************************************************************** ;; @doc function chord:invert ;; (chord:invert lst n) ;; Return a chord inversion. ;; The process works by taking each i from 0 to n, removing the first interval ;; of the list, add an octave to the removed interval, and finally place the ;; transposed interval to the end of the list. ;; ;; lst - list. A list of MIDI key numbers ;; ;; n - integer. Number of inversions. n >= 0 ;; ;; return - list. ;; (defun chord:invert (lst n) (-rotate lst n #'(lambda (q)(+ q 12)))) ; *************************************************************************** ;; @doc function chord:make-chord ;; (chord:make-chord template inversion octave) ;; Create new chord list by applying inversion and octaves to template. ;; ;; arg - template. list The chords template. For example a major ;; chord consist of the 0th 4th and 7th half-steps. The template ;; is therefore (0 4 7) ;; ;; inversion - integer. Number of inversions. ;; ;; octave - bool. If true an octave of the first list element is appended ;; to the list end. The octave is added after any inversions. ;; ;; return - list. ;; (defun chord:make-chord (template inversion octave) (chord:append-octave (chord:invert template inversion) octave)) ; *************************************************************************** ;; @doc macro defchord ;; (defchord name template) ;; Creates a new function named name with lambda list ;; #'(lambda (&optional (root 0)(inversion 0)(octave 'NIL))) ;; ;; name - symbol. The name of the new function ;; ;; template - list. The interval template ;; ;; (defmacro defchord (name template) `(defun ,name (&optional (root 0)(inversion 0)(octave NIL)) (let ((pat (chord:make-chord ,template inversion octave)) (acc '())) (dolist (a pat) (setq acc (cons (+ a root) acc))) (reverse acc)))) (defchord major '( 0 4 7)) (defchord minor '( 0 3 7)) (defchord dominant7 '( 0 4 7 10)) (defchord major7 '( 0 4 7 11)) (defchord minor7 '( 0 3 7 10)) (defchord major9 '( 0 4 7 10 14)) (defchord minor9 '( 0 3 7 10 14)) (defchord major11 '( 0 4 7 10 14 17)) (defchord minor11 '( 0 3 7 10 14 17)) (defchord major13 '( 0 4 7 10 14 17 20)) ;With 11th (defchord major13-11 '( 0 4 7 10 14 20)) ;Without 11th (defchord minor13 '( 0 3 7 10 14 17 20)) ;With 11th (defchord minor13-11 '( 0 3 7 10 14 20)) ;Without 11th (defchord major6 '( 0 4 7 9)) (defchord minor6 '( 0 3 7 9)) (defchord diminished '( 0 3 6)) (defchord diminished7 '( 0 3 6 9)) (defchord augmented '( 0 4 8)) (defchord augmented7 '( 0 4 8 10)) ;; For the heavy metal minded. (defchord powerchord-1 '( 0 4 7 12 16 24)) (defchord powerchord-2 '( 0 7 12 16 19 24)) (defchord powerchord-3 '(-5 0 7 12 16 24)) (defchord powerchord-min1 '( 0 3 7 12 15 24)) (defchord powerchord-min2 '( 0 7 12 15 19 24)) (defchord powerchord-min3 '(-5 0 7 12 15 24)) ; ************************************************************ Documentation ;; @doc function major ;; (major [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7)) ;; See defchord macro ;; @doc function minor ;; (minor [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7)) ;; See defchord macro ;; @doc function dominant7 ;; (dominant7 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 10)) ;; See defchord macro ;; @doc function major7 ;; (major7 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 11)) ;; See defchord macro ;; @doc function minor7 ;; (minor7 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 10)) ;; See defchord macro ;; @doc function major9 ;; (major9 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 10 14)) ;; See defchord macro ;; @doc function minor9 ;; (minor9 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 10 14)) ;; See defchord macro ;; @doc function major11 ;; (major11 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 10 14 17)) ;; See defchord macro ;; @doc function minor11 ;; (minor11 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 10 14 17)) ;; See defchord macro ;; @doc function major13 ;; (major13 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 10 14 17 20)) ;With 11th ;; See defchord macro ;; @doc function major13-11 ;; (major13-11 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 10 14 20)) ;Without 11th ;; See defchord macro ;; @doc function minor13 ;; (minor13 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 10 14 17 20)) ;With 11th ;; See defchord macro ;; @doc function minor13-11 ;; (minor13-11 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 10 14 20)) ;Without 11th ;; See defchord macro ;; @doc function major6 ;; (major6 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 9)) ;; See defchord macro ;; @doc function minor6 ;; (minor6 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 9)) ;; See defchord macro ;; @doc function diminished ;; (diminished [root [inversion [octave]]]) ;; A chord function with template '( 0 3 6)) ;; See defchord macro ;; @doc function diminished7 ;; (diminished7 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 6 9)) ;; See defchord macro ;; @doc function augmented ;; (augmented [root [inversion [octave]]]) ;; A chord function with template '( 0 4 8)) ;; See defchord macro ;; @doc function augmented7 ;; (augmented7 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 8 10)) ;; See defchord macro ;; @doc function d powerchord-1 ;; (d powerchord-1 [root [inversion [octave]]]) ;; A chord function with template '( 0 4 7 12 16 24)) ;; See defchord macro ;; @doc function powerchord-2 ;; (powerchord-2 [root [inversion [octave]]]) ;; A chord function with template '( 0 7 12 16 19 24)) ;; See defchord macro ;; @doc function powerchord-3 ;; (powerchord-3 [root [inversion [octave]]]) ;; A chord function with template '(-5 0 7 12 16 24)) ;; See defchord macro ;; @doc function powerchord-min1 ;; (powerchord-min1 [root [inversion [octave]]]) ;; A chord function with template '( 0 3 7 12 15 24)) ;; See defchord macro ;; @doc function powerchord-min2 ;; (powerchord-min2 [root [inversion [octave]]]) ;; A chord function with template '( 0 7 12 15 19 24)) ;; See defchord macro ;; @doc function powerchord-min3 ;; (powerchord-min3 [root [inversion [octave]]]) ;; A chord function with template '(-5 0 7 12 15 24)) ;; See defchord macro