harm-list.lsp

This is a function that uses get-harmonics to generate set-palettes.

sc-web-bar

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; File:    harm-list.lsp
;;;
;;; Author:  Daniel James Ross (mr.danielross@gmail.com)
;;;
;;; Date:    Wed Feb 11 15:15:47 GMT 2015
;;;
;;; Update:  Fri Sep 23 10:54:44 BST 2016
;;;
;;; Purpose: Create a list of pitches based on the harmonics of a
;;;          fundamental in any of the standard sc scales using an
;;;          extension of (get-harmonics).
;;;          Useful for making set-palettes.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun get-harmonics2 (start-freq
		       &key (start-partial 1) (min-freq 20)
			 (start-freq-is-partial 1) (max-freq 20000)
			 (skip 1)
			 (max-results most-positive-fixnum)
			 (get-harmonics2 nil))
  "Like get-harmonics, but different"
;;; ****
  (loop with fundamental = (float (/ start-freq start-freq-is-partial))
     for count from 1
     for h from start-partial by skip
     for freq = (* fundamental (* 0.2 h))
     while (= freq min-freq)
     collect freq))

(defun harm-list (fundamental &key
				(scale cm::*scale*)
				(max-freq 15000)
				(min-freq 20)
				(start-partial 1)
				(start-freq-is-partial 1)
				(max-results most-positive-fixnum)
				(skip 1)
				(get-harmonics2 nil)
				;; Wed Apr 20 10:01:12 BST 2016
				;; enharmonics = list of undesired
				;; black notes
				enharmonics
				;; Sun May 22 15:04:57 BST 2016
				;; all 'sharps or 'flats?
				black-notes)
  "Make a pitch list for a set palette"
  ;; make a list of pitches based on harmonics of a fundamental
  ;; pitch. Key arguments specify scale and all the key args
  ;; for (get-harmonics). See utilities/get-harmonics for
  ;; more information
  (unless (numberp fundamental)
    (setf fundamental (note-to-freq fundamental)))
  ;; DJR - Tue Mar 17 14:17:58 GMT 2015
  ;; max- and min-freq can now be expressed in pitch symbols
  (unless (numberp max-freq)
    (setf max-freq (note-to-freq max-freq)))
  (unless (numberp min-freq)
    (setf min-freq (note-to-freq min-freq)))
  (let ((fun 'get-harmonics))
    (when get-harmonics2 (setf fun 'get-harmonics2))
    (remove-duplicates
     ;; Now using funcall so the code is shorter
     (loop for i in
	  (funcall fun fundamental
		   :max-freq max-freq
		   :min-freq min-freq
		   :start-partial start-partial
		   :start-freq-is-partial start-freq-is-partial
		   :max-results max-results
		   :skip skip)
	while (and (>= i min-freq)(<= i max-freq))
	if (and enharmonics
		(pitch-member (freq-to-note i scale) enharmonics))
	collect (data (enharmonic (make-pitch (freq-to-note i scale))))
	else
	if (and (equalp black-notes 'sharp)
		(is-flat (freq-to-note i scale)))
	collect (data (enharmonic (make-pitch (freq-to-note i scale))))
	else
	if (and (equalp black-notes 'flat)
		(is-sharp (freq-to-note i scale)))
	collect (data (enharmonic (make-pitch (freq-to-note i scale))))
	else
	collect (freq-to-note i scale))
       :test #'equal)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Examples 

 ;(harm-list 'g1 :scale 'quarter-tone :max-freq 'c6 :min-freq 'c2)
 ;(harm-list 130 :skip 3 :scale 'chromatic-scale)
 ;(harm-list 'g4 :start-partial 3)
 ;(harm-list 'c1 :enharmonics '(bf3 fs4 bf4))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; EOF harm-list.lsp
Advertisements

One thought on “harm-list.lsp

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s