Main Page       Index


tempo.lsp


 tempo.lsp
 Version 1.01 03 Jun 2005, minor patch to tempo:set-whole-note
 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

 Defines functions to alter global duration values.
 
 w  h  q  i  s     non-modified durations
 wd hd qd id sd    dotted durations
 wt ht qt it st    triplets
 
 th -  1/32 note
 sx -  1/64 note
 
 w-  h-  q-  i-      Basic units minus 1/16
 wd- hd- qd- id-
 
 w+  h+  q+  i+      Basic units plus 1/16
 wd+ hd+ qd+ id+


function

set-tempo

 (set-tempo  n)
 Set the beats per minute.

 n      - Flonum. The new number of Beats Per Minute.
 return - Flonum. The number of Beats Per Minute.


function

get-tempo

 (get-tempo )
 return - Flonum. The current beats per minute.


function

get-time-symbol-value

 (get-time-symbol-value   sym [default])
 Return time value of metric symbol.

 sym     - symbol | number. The symbol under test. sym may either be a symbol
           representing a time value or a numeric value. If sym is a numeric
           value it is returned directly. If sym is any non-numeric value
           it is checked against a list of known time-symbols. If sym
           matches a known time symbol that time value is returned. The know
           time symbols are:
           w h q i s
           wd hd qd id sd wt
           ht qt it st th sx
           w- h- q- i- wd- hd- qd- id-
           w+ h+ q+ i+ wd+ hd+ qd+ id+

 default - Any. The default result if sym is not a recognized time symbol,
           default NIL
           ISSUE: Is it a good idea to return nil as a default. Would not an error 
           are a preset-time value, such as 1 second be more appropriate?

 return  - Flonum.


View the Sourcecode :



;; tempo.lsp
;; Version 1.01 03 Jun 2005, minor patch to tempo:set-whole-note
;; 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
;;
;; Defines functions to alter global duration values.
;; 
;; w  h  q  i  s     non-modified durations
;; wd hd qd id sd    dotted durations
;; wt ht qt it st    triplets
;; 
;; th -  1/32 note
;; sx -  1/64 note
;; 
;; w-  h-  q-  i-      Basic units minus 1/16
;; wd- hd- qd- id-
;; 
;; w+  h+  q+  i+      Basic units plus 1/16
;; wd+ hd+ qd+ id+
;; 

(provide 'tempo)
(current-file "tempo")


(setq tempo:*bpm* nil
      tempo:*symbol* '(   w   h   q   i   s   th   sx
			  wd  hd  qd  id  sd 
			  wt  ht  qt  it  st
			  w-  h-  q-  i-
			  w+  h+  q+  i+
			  wd- hd- qd- id-
			  wd+ hd+ qd+ id+))


(dolist (sym tempo:*symbol*)
  (putprop sym 't 'IS-TEMPO))


;; function tempo:set-whole-note 
;; (tempo:set-whole-note  n)
;; Update global tempo variables and tempo:*bpm*
;;
;; n - Flonum. The new duration of a whole note in seconds.
;;
;; return Flonum.  beats per minute.
;;

(defun tempo:set-whole-note (n)
  (let (dot trip)
    (setq dot 1.5 trip 0.666667)
    (setq n (float n))
    (setq w n h (/ w 2) q (/ w 4) i (/ w 8) s (/ w 16))
    (setq wd (* dot w) hd (* dot h) qd (* dot q) id (* dot i) sd (* dot s))
    (setq wt (* trip w) ht (* trip h) qt (* trip q) it (* trip i) st (* trip s))
    (setq th (/ s 2.0) sx (/ s 4.0))
    (setq w- (- w s) h- (- h s) q- (- q s) i- (- i s))
    (setq wd- (- wd s) hd- (- hd s) qd- (- qd s) id- (- id s))
    (setq w+ (+ w s) h+ (+ h s) q+ (+ q s) i+ (+ i s) )
    (setq wd+ (+ wd s) hd+ (+ hd s) qd+ (+ qd s) id+ (+ id s))
    (setq tempo:*bpm* (/ 60.0 q))))


;; function  tempo:set-quarter-note 
;; (tempo:set-quarter-note  n)
;; Syntax candy for (tempo:set-whole-note (/ n 4)
;;
;; n - Flonum. The new duration of a quarter note in seconds.
;;
;; return Flonum. Beats per minute.
;;

(defun tempo:set-quarter-note  (n)
  (tempo:set-whole-note (* 4 n)))


;; @doc function set-tempo
;; (set-tempo  n)
;; Set the beats per minute.
;;
;; n      - Flonum. The new number of Beats Per Minute.
;; return - Flonum. The number of Beats Per Minute.
;;

(defun set-tempo (n)
  (tempo:set-quarter-note (/ 60 (float n))))


;; @doc function get-tempo
;; (get-tempo )
;; return - Flonum. The current beats per minute.
;;

(defun get-tempo () 
  tempo:*bpm* )


;; @doc function get-time-symbol-value 
;; (get-time-symbol-value   sym [default])
;; Return time value of metric symbol.
;;
;; sym     - symbol | number. The symbol under test. sym may either be a symbol
;;           representing a time value or a numeric value. If sym is a numeric
;;           value it is returned directly. If sym is any non-numeric value
;;           it is checked against a list of known time-symbols. If sym
;;           matches a known time symbol that time value is returned. The know
;;           time symbols are:
;;           w h q i s
;;           wd hd qd id sd wt
;;           ht qt it st th sx
;;           w- h- q- i- wd- hd- qd- id-
;;           w+ h+ q+ i+ wd+ hd+ qd+ id+
;;
;; default - Any. The default result if sym is not a recognized time symbol,
;;           default NIL
;;           ISSUE: Is it a good idea to return nil as a default. Would not an error 
;;           are a preset-time value, such as 1 second be more appropriate?
;;
;; return  - Flonum.
;;

(defun get-time-symbol-value (sym &optional (default 'NIL))
  (if (numberp sym)
      sym
    (if (get sym 'IS-TEMPO)
	(symbol-value sym)
      default)))


Main Page       Index