[Function]
(keynum freq {keyword value}*)

Returns the key number of freq, which can be a note name, key number, Hertz value or list of the same. If freq is in Hertz then the return value will be a floating point keynum where the fractional portion times 100 represents that may cents above the integer keynum. For example, the floating point keynum 60.5 stands for the Hertz value 50 cents above Middle C, or 269.291 Hz.

keynum supports the following keyword arguments:

:hz boolean
If true then a numerical freq is interpreted as a Hertz value rather than as a key number.
:from { tuning | mode}
The tuning or mode to return the key number from. The default value is *scale*. If mode is specified then freq is a modal key number and the value returned is the equivalent key number in the mode's tuning. if tuning is specified then freq is an integer key number and the value returned is the corresponding, possibly floating point, key number in the standard chromatic scale.
:in? { tuning | mode}
Tests if freq references a key number in tuning or mode. Returns the key number or false.
:to mode
Forces freq to the closet key number in mode.
:through { tuning | mode}
Filters freq through tuning or mode and returns the closest integer tuning keynum.

Examples:

Example 1. Converting Hertz and note names to keynums.

(keynum 'c4)
 60
(keynum 440 :hz #t)
 69
(keynum 446.4 :hz #t)
 69.25
(keynum 446.4 :hz #t :through *scale*)
 69
(keynum '(cs5 ds fs gs as cs6))
 (73 75 78 80 82 85)

Example 2. Modal keynums.

(define dorian (new mode :notes '(c d ef f g a b c)))

(keynum 60 :to dorian)
 35
(keynum 35 :from dorian)
 60
(keynum 61 :in? dorian)
 #f
(keynum 61 :through dorian)
 60

See Also: