R


Intro       Symbols A B C D E F G H I J K L M N O P Q R S T U V W X Y Z       Index  
random [Pattern]

Enumerates items in random order. The probability of an item being selected may be altered by weighting items relative to one another and by constraining the minimum and maximum number of times an item may be consecutively selected. By default, each item in the pattern has an equal probability of selection and may be repeated in direct succession any number of times. To qualify the behavior of an element, specify the item in a list together with its qualifying options:

({item} {option value}*) item is the element to return from the pattern. Following item comes zero or more options value pairs. Each option may be specified using either keyword or symbol form:

weight {number | stream}
Sets number be the probability of the element relative to the weights of the other items. The default weight for each element is 1. weight may be also an item stream of numbers, in which case a weighting factor for the element will be selected each new period in the pattern.
min {number}
Sets a floor (low value) on how many direct repetitions the element must be made before a new element might be selected.
max {number}
Sets a ceiling on how many direct repetitions of the element might be made before a new element must be selected.
random implements the following option value pairs:

using {random-state}
Sets the random-state object of the stream, which default to *cm-state*.

Example:

? (setf x (notes c4 d (e weight 3) f g in random))
#<RANDOM-NOTE-STREAM 140173561>

? (read-items x 10)
(E4 D4 E4 D4 E4 G4 E4 E4 F4 E4)

See Also:

*cm-state*, Item Streams, *random-range*

 


*random-range* [Variable]

Controls how the random pattern calculates probabilites. If the value is nil (the default), then floating point values below the sum of weights are used. Otherwise, *random-range* should be a number, and individial weights are rescaled as a percentage of that number. Setting *random-range* to a large integer like most-positive-fixnum enables consless probability calculation and may run significantly faster in lisp implementations without floating point support.

See Also:

*cm-state*, random

 


read-items stream &optional length states [Function]

Returns length number of items from the item stream stream in a list. If length is t (the default) it defaults to the current period length of the stream. If states is t then a list of item stream states are returned as a second value

Example:

? (setf x (items 1 2 3 4 5))
#<CYCLIC-ITEM-STREAM 130412531>

? (read-items x)
(1 2 3 4 5)

? (read-items x 10)
(1 2 3 4 5 1 2 3 4 5)

See Also:

item, doitems, map-data

 


repeat stream times [Macro]

Repeats the current period of items in stream 0 or more times. times may be a constant value or an item stream.

Example:

? (setf x (repeat (items 1 2 3 in random) 1))
#<FUNCTIONAL-ITEM-STREAM 131611641>

? (read-items x)
(2 3 1)

? (read-items x)
(2 3 1)

? (read-items x)
(1 1 3)

? (read-items x)
(1 1 3)

See Also:

mirror, retrograde

 


rescale value min max newmin newmax &key :return-type [Function]

Returns value rescaled to lie between newmin and newmax. min and max are the old minimum and maximum values. The type of the value returned normally depends on the type of the arguments specified to the function. Use :return-type to force the return value to be either float, integer or ratio. float may be specified as a list (float digits) in which case the floating point return value will be rounded to digitnumber of places.

Example:

? (rescale .51 0 1 0 100)
51.0

? (rescale 1.2 1 2 80 90)
85.0

See Also:

fit

 


*respect-note-spelling* [Variable]

Determines if notes should preserve note names as it parses them. The default value is nil, which allows faster parsing, but if Common Music is built with the CMN syntax loaded then the default value is t, with the assumption that note names should be manuscripted exactly as specified in the data.

 


rest [Class]

An object that increments rhythmic time but does not produce sound. rest inherits all slots from note.

Example:

? (object rest rhythm .5)
<REST 0.5 #x114ED39>

See Also:

note

 


retrograde stream [Macro]

Produces each period of the item stream stream in its strict retrograde form, no matter what pattern stream implements.

Example:

? (setf x (retrograde (steps 1 2 in random for 8 from 'c4 returning note)))
#<FUNCTIONAL-ITEM-STREAM 131442261>

? (read-items x)
(GS4 G4 FS4 F4 DS4 D4 CS4 C4)

? (read-items x)
(C5 AS4 GS4 FS4 E4 D4 CS4 C4)

? (read-items x)
(AS4 A4 G4 F4 E4 DS4 CS4 C4)

See Also:

mirror, repeat

 


rewrite [Pattern]

Enumerates items based on user specified rewrite rules. Each item is represented by a node in the pattern. Rewrite rules are expressed in terms of node identifiers. Two different styles of rule specification are allowed.

The first method associates a rewrite expression with each node in the pattern. This method is capable of describing many sorts of context-free morphologies. The form of this node specification is similar to the graph pattern:

({item} {option value}+)

item is the item to return from the node. Following item come zero or more options value pairs:

id {datum}
Sets datum to be the unique identifier for the node in the pattern. The identifier may be any Lisp object as long as its uniquely represented in the pattern. If omitted, the identifier defaults to element. It is good practice to provide each node with an explicit id.
to {id | (id+) | stream | nil}
Sets the rewrite expression for the node. The value may be a single id, a list of ids, an item stream or nil. If the value is nil the node is terminal, i.e. produces no successor(s) in the next generation. If the value is an item stream then the stream is read to produce a successor term each time the node is rewritten. Otherwise the value should be the id or list of ids that name the successor node(s) in the next generation.
The second style of rule specification permits context-sensitive rules (rules involving more than one node in their left hand side) to be defined. In this method a list of rules is associated with the entire pattern rather than with nodes in the pattern. There may be more or fewer rules than there are nodes. The rule list is interpreted as an ordered set. To produce a new generation, each node in the current generation is matched against the rule list to find the successor rule to apply to the node. The first rule that matches is applied and the id(s) in the right-hand side of the rule produce the successor node(s) in the next generation. Node specification for the second method is similar to the first, except that the to option is ignored and if the id of the node is the same as its element then the node does not need to be specified as a list. Each rule is a list of the form:

({id}+ -> {id}*)

The -> operator divides each rule into two parts. The left-hand side of the rule defines the "matching target" and the right-hand side defines the rewrite succession. Either or both sides may contain more than one id. If the left-hand side of the rule is a single id then the rule matches any node with the same id. If the left-hand side has more than one id (a context-sensitive rule) then the rule matches if the "strict predecessor" in the left-hand side matches the current node and the nodes around the current node in the generation match the ids around the strict predecessor in the left-hand side. The strict predecessor id is marked by a list. Every context rule must contain exactly one strict predecessor in its left hand side. Here are three examples of context rules: (1 (1) 2 -> 3) means node 1 rewrites to node 3 whenever 1 is preceded by itself and followed by 2 in the current generation. (1 * (2) -> 1 2) means node 2 rewrites to 1 and 2 whenever 1 occurs two positions earlier in the current generation. (5 (3) 3 4 -> ) means node 3 rewrites to nothing if preceded by 5 and followed by itself and 4 in the current generation. Note that the right-hand side may be empty and that the left-hand side may contain the wild card * which matches any single element in the current generation.

rewrite implements the following option value pairs:

rules {list}
Sets the rewrite rule list for the pattern to list.
initially {id | list}
Sets the initial generation of the pattern to the specified id(s). Defaults to the first node in the pattern if not specified.
generations {integer}
Sets the number of generations to compute. Generations are counted from 1, while this count is less than integer the pattern performs rewriting. Generations later than integer reuse the last rewritten generation, as if the stream were implemented as a cyclic.

Example:

;;; rule specification method 1

? (setf x (items (1 to 2) (2 to 3) (3 to (3 1)) in rewrite))
#<REWRITE-ITEM-STREAM 132273601>

? (read-items x 20)
(1 2 3 3 1 3 1 2 3 1 2 3 3 1 2 3 3 1 3 1)

;;; rule specification method 2

? (setf x (notes a b c d in rewrite
                 rules '((a -> a b) (a b (b) c -> d)
                         (b -> b c) (c -> c a))))
#<REWRITE-NOTE-STREAM 132114101>

? (read-items x 30)
(A4 A4 B4 A4 B4 B4 C4 A4 B4 B4 C4 D4 C4 A4 A4 B4 B4 C4 D4 C4
  A4 C4 A4 A4 B4 A4 B4 B4 C4 D4)

See Also:

Item Streams

 


rhythm [Item Type]

A logical rhythm value. A logical rhythm can be symbolic or numeric. If numeric, the value represents the number of divisions of a whole note the time value occupies. For example, 4 means quarter note, 16 means sixteenth note, 7 means seventh note, and so on. If the logical rhythm is a symbol then it can be the ordinal equivalent of a number, i.e. 4er, 16th, 7th and so on, or else one of the rhythmic tokens m l b w h q e s which correspond to double, long, whole, half, quarter, eighth and sixteenth-note values, respectively. Here is a table showing some common logical notations:

Note Value       Logical Notations
               Symbol Number Ordinal
Maxima           M     1/8
Longa            L     1/4
Brevis           B     1/2
Whole            W      1      1st
Half             H      2      2nd
Quarter          Q      4      4th
5:4 (quarters)          5      5th
Eighth           E      8      8th
10:8 (eighths)         10     10th
Sixteeth         S     16     16th
Thirty-second          32     32nd
Sixty-fourth           64     64th
Any logical rhythm may be made triplet by prefixing t to it. For example, tq and t4 both mean triplet quarter note. A logical rhythm may also have any number of dots appended to it, i.e. tq., h..., 7th. and so on. Finally, complex rhythmic values may be written using + - * operators: w+e., q-t64, w*2-s, and so on. No space may separate the operators from the operands and the expression is parsed from left to right without any notion of operator precedence.

There is one caveat when writing dotted rhythms. Lisp reads a dotted integer value like 4. as the integer 4 without the dot. This means that Common Music cannot parse an integer followed by a single dot as a logical rhythm because it never sees the single dot! There are two ways to avoid this problem: use the ordinal form of the number, i.e. 4th. or 32nd. or else delimit the token using the | character, as in |4.| or |16.|, which forces the Lisp reader to interpret the token as a symbol. Numbers followed by more than one dot, for example, 16.. or 8..., are not read as numbers by Lisp and are parsed correctly.

See Also:

rhythm [Function], rhythms

 


rhythm rhythm &optional tempo [Function]

Returns the floating point time value of the logical rhythm rhythm in tempo, which defaults to the value of *standard-tempo*.

Example:

? (rhythm 'w)
4.0

? (rhythm 'w 90)
2.6666667

? (rhythm 7 120)
0.2857143

See Also:

rhythm [Item Type], rhythms, *standard-tempo*

 


rhythms {rhythm}+{option value}* [Macro]

Creates an item stream of floating point time values. Each rhythm may be a logical rhythm or an item stream.

rhythms implements the following option value pairs:

tempo {tempo}
Sets the tempo of the stream, which defaults to *standard-tempo*. The value may be either a metronome number or a tempo envelope. See tempo for more information.
An additional set of basic option valuepairs are available in all item stream macros. Others may be available based on the pattern type specified to the macro.

Example:

? (setf x (rhythms q 16 32.. w+e tempo 90))
#<CYCLIC-RHYTHM-STREAM 137413001>

? (read-items x)
(0.6666667 0.16666667 0.14583334 3.0)

See Also:

Item Streams, rhythm [Item Type], tempo

 


rotation [Pattern]

Enumerates items according to a "change value" controlling up to four independent rotational parameters. Each change value is a list of (up to) four optional numbers: ([start [step [width [end]]]]). where start is the starting index (zero based) for the rotation in the items, step is the stepping increment between successive rotations, width is the width between the items rotated, and end is the last position in the data to rotate. If omitted, the default change value is (0 1 1 *).

rotation implements the following option value pairs:

change {list | stream}
Sets the rotation change value, which defaults to (0 1 1 *). The change value is reset once each period.

Example:

? (setf x (notes a b c d in rotation))
#<ROTATIONAL-NOTE-STREAM 132202211>

? (loop repeat 4 collect (read-items x))
((A4 B4 C4 D4) (B4 C4 D4 A4) (C4 D4 A4 B4) (D4 A4 B4 C4))

;; Plain Hunt change ringing (thank you, Nicky Hind)

? (setf x (notes a b c d in rotation
                change (changes start '(0 1) step 2)))
#<ROTATIONAL-NOTE-STREAM 132220261>

? (loop repeat 8 collect (read-items x))
((A4 B4 C4 D4) (B4 A4 D4 C4) (B4 D4 A4 C4) (D4 B4 C4 A4)
 (D4 C4 B4 A4) (C4 D4 A4 B4) (C4 A4 D4 B4) (A4 C4 B4 D4))

See Also:

Item Streams, change-ring.lisp

 


RT [Syntax]

Implements score file output for RT, a sound file mixing program that runs under NeXTstep and IRIX. RT was written by Paul Lansky at Princeton.